mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[web] use web drivers as a library only. do not fetch/clone web_installers (flutter/engine#17299)
* use web drivers as a library only. do not fetch/clone web_installers * fixing comments * addressing reviewer comments * adding a trim to output. otherwise last fails
This commit is contained in:
parent
8a27563cf5
commit
cdff1342bf
@ -227,3 +227,64 @@ Future<String> fetchLatestChromeVersion() async {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the Chrome Driver version for the system Chrome.
|
||||
// TODO(nurhan): https://github.com/flutter/flutter/issues/53179
|
||||
Future<String> queryChromeDriverVersion() async {
|
||||
final int chromeVersion = await _querySystemChromeMajorVersion();
|
||||
final io.File lockFile = io.File(
|
||||
path.join(environment.webUiRootDir.path, 'dev', 'driver_version.yaml'));
|
||||
YamlMap _configuration = loadYaml(lockFile.readAsStringSync()) as YamlMap;
|
||||
final String chromeDriverVersion =
|
||||
_configuration['chrome'][chromeVersion] as String;
|
||||
return chromeDriverVersion;
|
||||
}
|
||||
|
||||
Future<int> _querySystemChromeMajorVersion() async {
|
||||
String chromeExecutable = '';
|
||||
if (io.Platform.isLinux) {
|
||||
chromeExecutable = 'google-chrome';
|
||||
} else if (io.Platform.isMacOS) {
|
||||
chromeExecutable = await _findChromeExecutableOnMac();
|
||||
} else {
|
||||
throw UnimplementedError('Web installers only work on Linux and Mac.');
|
||||
}
|
||||
|
||||
final io.ProcessResult versionResult =
|
||||
await io.Process.run('$chromeExecutable', <String>['--version']);
|
||||
|
||||
if (versionResult.exitCode != 0) {
|
||||
throw Exception('Failed to locate system Chrome.');
|
||||
}
|
||||
// The output looks like: Google Chrome 79.0.3945.36.
|
||||
final String output = versionResult.stdout as String;
|
||||
|
||||
print('INFO: chrome version in use $output');
|
||||
|
||||
// Version number such as 79.0.3945.36.
|
||||
try {
|
||||
final String versionAsString = output.trim().split(' ').last;
|
||||
final String majorVersion = versionAsString.split('.')[0];
|
||||
return int.parse(majorVersion);
|
||||
} catch (e) {
|
||||
throw Exception(
|
||||
'Was expecting a version of the form Google Chrome 79.0.3945.36., '
|
||||
'received $output');
|
||||
}
|
||||
}
|
||||
|
||||
/// Find Google Chrome App on Mac.
|
||||
Future<String> _findChromeExecutableOnMac() async {
|
||||
io.Directory chromeDirectory = io.Directory('/Applications')
|
||||
.listSync()
|
||||
.whereType<io.Directory>()
|
||||
.firstWhere(
|
||||
(d) => path.basename(d.path).endsWith('Chrome.app'),
|
||||
orElse: () => throw Exception('Failed to locate system Chrome'),
|
||||
);
|
||||
|
||||
final io.File chromeExecutableDir = io.File(
|
||||
path.join(chromeDirectory.path, 'Contents', 'MacOS', 'Google Chrome'));
|
||||
|
||||
return chromeExecutableDir.path;
|
||||
}
|
||||
|
||||
12
engine/src/flutter/lib/web_ui/dev/driver_version.yaml
Normal file
12
engine/src/flutter/lib/web_ui/dev/driver_version.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
## Map for driver versions to use for each browser version.
|
||||
## See: https://chromedriver.chromium.org/downloads
|
||||
chrome:
|
||||
81: '81.0.4044.69'
|
||||
80: '80.0.3987.106'
|
||||
79: '79.0.3945.36'
|
||||
78: '78.0.3904.105'
|
||||
77: '77.0.3865.40'
|
||||
76: '76.0.3809.126'
|
||||
75: '75.0.3770.140'
|
||||
74: '74.0.3729.6'
|
||||
@ -5,7 +5,9 @@
|
||||
import 'dart:io' as io;
|
||||
import 'package:path/path.dart' as pathlib;
|
||||
import 'package:web_driver_installer/chrome_driver_installer.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
import 'chrome_installer.dart';
|
||||
import 'common.dart';
|
||||
import 'environment.dart';
|
||||
import 'utils.dart';
|
||||
@ -46,24 +48,6 @@ class IntegrationTestsManager {
|
||||
}
|
||||
}
|
||||
|
||||
void _cloneWebInstallers() async {
|
||||
final int exitCode = await runProcess(
|
||||
'git',
|
||||
<String>[
|
||||
'clone',
|
||||
'https://github.com/flutter/web_installers.git',
|
||||
],
|
||||
workingDirectory: _browserDriverDir.path,
|
||||
);
|
||||
|
||||
if (exitCode != 0) {
|
||||
io.stderr.writeln('ERROR: '
|
||||
'Failed to clone web installers. Exited with exit code $exitCode');
|
||||
throw DriverException('ERROR: '
|
||||
'Failed to clone web installers. Exited with exit code $exitCode');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _runPubGet(String workingDirectory) async {
|
||||
final String executable = isCirrus ? environment.pubExecutable : 'flutter';
|
||||
final List<String> arguments = isCirrus
|
||||
@ -90,34 +74,14 @@ class IntegrationTestsManager {
|
||||
}
|
||||
|
||||
void _runDriver() async {
|
||||
final int exitCode = await runProcess(
|
||||
environment.dartExecutable,
|
||||
<String>[
|
||||
'lib/web_driver_installer.dart',
|
||||
'${_browser}driver',
|
||||
'--install-only',
|
||||
],
|
||||
workingDirectory: pathlib.join(
|
||||
_browserDriverDir.path, 'web_installers', 'packages', 'web_drivers'),
|
||||
);
|
||||
|
||||
if (exitCode != 0) {
|
||||
io.stderr.writeln(
|
||||
'ERROR: Failed to run driver. Exited with exit code $exitCode');
|
||||
throw DriverException(
|
||||
'ERROR: Failed to run driver. Exited with exit code $exitCode');
|
||||
}
|
||||
startProcess(
|
||||
'./chromedriver/chromedriver',
|
||||
['--port=4444'],
|
||||
workingDirectory: pathlib.join(
|
||||
_browserDriverDir.path, 'web_installers', 'packages', 'web_drivers'),
|
||||
);
|
||||
print('INFO: Driver started');
|
||||
}
|
||||
|
||||
void prepareDriver() async {
|
||||
final io.Directory priorCurrentDirectory = io.Directory.current;
|
||||
if (_browserDriverDir.existsSync()) {
|
||||
_browserDriverDir.deleteSync(recursive: true);
|
||||
}
|
||||
@ -125,22 +89,12 @@ class IntegrationTestsManager {
|
||||
_browserDriverDir.createSync(recursive: true);
|
||||
temporaryDirectories.add(_drivers);
|
||||
|
||||
// TODO(nurhan): We currently need git clone for getting the driver lock
|
||||
// file. Remove this after making changes in web_installers.
|
||||
await _cloneWebInstallers();
|
||||
// Change the directory to the driver_lock.yaml file's directory.
|
||||
io.Directory.current = pathlib.join(
|
||||
_browserDriverDir.path, 'web_installers', 'packages', 'web_drivers');
|
||||
// Chrome is the only browser supporting integration tests for now.
|
||||
ChromeDriverInstaller chromeDriverInstaller = ChromeDriverInstaller();
|
||||
bool installation = await chromeDriverInstaller.install();
|
||||
|
||||
if (installation) {
|
||||
io.Directory.current = priorCurrentDirectory;
|
||||
await _runDriver();
|
||||
} else {
|
||||
throw DriverException('ERROR: Installing driver failed');
|
||||
}
|
||||
// TODO(nurhan): https://github.com/flutter/flutter/issues/53179
|
||||
final String chromeDriverVersion = await queryChromeDriverVersion();
|
||||
ChromeDriverInstaller chromeDriverInstaller =
|
||||
ChromeDriverInstaller.withVersion(chromeDriverVersion);
|
||||
await chromeDriverInstaller.install(alwaysInstall: true);
|
||||
await _runDriver();
|
||||
}
|
||||
|
||||
/// Runs all the web tests under e2e_tests/web.
|
||||
|
||||
@ -25,4 +25,4 @@ dev_dependencies:
|
||||
git:
|
||||
url: git://github.com/flutter/web_installers.git
|
||||
path: packages/web_drivers/
|
||||
ref: dae38d8839cc39f997fb4229f1382680b8758b4f
|
||||
ref: 90c69a79b2764c93875dc8ed4f4932c27a6f3a86
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user