Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit a317b84

Browse files
committed
chore(driverProviders): add warnings to extra driver provider parameters
- builds the driver provider in lib/driverProviders/index instead of lib/runner closes #1945
1 parent 24ae714 commit a317b84

File tree

2 files changed

+71
-20
lines changed

2 files changed

+71
-20
lines changed

Diff for: lib/driverProviders/index.ts

+69
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,72 @@ export * from './hosted';
66
export * from './local';
77
export * from './mock';
88
export * from './sauce';
9+
10+
11+
import {AttachSession} from './attachSession';
12+
import {BrowserStack} from './browserStack';
13+
import {DriverProvider} from './driverProvider';
14+
import {Direct} from './direct';
15+
import {Hosted} from './hosted';
16+
import {Local} from './local';
17+
import {Mock} from './mock';
18+
import {Sauce} from './sauce';
19+
20+
import {Config} from '../config';
21+
import {Logger} from '../logger';
22+
23+
let logger = new Logger('driverProviders');
24+
25+
export let buildDriverProvider = (config: Config): DriverProvider => {
26+
let driverProvider: DriverProvider;
27+
28+
if (config.directConnect) {
29+
driverProvider = new Direct(config);
30+
logWarnings('direct', config);
31+
} else if (config.seleniumAddress) {
32+
if (config.seleniumSessionId) {
33+
driverProvider = new AttachSession(config);
34+
logWarnings('attachSession', config);
35+
} else {
36+
driverProvider = new Hosted(config);
37+
logWarnings('hosted', config);
38+
}
39+
} else if (config.browserstackUser && config.browserstackKey) {
40+
driverProvider = new BrowserStack(config);
41+
logWarnings('browserStack', config);
42+
} else if (config.sauceUser && config.sauceKey) {
43+
driverProvider = new Sauce(config);
44+
logWarnings('sauce', config);
45+
} else if (config.seleniumServerJar) {
46+
driverProvider = new Local(config);
47+
logWarnings('local', config);
48+
} else if (config.mockSelenium) {
49+
driverProvider = new Mock(config);
50+
logWarnings('mock', config);
51+
} else {
52+
driverProvider = new Local(config);
53+
logWarnings('local', config);
54+
}
55+
return driverProvider;
56+
};
57+
58+
export let logWarnings = (providerType: string, config: Config): void => {
59+
60+
let warnInto = 'Using driver provider ' + providerType + ', but also found extra';
61+
let warn = '';
62+
warn += 'direct' !== providerType && config.directConnect ? 'directConnect: ' : '';
63+
warn += 'attachSession' !== providerType && 'hosted' !== providerType && config.seleniumAddress ?
64+
'seleniumAddress, ' :
65+
'';
66+
warn += 'attachSession' !== providerType && config.seleniumSessionId ? 'seleniumSessionId, ' : '';
67+
warn += 'browserStack' !== providerType && config.browserstackUser ? 'browserstackUser, ' : '';
68+
warn += 'browserStack' !== providerType && config.browserstackKey ? 'browserstackKey, ' : '';
69+
warn += 'sauce' !== providerType && config.sauceUser ? 'sauceUser, ' : '';
70+
warn += 'sauce' !== providerType && config.sauceKey ? 'sauceKey, ' : '';
71+
warn += 'local' !== providerType && config.seleniumServerJar ? 'seleniumServerJar, ' : '';
72+
warn += 'mock' !== providerType && config.mockSelenium ? 'mockSelenium, ' : '';
73+
if (warn !== '') {
74+
logger.warn(warnInto);
75+
logger.warn('driver provider parameters: ' + warn.substring(0, warn.length - 2));
76+
}
77+
};

Diff for: lib/runner.ts

+2-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as util from 'util';
55

66
import {ProtractorBrowser} from './browser';
77
import {Config} from './config';
8-
import {AttachSession, BrowserStack, Direct, DriverProvider, Hosted, Local, Mock, Sauce} from './driverProviders';
8+
import {buildDriverProvider, DriverProvider} from './driverProviders';
99
import {Logger} from './logger';
1010
import {Plugins} from './plugins';
1111
import {protractor} from './ptor';
@@ -99,25 +99,7 @@ export class Runner extends EventEmitter {
9999
*/
100100
loadDriverProvider_(config: Config) {
101101
this.config_ = config;
102-
if (this.config_.directConnect) {
103-
this.driverprovider_ = new Direct(this.config_);
104-
} else if (this.config_.seleniumAddress) {
105-
if (this.config_.seleniumSessionId) {
106-
this.driverprovider_ = new AttachSession(this.config_);
107-
} else {
108-
this.driverprovider_ = new Hosted(this.config_);
109-
}
110-
} else if (this.config_.browserstackUser && this.config_.browserstackKey) {
111-
this.driverprovider_ = new BrowserStack(this.config_);
112-
} else if (this.config_.sauceUser && this.config_.sauceKey) {
113-
this.driverprovider_ = new Sauce(this.config_);
114-
} else if (this.config_.seleniumServerJar) {
115-
this.driverprovider_ = new Local(this.config_);
116-
} else if (this.config_.mockSelenium) {
117-
this.driverprovider_ = new Mock(this.config_);
118-
} else {
119-
this.driverprovider_ = new Local(this.config_);
120-
}
102+
this.driverprovider_ = buildDriverProvider(this.config_);
121103
}
122104

123105
/**

0 commit comments

Comments
 (0)