Skip to content

Commit e6294b5

Browse files
author
christopher.mbaike
committed
Updated bean creation condition
1 parent f530135 commit e6294b5

File tree

7 files changed

+10
-19
lines changed

7 files changed

+10
-19
lines changed

src/test/java/com/techboy/selenium/beanconfig/Beans.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,35 @@
33
import com.techboy.selenium.browserdriver.BrowserDriverExtended;
44
import com.techboy.selenium.config.BrowserCapabilities;
55
import org.openqa.selenium.Proxy;
6-
import org.springframework.beans.factory.annotation.Value;
76
import org.springframework.context.annotation.*;
87
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
98
import org.springframework.core.env.Environment;
109
import org.springframework.core.type.AnnotatedTypeMetadata;
1110

1211
import javax.annotation.PostConstruct;
13-
import javax.inject.Inject;
1412
import java.io.IOException;
1513

1614
import static org.openqa.selenium.Proxy.ProxyType.MANUAL;
1715

1816
/**
19-
* Created by christopher on 01/12/2015.
17+
*
2018
*/
2119
@PropertySource("classpath:app.properties")
2220
@Configuration
2321
public class Beans {
2422

25-
@Value("${browser}") String artist;
26-
27-
@Inject
28-
Environment env;
29-
3023
private String workingOS = System.getProperty("os.name").toLowerCase();
3124
private final boolean proxyEnabled = Boolean.getBoolean("proxyEnabled");
3225
private final String proxyHostname = System.getProperty("proxyHost");
3326
private final Integer proxyPort = Integer.getInteger("proxyPort");
3427
private final String proxyDetails = String.format("%s:%d", proxyHostname, proxyPort);
35-
private static String browser="firefox";
3628

3729

3830
@PostConstruct
3931
public void systemPath() throws IOException {
4032

41-
System.out.println(artist);
42-
4333
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");
4535
} else if (workingOS.contains("mac")) {
4636
System.setProperty("webdriver.chrome.driver", "selenium_browser_drivers/macChromedriver/chromedriver");
4737
} else if (workingOS.contains("linux")) {
@@ -75,26 +65,29 @@ public BrowserDriverExtended.ChromeDriverExtended chrome() {
7565
return new BrowserDriverExtended.ChromeDriverExtended(BrowserCapabilities.newInstance().getChromeCapabilities());
7666
}
7767

78-
private static class FirefoxCondition implements Condition {
68+
private static class FirefoxCondition implements Condition {
7969
@Override
8070
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("");
8273
}
8374

8475
}
8576

8677
private static class ChromeCondition implements Condition {
8778
@Override
8879
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
89-
return browser.contentEquals("chrome");
80+
Environment env =context.getEnvironment();
81+
return env.getProperty("browser").equalsIgnoreCase("chrome");
9082
}
9183

9284
}
9385

9486
private static class IECondition implements Condition {
9587
@Override
9688
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
97-
return browser.contentEquals("IE");
89+
Environment env =context.getEnvironment();
90+
return env.getProperty("browser").equalsIgnoreCase("IE");
9891
}
9992
}
10093

@@ -104,8 +97,6 @@ static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
10497
return new PropertySourcesPlaceholderConfigurer();
10598
}
10699

107-
108-
109100
}
110101

111102

src/test/resources/app.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
browser= firefox
1+
browser= chrome

0 commit comments

Comments
 (0)