diff --git a/.travis.yml b/.travis.yml index 87954704..ba507adb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ addons: - pkg-config before_install: - - wget https://github.com/bazelbuild/bazel/releases/download/0.4.2/bazel_0.4.2-linux-x86_64.deb - - sudo dpkg -i bazel_0.4.2-linux-x86_64.deb + - wget https://github.com/bazelbuild/bazel/releases/download/0.4.3/bazel_0.4.3-linux-x86_64.deb + - sudo dpkg -i bazel_0.4.3-linux-x86_64.deb script: - bazel test --test_output=streamed --keep_going ... diff --git a/BUILD b/BUILD index 96874e65..007c81e7 100644 --- a/BUILD +++ b/BUILD @@ -13,7 +13,7 @@ # limitations under the License. load("@io_bazel_rules_dart//dart/build_rules:core.bzl", "dart_library") -load("@io_bazel_rules_dart//dart/build_rules:vm.bzl", "dart_vm_test") +load("@io_bazel_rules_dart//dart/build_rules:vm.bzl", "dart_vm_binary", "dart_vm_test") licenses(["notice"]) # Apache (Google-authored with external contributions) @@ -22,6 +22,7 @@ exports_files(["LICENSE"]) dart_library( name = "webdriver", srcs = glob(["lib/**"]), + enable_ddc = False, license_files = ["LICENSE"], pub_pkg_name = "webdriver", visibility = ["//visibility:public"], @@ -34,5 +35,12 @@ dart_library( ], ) +dart_vm_binary( + name = "transform_tests", + srcs = ["bin/transform_tests.dart"], + script_file = "bin/transform_tests.dart", + visibility = ["//test:__subpackages__"], +) + # Test BUILD rules are defined test/BUILD instead of here to prevent cyclic # dependency between this and rules_webtesting. diff --git a/bin/transform_tests.dart b/bin/transform_tests.dart new file mode 100644 index 00000000..819b4dc5 --- /dev/null +++ b/bin/transform_tests.dart @@ -0,0 +1,65 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +library webdriver.transform_tests; + +import 'dart:io'; + +void main(List args) { + String inExtension; + String outExtension; + String outDirectory; + String srcsFile; + + // Stupid simple arg parsing. + for (var arg in args.takeWhile((arg) => arg != '--')) { + if (arg.startsWith('--in-extension=')) { + inExtension = arg.split('=')[1]; + } else if (arg.startsWith('--out-extension=')) { + outExtension = arg.split('=')[1]; + } else if (arg.startsWith('--out=')) { + outDirectory = arg.split('=')[1]; + } else if (arg.startsWith('--srcs-file=')) { + srcsFile = arg.split('=')[1]; + } + } + + print('Parsed --in-extension $inExtension'); + print('Parsed --out-extension $outExtension'); + print('Parsed --out $outDirectory'); + print('Parsed --srcs-file $srcsFile'); + + String testUtilImport; + for (var arg in args.skipWhile((arg) => arg != '--')) { + if (arg.startsWith('--test_util_import=')) { + testUtilImport = arg.split('=')[1]; + } + } + + print('Parsed --test_util_import $testUtilImport'); + + var srcsList = new File(srcsFile).readAsLinesSync(); + var year = new DateTime.now().year; + for (var srcFile in srcsList) { + if (!srcFile.endsWith(inExtension)) { + continue; + } + var outFile = '$outDirectory/$srcFile' + .replaceFirst(new RegExp('$inExtension\$'), outExtension); + + var srcContents = new File(srcFile).readAsStringSync(); + srcContents = srcContents.replaceFirst('test_util.dart', '$testUtilImport'); + new File(outFile).writeAsString(srcContents); + } +} \ No newline at end of file diff --git a/test/BUILD b/test/BUILD index 36785b24..8dc024ab 100644 --- a/test/BUILD +++ b/test/BUILD @@ -13,35 +13,48 @@ # limitations under the License. load("@io_bazel_rules_dart//dart/build_rules:vm.bzl", "dart_vm_test") +load("@io_bazel_rules_dart//dart/build_rules:code_gen.bzl", "dart_code_gen") load("@io_bazel_rules_webtesting//web:dart.bzl", "dart_web_test_suite") licenses(["notice"]) # Apache (Google-authored with external contributions) -dart_web_test_suite( - name = "io_test", - srcs = glob( - ["**/*.dart"], - exclude = [ - "**/html_*.dart", - "support/async_test.dart", - ], - ), - browsers = ["//browsers:chromium-native"], - data = glob( - ["**"], - exclude = ["**/*.dart"], - ), - local = True, - pub_pkg_name = "webdriver_test", - script_file = "io_test.dart", - deps = [ - "//:webdriver", - "@org_dartlang_pub_matcher//:matcher", - "@org_dartlang_pub_path//:path", - "@org_dartlang_pub_test//:test", - ], +# TODO(DrMarcII) Add support html webdriver tests when rules_dart support dart_web_test + +dart_code_gen( + name = "generate_io_tests", + srcs = glob(["*_test.dart"]), + generator = "//:transform_tests", + generator_args = ["--test_util_import=io_test_util.dart"], + out_extensions = [".io.dart"], ) +[ + dart_web_test_suite( + name = dart_file[:-5] + "_io", + srcs = [ + dart_file[:-5] + ".io.dart", + "io_test_util.dart", + "test_util.dart", + ], + browsers = ["//browsers:chromium-native"], + data = [ + "frame.html", + "test_page.html", + ], + flaky = True, + local = True, + pub_pkg_name = "webdriver_test", + script_file = dart_file[:-5] + ".io.dart", + deps = [ + "//:webdriver", + "@org_dartlang_pub_matcher//:matcher", + "@org_dartlang_pub_path//:path", + "@org_dartlang_pub_test//:test", + ], + ) + for dart_file in glob(["*_test.dart"]) +] + dart_vm_test( name = "async_test", srcs = ["support/async_test.dart"], diff --git a/test/src/alert.dart b/test/alert_test.dart similarity index 97% rename from test/src/alert.dart rename to test/alert_test.dart index ec2e52b1..80866b4b 100644 --- a/test/src/alert.dart +++ b/test/alert_test.dart @@ -17,9 +17,9 @@ library webdriver.alert_test; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Alert', () { WebDriver driver; WebElement button; diff --git a/test/src/command_event.dart b/test/command_event_test.dart similarity index 98% rename from test/src/command_event.dart rename to test/command_event_test.dart index c3a25410..d2c4aa5d 100644 --- a/test/src/command_event.dart +++ b/test/command_event_test.dart @@ -19,9 +19,9 @@ import 'package:test/test.dart'; import 'package:webdriver/core.dart'; import 'package:webdriver/support/async.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('CommandEvent', () { WebDriver driver; diff --git a/test/html_test.dart b/test/html_test.dart deleted file mode 100644 index 401936ff..00000000 --- a/test/html_test.dart +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@TestOn('browser') -library webdriver.html_test; - -import 'dart:html' as html; - -import 'package:test/test.dart'; -import 'package:webdriver/html.dart' - show WebDriver, Capabilities, createDriver, fromExistingSession; - -import 'src/alert.dart' as alert; -import 'src/command_event.dart' as command_event; -import 'src/keyboard.dart' as keyboard; -import 'src/logs.dart' as logs; -import 'src/mouse.dart' as mouse; -import 'src/navigation.dart' as navigation; -import 'src/options.dart' as options; -import 'src/target_locator.dart' as target_locator; -import 'src/web_driver.dart' as web_driver; -import 'src/web_element.dart' as web_element; -import 'src/window.dart' as window; -import 'test_util.dart' as test_util; - -void main() { - test_util.runningOnTravis = false; - test_util.createTestDriver = ({Map additionalCapabilities}) { - var capabilities = Capabilities.chrome; - - if (additionalCapabilities != null) { - capabilities.addAll(additionalCapabilities); - } - - return createDriver(desired: capabilities); - }; - - test_util.testPagePath = - Uri.parse(html.window.location.href).resolve('test_page.html').toString(); - - group('html-specific tests', () { - WebDriver driver; - setUp(() async { - driver = await test_util.createTestDriver(); - await driver.get(test_util.testPagePath); - }); - - tearDown(() => driver.quit()); - - test('fromExistingSession', () async { - WebDriver newDriver = - await fromExistingSession(driver.id, uri: driver.uri); - expect(newDriver.capabilities, driver.capabilities); - var url = await newDriver.currentUrl; - expect(url, startsWith('http:')); - expect(url, endsWith('test_page.html')); - await newDriver.get('http://www.google.com/ncr'); - url = await driver.currentUrl; - expect(url, contains('www.google.com')); - }); - }); - - alert.runTests(); - command_event.runTests(); - keyboard.runTests(); - logs.runTests(); - mouse.runTests(); - navigation.runTests(); - options.runTests(); - target_locator.runTests(); - web_driver.runTests(); - web_element.runTests(); - window.runTests(); -} diff --git a/test/io_test.dart b/test/io_test.dart deleted file mode 100644 index f612e863..00000000 --- a/test/io_test.dart +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2015 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@TestOn("vm") -library webdriver.io_test; - -import 'package:test/test.dart'; - -import 'src/alert.dart' as alert; -import 'src/command_event.dart' as command_event; -import 'src/keyboard.dart' as keyboard; -import 'src/logs.dart' as logs; -import 'src/mouse.dart' as mouse; -import 'src/navigation.dart' as navigation; -import 'src/options.dart' as options; -import 'src/target_locator.dart' as target_locator; -import 'src/web_driver.dart' as web_driver; -import 'src/web_element.dart' as web_element; -import 'src/window.dart' as window; -import 'support/firefox_profile.dart' as firefox_profile; - -import 'io_config.dart' as config; - -void main() { - config.config(); - - alert.runTests(); - command_event.runTests(); - firefox_profile.runTests(); - keyboard.runTests(); - logs.runTests(); - mouse.runTests(); - navigation.runTests(); - options.runTests(); - target_locator.runTests(); - web_driver.runTests(); - web_element.runTests(); - window.runTests(); -} diff --git a/test/io_config.dart b/test/io_test_util.dart similarity index 73% rename from test/io_config.dart rename to test/io_test_util.dart index 6f2460de..3c30d415 100644 --- a/test/io_config.dart +++ b/test/io_test_util.dart @@ -1,4 +1,4 @@ -// Copyright 2015 Google Inc. All Rights Reserved. +// Copyright 2017 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,25 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.io_test; +library io_test_util; import 'dart:io' show FileSystemEntity, Platform; import 'package:path/path.dart' as path; -import 'package:webdriver/io.dart' show Capabilities, createDriver; +import 'package:webdriver/core.dart' show WebDriver; +import 'package:webdriver/io.dart' as wdio; -import 'test_util.dart' as test_util; +export 'test_util.dart' show isWebElement, isRectangle, isPoint; -void config() { - test_util.runningOnTravis = Platform.environment['TRAVIS'] == 'true'; - test_util.createTestDriver = ({Map additionalCapabilities}) { +Future createTestDriver({Map additionalCapabilities}) { var address = Platform.environment['WEB_TEST_WEBDRIVER_SERVER']; if (!address.endsWith('/')) { address += '/'; } var uri = Uri.parse(address); - return createDriver(uri: uri, desired: additionalCapabilities); - }; + return wdio.createDriver(uri: uri, desired: additionalCapabilities); +} + +String get testPagePath { var testSrcDir = Platform.environment['TEST_SRCDIR']; String testPagePath; if (testSrcDir != null) { @@ -43,5 +44,5 @@ void config() { throw new Exception('Could not find the test file at "$testPagePath".' ' Make sure you are running tests from the root of the project.'); } - test_util.testPagePath = path.toUri(testPagePath).toString(); + return path.toUri(testPagePath).toString(); } diff --git a/test/src/keyboard.dart b/test/keyboard_test.dart similarity index 98% rename from test/src/keyboard.dart rename to test/keyboard_test.dart index 745ad6a1..c2bb7247 100644 --- a/test/src/keyboard.dart +++ b/test/keyboard_test.dart @@ -19,9 +19,9 @@ import 'dart:io'; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Keyboard', () { WebDriver driver; WebElement textInput; diff --git a/test/src/logs.dart b/test/logs_test.dart similarity index 96% rename from test/src/logs.dart rename to test/logs_test.dart index af81378b..963ff67d 100644 --- a/test/src/logs.dart +++ b/test/logs_test.dart @@ -17,9 +17,9 @@ library webdriver.logs_test; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Logs', () { WebDriver driver; diff --git a/test/src/mouse.dart b/test/mouse_test.dart similarity index 98% rename from test/src/mouse.dart rename to test/mouse_test.dart index 4c5327c6..fb25783d 100644 --- a/test/src/mouse.dart +++ b/test/mouse_test.dart @@ -17,9 +17,9 @@ library webdriver.mouse_test; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Mouse', () { WebDriver driver; WebElement button; diff --git a/test/src/navigation.dart b/test/navigation_test.dart similarity index 96% rename from test/src/navigation.dart rename to test/navigation_test.dart index 95723729..121717e4 100644 --- a/test/src/navigation.dart +++ b/test/navigation_test.dart @@ -18,9 +18,9 @@ import 'package:test/test.dart'; import 'package:webdriver/support/async.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Navigation', () { WebDriver driver; diff --git a/test/src/options.dart b/test/options_test.dart similarity index 98% rename from test/src/options.dart rename to test/options_test.dart index c1ff7234..82b0180b 100644 --- a/test/src/options.dart +++ b/test/options_test.dart @@ -17,9 +17,9 @@ library webdriver.options_test; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Cookies', () { WebDriver driver; diff --git a/test/src/target_locator.dart b/test/target_locator_test.dart similarity index 97% rename from test/src/target_locator.dart rename to test/target_locator_test.dart index 0a0940f4..82995cfa 100644 --- a/test/src/target_locator.dart +++ b/test/target_locator_test.dart @@ -17,13 +17,13 @@ library webdriver.target_locator_test; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; /** * Tests for switchTo.frame(). switchTo.window() and switchTo.alert are tested * in other classes. */ -void runTests() { +void main() { group('TargetLocator', () { WebDriver driver; WebElement frame; diff --git a/test/test_util.dart b/test/test_util.dart index d32901b8..34bdff70 100644 --- a/test/test_util.dart +++ b/test/test_util.dart @@ -24,11 +24,10 @@ final Matcher isWebElement = new isInstanceOf(); final Matcher isRectangle = new isInstanceOf>(); final Matcher isPoint = new isInstanceOf>(); -String testPagePath; +Future createTestDriver({Map additionalCapabilities}) async { + throw new Exception("createTestDriverFn is not implemented."); +} -typedef Future createTestDriverFn( - {Map additionalCapabilities}); - -createTestDriverFn createTestDriver; - -bool runningOnTravis; +String get testPagePath { + throw new Exception("testPagePath is not implemented."); +} diff --git a/test/src/web_driver.dart b/test/web_driver_test.dart similarity index 99% rename from test/src/web_driver.dart rename to test/web_driver_test.dart index bf6e7a9e..dd6161e5 100644 --- a/test/src/web_driver.dart +++ b/test/web_driver_test.dart @@ -19,9 +19,9 @@ import 'dart:async'; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('WebDriver', () { group('create', () { test('default', () async { diff --git a/test/src/web_element.dart b/test/web_element_test.dart similarity index 99% rename from test/src/web_element.dart rename to test/web_element_test.dart index 06193a59..6f51028e 100644 --- a/test/src/web_element.dart +++ b/test/web_element_test.dart @@ -17,9 +17,9 @@ library webdriver.web_element_test; import 'package:test/test.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('WebElement', () { WebDriver driver; WebElement table; diff --git a/test/src/window.dart b/test/window_test.dart similarity index 98% rename from test/src/window.dart rename to test/window_test.dart index 15a76728..86432e0e 100644 --- a/test/src/window.dart +++ b/test/window_test.dart @@ -20,9 +20,9 @@ import 'package:test/test.dart'; import 'package:webdriver/support/async.dart'; import 'package:webdriver/core.dart'; -import '../test_util.dart'; +import 'test_util.dart'; -void runTests() { +void main() { group('Window', () { WebDriver driver;