Allow user to specify which Chrome binary to use. (#53275)
* Allow user to specify which Chrome binary to use.
This commit is contained in:
@@ -108,7 +108,10 @@ class DriveCommand extends RunCommandBase {
|
||||
..addFlag('android-emulator',
|
||||
defaultsTo: true,
|
||||
help: 'Whether to perform Flutter Driver testing on Android Emulator.'
|
||||
'Works only if \'browser-name\' is set to \'android-chrome\'');
|
||||
'Works only if \'browser-name\' is set to \'android-chrome\'')
|
||||
..addOption('chrome-binary',
|
||||
help: 'Location of Chrome binary. '
|
||||
'Works only if \'browser-name\' is set to \'chrome\'');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -245,6 +248,7 @@ class DriveCommand extends RunCommandBase {
|
||||
driverPort,
|
||||
browser,
|
||||
argResults['headless'].toString() == 'true',
|
||||
stringArg('chrome-binary'),
|
||||
);
|
||||
} on Exception catch (ex) {
|
||||
throwToolExit(
|
||||
@@ -529,17 +533,18 @@ Browser _browserNameToEnum(String browserName){
|
||||
throw UnsupportedError('Browser $browserName not supported');
|
||||
}
|
||||
|
||||
Future<async_io.WebDriver> _createDriver(String driverPort, Browser browser, bool headless) async {
|
||||
Future<async_io.WebDriver> _createDriver(String driverPort, Browser browser, bool headless, String chromeBinary) async {
|
||||
return async_io.createDriver(
|
||||
uri: Uri.parse('http://localhost:$driverPort/'),
|
||||
desired: getDesiredCapabilities(browser, headless),
|
||||
desired: getDesiredCapabilities(browser, headless, chromeBinary),
|
||||
spec: async_io.WebDriverSpec.Auto
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns desired capabilities for given [browser] and [headless].
|
||||
/// Returns desired capabilities for given [browser], [headless] and
|
||||
/// [chromeBinary].
|
||||
@visibleForTesting
|
||||
Map<String, dynamic> getDesiredCapabilities(Browser browser, bool headless) {
|
||||
Map<String, dynamic> getDesiredCapabilities(Browser browser, bool headless, [String chromeBinary]) {
|
||||
switch (browser) {
|
||||
case Browser.chrome:
|
||||
return <String, dynamic>{
|
||||
@@ -547,6 +552,8 @@ Map<String, dynamic> getDesiredCapabilities(Browser browser, bool headless) {
|
||||
'browserName': 'chrome',
|
||||
'goog:loggingPrefs': <String, String>{ async_io.LogType.performance: 'ALL'},
|
||||
'chromeOptions': <String, dynamic>{
|
||||
if (chromeBinary != null)
|
||||
'binary': chromeBinary,
|
||||
'w3c': false,
|
||||
'args': <String>[
|
||||
'--bwsi',
|
||||
@@ -566,7 +573,7 @@ Map<String, dynamic> getDesiredCapabilities(Browser browser, bool headless) {
|
||||
'v8,blink.console,benchmark,blink,'
|
||||
'blink.user_timing'
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
break;
|
||||
case Browser.firefox:
|
||||
|
||||
@@ -612,11 +612,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('Chrome with headless off', () {
|
||||
const String chromeBinary = 'random-binary';
|
||||
final Map<String, dynamic> expected = <String, dynamic>{
|
||||
'acceptInsecureCerts': true,
|
||||
'browserName': 'chrome',
|
||||
'goog:loggingPrefs': <String, String>{ sync_io.LogType.performance: 'ALL'},
|
||||
'chromeOptions': <String, dynamic>{
|
||||
'binary': chromeBinary,
|
||||
'w3c': false,
|
||||
'args': <String>[
|
||||
'--bwsi',
|
||||
@@ -638,7 +640,7 @@ void main() {
|
||||
}
|
||||
};
|
||||
|
||||
expect(getDesiredCapabilities(Browser.chrome, false), expected);
|
||||
expect(getDesiredCapabilities(Browser.chrome, false, chromeBinary), expected);
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user