2016-06-02 20:30:40 -04:00
|
|
|
import {ReflectiveInjector} from '@angular/core';
|
2016-08-03 15:32:26 -04:00
|
|
|
import {isPresent, isBlank} from '@angular/facade/src/lang';
|
|
|
|
import {PromiseWrapper} from '@angular/facade/src/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';
|
2016-04-20 20:01:51 -04:00
|
|
|
import {UserMetric} from './metric/user_metric';
|
2015-05-27 17:57:54 -04:00
|
|
|
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 {
|
2016-06-02 20:30:40 -04:00
|
|
|
private _defaultProviders: any[];
|
|
|
|
constructor(defaultProviders: any[] = null) {
|
2016-03-21 06:57:17 -04:00
|
|
|
if (isBlank(defaultProviders)) {
|
|
|
|
defaultProviders = [];
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2016-03-21 06:57:17 -04:00
|
|
|
this._defaultProviders = defaultProviders;
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
2016-04-20 20:01:51 -04:00
|
|
|
sample({id, execute, prepare, microMetrics, providers, userMetrics}:
|
|
|
|
{id: string, execute?: any, prepare?: any, microMetrics?: any, providers?: any, userMetrics?: any}):
|
2016-02-19 14:49:31 -05:00
|
|
|
Promise<SampleState> {
|
2016-03-21 06:57:17 -04:00
|
|
|
var sampleProviders = [
|
2016-04-12 12:40:37 -04:00
|
|
|
_DEFAULT_PROVIDERS,
|
2016-03-21 06:57:17 -04:00
|
|
|
this._defaultProviders,
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: Options.SAMPLE_ID, useValue: id},
|
|
|
|
{provide: Options.EXECUTE, useValue: execute}
|
2015-05-27 17:57:54 -04:00
|
|
|
];
|
|
|
|
if (isPresent(prepare)) {
|
2016-06-02 20:30:40 -04:00
|
|
|
sampleProviders.push({provide: Options.PREPARE, useValue: prepare});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
if (isPresent(microMetrics)) {
|
2016-06-02 20:30:40 -04:00
|
|
|
sampleProviders.push({provide: Options.MICRO_METRICS, useValue: microMetrics});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2016-04-20 20:01:51 -04:00
|
|
|
if (isPresent(userMetrics)) {
|
|
|
|
sampleProviders.push({provide: Options.USER_METRICS, useValue: userMetrics});
|
|
|
|
}
|
2016-03-21 06:57:17 -04:00
|
|
|
if (isPresent(providers)) {
|
|
|
|
sampleProviders.push(providers);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
2015-06-26 18:59:18 -04:00
|
|
|
|
2016-03-21 06:57:17 -04:00
|
|
|
var inj = ReflectiveInjector.resolveAndCreate(sampleProviders);
|
2015-06-26 18:59:18 -04:00
|
|
|
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.
|
2016-04-14 15:35:24 -04:00
|
|
|
var injector = ReflectiveInjector.resolveAndCreate([
|
2016-03-21 06:57:17 -04:00
|
|
|
sampleProviders,
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: Options.CAPABILITIES, useValue: capabilities},
|
|
|
|
{provide: Options.USER_AGENT, useValue: userAgent},
|
|
|
|
{provide: WebDriverAdapter, useValue: 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,
|
2016-03-21 06:57:17 -04:00
|
|
|
Sampler.PROVIDERS,
|
|
|
|
ConsoleReporter.PROVIDERS,
|
|
|
|
RegressionSlopeValidator.PROVIDERS,
|
|
|
|
SizeValidator.PROVIDERS,
|
|
|
|
ChromeDriverExtension.PROVIDERS,
|
|
|
|
FirefoxDriverExtension.PROVIDERS,
|
|
|
|
IOsDriverExtension.PROVIDERS,
|
|
|
|
PerflogMetric.PROVIDERS,
|
2016-08-03 15:32:26 -04:00
|
|
|
UserMetric.PROVIDERS,
|
2016-03-21 06:57:17 -04:00
|
|
|
SampleDescription.PROVIDERS,
|
2015-05-27 17:57:54 -04:00
|
|
|
MultiReporter.createBindings([ConsoleReporter]),
|
2016-04-20 20:01:51 -04:00
|
|
|
MultiMetric.createBindings([PerflogMetric, UserMetric]),
|
2015-05-27 17:57:54 -04:00
|
|
|
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),
|
|
|
|
];
|