Flutter Web Driver Support (#47890)

This commit is contained in:
Angjie Li
2020-01-02 19:48:01 -08:00
committed by Flutter GitHub Bot
parent 57a93419b4
commit 9df1790f24
43 changed files with 2023 additions and 703 deletions

View File

@@ -69,6 +69,34 @@ class DriveCommand extends RunCommandBase {
..addFlag('build',
defaultsTo: true,
help: 'Build the app before running.',
)
..addOption('driver-port',
defaultsTo: '4444',
help: 'The port where Webdriver server is launched at. Defaults to 4444.',
valueHelp: '4444'
)
..addFlag('headless',
defaultsTo: true,
help: 'Whether the driver browser is going to be launched in headless mode. Defaults to true.',
)
..addOption('browser-name',
defaultsTo: 'chrome',
help: 'Name of browser where tests will be executed. \n'
'Following browsers are supported: \n'
'Chrome, Firefox, Safari (macOS and iOS) and Edge. Defaults to Chrome.',
allowed: <String>[
'chrome',
'edge',
'firefox',
'ios-safari',
'safari',
]
)
..addOption('browser-dimension',
defaultsTo: '1600,1024',
help: 'The dimension of browser when running Flutter Web test. \n'
'This will affect screenshot and all offset-related actions. \n'
'By default. it is set to 1600,1024 (1600 by 1024).',
);
}
@@ -133,8 +161,16 @@ class DriveCommand extends RunCommandBase {
Cache.releaseLockEarly();
final Map<String, String> environment = <String, String>{
'VM_SERVICE_URL': observatoryUri,
'SELENIUM_PORT': argResults['driver-port'].toString(),
'BROWSER_NAME': argResults['browser-name'].toString(),
'BROWSER_DIMENSION': argResults['browser-dimension'].toString(),
'HEADLESS': argResults['headless'].toString(),
};
try {
await testRunner(<String>[testFile], observatoryUri);
await testRunner(<String>[testFile], environment);
} catch (error, stackTrace) {
if (error is ToolExit) {
rethrow;
@@ -291,13 +327,13 @@ Future<LaunchResult> _startApp(DriveCommand command) async {
}
/// Runs driver tests.
typedef TestRunner = Future<void> Function(List<String> testArgs, String observatoryUri);
typedef TestRunner = Future<void> Function(List<String> testArgs, Map<String, String> environment);
TestRunner testRunner = _runTests;
void restoreTestRunner() {
testRunner = _runTests;
}
Future<void> _runTests(List<String> testArgs, String observatoryUri) async {
Future<void> _runTests(List<String> testArgs, Map<String, String> environment) async {
printTrace('Running driver tests.');
PackageMap.globalPackagesPath = fs.path.normalize(fs.path.absolute(PackageMap.globalPackagesPath));
@@ -310,7 +346,7 @@ Future<void> _runTests(List<String> testArgs, String observatoryUri) async {
'--packages=${PackageMap.globalPackagesPath}',
'-rexpanded',
],
environment: <String, String>{'VM_SERVICE_URL': observatoryUri},
environment: environment,
);
if (result != 0) {
throwToolExit('Driver tests failed: $result', exitCode: result);