refactor(benchpress): export webdriver adapters in benchpress/benchpress

Also adds default bindings for protractor.
Also removes sync web driver adapter for Dart as we don’t have tests
for it yet.
This commit is contained in:
Tobias Bosch 2015-03-02 09:23:09 -08:00
parent f783841f16
commit 821d01ab34
19 changed files with 25 additions and 60 deletions

View File

@ -0,0 +1,2 @@
export './common.dart';
export './src/webdriver/async_webdriver_adapter.dart' show AsyncWebDriverAdapter;

View File

@ -0,0 +1,2 @@
export * from './common';
export { SeleniumWebDriverAdapter } from './src/webdriver/selenium_webdriver_adapter';

View File

@ -16,8 +16,8 @@ class AsyncWebDriverAdapter extends WebDriverAdapter {
return _driver.execute(script, const[]);
}
Map capabilities() {
return _driver.capabilities;
Future<Map> capabilities() {
return new Future.value(_driver.capabilities);
}
Future<List<Map>> logs(String type) {

View File

@ -8,6 +8,9 @@ import webdriver from 'selenium-webdriver';
* Adapter for the selenium-webdriver.
*/
export class SeleniumWebDriverAdapter extends WebDriverAdapter {
// TODO(tbosch): use static values when our transpiler supports them
static get PROTRACTOR_BINDINGS() { return _PROTRACTOR_BINDINGS; }
_driver:any;
constructor(driver) {
@ -59,3 +62,7 @@ function convertToLocalProcess(data) {
}
return JSON.parse(serialized);
}
var _PROTRACTOR_BINDINGS = [
bind(WebDriverAdapter).toFactory( () => new SeleniumWebDriverAdapter(global.browser), [])
];

View File

@ -1,41 +0,0 @@
library benchpress.src.webdriver.sync_webdriver_adapter_dart;
import 'package:angular2/src/facade/async.dart' show Future, PromiseWrapper;
import '../web_driver_adapter.dart' show WebDriverAdapter;
class SyncWebDriverAdapter extends WebDriverAdapter {
dynamic _driver;
SyncWebDriverAdapter(driver) {
this._driver = driver;
}
Future waitFor(Function callback) {
return this._convertToAsync(callback);
}
Future _convertToAsync(callback) {
try {
var result = callback();
if (result is Promise) {
return result;
} else {
return PromiseWrapper.resolve(result);
}
} catch (e) {
return PromiseWrapper.reject(result);
}
}
Future executeScript(String script) {
return this._convertToAsync(() {
return this._driver.execute(script);
});
}
Future capabilities() {
return this._convertToAsync(() {
return this._driver.capabilities;
});
}
Future logs(String type) {
return this._convertToAsync(() {
return this._driver.logs.get(script);
});
}
}

View File

@ -3,7 +3,7 @@ import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from '
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
import { Metric, MultiMetric, bind, Injector } from 'benchpress/benchpress';
import { Metric, MultiMetric, bind, Injector } from 'benchpress/common';
export function main() {
function createMetric(ids) {

View File

@ -3,7 +3,7 @@ import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from '
import { List, ListWrapper } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
import { Metric, PerflogMetric, WebDriverExtension, bind, Injector } from 'benchpress/benchpress';
import { Metric, PerflogMetric, WebDriverExtension, bind, Injector } from 'benchpress/common';
import { TraceEventFactory } from '../trace_event_factory';

View File

@ -6,7 +6,7 @@ import { List, ListWrapper } from 'angular2/src/facade/collection';
import {
SampleState, Reporter, bind, Injector,
ConsoleReporter, SampleDescription, MeasureValues
} from 'benchpress/benchpress';
} from 'benchpress/common';
export function main() {
describe('console reporter', () => {

View File

@ -4,7 +4,7 @@ import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
import { DateWrapper } from 'angular2/src/facade/lang';
import { Reporter, MultiReporter, bind, Injector, MeasureValues } from 'benchpress/benchpress';
import { Reporter, MultiReporter, bind, Injector, MeasureValues } from 'benchpress/common';
export function main() {
function createReporters(ids) {

View File

@ -3,7 +3,7 @@ import {
Runner, Sampler, SampleDescription,
Validator, bind, Injector, Metric,
Options, WebDriverAdapter
} from 'benchpress/benchpress';
} from 'benchpress/common';
import { isBlank } from 'angular2/src/facade/lang';
import { Promise, PromiseWrapper } from 'angular2/src/facade/async';

View File

@ -8,7 +8,7 @@ import {
Sampler, WebDriverAdapter, WebDriverExtension,
Validator, Metric, Reporter, Browser,
bind, Injector, Options, MeasureValues
} from 'benchpress/benchpress';
} from 'benchpress/common';
export function main() {
var EMPTY_EXECUTE = () => {};

View File

@ -4,7 +4,7 @@ import { ListWrapper } from 'angular2/src/facade/collection';
import {
Validator, RegressionSlopeValidator, Injector, bind, MeasureValues
} from 'benchpress/benchpress';
} from 'benchpress/common';
export function main() {
describe('regression slope validator', () => {

View File

@ -4,7 +4,7 @@ import { ListWrapper } from 'angular2/src/facade/collection';
import {
Validator, SizeValidator, Injector, bind, MeasureValues
} from 'benchpress/benchpress';
} from 'benchpress/common';
export function main() {
describe('size validator', () => {

View File

@ -4,7 +4,7 @@ import { StringMap, ListWrapper } from 'angular2/src/facade/collection';
import { isPresent, StringWrapper } from 'angular2/src/facade/lang';
import { PromiseWrapper } from 'angular2/src/facade/async';
import { WebDriverExtension, bind, Injector, Options } from 'benchpress/benchpress';
import { WebDriverExtension, bind, Injector, Options } from 'benchpress/common';
export function main() {
function createExtension(ids, caps) {

View File

@ -7,7 +7,7 @@ import { Json, isBlank } from 'angular2/src/facade/lang';
import {
WebDriverExtension, ChromeDriverExtension,
WebDriverAdapter, Injector, bind
} from 'benchpress/benchpress';
} from 'benchpress/common';
import { TraceEventFactory } from '../trace_event_factory';

View File

@ -7,7 +7,7 @@ import { Json, isBlank, isPresent } from 'angular2/src/facade/lang';
import {
WebDriverExtension, IOsDriverExtension,
WebDriverAdapter, Injector, bind
} from 'benchpress/benchpress';
} from 'benchpress/common';
import { TraceEventFactory } from '../trace_event_factory';

View File

@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io' show Platform;
import 'package:guinness/guinness.dart';
import 'package:benchpress/benchpress.dart';
import 'package:benchpress/src/webdriver/async_webdriver_adapter.dart';
import 'package:webdriver/webdriver.dart' show WebDriver, Capabilities, LogType, LogLevel, By;
main() {

View File

@ -169,8 +169,6 @@ var config = exports.config = {
exports.createBenchpressRunner = function(options) {
var nodeUuid = require('node-uuid');
var benchpress = require('./dist/js/cjs/benchpress/benchpress');
var SeleniumWebDriverAdapter =
require('./dist/js/cjs/benchpress/src/webdriver/selenium_webdriver_adapter').SeleniumWebDriverAdapter;
// TODO(tbosch): add cloud reporter again (only when !options.test)
// var cloudReporterConfig;
@ -189,9 +187,7 @@ exports.createBenchpressRunner = function(options) {
runId = process.env.GIT_SHA + ' ' + runId;
}
var bindings = [
benchpress.bind(benchpress.WebDriverAdapter).toFactory(
function() { return new SeleniumWebDriverAdapter(global.browser); }, []
),
benchpress.SeleniumWebDriverAdapter.PROTRACTOR_BINDINGS,
benchpress.bind(benchpress.Options.FORCE_GC).toValue(argv['force-gc']),
benchpress.bind(benchpress.Options.DEFAULT_DESCRIPTION).toValue({
'lang': options.lang,