Skip to content

Commit

Permalink
Merge pull request #72 from goderbauer/testRefactor
Browse files Browse the repository at this point in the history
refactored test setup
  • Loading branch information
goderbauer committed Apr 4, 2016
2 parents 42d322c + 9f8ff56 commit 4ee4177
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 143 deletions.
2 changes: 1 addition & 1 deletion dart/async/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pageloader
version: 2.0.0
version: 2.0.1
author: Marc Fisher II <[email protected]>
description: >
Supports the creation of page objects that can be shared between in-browser tests
Expand Down
23 changes: 5 additions & 18 deletions dart/async/test/html_no_shadow_dom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,17 @@
@TestOn('browser')
library pageloader.test.html_no_shadow_dom;

import 'dart:async';

import 'package:pageloader/html.dart';

import 'package:test/test.dart';

import 'data/html_no_shadow_dom_setup.dart' as html_setup;
import 'src/common.dart' as plt;
import 'src/html_pageloader.dart' as html_test;
import 'src/shared.dart' as shared;
import 'setup/html_test_setup.dart' show runTests, syncFn;

void main() {
setUp(() {
var div = html_setup.setUp();
shared.loader =
new HtmlPageLoader(div, executeSyncedFn: syncFn, useShadowDom: false);
});

plt.runTests();
html_test.runTests();
runTests(pageloaderFactory);
}

syncFn(fn) async {
var value = await fn();
await new Future.delayed(new Duration(milliseconds: 200));
return value;
PageLoader pageloaderFactory() {
var div = html_setup.setUp();
return new HtmlPageLoader(div, executeSyncedFn: syncFn, useShadowDom: false);
}
21 changes: 5 additions & 16 deletions dart/async/test/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,17 @@
@TestOn('browser')
library pageloader.test.html_no_shadow_dom;

import 'dart:async';

import 'package:pageloader/html.dart';
import 'package:test/test.dart';

import 'data/html_setup.dart' as html_setup;
import 'src/common.dart' as plt;
import 'src/html_pageloader.dart' as html_test;
import 'src/shared.dart' as shared;
import 'setup/html_test_setup.dart' show runTests, syncFn;

void main() {
setUp(() {
var div = html_setup.setUp();
shared.loader = new HtmlPageLoader(div, executeSyncedFn: syncFn);
});

plt.runTests();
html_test.runTests();
runTests(pageloaderFactory);
}

syncFn(fn) async {
var value = await fn();
await new Future.delayed(new Duration(milliseconds: 200));
return value;
PageLoader pageloaderFactory() {
var div = html_setup.setUp();
return new HtmlPageLoader(div, executeSyncedFn: syncFn);
}
37 changes: 37 additions & 0 deletions dart/async/test/setup/html_test_setup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2014 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 pageloader.test.html_test_setup;

import 'dart:async';

import 'package:test/test.dart';

import '../src/common.dart' as plt;
import '../src/html_pageloader.dart' as html_test;
import '../src/shared.dart' as shared;

void runTests(pageLoaderFactory) {
setUp(() {
shared.loader = pageLoaderFactory();
});

plt.runTests();
html_test.runTests();
}

syncFn(fn) async {
var value = await fn();
await new Future.delayed(new Duration(milliseconds: 200));
return value;
}
80 changes: 80 additions & 0 deletions dart/async/test/setup/webdriver_test_setup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2014 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 pageloader.test.webdriver_test_setup;

import 'dart:async';
import 'dart:io';
import 'dart:mirrors' show currentMirrorSystem;

import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:webdriver/io.dart' show Capabilities, WebDriver, createDriver;

import '../src/common.dart' as plt;
import '../src/shared.dart' as shared;

void runTests(pageLoaderFactory, String testPage) {
WebDriver driver;

setUp(() async {
driver = await _createTestDriver();
await driver.get(_testPagePath(testPage));
shared.loader = pageLoaderFactory(driver);
});

tearDown(() async {
await driver.quit();
shared.loader = null;
});

plt.runTests();
}

String _testPagePath(String testPage) {
var pathToTest = path.split(currentMirrorSystem()
.findLibrary(#pageloader.test.webdriver_test_setup)
.uri
.path);
pathToTest = pathToTest.sublist(0, pathToTest.length - 2)
..add('data')
..add(testPage);
var testPagePath = path.joinAll(pathToTest);
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();
}

Future<WebDriver> _createTestDriver() {
Map capabilities = Capabilities.chrome;
Map env = Platform.environment;

Map chromeOptions = {};

if (env['CHROMEDRIVER_BINARY'] != null) {
chromeOptions['binary'] = env['CHROMEDRIVER_BINARY'];
}

if (env['CHROMEDRIVER_ARGS'] != null) {
chromeOptions['args'] = env['CHROMEDRIVER_ARGS'].split(' ');
}

if (chromeOptions.isNotEmpty) {
capabilities['chromeOptions'] = chromeOptions;
}

return createDriver(desired: capabilities);
}
62 changes: 7 additions & 55 deletions dart/async/test/webdriver_no_shadow_dom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,17 @@
// limitations under the License.

@TestOn('vm')
library pageloader.test.webdriver;
library pageloader.test.webdriver_no_shadow_dom;

import 'dart:async';
import 'dart:io';

import 'package:pageloader/webdriver.dart' show WebDriverPageLoader;
import 'package:path/path.dart' as path;
import 'package:pageloader/webdriver.dart';
import 'package:test/test.dart';
import 'package:webdriver/io.dart' show Capabilities, WebDriver, createDriver;
import 'package:webdriver/io.dart' show WebDriver;

import 'src/common.dart' as plt;
import 'src/shared.dart' as shared;
import 'setup/webdriver_test_setup.dart' show runTests;

void main() {
WebDriver driver;

setUp(() async {
driver = await _createTestDriver();
await driver.get(_testPagePath);
shared.loader = new WebDriverPageLoader(driver, useShadowDom: false);
});

tearDown(() async {
await driver.quit();
shared.loader = null;
});

plt.runTests();
}

String get _testPagePath {
var testPagePath =
path.join('test', 'data', 'webdriver_no_shadow_dom_test_page.html');

testPagePath = path.absolute(testPagePath);
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();
runTests(pageLoaderFactory, 'webdriver_no_shadow_dom_test_page.html');
}

Future<WebDriver> _createTestDriver() {
Map capabilities = Capabilities.chrome;
Map env = Platform.environment;

Map chromeOptions = {};

if (env['CHROMEDRIVER_BINARY'] != null) {
chromeOptions['binary'] = env['CHROMEDRIVER_BINARY'];
}

if (env['CHROMEDRIVER_ARGS'] != null) {
chromeOptions['args'] = env['CHROMEDRIVER_ARGS'].split(' ');
}

if (chromeOptions.isNotEmpty) {
capabilities['chromeOptions'] = chromeOptions;
}

return createDriver(desired: capabilities);
}
PageLoader pageLoaderFactory(WebDriver driver) =>
new WebDriverPageLoader(driver, useShadowDom: false);
60 changes: 7 additions & 53 deletions dart/async/test/webdriver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,17 @@
// limitations under the License.

@TestOn('vm')
library pageloader.test.webdriver;
library pageloader.test.webdriver_no_shadow_dom;

import 'dart:async';
import 'dart:io';

import 'package:pageloader/webdriver.dart' show WebDriverPageLoader;
import 'package:path/path.dart' as path;
import 'package:pageloader/webdriver.dart';
import 'package:test/test.dart';
import 'package:webdriver/io.dart' show Capabilities, WebDriver, createDriver;
import 'package:webdriver/io.dart' show WebDriver;

import 'src/common.dart' as plt;
import 'src/shared.dart' as shared;
import 'setup/webdriver_test_setup.dart' show runTests;

void main() {
WebDriver driver;

setUp(() async {
driver = await _createTestDriver();
await driver.get(_testPagePath);
shared.loader = new WebDriverPageLoader(driver);
});

tearDown(() async {
await driver.quit();
shared.loader = null;
});

plt.runTests();
}

String get _testPagePath {
var testPagePath = path.join('test', 'data', 'webdriver_test_page.html');
testPagePath = path.absolute(testPagePath);
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();
runTests(pageLoaderFactory, 'webdriver_test_page.html');
}

Future<WebDriver> _createTestDriver() {
Map capabilities = Capabilities.chrome;
Map env = Platform.environment;

Map chromeOptions = {};

if (env['CHROMEDRIVER_BINARY'] != null) {
chromeOptions['binary'] = env['CHROMEDRIVER_BINARY'];
}

if (env['CHROMEDRIVER_ARGS'] != null) {
chromeOptions['args'] = env['CHROMEDRIVER_ARGS'].split(' ');
}

if (chromeOptions.isNotEmpty) {
capabilities['chromeOptions'] = chromeOptions;
}

return createDriver(desired: capabilities);
}
PageLoader pageLoaderFactory(WebDriver driver) =>
new WebDriverPageLoader(driver);

0 comments on commit 4ee4177

Please sign in to comment.