Flutter IntegrationTest OAuth Login with Chrome Tab

249 Views Asked by At

I have to write a flutter integration test, which needs to perform a login to my app. The login is an external website (using a chrome tab).

How can I enter the login credentials on the chrome tab? Right now, it looks like the integration test API is not working here. I can't identify any finders, nor can I enter text.

This is my setup:

  1. Flutter screen with Login Button:

enter image description here

  1. When clicking on "LOGIN", the chrome tab is loaded to enter the credentials: enter image description here

This is my current test code:

Future loginIfPresent(WidgetTester tester) async {
  final loginButtonFinder = find.widgetWithText(ElevatedButton, 'LOGIN');
  if (tester.widgetList(loginButtonFinder).isEmpty) {
    return;
  }
  await tester.tap(loginButtonFinder);
  await tester.pump();

  // Entering user name, but this does not work, too
  await tester.enterText(<<which_finder_to_use>>, 'service');

  // Entering user name, but this does not work, too
  await tester.sendKeyEvent(LogicalKeyboardKey.keyS);
  await tester.sendKeyEvent(LogicalKeyboardKey.keyE);
  await tester.sendKeyEvent(LogicalKeyboardKey.keyR);
  await tester.sendKeyEvent(LogicalKeyboardKey.keyV);
  await tester.sendKeyEvent(LogicalKeyboardKey.keyI);
  await tester.sendKeyEvent(LogicalKeyboardKey.keyC);
  await tester.sendKeyEvent(LogicalKeyboardKey.keyE);

}

I am not able to enter the credentials using the integration test. How can I do this?

0

There are 0 best solutions below