2015-10-11 01:11:13 -04:00
|
|
|
import {Injector, bind, provide, Provider} from 'angular2/src/core/di';
|
2015-08-20 17:28:25 -04:00
|
|
|
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
|
|
|
|
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {Sampler, SampleState} from './sampler';
|
|
|
|
import {ConsoleReporter} from './reporter/console_reporter';
|
|
|
|
import {MultiReporter} from './reporter/multi_reporter';
|
|
|
|
import {RegressionSlopeValidator} from './validator/regression_slope_validator';
|
|
|
|
import {SizeValidator} from './validator/size_validator';
|
|
|
|
import {Validator} from './validator';
|
|
|
|
import {PerflogMetric} from './metric/perflog_metric';
|
|
|
|
import {MultiMetric} from './metric/multi_metric';
|
|
|
|
import {ChromeDriverExtension} from './webdriver/chrome_driver_extension';
|
2015-06-08 16:51:10 -04:00
|
|
|
import {FirefoxDriverExtension} from './webdriver/firefox_driver_extension';
|
2015-05-27 17:57:54 -04:00
|
|
|
import {IOsDriverExtension} from './webdriver/ios_driver_extension';
|
|
|
|
import {WebDriverExtension} from './web_driver_extension';
|
|
|
|
import {SampleDescription} from './sample_description';
|
|
|
|
import {WebDriverAdapter} from './web_driver_adapter';
|
|
|
|
import {Reporter} from './reporter';
|
|
|
|
import {Metric} from './metric';
|
|
|
|
import {Options} from './common_options';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Runner is the main entry point for executing a sample run.
|
|
|
|
* It provides defaults, creates the injector and calls the sampler.
|
|
|
|
*/
|
|
|
|
export class Runner {
|
2015-10-11 01:11:13 -04:00
|
|
|
private _defaultBindings: Provider[];
|
|
|
|
constructor(defaultBindings: Provider[] = null) {
|
2015-05-27 17:57:54 -04:00
|
|
|
if (isBlank(defaultBindings)) {
|
|
|
|
defaultBindings = [];
|
|
|
|
}
|
|
|
|
this._defaultBindings = defaultBindings;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample({id, execute, prepare, microMetrics, bindings}): Promise<SampleState> {
|
|
|
|
var sampleBindings = [
|
2015-10-11 01:11:13 -04:00
|
|
|
_DEFAULT_PROVIDERS,
|
2015-05-27 17:57:54 -04:00
|
|
|
this._defaultBindings,
|
|
|
|
bind(Options.SAMPLE_ID).toValue(id),
|
|
|
|
bind(Options.EXECUTE).toValue(execute)
|
|
|
|
];
|
|
|
|
if (isPresent(prepare)) {
|
2015-06-17 14:17:21 -04:00
|
|
|
sampleBindings.push(bind(Options.PREPARE).toValue(prepare));
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
if (isPresent(microMetrics)) {
|
2015-06-17 14:17:21 -04:00
|
|
|
sampleBindings.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
if (isPresent(bindings)) {
|
2015-06-17 14:17:21 -04:00
|
|
|
sampleBindings.push(bindings);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2015-06-26 18:59:18 -04:00
|
|
|
|
|
|
|
var inj = Injector.resolveAndCreate(sampleBindings);
|
|
|
|
var adapter = inj.get(WebDriverAdapter);
|
|
|
|
|
|
|
|
return PromiseWrapper
|
|
|
|
.all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
|
|
|
|
.then((args) => {
|
|
|
|
var capabilities = args[0];
|
|
|
|
var userAgent = args[1];
|
|
|
|
|
|
|
|
// This might still create instances twice. We are creating a new injector with all the
|
2015-10-11 01:11:13 -04:00
|
|
|
// providers.
|
2015-06-26 18:59:18 -04:00
|
|
|
// Only WebDriverAdapter is reused.
|
|
|
|
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
|
|
|
|
// injectors are handled better.
|
|
|
|
var injector = Injector.resolveAndCreate([
|
|
|
|
sampleBindings,
|
|
|
|
bind(Options.CAPABILITIES).toValue(capabilities),
|
|
|
|
bind(Options.USER_AGENT).toValue(userAgent),
|
2015-10-11 01:11:13 -04:00
|
|
|
provide(WebDriverAdapter, {asValue: adapter})
|
2015-06-26 18:59:18 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
var sampler = injector.get(Sampler);
|
|
|
|
return sampler.sample();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
var _DEFAULT_PROVIDERS = [
|
|
|
|
Options.DEFAULT_PROVIDERS,
|
2015-05-27 17:57:54 -04:00
|
|
|
Sampler.BINDINGS,
|
|
|
|
ConsoleReporter.BINDINGS,
|
|
|
|
RegressionSlopeValidator.BINDINGS,
|
|
|
|
SizeValidator.BINDINGS,
|
|
|
|
ChromeDriverExtension.BINDINGS,
|
2015-06-08 16:51:10 -04:00
|
|
|
FirefoxDriverExtension.BINDINGS,
|
2015-05-27 17:57:54 -04:00
|
|
|
IOsDriverExtension.BINDINGS,
|
|
|
|
PerflogMetric.BINDINGS,
|
|
|
|
SampleDescription.BINDINGS,
|
|
|
|
MultiReporter.createBindings([ConsoleReporter]),
|
|
|
|
MultiMetric.createBindings([PerflogMetric]),
|
|
|
|
|
|
|
|
Reporter.bindTo(MultiReporter),
|
|
|
|
Validator.bindTo(RegressionSlopeValidator),
|
2015-06-08 16:51:10 -04:00
|
|
|
WebDriverExtension.bindTo([ChromeDriverExtension, FirefoxDriverExtension, IOsDriverExtension]),
|
2015-05-27 17:57:54 -04:00
|
|
|
Metric.bindTo(MultiMetric),
|
|
|
|
];
|