jeudi 28 janvier 2021

Writing a flutter integration test for logging in using the new package 'integration_test' and getting errors

Writing a flutter integration test for logging in using the new package 'integration_test' and getting errors. It take a long time for the test to start and then exits the app even though it says all tests passed. It doesnt seem to be entering the email and password as well (and if it is then it is going too quick) Any help would be appreciated!

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  //group('App Test', () {

  testWidgets("Sign in test example", (WidgetTester tester) async {
    await tester.runAsync(() async {
      /*
    * Setups the finder*/
      final Finder signInEmailField = find.byKey(Key('email-field'));
      final Finder signInPasswordField = find.byKey(Key('password-field'));
      final Finder signInSaveButton = find.byKey(Key('login-button'));

      //await tester.pumpWidget(app.main());

      await app.main();

      /*
    * pump and settle is same like waitfor in flutter_driver
    * */
      await tester.pumpAndSettle();
      expect(
          find.byWidgetPredicate((Widget widget) =>
              widget is Text && widget.data.startsWith('Login')),
          findsOneWidget);
      final loginFinder = find.byWidgetPredicate((widget) =>
          widget is BusyButton &&
          widget is Text &&
          (widget as Text).data.startsWith('Login'));
      expect(loginFinder, findsOneWidget);
      await tester.tap(loginFinder);
      await tester.pumpAndSettle();
      await tester.tap(find.byKey(Key('email-field')));
      await tester.enterText(signInEmailField, "o.whayman@smartspaces.app");

      await tester.tap(signInPasswordField);
      await tester.enterText(signInPasswordField, "Test1234!");

      await tester.tap(signInSaveButton);
      print("button tapped");

      await tester.pumpAndSettle(Duration(seconds: 1));

      expect(
          find.byWidgetPredicate((widget) => widget is WelcomePagesViewModel),
          findsOneWidget);

      await tester.pumpAndSettle(Duration(seconds: 1));
    });
  });
}
Starting application: integration_test/app_test.dart
Installing build\app\outputs\flutter-apk\app.apk...                 2.4s
Running Gradle task 'assembleDevDebug'...                               
Running Gradle task 'assembleDevDebug'... Done                     19.6s
√ Built build\app\outputs\flutter-apk\app-dev-debug.apk.
I/flutter ( 4526): Observatory listening on http://127.0.0.1:35221/b7p9NQa_6RA=/
E/FlutterFcmService( 4526): Fatal: failed to find callback
VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:52618/b7p9NQa_6RA=/
VMServiceFlutterDriver: Isolate found with number: 2418217539924163
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
I/flutter ( 4526): 00:00 +0: Sign in test example
VMServiceFlutterDriver: Connected to Flutter application.
VMServiceFlutterDriver: request_data message is taking a long time to complete...
I/flutter ( 4526): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter ( 4526): The following assertion was thrown while running async test code:
I/flutter ( 4526): pumpAndSettle timed out
I/flutter ( 4526):
I/flutter ( 4526): When the exception was thrown, this was the stack:
I/flutter ( 4526): #0      WidgetTester.pumpAndSettle.<anonymous closure> (package:flutter_test/src/widget_tester.dart:688:11)      
I/flutter ( 4526): <asynchronous suspension>
I/flutter ( 4526): #1      WidgetTester.pumpAndSettle.<anonymous closure> (package:flutter_test/src/widget_tester.dart)
I/flutter ( 4526): #4      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
I/flutter ( 4526): #5      WidgetTester.pumpAndSettle (package:flutter_test/src/widget_tester.dart:683:27)
I/flutter ( 4526): #6      main.<anonymous closure>.<anonymous closure>
(file:///C:/src/ss-mobile/integration_test/app_test.dart:28:20)
I/flutter ( 4526): <asynchronous suspension>
I/flutter ( 4526): #7      main.<anonymous closure>.<anonymous closure> (file:///C:/src/ss-mobile/integration_test/app_test.dart)   
I/flutter ( 4526): #8      LiveTestWidgetsFlutterBinding.runAsync (package:flutter_test/src/binding.dart:1568:28)
I/flutter ( 4526): #9      WidgetTester.runAsync (package:flutter_test/src/widget_tester.dart:801:17)
I/flutter ( 4526): #10     main.<anonymous closure> (file:///C:/src/ss-mobile/integration_test/app_test.dart:14:18)
I/flutter ( 4526): #11     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:146:29) 
I/flutter ( 4526): <asynchronous suspension>
I/flutter ( 4526): #12     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart)        
I/flutter ( 4526): #13     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:784:19)
I/flutter ( 4526): <asynchronous suspension>
I/flutter ( 4526): #16     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:764:14)
I/flutter ( 4526): #17     LiveTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1592:12)
I/flutter ( 4526): #18     IntegrationTestWidgetsFlutterBinding.runTest (package:integration_test/integration_test.dart:194:17)     
I/flutter ( 4526): #19     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:138:24)
I/flutter ( 4526): #20     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:175:19)I/flutter ( 4526): <asynchronous suspension>
I/flutter ( 4526): #21     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart)       
I/flutter ( 4526): #26     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:173:13)
I/flutter ( 4526): #27     Invoker.waitForOutstandingCallbacks.<anonymous closure>
(package:test_api/src/backend/invoker.dart:231:15)
I/flutter ( 4526): #32     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:228:5)
I/flutter ( 4526): #33     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>
(package:test_api/src/backend/invoker.dart:383:17)
I/flutter ( 4526): <asynchronous suspension>
I/flutter ( 4526): #34     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>
(package:test_api/src/backend/invoker.dart)
I/flutter ( 4526): #39     Invoker._onRun.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:370:9) 
I/flutter ( 4526): #40     Invoker._guardIfGuarded (package:test_api/src/backend/invoker.dart:415:15)
I/flutter ( 4526): #41     Invoker._onRun.<anonymous closure> (package:test_api/src/backend/invoker.dart:369:7)
I/flutter ( 4526): #48     Invoker._onRun (package:test_api/src/backend/invoker.dart:368:11)
I/flutter ( 4526): #49     LiveTestController.run (package:test_api/src/backend/live_test_controller.dart:153:11)
I/flutter ( 4526): (elided 33 frames from dart:async and package:stack_trace)
I/flutter ( 4526): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 4526): 10:01 +1: (tearDownAll)
I/flutter ( 4526): 10:01 +2: All tests passed!
All tests passed.
Stopping application instance.

Aucun commentaire:

Enregistrer un commentaire