-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from goderbauer/testRefactor
refactored test setup
- Loading branch information
Showing
7 changed files
with
142 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters