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

Commit ca4f1ac

Browse files
authored
chore(driverProviders): add warnings to extra driver provider parameters (#3873)
- builds the driver provider in lib/driverProviders/index instead of lib/runner closes #1945
1 parent 1345137 commit ca4f1ac

File tree

2 files changed

+87
-20
lines changed

2 files changed

+87
-20
lines changed

lib/driverProviders/index.ts

+85
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,88 @@ 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('directConnect', 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 +
61+
', but also found extra driver provider parameter(s): ';
62+
let warnList: string[] = [];
63+
if ('directConnect' !== providerType && config.directConnect) {
64+
warnList.push('directConnect');
65+
}
66+
if ('attachSession' !== providerType && 'hosted' !== providerType && config.seleniumAddress) {
67+
warnList.push('seleniumAddress');
68+
}
69+
if ('attachSession' !== providerType && config.seleniumSessionId) {
70+
warnList.push('seleniumSessionId');
71+
}
72+
if ('browserStack' !== providerType && config.browserstackUser) {
73+
warnList.push('browserstackUser');
74+
}
75+
if ('browserStack' !== providerType && config.browserstackKey) {
76+
warnList.push('browserstackKey');
77+
}
78+
if ('sauce' !== providerType && config.sauceUser) {
79+
warnList.push('sauceUser');
80+
}
81+
if ('sauce' !== providerType && config.sauceKey) {
82+
warnList.push('sauceKey');
83+
}
84+
if ('local' !== providerType && config.seleniumServerJar) {
85+
warnList.push('seleniumServerJar');
86+
}
87+
if ('mock' !== providerType && config.mockSelenium) {
88+
warnList.push('mockSelenium');
89+
}
90+
if (warnList.length !== 0) {
91+
logger.warn(warnInto + warnList.join(', '));
92+
}
93+
};

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)