|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +// This test is used by devicelab, test "integration_ui_ios_screenshot". |
| 6 | +// Its use of package:image is, at the time of writing, the only use of that |
| 7 | +// package in this repository. If package:image is a problem, it is probably |
| 8 | +// fine to just remove this test since the value of the test is probably not |
| 9 | +// as much as the cost of the dependency. |
| 10 | + |
| 11 | +import 'package:flutter_driver/flutter_driver.dart'; |
| 12 | +import 'package:image/image.dart'; |
| 13 | + |
| 14 | +import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; |
| 15 | + |
| 16 | +void main() { |
| 17 | + group('FlutterDriver', () { |
| 18 | + late FlutterDriver driver; |
| 19 | + |
| 20 | + setUpAll(() async { |
| 21 | + driver = await FlutterDriver.connect(); |
| 22 | + }); |
| 23 | + |
| 24 | + tearDownAll(() async { |
| 25 | + await driver.close(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('should take screenshot', () async { |
| 29 | + final SerializableFinder toggleBtn = find.byValueKey('toggle'); |
| 30 | + // Cards use a magic background color that we look for in the screenshots. |
| 31 | + final Matcher cardsAreVisible = contains(getColor(0xff, 0x01, 0x02)); |
| 32 | + await driver.waitFor(toggleBtn); |
| 33 | + |
| 34 | + bool cardsShouldBeVisible = false; |
| 35 | + Image? imageBefore = decodePng(await driver.screenshot()); |
| 36 | + for (int i = 0; i < 10; i += 1) { |
| 37 | + await driver.tap(toggleBtn); |
| 38 | + cardsShouldBeVisible = !cardsShouldBeVisible; |
| 39 | + final Image? imageAfter = decodePng(await driver.screenshot()); |
| 40 | + |
| 41 | + if (cardsShouldBeVisible) { |
| 42 | + expect(imageBefore?.data, isNot(cardsAreVisible)); |
| 43 | + expect(imageAfter?.data, cardsAreVisible); |
| 44 | + } else { |
| 45 | + expect(imageBefore?.data, cardsAreVisible); |
| 46 | + expect(imageAfter?.data, isNot(cardsAreVisible)); |
| 47 | + } |
| 48 | + |
| 49 | + imageBefore = imageAfter; |
| 50 | + } |
| 51 | + }, timeout: Timeout.none); |
| 52 | + }); |
| 53 | +} |
0 commit comments