FlutterDriver.Connect Requires VM_SERVICE_URL or String?

Viewed 460

My app is the basic counter, with a FlutterDriver for UI Automation. My conundrum is when I attempt to run my test, it tells me that I need to specify a connection or set the VM_SERVICE_URL

ERROR:

DriverError: Could not determine URL to connect to application. Either the VM_SERVICE_URL environment variable should be set, or an explicit URL should be provided to the FlutterDriver.connect() method.

I've tried a few things.

  • Using FlutterDriver.connect();
  • Setting the VM_SERVICE_URL in Terminal (MacOS)
  • Setting the Dart Command Line to include VM_SERVICE_URL with a value

The most success I've had is with the code below. By adding enableFlutterDriverExtension to the lib/main.dart, then executing lib/main.dart, I can copy/paste the ws://127.0.0.1 connection into the test/my_test.dart. This allows me to successfully run my tests, but this isn't an ideal process.

Is there a way to pull in the connection string automatically?

Why does Platform.environment['VM_SERVICE_URL'] always return null despite my having set it?

lib/main.dart

void main() {

  enableFlutterDriverExtension();
  runApp(const MyApp());
}

test/main_app.dart

void main() {
//  enableFlutterDriverExtension();
  MainApp.main();
  MyTest.main();

}

test/my_test.dart

void main() {

  FlutterDriver? driver;

  dynamic DartVmServiceUrl;
  DartVmServiceUrl ??= Platform.environment['VM_SERVICE_URL'];
  print('VM_SERVICE_URL:\t${DartVmServiceUrl}');
  String vmServURL = 'ws://127.0.0.1:59488/WK8KTNVXXOo=/ws';

  setUpAll( () async {
    driver = await FlutterDriver.connect(dartVmServiceUrl: vmServURL);
  });

  tearDownAll( () {
    driver?.close();
  });

  test('Push Button',() async {
    var pushMeButton = find.byValueKey('IncrementButton');
    await driver!.tap(pushMeButton);

  }  );


}
0 Answers
Related