Created
June 15, 2020 16:41
-
-
Save ookami-kb/80a89dd66b3a9a81b359db49d9ff8de6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:io'; | |
| import 'package:flutter_driver/flutter_driver.dart'; | |
| extension DriverExt on FlutterDriver { | |
| Future<void> saveScreenshot() async { | |
| final path = 'screenshots/' | |
| '${DateTime.now().toIso8601String().replaceAll(':', '-')}' | |
| '.png'; | |
| final List<int> pixels = await screenshot(); | |
| final file = File(path); | |
| await file.writeAsBytes(pixels); | |
| } | |
| Future<void> assertElementPresent( | |
| String valueKey, { | |
| Duration timeout = const Duration(seconds: 5), | |
| }) async { | |
| try { | |
| return await waitFor(find.byValueKey(valueKey), timeout: timeout); | |
| // ignore: avoid_catching_errors | |
| } on DriverError catch (_) { | |
| await saveScreenshot(); | |
| rethrow; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment