@@ -6,3 +6,88 @@ 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 ( '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
+ } ;
0 commit comments