@@ -6,3 +6,72 @@ export * from './hosted';
6
6
export * from './local' ;
7
7
export * from './mock' ;
8
8
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
+ } ;
0 commit comments