Skip to content

Instantly share code, notes, and snippets.

@adam-stasiak
Last active September 19, 2019 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-stasiak/1ca996906e2828f0a26a8d1461e514d1 to your computer and use it in GitHub Desktop.
Save adam-stasiak/1ca996906e2828f0a26a8d1461e514d1 to your computer and use it in GitHub Desktop.
import 'dart:io';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
import 'package:ozzie/ozzie.dart';
import 'package:path/path.dart' as p;
Future diff(snap) async {
final diffsDir = new Directory('ozzie/Diffs');
var outputFile = new File(p.join(diffsDir.path, snap) + "-output.png");
final String blinkdiffPath = 'node_modules/blink-diff/bin/blink-diff';
await outputFile.create(recursive: true);
await Process.run(blinkdiffPath, [
'--output',
outputFile.path,
p.join('ozzie/Veggie/', snap) + ".png",
p.join(
'reference_snaps/Veggie/',
snap,
) +
".png",
'--threshold',
'10'
]).then((ProcessResult results) {
if (results.stdout.toString().contains("FAIL") == false) {
outputFile.delete();
}
expect(results.stdout.toString().contains("FAIL"), isFalse);
});
}
void main(){
group('Veggie', () {
FlutterDriver driver;
Ozzie ozzie;
setUp(() async {
await driver.tap(find.text("Home"));
});
setUpAll(() async {
driver = await FlutterDriver.connect();
ozzie = await Ozzie.initWith(driver, groupName: "Veggie");
});
tearDownAll(() async {
if (driver != null){
await driver.close();
}
await ozzie.generateHtmlReport();
});
test('Apples are displayed', () async {
final cardTitle = find.byValueKey("cardTitleApples");
await ozzie.takeScreenshot("Apples");
await diff("Apples");
expect(await driver.getText(cardTitle),"Apples");
});
test('Plums are displayed', () async {
final cardTitle = find.byValueKey("cardTitlePlums");
await driver.scrollUntilVisible(find.byValueKey("list"), cardTitle, dyScroll: -500);
await ozzie.takeScreenshot("Plums");
await diff("Plums");
expect(await driver.getText(cardTitle),"Plums");
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment