main_test.dart.tmpl 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9
// This is a basic Flutter Driver test for the application. A Flutter Driver
// test is an end-to-end test that "drives" your application from another
// process or even from another computer. If you are familiar with
// Selenium/WebDriver for web, Espresso for Android or UI Automation for iOS,
// this is simply Flutter's version of that.
//
// To start the test run the following command from the root of your application
// package:
//
10 11
//     flutter drive --target=test_driver/main_test.dart

12 13 14 15 16 17 18 19 20 21 22 23 24
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

main() {
  group('end-to-end test', () {
    FlutterDriver driver;

    setUpAll(() async {
      // Connect to a running Flutter application instance.
      driver = await FlutterDriver.connect();
    });

    tearDownAll(() async {
25 26
      if (driver != null)
        driver.close();
27 28 29
    });

    test('tap on the floating action button; verify counter', () async {
30
      // Find floating action button (fab) to tap on
31
      ObjectRef fab = await driver.findByTooltipMessage('Increment');
32
      expect(fab, isNotNull);
33 34

      // Tap on the fab
35
      await driver.tap(fab);
36 37

      // Wait for text to change to the desired value
38
      expect(await driver.findByText('Button tapped 1 time.'), isNotNull);
39 40 41
    });
  });
}