Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save huycozy/36914852af216f29ae230bc8b9387f91 to your computer and use it in GitHub Desktop.
Save huycozy/36914852af216f29ae230bc8b9387f91 to your computer and use it in GitHub Desktop.
  1. Add test package to pubspec.yaml
  • Old:
flutter_driver:
  sdk: flutter
  • New:
integration_test:
  sdk: flutter

See (Migrating from flutter_driver)[https://docs.flutter.dev/testing/integration-tests/migration] for more information.

  1. Create test_driver and integration_test directory from project root dir

  2. Create test_driver/integration_test.dart file:

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
  1. Create integration_test/app_test.dart file:
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'package:reproduce_issues_test/main.dart' as app;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  group('end-to-end test', () {
    testWidgets('tap on the floating action button, verify counter',
            (tester) async {
          app.main();
          await tester.pumpAndSettle();

          // Verify the counter starts at 0.
          expect(find.text('0'), findsOneWidget);

          // Finds the floating action button to tap on.
          final Finder fab = find.byTooltip('Increment');

          // Emulate a tap on the floating action button.
          await tester.tap(fab);

          // Trigger a frame.
          await tester.pumpAndSettle();

          // Verify the counter increments by 1.
          expect(find.text('1'), findsOneWidget);
        });
  });
}

main.dart is counter default app since a new Flutter project created.

  1. Run integration test
  • Old flutter drive test:
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart 
  • New flutter test:
flutter test integration_test/app_test.dart
@huycozy
Copy link
Author

huycozy commented Mar 16, 2023

If you run on Web, check this: https://github.com/flutter/flutter/wiki/Running-Flutter-Driver-tests-with-Web

chromedriver-mac-x64 ./chromedriver --port=4444

If get error about permission (by gatekeeper on macos, use xattr -cr chromedriver before running it)

  • Run test:
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart -d web-server

@huycozy
Copy link
Author

huycozy commented Jul 8, 2024

If you run on Safari, check this https://github.com/flutter/flutter/blob/master/docs/contributing/testing/Running-Flutter-Driver-tests-with-Web.md#using-safari.

  • Safari driver is located on /usr/bin/safaridriver
  • Start the driver on port 4444:
cd /usr/bin/
./safaridriver --port=4444
  • Run test:
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/main_tf_test.dart -d web-server --browser-name=ios-safari --web-port=60000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment