Unverified Commit 2f4e3ce5 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Improve error message for when you're not running chromedriver (#91789)

parent 59a6ba7c
...@@ -13,6 +13,7 @@ import 'package:package_config/package_config.dart'; ...@@ -13,6 +13,7 @@ import 'package:package_config/package_config.dart';
import 'package:webdriver/async_io.dart' as async_io; import 'package:webdriver/async_io.dart' as async_io;
import '../base/common.dart'; import '../base/common.dart';
import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -126,9 +127,9 @@ class WebDriverService extends DriverService { ...@@ -126,9 +127,9 @@ class WebDriverService extends DriverService {
@override @override
Future<int> startTest(String testFile, List<String> arguments, Map<String, String> environment, PackageConfig packageConfig, { Future<int> startTest(String testFile, List<String> arguments, Map<String, String> environment, PackageConfig packageConfig, {
bool headless, @required bool headless,
String chromeBinary, String chromeBinary,
String browserName, @required String browserName,
bool androidEmulator, bool androidEmulator,
int driverPort, int driverPort,
List<String> browserDimension, List<String> browserDimension,
...@@ -142,14 +143,13 @@ class WebDriverService extends DriverService { ...@@ -142,14 +143,13 @@ class WebDriverService extends DriverService {
desired: getDesiredCapabilities(browser, headless, chromeBinary), desired: getDesiredCapabilities(browser, headless, chromeBinary),
spec: async_io.WebDriverSpec.Auto spec: async_io.WebDriverSpec.Auto
); );
} on Exception catch (ex) { } on SocketException catch (error) {
_logger.printTrace('$error');
throwToolExit( throwToolExit(
'Unable to start WebDriver Session for Flutter for Web testing.\n' 'Unable to start a WebDriver session for web testing.\n'
'Make sure you have the correct WebDriver Server running at $driverPort.\n' 'Make sure you have the correct WebDriver server (e.g. chromedriver) running at $driverPort.\n'
'Make sure the WebDriver Server matches option --browser-name.\n' 'For instructions on how to obtain and run a WebDriver server, see:\n'
'For more information see: '
'https://flutter.dev/docs/testing/integration-tests#running-in-a-browser\n' 'https://flutter.dev/docs/testing/integration-tests#running-in-a-browser\n'
'$ex'
); );
} }
...@@ -331,5 +331,5 @@ Browser _browserNameToEnum(String browserName) { ...@@ -331,5 +331,5 @@ Browser _browserNameToEnum(String browserName) {
case 'ios-safari': return Browser.iosSafari; case 'ios-safari': return Browser.iosSafari;
case 'safari': return Browser.safari; case 'safari': return Browser.safari;
} }
throw UnsupportedError('Browser $browserName not supported'); // dead code; remove with null safety migration throw UnsupportedError('Browser $browserName not supported');
} }
...@@ -16,7 +16,6 @@ import 'package:flutter_tools/src/build_info.dart'; ...@@ -16,7 +16,6 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/drive/drive_service.dart'; import 'package:flutter_tools/src/drive/drive_service.dart';
import 'package:flutter_tools/src/drive/web_driver_service.dart';
import 'package:flutter_tools/src/resident_runner.dart'; import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
...@@ -454,26 +453,6 @@ void main() { ...@@ -454,26 +453,6 @@ void main() {
); );
await driverService.stop(); await driverService.stop();
}); });
testWithoutContext('WebDriver error message includes link to documentation', () async {
const String link = 'https://flutter.dev/docs/testing/integration-tests#running-in-a-browser';
final DriverService driverService = WebDriverService(
logger: BufferLogger.test(),
dartSdkPath: 'dart',
processUtils: ProcessUtils(
processManager: FakeProcessManager.empty(),
logger: BufferLogger.test(),
),
);
expect(() => driverService.startTest(
'foo.test',
<String>[],
<String, String>{},
PackageConfig(<Package>[Package('test', Uri.base)]),
browserName: 'chrome',
), throwsToolExit(message: RegExp('\nFor more information see: $link\n')));
});
} }
FlutterDriverService setUpDriverService({ FlutterDriverService setUpDriverService({
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/drive/web_driver_service.dart';
import 'package:package_config/package_config_types.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
testWithoutContext('WebDriverService catches SocketExceptions cleanly and includes link to documentation', () async {
final BufferLogger logger = BufferLogger.test();
final WebDriverService service = WebDriverService(
logger: logger,
processUtils: ProcessUtils(
logger: logger,
processManager: FakeProcessManager.empty(),
),
dartSdkPath: 'dart',
);
const String link = 'https://flutter.dev/docs/testing/integration-tests#running-in-a-browser';
try {
await service.startTest(
'foo.test',
<String>[],
<String, String>{},
PackageConfig(<Package>[Package('test', Uri.base)]),
driverPort: 1,
headless: true,
browserName: 'chrome',
);
fail('WebDriverService did not throw as expected.');
} on ToolExit catch (error) {
expect(error.message, isNot(contains('SocketException')));
expect(error.message, contains(link));
}
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment