flutter/dev/integration_tests/ui/test_driver/screenshot_test.dart
Jonah Williams 938dd5a4aa
Revert "Update driver script to execute test through test_core" (#24401)
* Revert "Add dashing config file for generating docset from flutter docs (#24374)"

This reverts commit ec8ca8606c.

* Revert "Update driver script to execute test through test_core (#24168)"

This reverts commit 6c62cf337f.
2018-11-15 11:17:00 -08:00

48 lines
1.5 KiB
Dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_driver/flutter_driver.dart';
import 'package:image/image.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
void main() {
group('FlutterDriver', () {
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
await driver.close();
});
test('should take screenshot', () async {
final SerializableFinder toggleBtn = find.byValueKey('toggle');
// Cards use a magic background color that we look for in the screenshots.
final Matcher cardsAreVisible = contains(0xff0201ff);
await driver.waitFor(toggleBtn);
bool cardsShouldBeVisible = false;
Image imageBefore = decodePng(await driver.screenshot());
for (int i = 0; i < 10; i += 1) {
await driver.tap(toggleBtn);
cardsShouldBeVisible = !cardsShouldBeVisible;
final Image imageAfter = decodePng(await driver.screenshot());
if (cardsShouldBeVisible) {
expect(imageBefore.data, isNot(cardsAreVisible));
expect(imageAfter.data, cardsAreVisible);
} else {
expect(imageBefore.data, cardsAreVisible);
expect(imageAfter.data, isNot(cardsAreVisible));
}
imageBefore = imageAfter;
}
}, timeout: const Timeout(Duration(minutes: 2)));
});
}