({
id,
execute,
prepare,
microMetrics,
providers,
userMetrics,
}: {
id: string;
execute?: Function;
prepare?: Function;
microMetrics?: {[key: string]: string};
providers?: StaticProvider[];
userMetrics?: {[key: string]: string};
})
| 35 | constructor(private _defaultProviders: StaticProvider[] = []) {} |
| 36 | |
| 37 | sample({ |
| 38 | id, |
| 39 | execute, |
| 40 | prepare, |
| 41 | microMetrics, |
| 42 | providers, |
| 43 | userMetrics, |
| 44 | }: { |
| 45 | id: string; |
| 46 | execute?: Function; |
| 47 | prepare?: Function; |
| 48 | microMetrics?: {[key: string]: string}; |
| 49 | providers?: StaticProvider[]; |
| 50 | userMetrics?: {[key: string]: string}; |
| 51 | }): Promise<SampleState> { |
| 52 | const sampleProviders: StaticProvider[] = [ |
| 53 | _DEFAULT_PROVIDERS, |
| 54 | this._defaultProviders, |
| 55 | {provide: Options.SAMPLE_ID, useValue: id}, |
| 56 | {provide: Options.EXECUTE, useValue: execute}, |
| 57 | ]; |
| 58 | if (prepare != null) { |
| 59 | sampleProviders.push({provide: Options.PREPARE, useValue: prepare}); |
| 60 | } |
| 61 | if (microMetrics != null) { |
| 62 | sampleProviders.push({provide: Options.MICRO_METRICS, useValue: microMetrics}); |
| 63 | } |
| 64 | if (userMetrics != null) { |
| 65 | sampleProviders.push({provide: Options.USER_METRICS, useValue: userMetrics}); |
| 66 | } |
| 67 | if (providers != null) { |
| 68 | sampleProviders.push(providers); |
| 69 | } |
| 70 | |
| 71 | const inj = Injector.create({providers: sampleProviders}); |
| 72 | const adapter: WebDriverAdapter = inj.get(WebDriverAdapter); |
| 73 | |
| 74 | return Promise.all([ |
| 75 | adapter.capabilities(), |
| 76 | adapter.executeScript('return window.navigator.userAgent;'), |
| 77 | ]).then((args) => { |
| 78 | const capabilities = args[0]; |
| 79 | const userAgent = args[1]; |
| 80 | |
| 81 | // This might still create instances twice. We are creating a new injector with all the |
| 82 | // providers. |
| 83 | // Only WebDriverAdapter is reused. |
| 84 | // TODO(vsavkin): consider changing it when toAsyncFactory is added back or when child |
| 85 | // injectors are handled better. |
| 86 | const injector = Injector.create({ |
| 87 | providers: [ |
| 88 | sampleProviders, |
| 89 | {provide: Options.CAPABILITIES, useValue: capabilities}, |
| 90 | {provide: Options.USER_AGENT, useValue: userAgent}, |
| 91 | {provide: WebDriverAdapter, useValue: adapter}, |
| 92 | ], |
| 93 | }); |
| 94 |
no test coverage detected