Flutter Web Driver Support (#45951)

* Support Flutter Driver test for Flutter Web application.

* Support Flutter Driver test for Flutter Web application.

* Fix documentation issues.

* Support Flutter Driver test for Flutter Web application.

* Fix documentation.

* Remove unused file from dartdoc check.

* Sync to date.

* Revert change to dartdoc.

* Address comments.

* Apply suggestions from code review

Co-Authored-By: Jonah Williams <jonahwilliams@google.com>

* Update copyrights.

* Update allowed list for browsers.

* Verify command line arguments for Drive command is correctly parsed.

* Make waitUntilFirstFrameRasterized throw unimplementedError for Flutter Web Driver.

* Add comment for why sync WebDriver is used.

* Update documentations.

* Add more unit tests and update documentation.

* Configure test.dart so that web_extension_test will be executed with --platform=chrome.

* Revert unnecessary changes.

* Add new file path for Windows to blacklist.

* Reconstruct the structure of flutter_driver/test/src folder to remove filtering logic in dev/bots/test.dart/

* Fix path to web_extension_test.dart.

* Add instructions for how to use WebFlutterDriver.

* Update getLayerTree to use sendCommand instead of _sendCommand.

* Update pubspec files.
This commit is contained in:
Angjie Li
2019-12-18 10:45:39 -08:00
committed by Jonah Williams
parent f546aa7def
commit 1ef0eadb45
54 changed files with 2062 additions and 753 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);

View File

@@ -11,9 +11,9 @@ dependencies:
# To update these, use "flutter update-packages --force-upgrade".
archive: 2.0.11
args: 1.5.2
dwds: 0.8.1
dwds: 0.8.5
completion: 0.2.1+1
coverage: 0.13.3+1
coverage: 0.13.3+3
crypto: 2.1.3
file: 5.1.0
http: 0.12.0+2
@@ -46,7 +46,7 @@ dependencies:
test_core: 0.2.15
# Code generation dependencies
build_runner_core: 4.2.0
build_runner_core: 4.3.0
dart_style: 1.3.3
code_builder: 3.2.1
build: 1.2.2
@@ -118,7 +118,7 @@ dev_dependencies:
test: 1.9.4
build_runner: 1.7.2
build_vm_compilers: 1.0.4
build_test: 0.10.10
build_test: 0.10.11
multi_server_socket: 1.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
node_preamble: 1.4.8 # 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: de88
# PUBSPEC CHECKSUM: 6e90

View File

@@ -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(