Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.