Flutter Web Driver Support (#47890)
This commit is contained in:
committed by
Flutter GitHub Bot
parent
57a93419b4
commit
9df1790f24
@@ -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);
|
||||
|
||||
@@ -52,7 +52,7 @@ dependencies:
|
||||
build: 1.2.2
|
||||
build_modules: 2.7.0
|
||||
build_daemon: 2.1.2
|
||||
build_web_compilers: 2.7.1
|
||||
build_web_compilers: 2.7.2
|
||||
|
||||
analyzer: 0.38.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
async: 2.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -61,8 +61,8 @@ dependencies:
|
||||
browser_launcher: 0.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
build_config: 0.4.1+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
build_resolvers: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
built_collection: 4.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
built_value: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
built_collection: 4.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
built_value: 7.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
charcode: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
checked_yaml: 1.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
convert: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -128,4 +128,4 @@ dartdoc:
|
||||
# Exclude this package from the hosted API docs.
|
||||
nodoc: true
|
||||
|
||||
# PUBSPEC CHECKSUM: a092
|
||||
# PUBSPEC CHECKSUM: f199
|
||||
|
||||
@@ -46,7 +46,7 @@ void main() {
|
||||
appStarter = (DriveCommand command) {
|
||||
throw 'Unexpected call to appStarter';
|
||||
};
|
||||
testRunner = (List<String> testArgs, String observatoryUri) {
|
||||
testRunner = (List<String> testArgs, Map<String, String> environment) {
|
||||
throw 'Unexpected call to testRunner';
|
||||
};
|
||||
appStopper = (DriveCommand command) {
|
||||
@@ -171,8 +171,16 @@ void main() {
|
||||
appStarter = expectAsync1((DriveCommand command) async {
|
||||
return LaunchResult.succeeded();
|
||||
});
|
||||
testRunner = expectAsync2((List<String> testArgs, String observatoryUri) async {
|
||||
testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async {
|
||||
expect(testArgs, <String>[testFile]);
|
||||
// VM_SERVICE_URL is not set by drive command arguments
|
||||
expect(environment, <String, String>{
|
||||
'VM_SERVICE_URL': 'null',
|
||||
'SELENIUM_PORT': '4567',
|
||||
'BROWSER_NAME': 'firefox',
|
||||
'BROWSER_DIMENSION': '1024,768',
|
||||
'HEADLESS': 'false',
|
||||
});
|
||||
return null;
|
||||
});
|
||||
appStopper = expectAsync1((DriveCommand command) async {
|
||||
@@ -187,6 +195,10 @@ void main() {
|
||||
'drive',
|
||||
'--target=$testApp',
|
||||
'--no-pub',
|
||||
'--no-headless',
|
||||
'--driver-port=4567',
|
||||
'--browser-name=firefox',
|
||||
'--browser-dimension=1024,768',
|
||||
];
|
||||
await createTestCommandRunner(command).run(args);
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
@@ -204,7 +216,7 @@ void main() {
|
||||
appStarter = expectAsync1((DriveCommand command) async {
|
||||
return LaunchResult.succeeded();
|
||||
});
|
||||
testRunner = (List<String> testArgs, String observatoryUri) async {
|
||||
testRunner = (List<String> testArgs, Map<String, String> environment) async {
|
||||
throwToolExit(null, exitCode: 123);
|
||||
};
|
||||
appStopper = expectAsync1((DriveCommand command) async {
|
||||
@@ -361,7 +373,7 @@ void main() {
|
||||
testApp = fs.path.join(tempDir.path, 'test', 'e2e.dart');
|
||||
testFile = fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
|
||||
|
||||
testRunner = (List<String> testArgs, String observatoryUri) async {
|
||||
testRunner = (List<String> testArgs, Map<String, String> environment) async {
|
||||
throwToolExit(null, exitCode: 123);
|
||||
};
|
||||
appStopper = expectAsync1(
|
||||
@@ -494,7 +506,7 @@ void main() {
|
||||
testApp = fs.path.join(tempDir.path, 'test', 'e2e.dart');
|
||||
testFile = fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
|
||||
|
||||
testRunner = (List<String> testArgs, String observatoryUri) async {
|
||||
testRunner = (List<String> testArgs, Map<String, String> environment) async {
|
||||
throwToolExit(null, exitCode: 123);
|
||||
};
|
||||
appStopper = expectAsync1(
|
||||
|
||||
Reference in New Issue
Block a user