From 821d01ab34c6bbea23449c8c58f910c01ea44fb2 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Mon, 2 Mar 2015 09:23:09 -0800 Subject: [PATCH] refactor(benchpress): export webdriver adapters in benchpress/benchpress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also adds default bindings for protractor. Also removes sync web driver adapter for Dart as we don’t have tests for it yet. --- modules/benchpress/benchpress.dart | 2 + modules/benchpress/benchpress.es6 | 2 + .../benchpress/{benchpress.js => common.js} | 0 .../webdriver/async_webdriver_adapter.dart | 4 +- .../webdriver/selenium_webdriver_adapter.es6 | 7 ++++ .../src/webdriver/sync_webdriver_adapter.dart | 41 ------------------- .../test/metric/multi_metric_spec.js | 2 +- .../test/metric/perflog_metric_spec.js | 2 +- .../test/reporter/console_reporter_spec.js | 2 +- .../test/reporter/multi_reporter_spec.js | 2 +- modules/benchpress/test/runner_spec.js | 2 +- modules/benchpress/test/sampler_spec.js | 2 +- .../regression_slope_validator_spec.js | 2 +- .../test/validator/size_validator_spec.js | 2 +- .../test/web_driver_extension_spec.js | 2 +- .../webdriver/chrome_driver_extension_spec.js | 2 +- .../webdriver/ios_driver_extension_spec.js | 2 +- .../webdriver_async.server.spec.dart | 1 - protractor-shared.js | 6 +-- 19 files changed, 25 insertions(+), 60 deletions(-) create mode 100644 modules/benchpress/benchpress.dart create mode 100644 modules/benchpress/benchpress.es6 rename modules/benchpress/{benchpress.js => common.js} (100%) delete mode 100644 modules/benchpress/src/webdriver/sync_webdriver_adapter.dart diff --git a/modules/benchpress/benchpress.dart b/modules/benchpress/benchpress.dart new file mode 100644 index 0000000000..0b08f0d01b --- /dev/null +++ b/modules/benchpress/benchpress.dart @@ -0,0 +1,2 @@ +export './common.dart'; +export './src/webdriver/async_webdriver_adapter.dart' show AsyncWebDriverAdapter; diff --git a/modules/benchpress/benchpress.es6 b/modules/benchpress/benchpress.es6 new file mode 100644 index 0000000000..7b9e8b8681 --- /dev/null +++ b/modules/benchpress/benchpress.es6 @@ -0,0 +1,2 @@ +export * from './common'; +export { SeleniumWebDriverAdapter } from './src/webdriver/selenium_webdriver_adapter'; diff --git a/modules/benchpress/benchpress.js b/modules/benchpress/common.js similarity index 100% rename from modules/benchpress/benchpress.js rename to modules/benchpress/common.js diff --git a/modules/benchpress/src/webdriver/async_webdriver_adapter.dart b/modules/benchpress/src/webdriver/async_webdriver_adapter.dart index ab3095bf30..bbe69d15fc 100644 --- a/modules/benchpress/src/webdriver/async_webdriver_adapter.dart +++ b/modules/benchpress/src/webdriver/async_webdriver_adapter.dart @@ -16,8 +16,8 @@ class AsyncWebDriverAdapter extends WebDriverAdapter { return _driver.execute(script, const[]); } - Map capabilities() { - return _driver.capabilities; + Future capabilities() { + return new Future.value(_driver.capabilities); } Future> logs(String type) { diff --git a/modules/benchpress/src/webdriver/selenium_webdriver_adapter.es6 b/modules/benchpress/src/webdriver/selenium_webdriver_adapter.es6 index 439caaaf86..26ae6e31c3 100644 --- a/modules/benchpress/src/webdriver/selenium_webdriver_adapter.es6 +++ b/modules/benchpress/src/webdriver/selenium_webdriver_adapter.es6 @@ -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), []) +]; \ No newline at end of file diff --git a/modules/benchpress/src/webdriver/sync_webdriver_adapter.dart b/modules/benchpress/src/webdriver/sync_webdriver_adapter.dart deleted file mode 100644 index c7b2dbfa94..0000000000 --- a/modules/benchpress/src/webdriver/sync_webdriver_adapter.dart +++ /dev/null @@ -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); - }); - } -} diff --git a/modules/benchpress/test/metric/multi_metric_spec.js b/modules/benchpress/test/metric/multi_metric_spec.js index 8a7b5841f0..79beb1de80 100644 --- a/modules/benchpress/test/metric/multi_metric_spec.js +++ b/modules/benchpress/test/metric/multi_metric_spec.js @@ -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) { diff --git a/modules/benchpress/test/metric/perflog_metric_spec.js b/modules/benchpress/test/metric/perflog_metric_spec.js index bccfcbfa41..61dffee193 100644 --- a/modules/benchpress/test/metric/perflog_metric_spec.js +++ b/modules/benchpress/test/metric/perflog_metric_spec.js @@ -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'; diff --git a/modules/benchpress/test/reporter/console_reporter_spec.js b/modules/benchpress/test/reporter/console_reporter_spec.js index 8c06442c49..05866b617e 100644 --- a/modules/benchpress/test/reporter/console_reporter_spec.js +++ b/modules/benchpress/test/reporter/console_reporter_spec.js @@ -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', () => { diff --git a/modules/benchpress/test/reporter/multi_reporter_spec.js b/modules/benchpress/test/reporter/multi_reporter_spec.js index 84906764df..7c0b64d83e 100644 --- a/modules/benchpress/test/reporter/multi_reporter_spec.js +++ b/modules/benchpress/test/reporter/multi_reporter_spec.js @@ -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) { diff --git a/modules/benchpress/test/runner_spec.js b/modules/benchpress/test/runner_spec.js index 193519af60..1834f27295 100644 --- a/modules/benchpress/test/runner_spec.js +++ b/modules/benchpress/test/runner_spec.js @@ -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'; diff --git a/modules/benchpress/test/sampler_spec.js b/modules/benchpress/test/sampler_spec.js index caa33d24b1..9da9bacdbb 100644 --- a/modules/benchpress/test/sampler_spec.js +++ b/modules/benchpress/test/sampler_spec.js @@ -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 = () => {}; diff --git a/modules/benchpress/test/validator/regression_slope_validator_spec.js b/modules/benchpress/test/validator/regression_slope_validator_spec.js index bf8570eef7..4bdef96581 100644 --- a/modules/benchpress/test/validator/regression_slope_validator_spec.js +++ b/modules/benchpress/test/validator/regression_slope_validator_spec.js @@ -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', () => { diff --git a/modules/benchpress/test/validator/size_validator_spec.js b/modules/benchpress/test/validator/size_validator_spec.js index 3e22222736..1d6e271d70 100644 --- a/modules/benchpress/test/validator/size_validator_spec.js +++ b/modules/benchpress/test/validator/size_validator_spec.js @@ -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', () => { diff --git a/modules/benchpress/test/web_driver_extension_spec.js b/modules/benchpress/test/web_driver_extension_spec.js index d19e75c419..896d5b45dd 100644 --- a/modules/benchpress/test/web_driver_extension_spec.js +++ b/modules/benchpress/test/web_driver_extension_spec.js @@ -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) { diff --git a/modules/benchpress/test/webdriver/chrome_driver_extension_spec.js b/modules/benchpress/test/webdriver/chrome_driver_extension_spec.js index 3e3fcae01c..52b1e00a04 100644 --- a/modules/benchpress/test/webdriver/chrome_driver_extension_spec.js +++ b/modules/benchpress/test/webdriver/chrome_driver_extension_spec.js @@ -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'; diff --git a/modules/benchpress/test/webdriver/ios_driver_extension_spec.js b/modules/benchpress/test/webdriver/ios_driver_extension_spec.js index 7a1d8629b9..c774e27379 100644 --- a/modules/benchpress/test/webdriver/ios_driver_extension_spec.js +++ b/modules/benchpress/test/webdriver/ios_driver_extension_spec.js @@ -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'; diff --git a/modules/examples/test/benchpress/webdriver_async.server.spec.dart b/modules/examples/test/benchpress/webdriver_async.server.spec.dart index 86990dc720..3a4150960f 100644 --- a/modules/examples/test/benchpress/webdriver_async.server.spec.dart +++ b/modules/examples/test/benchpress/webdriver_async.server.spec.dart @@ -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() { diff --git a/protractor-shared.js b/protractor-shared.js index e004925487..ead58a61df 100644 --- a/protractor-shared.js +++ b/protractor-shared.js @@ -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,