Search code examples
flutterwebviewflutter-test

Can integration_test package interact with webview?


I use integration_test package to write UI tests on Dart for iOS and Android platforms. I also have a webview in my app showing login page with text fields. I use webview_flutter for it.

Does anybody know if tester can interact with my webview within integration test? Can I find a textfield on the webpage and enter text into it?

I want to write test code like this, but for the webview:

testWidgets('Authorization test', (tester) async {
  ...
  await tester.enterText(find.byKey(Key('login_text_field')), 'login');
  await tester.enterText(find.byKey(Key('password_text_field')), 'password');
  await tester.tap(find.byKey(Key('sign_in_button')));
  await tester.pumpAndSettle();
}

Here is content of the web page:

enter image description here


Solution

  • This is now possible with Patrol!

    You could write your test like this:

    patrolTest(
      'Authorization test',
      nativeAutomation: true,
      ($) async {
        // ...
        await $.native.enterTextByIndex('login', index: 0);
        await $.native.enterTextByIndex('password', index: 1);
        await $.native.tap(Selector(text: 'Sign in'));
        // ...
      },
    );