Skip to content

Commit 79d7e5f

Browse files
author
Nilesh Rakshe
committed
Added enum for project options
1 parent b868de3 commit 79d7e5f

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/main/java/com/mindstix/cb/utils/Constants.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,16 @@ public final class Constants {
1515
*/
1616
private Constants() {
1717
}
18+
19+
public static enum Platform {
20+
LOCAL, BROWSERSTACK, SAUCELABS
21+
}
22+
23+
public static enum Browser {
24+
CHROME, FIREFOX, IE
25+
}
26+
27+
public static enum Mode {
28+
NORMAL, HEADLESS, GRID, ICOGNITO
29+
}
1830
}

src/main/java/com/mindstix/cb/utils/DriverUtility.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ public static WebDriver loadDriver(String browserName) {
5252
InputStream driverInput = null;
5353
WebDriver webDriver = null;
5454
try {
55-
switch (System.getProperty("env.platform")) {
56-
case "local":
55+
String platform = System.getProperty("env.platform");
56+
switch (Constants.Platform.valueOf(platform.toUpperCase())) {
57+
case LOCAL:
5758
webDriver = initDriver(browserName);
5859
break;
59-
case "browserStack":
60+
case BROWSERSTACK:
6061
webDriver = initBrowserStack();
6162
break;
62-
case "sauceLabs":
63+
case SAUCELABS:
6364
webDriver = initSauceLabs();
6465
break;
6566
default:
@@ -94,14 +95,14 @@ public void closeWebDriver(WebDriver webDriver) {
9495
*/
9596
private static WebDriver initDriver(String browserType) {
9697
WebDriver webDriver;
97-
switch (browserType) {
98-
case "chrome":
98+
switch (Constants.Browser.valueOf(browserType.toUpperCase())) {
99+
case CHROME:
99100
webDriver = initChromeDriver();
100101
break;
101-
case "firefox":
102+
case FIREFOX:
102103
webDriver = initFirefoxDriver();
103104
break;
104-
case "IE":
105+
case IE:
105106
webDriver = initIEDriver();
106107
break;
107108
default:
@@ -122,19 +123,19 @@ private static WebDriver initChromeDriver() {
122123
ChromeOptions options = null;
123124
WebDriver webDriver = null;
124125
if (mode != null) {
125-
switch (mode) {
126-
case "normal":
126+
switch (Constants.Mode.valueOf(mode.toUpperCase())) {
127+
case NORMAL:
127128
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome();
128129
handlSSLErr.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
129130
webDriver = new ChromeDriver(handlSSLErr);
130131
break;
131-
case "headless":
132+
case HEADLESS:
132133
options = new ChromeOptions();
133134
options.addArguments("--headless");
134135
options.addArguments("--start-maximized");
135136
webDriver = new ChromeDriver(options);
136137
break;
137-
case "grid":
138+
case GRID:
138139
String hubIPAddress = System.getProperty("env.hubIP");
139140
DesiredCapabilities dc = DesiredCapabilities.chrome();
140141
try {
@@ -143,7 +144,7 @@ private static WebDriver initChromeDriver() {
143144
throw new RuntimeException(e.getMessage());
144145
}
145146
break;
146-
case "incognito":
147+
case ICOGNITO:
147148
options = new ChromeOptions();
148149
options.addArguments("--incognito");
149150
webDriver = new ChromeDriver(options);

0 commit comments

Comments
 (0)