Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions lib/web_ui/dev/chrome_installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 12 additions & 0 deletions lib/web_ui/dev/driver_version.yaml
Original file line number Diff line number Diff line change
@@ -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'
62 changes: 8 additions & 54 deletions lib/web_ui/dev/integration_tests_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -90,57 +74,27 @@ 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);
}

_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.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ dev_dependencies:
git:
url: git://github.com/flutter/web_installers.git
path: packages/web_drivers/
ref: dae38d8839cc39f997fb4229f1382680b8758b4f
ref: 90c69a79b2764c93875dc8ed4f4932c27a6f3a86