Skip to content

Instantly share code, notes, and snippets.

@ookami-kb
Created June 15, 2020 16:41
Show Gist options
  • Select an option

  • Save ookami-kb/80a89dd66b3a9a81b359db49d9ff8de6 to your computer and use it in GitHub Desktop.

Select an option

Save ookami-kb/80a89dd66b3a9a81b359db49d9ff8de6 to your computer and use it in GitHub Desktop.
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