Fix test code. (#138)
- Run dartfmt against all files.
- Adding missing import.
- Remove external dependencies (e.g. http://www.google.com) whereever
possible.
- Get more tests running.
diff --git a/bin/transform_tests.dart b/bin/transform_tests.dart
index 819b4dc..f624129 100644
--- a/bin/transform_tests.dart
+++ b/bin/transform_tests.dart
@@ -62,4 +62,4 @@
srcContents = srcContents.replaceFirst('test_util.dart', '$testUtilImport');
new File(outFile).writeAsString(srcContents);
}
-}
\ No newline at end of file
+}
diff --git a/lib/html.dart b/lib/html.dart
index 1072077..f2208bc 100644
--- a/lib/html.dart
+++ b/lib/html.dart
@@ -102,5 +102,7 @@
return respBody;
}
- Map<String, String> get _headers => {'Accept': 'application/json',};
+ Map<String, String> get _headers => {
+ 'Accept': 'application/json',
+ };
}
diff --git a/test/BUILD b/test/BUILD
index 8dc024a..38d35bb 100644
--- a/test/BUILD
+++ b/test/BUILD
@@ -18,11 +18,13 @@
licenses(["notice"]) # Apache (Google-authored with external contributions)
-# TODO(DrMarcII) Add support html webdriver tests when rules_dart support dart_web_test
+# TODO(DrMarcII) Add support for html webdriver tests when rules_dart support dart_web_test
+
+_TESTS_TO_RUN = glob(["*_test.dart"])
dart_code_gen(
name = "generate_io_tests",
- srcs = glob(["*_test.dart"]),
+ srcs = _TESTS_TO_RUN,
generator = "//:transform_tests",
generator_args = ["--test_util_import=io_test_util.dart"],
out_extensions = [".io.dart"],
@@ -39,6 +41,7 @@
browsers = ["//browsers:chromium-native"],
data = [
"frame.html",
+ "support/forwarder_test_page.html",
"test_page.html",
],
flaky = True,
@@ -52,7 +55,7 @@
"@org_dartlang_pub_test//:test",
],
)
- for dart_file in glob(["*_test.dart"])
+ for dart_file in _TESTS_TO_RUN
]
dart_vm_test(
@@ -67,3 +70,22 @@
"@org_dartlang_pub_unittest//:unittest",
],
)
+
+dart_vm_test(
+ name = "firefox_profile_test",
+ srcs = [
+ "io_test_util.dart",
+ "support/firefox_profile_test.dart",
+ "test_util.dart",
+ ],
+ data = glob(["support/firefox_profile/**"]),
+ pub_pkg_name = "webdriver_test",
+ script_file = "support/firefox_profile_test.dart",
+ deps = [
+ "//:webdriver",
+ "@org_dartlang_pub_archive//:archive",
+ "@org_dartlang_pub_matcher//:matcher",
+ "@org_dartlang_pub_path//:path",
+ "@org_dartlang_pub_test//:test",
+ ],
+)
diff --git a/test/support/forwarder_test.dart b/test/forwarder_test.dart
similarity index 96%
rename from test/support/forwarder_test.dart
rename to test/forwarder_test.dart
index e081cb6..9956826 100644
--- a/test/support/forwarder_test.dart
+++ b/test/forwarder_test.dart
@@ -22,15 +22,12 @@
import 'package:webdriver/io.dart';
import 'package:webdriver/support/forwarder.dart';
-import '../io_config.dart' as config;
-import '../test_util.dart' as test_util;
+import 'test_util.dart' as test_util;
const buttonClicked = 'Button clicked';
const buttonNotClicked = 'Button not clicked';
void main() {
- config.config();
-
group('WebDriverForwarder', () {
WebDriver driver;
WebDriverForwarder forwarder;
@@ -49,8 +46,8 @@
forwarder.forward(request);
} else if (request.method == 'GET' &&
request.uri.path.endsWith('test_page.html')) {
- File file = new File(
- path.join('test', 'support', 'forwarder_test_page.html'));
+ File file = new File(test_util.runfile(
+ path.join('test', 'support', 'forwarder_test_page.html')));
request.response
..statusCode = HttpStatus.OK
..headers.set('Content-type', 'text/html');
diff --git a/test/io_test_util.dart b/test/io_test_util.dart
index 3c30d41..8e228c7 100644
--- a/test/io_test_util.dart
+++ b/test/io_test_util.dart
@@ -14,6 +14,7 @@
library io_test_util;
+import 'dart:async' show Future;
import 'dart:io' show FileSystemEntity, Platform;
import 'package:path/path.dart' as path;
@@ -22,27 +23,26 @@
export 'test_util.dart' show isWebElement, isRectangle, isPoint;
-Future<WebDriver> createTestDriver({Map<String, dynamic> additionalCapabilities}) {
- var address = Platform.environment['WEB_TEST_WEBDRIVER_SERVER'];
- if (!address.endsWith('/')) {
- address += '/';
- }
- var uri = Uri.parse(address);
- return wdio.createDriver(uri: uri, desired: additionalCapabilities);
+Future<WebDriver> createTestDriver(
+ {Map<String, dynamic> additionalCapabilities}) {
+ var address = Platform.environment['WEB_TEST_WEBDRIVER_SERVER'];
+ if (!address.endsWith('/')) {
+ address += '/';
+ }
+ var uri = Uri.parse(address);
+ return wdio.createDriver(uri: uri, desired: additionalCapabilities);
}
String get testPagePath {
- var testSrcDir = Platform.environment['TEST_SRCDIR'];
- String testPagePath;
- if (testSrcDir != null) {
- testPagePath = path.join(testSrcDir, 'com_github_google_webdriver_dart', 'test', 'test_page.html');
- } else {
- testPagePath = path.join('test', 'test_page.html');
- }
- testPagePath = path.absolute(testPagePath);
+ String testPagePath = runfile(path.join('test', 'test_page.html'));
if (!FileSystemEntity.isFileSync(testPagePath)) {
throw new Exception('Could not find the test file at "$testPagePath".'
' Make sure you are running tests from the root of the project.');
}
return path.toUri(testPagePath).toString();
}
+
+String runfile(String p) => path.absolute(path.join(
+ Platform.environment['TEST_SRCDIR'],
+ 'com_github_google_webdriver_dart',
+ p));
diff --git a/test/keyboard_test.dart b/test/keyboard_test.dart
index c2bb724..60f68b3 100644
--- a/test/keyboard_test.dart
+++ b/test/keyboard_test.dart
@@ -34,11 +34,7 @@
ctrlCmdKey = Keyboard.control;
}
- // Note: Firefox used as Chrome + Mac OSX prevents use of control/meta
- // in chords.
- // https://bugs.chromium.org/p/chromedriver/issues/detail?id=30
- driver =
- await createTestDriver(additionalCapabilities: Capabilities.firefox);
+ driver = await createTestDriver();
await driver.get(testPagePath);
textInput =
await driver.findElement(const By.cssSelector('input[type=text]'));
diff --git a/test/logs_test.dart b/test/logs_test.dart
index 963ff67..4a8c887 100644
--- a/test/logs_test.dart
+++ b/test/logs_test.dart
@@ -29,7 +29,7 @@
};
driver = await createTestDriver(additionalCapabilities: capabilities);
- await driver.get('http://www.google.com/ncr');
+ await driver.get(testPagePath);
});
tearDown(() async {
diff --git a/test/navigation_test.dart b/test/navigation_test.dart
index 121717e..755bd99 100644
--- a/test/navigation_test.dart
+++ b/test/navigation_test.dart
@@ -26,7 +26,7 @@
setUp(() async {
driver = await createTestDriver();
- await driver.get('http://www.google.com/ncr');
+ await driver.get(testPagePath);
});
tearDown(() async {
@@ -37,7 +37,7 @@
});
test('refresh', () async {
- var element = await driver.findElement(const By.name('q'));
+ var element = await driver.findElement(const By.tagName('button'));
await driver.navigate.refresh();
await waitFor(() async {
try {
diff --git a/test/support/firefox_profile.dart b/test/support/firefox_profile_test.dart
similarity index 97%
rename from test/support/firefox_profile.dart
rename to test/support/firefox_profile_test.dart
index 6910e3a..6bb1ed0 100644
--- a/test/support/firefox_profile.dart
+++ b/test/support/firefox_profile_test.dart
@@ -22,7 +22,9 @@
import 'package:webdriver/core.dart';
import 'package:webdriver/support/firefox_profile.dart';
-void runTests() {
+import '../io_test_util.dart' as test_util;
+
+void main() {
group('Firefox profile', () {
test('parse and serialize string value with quotes', () {
const value =
@@ -144,7 +146,8 @@
test('encode/decode profile directory from disk', () {
var profile = new FirefoxProfile(
- profileDirectory: new io.Directory('test/support/firefox_profile'));
+ profileDirectory: new io.Directory(
+ test_util.runfile('test/support/firefox_profile')));
profile.setOption(new PrefsOption(Capabilities.hasNativeEvents, true));
var archive = unpackArchiveData(profile.toJson());
diff --git a/test/test_util.dart b/test/test_util.dart
index 34bdff7..ff13e68 100644
--- a/test/test_util.dart
+++ b/test/test_util.dart
@@ -24,10 +24,15 @@
final Matcher isRectangle = new isInstanceOf<Rectangle<int>>();
final Matcher isPoint = new isInstanceOf<Point<int>>();
-Future<WebDriver> createTestDriver({Map<String, dynamic> additionalCapabilities}) async {
- throw new Exception("createTestDriverFn is not implemented.");
+Future<WebDriver> createTestDriver(
+ {Map<String, dynamic> additionalCapabilities}) async {
+ throw new Exception("createTestDriverFn is not implemented.");
}
String get testPagePath {
- throw new Exception("testPagePath is not implemented.");
+ throw new Exception("testPagePath is not implemented.");
+}
+
+String runfile(String p) {
+ throw new Exception("runfile is not implemented.");
}
diff --git a/test/web_driver_test.dart b/test/web_driver_test.dart
index dd6161e..1c2e1f7 100644
--- a/test/web_driver_test.dart
+++ b/test/web_driver_test.dart
@@ -26,17 +26,9 @@
group('create', () {
test('default', () async {
WebDriver driver = await createTestDriver();
- await driver.get('http://www.google.com/ncr');
- var element = await driver.findElement(const By.name('q'));
- expect(await element.name, 'input');
- await driver.quit();
- });
-
- test('chrome', () async {
- WebDriver driver = await createTestDriver();
- await driver.get('http://www.google.com/ncr');
- var element = await driver.findElement(const By.name('q'));
- expect(await element.name, 'input');
+ await driver.get(testPagePath);
+ var element = await driver.findElement(const By.tagName('button'));
+ expect(await element.name, 'button');
await driver.quit();
});
});
@@ -57,17 +49,15 @@
});
test('get', () async {
- await driver.get('http://www.google.com/ncr');
- await driver.findElement(const By.name('q'));
+ await driver.get(testPagePath);
+ await driver.findElement(const By.tagName('button'));
+ ;
});
test('currentUrl', () async {
var url = await driver.currentUrl;
expect(url, anyOf(startsWith('file:'), startsWith('http:')));
expect(url, endsWith('test_page.html'));
- await driver.get('http://www.google.com/ncr');
- url = await driver.currentUrl;
- expect(url, contains('www.google.com'));
});
test('findElement -- success', () async {