jonsamwell / flutter_gherkin

A Gherkin parsers and runner for Dart and Flutter which is very similar to cucumber
MIT License
205 stars 109 forks source link

VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM... #151

Open aliakbr opened 2 years ago

aliakbr commented 2 years ago

Hi all, I am experiencing a very weird issue. I've pulled the example code from this repo and successfully run the example code. Meanwhile, after copying the example code to my current repo project I am facing this issue :

MServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:41469/fHuAGuubaqw=/
VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM...
VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM...
VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM...
VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM...
VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM...

It seems like the flutter driver can't connect to. any of my simulator/devices in this project. This is some detail of my environment and how to run the test :

flutter doctor :

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale
    en-ID)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] IntelliJ IDEA Community Edition (version 2020.1.2)
[✓] VS Code (version 1.60.1)
[✓] Connected device (2 available)

Project structure (test_driver folder):

.
├── app.dart
├── app_test.dart
├── features
│   └── login.feature
├── hook
│   └── hook_example.dart
├── report.json

app.dart (test_driver)

import 'package:flutter_driver/driver_extension.dart';
import 'package:frontend/main_test.dart' as app;  // Change to your main app

void main() {
  enableFlutterDriverExtension();

  // Switch services impls to mock services
  app.main();
}

app_test.dart (test_driver)

import 'dart:async';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';

Future<void> main() {
  final config = FlutterTestConfiguration.DEFAULT(
    [],
    featurePath: 'features/*.*.feature',
    targetAppPath: 'test_driver/app.dart',
  )
  // ..logFlutterProcessOutput = true
  // ..verboseFlutterProcessLogs = true
    ..restartAppBetweenScenarios = true
    ..targetAppWorkingDirectory = '../'
    ..targetAppPath = 'test_driver/app.dart';
  // ..buildFlavor = "staging" // uncomment when using build flavor and check android/ios flavor setup see android file android\app\build.gradle
  // ..targetDeviceId = "all" // uncomment to run tests on all connected devices or set specific device target id
  // ..tagExpression = '@smoke and not @ignore' // uncomment to see an example of running scenarios based on tag expressions
  // ..logFlutterProcessOutput = true // uncomment to see command invoked to start the flutter test app
  // ..verboseFlutterProcessLogs = true // uncomment to see the verbose output from the Flutter process
  // ..flutterBuildTimeout = Duration(minutes: 3) // uncomment to change the default period that flutter is expected to build and start the app within
  // ..runningAppProtocolEndpointUri =
  //     'http://127.0.0.1:51540/bkegoer6eH8=/' // already running app observatory / service protocol uri (with enableFlutterDriverExtension method invoked) to test against if you use this set `restartAppBetweenScenarios` to false

  return GherkinRunner().execute(config);
}

login.feature

Feature: Login into app

  Scenario: Splash Screen should appear
    Then I wait until the "splashScreen" is present

This is my app code : main_test.dart

import 'package:flutter/material.dart';

import 'app_test.dart';

void main() {
  runApp(MyApp());
}

app_test.dart

import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Counter App',
      home: MyHomePage(key: Key('splashScreen'), title: 'Counter App Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  bool hasLongPressedText = false;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      drawer: Drawer(
        key: const Key('drawer'),
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
              child: const Text('Drawer Header'),
            ),
            ListTile(
              title: const Text('Item 1'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: const Text('Item 2'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              // Provide a Key to this specific Text Widget. This allows us
              // to identify this specific Widget from inside our test suite and
              // read the text.
              key: const Key('counter'),
              style: Theme.of(context).textTheme.headline4,
            ),
            TextButton(
              key: Key('openPage2'),
              onLongPress: () {
                Future.delayed(
                    Duration(seconds: 12),
                        () => Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context) => PageTwo()),
                    ));
              },
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => PageTwo()),
                );
              },
              child: Text('Open page 2'),
            ),
            GestureDetector(
              onLongPress: () {
                setState(() {
                  hasLongPressedText = true;
                });
              },
              child: Container(
                color:
                hasLongPressedText ? Colors.blueGrey : Colors.transparent,
                child: Text(
                  hasLongPressedText
                      ? 'Text has been long pressed!'
                      : 'Text that has not been long pressed',
                  key: const Key('longPressText'),
                ),
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        // Provide a Key to this the button. This allows us to find this
        // specific button and tap it inside the test suite.
        key: const Key('increment'),
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

class PageTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: Key('pageTwo'),
      appBar: AppBar(
        automaticallyImplyLeading: true,
        title: Text('Page 2'),
      ),
      body: SafeArea(
        child: Center(
          child: Text('Contents of page 2'),
        ),
      ),
    );
  }
}

pubspec.yaml

name: frontend
description: App Description

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.3.7
versionProd: 1.3.6

environment:
  sdk: '>=2.12.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  google_fonts: ^2.0.0
  flutter_feather_icons: ^2.0.0+1

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  get_it: ^7.1.3
  provider: ^5.0.0
  firebase_analytics: ^8.3.1
  firebase_core: ^1.6.0
  flutter_secure_storage: ^4.2.0
  flutter_dotenv: ^4.0.0-nullsafety.1
  environment_config: ^3.0.0
  intl: ^0.17.0
  blobs: ^2.0.0
  sentry_flutter: ^6.0.0
  #flutter_segment: ^3.1.0
  flutter_segment:
    git: https://github.com/gotlostinparadise/flutter-segment.git
  video_player: ^2.1.1
  better_player: ^0.0.72
  webview_flutter: ^2.0.4
  graphql: ^5.0.0-nullsafety.4
  flutter_native_timezone: ^2.0.0
  # wakelock Held back until chewie updates its wakelock dependency
  wakelock: ^0.5.2
  confetti: ^0.6.0-nullsafety
  stream_chat_flutter: ^2.0.0-nullsafety.4
  flutter_svg: ^0.22.0
  pedantic: ^1.11.0
  # keyboard_avoider: ^0.1.2 # unmaintained?
  # keyboard_avoider:
  #   git:
  #     url: https://github.com/KingsCards/keyboard_avoider.git
  #     ref: feature/null-safety
  keyboard_avoider:
    git:
      url: https://github.com/ryanheise/keyboard_avoider.git
      ref: fix/mounted-bug
  multi_image_picker: ^4.8.0
  path_provider: ^2.0.1
  dio: ^4.0.0
  styled_text: ^3.0.1
  scroll_to_index: ^2.0.0
  shimmer: ^2.0.0
  libphonenumber: ^2.0.0
  country_code_picker: ^2.0.1
  string_validator: ^0.3.0
  device_info: ^2.0.0
  # zendesk: ^2.0.0
  zendesk:
    git:
      url: https://github.com/ryanheise/flutter-zendesk.git
      ref: nnbd
  share: ^2.0.1
  upgrader: ^3.2.1
  in_app_update: ^2.0.0
  pin_code_fields: ^7.0.0
  firebase_messaging: ^10.0.6
  url_launcher: ^6.0.3
  adjust_sdk: ^4.29.0
  flutter_uxcam: ^2.0.0
  transparent_image: ^2.0.0
  firebase_remote_config: ^0.10.0+5
  awesome_emojis: ^0.1.1
  shared_preferences: ^2.0.6
  collection: ^1.15.0-nullsafety.4
  infinite_scroll_pagination: ^3.0.1+1
  in_app_review: ^2.0.2
  jiffy: ^4.1.0
  package_info: ^2.0.2
  moengage_flutter: ^4.0.2
  tutorial_coach_mark: ^1.0.3
  otp_autofill: ^1.1.0
  firebase_in_app_messaging: ^0.5.0+8
  storybook_flutter: ^0.5.1
  uni_links: ^0.5.1

dependency_overrides:
  # stream_chat_flutter depends on this while graphql is still pinned on 0.26.0.
  # Watch for updates on: https://github.com/zino-app/graphql-flutter/issues/899
  rxdart: ^0.27.0

dev_dependencies:
  intl_utils: 2.1.0
  flutter_launcher_icons: ^0.9.0
  mockito:
  build_runner:
  flutter_driver:
    sdk: flutter
  test: any
  flutter_test:
    sdk: flutter
  flutter_gherkin: ^2.0.0
  sentry_dart_plugin: ^1.0.0-alpha.2

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/mentors/
    - assets/experience/
    - assets/images/
    - assets/intro/
    - assets/onboarding/
    - assets/onboarding_small/
    - assets/library/
    - assets/ratings/

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
flutter_intl:
  main_locale: en_US
  enabled: true

# The adaptive foreground need extra padding for better look in android
# example https://github.com/fluttercommunity/flutter_launcher_icons/blob/master/example/default/assets/images/icon-foreground-432x432.png
# ref https://pub.dev/packages/flutter_launcher_icons
flutter_icons:
  android: true
  ios: true
  image_path: "assets/icon/icon.png"
  adaptive_icon_background: "assets/icon/key_launch_background.png"
  adaptive_icon_foreground: "assets/icon/key_launch_icon.png"
jonsamwell commented 2 years ago

This is odd. I will try and run the sample code again tomorrow.

Are you trying to run against an ios or Android emulator? If it is Android try and ensure use use an x86 image as I have had trouble with this on my CI server using x86_64 images.

If you are starting a new project I strongly suggest you use the new integration_tests way of doing things as I'll soon be moving flutter_gherkin over to this way of doing things. https://pub.dev/packages/flutter_gherkin/versions/3.0.0-rc.5

aliakbr commented 2 years ago

I use iOS Simulator (iOS version 14.5, iPhone 12 Pro Max) and also a real device for android (OPPO).

Thank you for the help and thank you for your information, will take a look on the version later.

gobearjr commented 2 years ago

Hi @jonsamwell

Me (I am the QA) and @aliakbr (Dev) working on the same company. I try using 3.0.0-rc-5 but it seem to have a dependencies issue. This does not happen using 3.0.0rc-2.

Because flutter_gherkin >=3.0.0-rc.3 depends on source_gen ^1.1.0 which depends on analyzer ^2.1.0, flutter_gherkin >=3.0.0-rc.3 requires analyzer ^2.1.0. And because intl_utils 2.1.0 depends on analyzer ^1.0.0, flutter_gherkin >=3.0.0-rc.3 is incompatible with intl_utils 2.1.0. So, because frontend depends on both intl_utils 2.1.0 and flutter_gherkin 3.0.0-rc.5, version solving failed.

Here are our dev dependencies :

dev_dependencies: intl_utils: 2.1.0 flutter_launcher_icons: ^0.9.0 mockito: build_runner: flutter_driver: sdk: flutter test: any flutter_test: sdk: flutter integration_test: sdk: flutter flutter_gherkin: 3.0.0-rc.5 gherkin: ^2.0.4

If I add analyzer: ^2.1.0 it will conflict with intl_utils: 2.1.0

Because frontend depends on intl_utils 2.1.0 which depends on analyzer ^1.0.0, analyzer ^1.0.0 is required. So, because frontend depends on analyzer ^2.1.0, version solving failed.

jonsamwell commented 2 years ago

@gobearjr could you add a dependency override?

 dependency_overrides:
  analyzer: ^1.0.0
jonsamwell commented 2 years ago

Or ask https://github.com/localizely/intl_utils/blob/master/pubspec.yaml to upgrade their dependency on anaylzer as it is out of date.

gobearjr commented 2 years ago

Ok, Thank you. I will follow up with them and try overriding the dependencies.

Yuiry-IV commented 2 years ago

Same for Windows + Android tablet: image

My configuration: image image

fadhlimaulidri commented 2 years ago

hi @jonsamwell , we have try update to version 3.0.0-rc.5. and then it ask to remove deprecated library and ask to update latest version other library. and we have do it. but at the end we got error like below

$ flutter drive --target=test_driver/app.dart
Downloading android-arm-profile/linux-x64 tools...              
   313ms
Downloading android-arm-release/linux-x64 tools...                 130ms
Downloading android-arm64-profile/linux-x64 tools...            
   122ms
Downloading android-arm64-release/linux-x64 tools...                92ms
Downloading android-x64-profile/linux-x64 tools...                  87ms
Downloading android-x64-release/linux-x64 tools...                  76ms
Running "flutter pub get" in flutter_apps...           
 1,940ms
Running Gradle task 'assembleDebug'...                          
Checking the license for package Android SDK Build-Tools 29.0.2 in /opt/android-sdk-linux/licenses
License for package Android SDK Build-Tools 29.0.2 accepted.
Preparing "Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)".
"Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)" ready.
Installing Android SDK Build-Tools 29.0.2 in /opt/android-sdk-linux/build-tools/29.0.2
"Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)" complete.
"Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)" finished.
Checking the license for package Android SDK Platform 31 in /opt/android-sdk-linux/licenses
License for package Android SDK Platform 31 accepted.
Preparing "Install Android SDK Platform 31 (revision: 1)".
"Install Android SDK Platform 31 (revision: 1)" ready.
Installing Android SDK Platform 31 in /opt/android-sdk-linux/platforms/android-31
"Install Android SDK Platform 31 (revision: 1)" complete.
"Install Android SDK Platform 31 (revision: 1)" finished.
Note: /root/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.7.0/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /root/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-5.0.0+4/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /root/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.4+2/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /root/.pub-cache/hosted/pub.dartlang.org/uni_links-0.5.1/android/src/main/java/name/avioli/unilinks/UniLinksPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Running Gradle task 'assembleDebug'...                            203.6s
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...             
 1,789ms
W/Gralloc3( 5044): mapper 3.x is not supported
I/OpenGLRenderer( 5044): Davey! duration=3265ms; Flags=1, IntendedVsync=415135300393, Vsync=415201967057, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=415212221212, AnimationStart=415212257177, PerformTraversalsStart=415212260047, DrawStart=415938930329, SyncQueued=415939668487, SyncStart=415939835028, IssueDrawCommandsStart=415939953219, SwapBuffers=418310096422, FrameCompleted=418401312435, DequeueBufferDuration=548000, QueueBufferDuration=242000, 
I/Choreographer( 5044): Skipped 194 frames!  The application may be doing too much work on its main thread.
/root/.pub-cache/hosted/pub.dartlang.org/flutter_gherkin-3.0.0-rc.5/lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart:2:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show ImageByteFormat;
       ^
/sdks/flutter/packages/integration_test/lib/integration_test.dart:7:8: Error: Not found: 'dart:ui'
import 'dart:ui';
       ^
/sdks/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
       ^
/sdks/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
/sdks/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
       ^
/sdks/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
/sdks/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
/sdks/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
/sdks/flutter/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
/sdks/flutter/packages/flutter/lib/src/material/bottom_sheet.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
adb uninstall failed: ProcessException: Process exited abnormally:
Failure [DELETE_FAILED_INTERNAL_ERROR]
  Command: /opt/android-sdk-linux/platform-tools/adb -s 172.21.65.153:5555 uninstall com.flutter.android
Failed to uninstall app

we try at macOS big sur and linux

gofur commented 2 years ago

hi any update for this issue? i'm use macOS monterey and flutter 2.8.1 @jonsamwell

bartekpacia commented 1 year ago

Looks like we're having the same problem with Flutter Driver in Patrol. I've been doing some investigation in https://github.com/leancodepl/patrol/issues/272, but no luck so far.

This is a Flutter problem. Unfortunately after googling the problem, the first result is a close issue in flutter/flutter: https://github.com/flutter/flutter/issues/72484

I find this problem hard to debug because in my case it rarely occurs locally. It occurs much more often when integration tests run on GitHub Actions, though. The GHA runners are much slower than the M1 I'm developing on, so that may be a possible cause?

Sorry for this bit of off-topic, but I just wanted to let you know that you're not alone and add some more, possibly useful info.

hiraowais commented 3 months ago

I'm having the same issue. Using the sample code. Tried Android emulator and a physical Samsung device. Any solutions for this yet?