3
3
import com .techboy .selenium .browserdriver .BrowserDriverExtended ;
4
4
import com .techboy .selenium .config .BrowserCapabilities ;
5
5
import org .openqa .selenium .Proxy ;
6
- import org .springframework .beans .factory .annotation .Value ;
7
6
import org .springframework .context .annotation .*;
8
7
import org .springframework .context .support .PropertySourcesPlaceholderConfigurer ;
9
8
import org .springframework .core .env .Environment ;
10
9
import org .springframework .core .type .AnnotatedTypeMetadata ;
11
10
12
11
import javax .annotation .PostConstruct ;
13
- import javax .inject .Inject ;
14
12
import java .io .IOException ;
15
13
16
14
import static org .openqa .selenium .Proxy .ProxyType .MANUAL ;
17
15
18
16
/**
19
- * Created by christopher on 01/12/2015.
17
+ *
20
18
*/
21
19
@ PropertySource ("classpath:app.properties" )
22
20
@ Configuration
23
21
public class Beans {
24
22
25
- @ Value ("${browser}" ) String artist ;
26
-
27
- @ Inject
28
- Environment env ;
29
-
30
23
private String workingOS = System .getProperty ("os.name" ).toLowerCase ();
31
24
private final boolean proxyEnabled = Boolean .getBoolean ("proxyEnabled" );
32
25
private final String proxyHostname = System .getProperty ("proxyHost" );
33
26
private final Integer proxyPort = Integer .getInteger ("proxyPort" );
34
27
private final String proxyDetails = String .format ("%s:%d" , proxyHostname , proxyPort );
35
- private static String browser ="firefox" ;
36
28
37
29
38
30
@ PostConstruct
39
31
public void systemPath () throws IOException {
40
32
41
- System .out .println (artist );
42
-
43
33
if (workingOS .contains ("windows" )) {
44
- System .setProperty ("webdriver.chrome.driver" ,"selenium_browser_drivers/windowsChromedriver/chromedriver.exe" );
34
+ System .setProperty ("webdriver.chrome.driver" , "selenium_browser_drivers/windowsChromedriver/chromedriver.exe" );
45
35
} else if (workingOS .contains ("mac" )) {
46
36
System .setProperty ("webdriver.chrome.driver" , "selenium_browser_drivers/macChromedriver/chromedriver" );
47
37
} else if (workingOS .contains ("linux" )) {
@@ -75,26 +65,29 @@ public BrowserDriverExtended.ChromeDriverExtended chrome() {
75
65
return new BrowserDriverExtended .ChromeDriverExtended (BrowserCapabilities .newInstance ().getChromeCapabilities ());
76
66
}
77
67
78
- private static class FirefoxCondition implements Condition {
68
+ private static class FirefoxCondition implements Condition {
79
69
@ Override
80
70
public boolean matches (ConditionContext context , AnnotatedTypeMetadata metadata ) {
81
- return browser .contentEquals ("firefox" ) || browser .contentEquals ("" );
71
+ Environment env =context .getEnvironment ();
72
+ return env .getProperty ("browser" ).equalsIgnoreCase ("firefox" ) || env .getProperty ("browser" ).equalsIgnoreCase ("" );
82
73
}
83
74
84
75
}
85
76
86
77
private static class ChromeCondition implements Condition {
87
78
@ Override
88
79
public boolean matches (ConditionContext context , AnnotatedTypeMetadata metadata ) {
89
- return browser .contentEquals ("chrome" );
80
+ Environment env =context .getEnvironment ();
81
+ return env .getProperty ("browser" ).equalsIgnoreCase ("chrome" );
90
82
}
91
83
92
84
}
93
85
94
86
private static class IECondition implements Condition {
95
87
@ Override
96
88
public boolean matches (ConditionContext context , AnnotatedTypeMetadata metadata ) {
97
- return browser .contentEquals ("IE" );
89
+ Environment env =context .getEnvironment ();
90
+ return env .getProperty ("browser" ).equalsIgnoreCase ("IE" );
98
91
}
99
92
}
100
93
@@ -104,8 +97,6 @@ static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
104
97
return new PropertySourcesPlaceholderConfigurer ();
105
98
}
106
99
107
-
108
-
109
100
}
110
101
111
102
0 commit comments