Skip to content

Commit 7a345fe

Browse files
committed
[master] - created EnvironmentConstants class
1 parent 7cded70 commit 7a345fe

File tree

4 files changed

+88
-58
lines changed

4 files changed

+88
-58
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package environment;
2+
3+
public class EnvironmentConstants {
4+
public static final String IS_MOBILE = "IS_MOBILE";
5+
public static final String IS_LOCAL = "IS_LOCAL";
6+
public static final String IS_REMOTE = "IS_REMOTE";
7+
public static final String IS_HEADLESS = "IS_HEADLESS";
8+
public static final String IS_SAUCE = "IS_SAUCE";
9+
public static final String BROWSER = "BROWSER";
10+
public static final String PLATFORM = "PLATFORM";
11+
public static final String EXECUTOR = "EXECUTOR";
12+
public static final String PLATFORM_VERSION = "PLATFORM_VERSION";
13+
public static final String PHANTOM_JS_PATH = "PHANTOM_JS_PATH";
14+
public static final String DEVICE = "DEVICE";
15+
public static final String MOBILE_DEVICE_EMULATION = "MOBILE_DEVICE_EMULATION";
16+
public static final String NAME = "NAME";
17+
public static final String APP_PACKAGE = "APP_PACKAGE";
18+
public static final String APP_ACTIVITY = "APP_ACTIVITY";
19+
public static final String APP = "APP";
20+
public static final String AUTOMATION_NAME = "AUTOMATION_NAME";
21+
public static final String APPIUM_VERSION = "APPIUM_VERSION";
22+
public static final String UDID = "UDID";
23+
public static final String MOBILE_BROWSER = "MOBILE_BROWSER";
24+
public static final String NEW_COMMAND_TIMEOUT = "NEW_COMMAND_TIMEOUT";
25+
public static final String SL_DESKTOP_PLATFORM = "SL_DESKTOP_PLATFORM";
26+
public static final String SL_BROWSER_VERSION = "SL_BROWSER_VERSION";
27+
public static final String SL_DESKTOP_RESOLUTION = "SL_DESKTOP_RESOLUTION";
28+
}

src/main/java/environment/EnvironmentFactory.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,131 +5,130 @@ public class EnvironmentFactory {
55
private static String BROWSER;
66

77
public static boolean isMobile() {
8-
String IS_MOBILE = System.getenv("IS_MOBILE") != null ? System.getenv("IS_MOBILE") : System.getProperty("IS_MOBILE");
8+
String IS_MOBILE = System.getenv(EnvironmentConstants.IS_MOBILE) != null ? System.getenv(EnvironmentConstants.IS_MOBILE) : System.getProperty(EnvironmentConstants.IS_MOBILE);
99
return IS_MOBILE != null && IS_MOBILE.toUpperCase().equals("TRUE");
1010
}
1111

1212
public static boolean isLocal() {
13-
String IS_LOCAL = System.getenv("IS_LOCAL") != null ? System.getenv("IS_LOCAL") : System.getProperty("IS_LOCAL");
13+
String IS_LOCAL = System.getenv(EnvironmentConstants.IS_LOCAL) != null ? System.getenv(EnvironmentConstants.IS_LOCAL) : System.getProperty(EnvironmentConstants.IS_LOCAL);
1414
return IS_LOCAL != null && IS_LOCAL.toUpperCase().equals("TRUE");
1515
}
1616

1717
public static boolean isRemote() {
18-
String IS_REMOTE = System.getenv("IS_REMOTE") != null ? System.getenv("IS_REMOTE") : System.getProperty("IS_REMOTE");
18+
String IS_REMOTE = System.getenv(EnvironmentConstants.IS_REMOTE) != null ? System.getenv(EnvironmentConstants.IS_REMOTE) : System.getProperty(EnvironmentConstants.IS_REMOTE);
1919
return IS_REMOTE != null && IS_REMOTE.toUpperCase().equals("TRUE");
2020
}
2121

2222
public static boolean isHeadless() {
23-
24-
String IS_HEADLESS = System.getenv("IS_HEADLESS") != null ? System.getenv("IS_HEADLESS") : System.getProperty("IS_HEADLESS");
23+
String IS_HEADLESS = System.getenv(EnvironmentConstants.IS_HEADLESS) != null ? System.getenv(EnvironmentConstants.IS_HEADLESS) : System.getProperty(EnvironmentConstants.IS_HEADLESS);
2524
return IS_HEADLESS != null && IS_HEADLESS.toUpperCase().equals("TRUE");
2625
}
2726

2827
public static boolean isSauce() {
29-
String IS_SAUCE = System.getenv("IS_SAUCE") != null ? System.getenv("IS_SAUCE") : System.getProperty("IS_SAUCE");
28+
String IS_SAUCE = System.getenv(EnvironmentConstants.IS_SAUCE) != null ? System.getenv(EnvironmentConstants.IS_SAUCE) : System.getProperty(EnvironmentConstants.IS_SAUCE);
3029
return IS_SAUCE != null && IS_SAUCE.toUpperCase().equals("TRUE");
3130
}
3231

3332
public static boolean isFirefox() {
34-
BROWSER = System.getenv("BROWSER") != null ? System.getenv("BROWSER") : System.getProperty("BROWSER");
33+
BROWSER = System.getenv(EnvironmentConstants.BROWSER) != null ? System.getenv(EnvironmentConstants.BROWSER) : System.getProperty(EnvironmentConstants.BROWSER);
3534
return BROWSER != null && BROWSER.toUpperCase().equals("FIREFOX");
3635
}
3736

3837
public static boolean isChrome() {
39-
BROWSER = System.getenv("BROWSER") != null ? System.getenv("BROWSER") : System.getProperty("BROWSER");
38+
BROWSER = System.getenv(EnvironmentConstants.BROWSER) != null ? System.getenv(EnvironmentConstants.BROWSER) : System.getProperty(EnvironmentConstants.BROWSER);
4039
return BROWSER != null && BROWSER.toUpperCase().equals("CHROME");
4140
}
4241

4342
public static boolean isSafari() {
44-
BROWSER = System.getenv("BROWSER") != null ? System.getenv("BROWSER") : System.getProperty("BROWSER");
43+
BROWSER = System.getenv(EnvironmentConstants.BROWSER) != null ? System.getenv(EnvironmentConstants.BROWSER) : System.getProperty(EnvironmentConstants.BROWSER);
4544
return BROWSER != null && BROWSER.toUpperCase().equals("SAFARI");
4645
}
4746

4847
public static boolean isInternetExplorer() {
49-
BROWSER = System.getenv("BROWSER") != null ? System.getenv("BROWSER") : System.getProperty("BROWSER");
48+
BROWSER = System.getenv(EnvironmentConstants.BROWSER) != null ? System.getenv(EnvironmentConstants.BROWSER) : System.getProperty(EnvironmentConstants.BROWSER);
5049
return BROWSER != null && BROWSER.toUpperCase().equals("IE");
5150
}
5251

5352
public static boolean isAndroid() {
54-
String PLATFORM = System.getenv("PLATFORM") != null ? System.getenv("PLATFORM") : System.getProperty("PLATFORM");
53+
String PLATFORM = System.getenv(EnvironmentConstants.PLATFORM) != null ? System.getenv(EnvironmentConstants.PLATFORM) : System.getProperty(EnvironmentConstants.PLATFORM);
5554
return PLATFORM != null && PLATFORM.toUpperCase().equals("ANDROID");
5655
}
5756

5857
public static boolean isIOS() {
59-
String PLATFORM = System.getenv("PLATFORM") != null ? System.getenv("PLATFORM") : System.getProperty("PLATFORM");
58+
String PLATFORM = System.getenv(EnvironmentConstants.PLATFORM) != null ? System.getenv(EnvironmentConstants.PLATFORM) : System.getProperty(EnvironmentConstants.PLATFORM);
6059
return PLATFORM != null && PLATFORM.toUpperCase().equals("IOS");
6160
}
6261

6362
public static String getRemoteUrlPath() {
64-
return System.getenv("EXECUTOR") != null ? System.getenv("EXECUTOR") : System.getProperty("EXECUTOR");
63+
return System.getenv(EnvironmentConstants.EXECUTOR) != null ? System.getenv(EnvironmentConstants.EXECUTOR) : System.getProperty(EnvironmentConstants.EXECUTOR);
6564
}
6665

6766
public static String getPlatformVersion() {
68-
return System.getenv("PLATFORM_VERSION") != null ? System.getenv("PLATFORM_VERSION") : System.getProperty("PLATFORM_VERSION");
67+
return System.getenv(EnvironmentConstants.PLATFORM_VERSION) != null ? System.getenv(EnvironmentConstants.PLATFORM_VERSION) : System.getProperty(EnvironmentConstants.PLATFORM_VERSION);
6968
}
7069

7170
public static String getPhantomJsPath() {
72-
return System.getenv("PHANTOM_JS_PATH") != null ? System.getenv("PHANTOM_JS_PATH") : System.getProperty("PHANTOM_JS_PATH");
71+
return System.getenv(EnvironmentConstants.PHANTOM_JS_PATH) != null ? System.getenv(EnvironmentConstants.PHANTOM_JS_PATH) : System.getProperty(EnvironmentConstants.PHANTOM_JS_PATH);
7372
}
7473

7574
public static String getDevice() {
76-
return System.getenv("DEVICE") != null ? System.getenv("DEVICE") : System.getProperty("DEVICE");
75+
return System.getenv(EnvironmentConstants.DEVICE) != null ? System.getenv(EnvironmentConstants.DEVICE) : System.getProperty(EnvironmentConstants.DEVICE);
7776
}
7877

7978
public static String getMobileDeviveEmulation() {
80-
return System.getenv("MOBILE_DEVICE_EMULATION") != null ? System.getenv("MOBILE_DEVICE_EMULATION") : System.getProperty("MOBILE_DEVICE_EMULATION");
79+
return System.getenv(EnvironmentConstants.MOBILE_DEVICE_EMULATION) != null ? System.getenv(EnvironmentConstants.MOBILE_DEVICE_EMULATION) : System.getProperty(EnvironmentConstants.MOBILE_DEVICE_EMULATION);
8180
}
8281

8382
public static String getName() {
84-
return System.getenv("NAME") != null ? System.getenv("NAME") : System.getProperty("NAME");
83+
return System.getenv(EnvironmentConstants.NAME) != null ? System.getenv(EnvironmentConstants.NAME) : System.getProperty(EnvironmentConstants.NAME);
8584
}
8685

8786
public static String getBrowserName() {
88-
BROWSER = System.getenv("BROWSER") != null ? System.getenv("BROWSER") : System.getProperty("BROWSER");
87+
BROWSER = System.getenv(EnvironmentConstants.BROWSER) != null ? System.getenv(EnvironmentConstants.BROWSER) : System.getProperty(EnvironmentConstants.BROWSER);
8988
return BROWSER;
9089
}
9190

9291
public static String getAppPackage() {
93-
return System.getenv("APP_PACKAGE") != null ? System.getenv("APP_PACKAGE") : System.getProperty("APP_PACKAGE");
92+
return System.getenv(EnvironmentConstants.APP_PACKAGE) != null ? System.getenv(EnvironmentConstants.APP_PACKAGE) : System.getProperty(EnvironmentConstants.APP_PACKAGE);
9493
}
9594

9695
public static String getAppActivity() {
97-
return System.getenv("APP_ACTIVITY") != null ? System.getenv("APP_ACTIVITY") : System.getProperty("APP_ACTIVITY");
96+
return System.getenv(EnvironmentConstants.APP_ACTIVITY) != null ? System.getenv(EnvironmentConstants.APP_ACTIVITY) : System.getProperty(EnvironmentConstants.APP_ACTIVITY);
9897
}
9998

10099
public static String getApp() {
101-
return System.getenv("APP") != null ? System.getenv("APP") : System.getProperty("APP");
100+
return System.getenv(EnvironmentConstants.APP) != null ? System.getenv(EnvironmentConstants.APP) : System.getProperty(EnvironmentConstants.APP);
102101
}
103102

104103
public static String getAutomationName() {
105-
return System.getenv("AUTOMATION_NAME") != null ? System.getenv("AUTOMATION_NAME") : System.getProperty("AUTOMATION_NAME");
104+
return System.getenv(EnvironmentConstants.AUTOMATION_NAME) != null ? System.getenv(EnvironmentConstants.AUTOMATION_NAME) : System.getProperty(EnvironmentConstants.AUTOMATION_NAME);
106105
}
107106

108107
public static String getAppiumVersion() {
109-
return System.getenv("APPIUM_VERSION") != null ? System.getenv("APPIUM_VERSION") : System.getProperty("APPIUM_VERSION");
108+
return System.getenv(EnvironmentConstants.APPIUM_VERSION) != null ? System.getenv(EnvironmentConstants.APPIUM_VERSION) : System.getProperty(EnvironmentConstants.APPIUM_VERSION);
110109
}
111110

112111
public static String getUDIDDevice() {
113-
return System.getenv("UDID") != null ? System.getenv("UDID") : System.getProperty("UDID");
112+
return System.getenv(EnvironmentConstants.UDID) != null ? System.getenv(EnvironmentConstants.UDID) : System.getProperty(EnvironmentConstants.UDID);
114113
}
115114

116115
public static String getMobileBrowser() {
117-
return System.getenv("MOBILE_BROWSER") != null ? System.getenv("MOBILE_BROWSER") : System.getProperty("MOBILE_BROWSER");
116+
return System.getenv(EnvironmentConstants.MOBILE_BROWSER) != null ? System.getenv(EnvironmentConstants.MOBILE_BROWSER) : System.getProperty(EnvironmentConstants.MOBILE_BROWSER);
118117
}
119118

120119
public static String getNewCommandTimeout() {
121-
return System.getenv("NEW_COMMAND_TIMEOUT") != null ? System.getenv("NEW_COMMAND_TIMEOUT") : System.getProperty("NEW_COMMAND_TIMEOUT");
120+
return System.getenv(EnvironmentConstants.NEW_COMMAND_TIMEOUT) != null ? System.getenv(EnvironmentConstants.NEW_COMMAND_TIMEOUT) : System.getProperty(EnvironmentConstants.NEW_COMMAND_TIMEOUT);
122121
}
123122

124123
public static String getSlDesktopPlatform() {
125-
return System.getenv("SL_DESKTOP_PLATFORM") != null ? System.getenv("SL_DESKTOP_PLATFORM") : System.getProperty("SL_DESKTOP_PLATFORM");
124+
return System.getenv(EnvironmentConstants.SL_DESKTOP_PLATFORM) != null ? System.getenv(EnvironmentConstants.SL_DESKTOP_PLATFORM) : System.getProperty(EnvironmentConstants.SL_DESKTOP_PLATFORM);
126125
}
127126

128127
public static String getSlBrowserVersion() {
129-
return System.getenv("SL_BROWSER_VERSION") != null ? System.getenv("SL_BROWSER_VERSION") : System.getProperty("SL_BROWSER_VERSION");
128+
return System.getenv(EnvironmentConstants.SL_BROWSER_VERSION) != null ? System.getenv(EnvironmentConstants.SL_BROWSER_VERSION) : System.getProperty(EnvironmentConstants.SL_BROWSER_VERSION);
130129
}
131130

132131
public static String getSlDesktopResolution() {
133-
return System.getenv("SL_DESKTOP_RESOLUTION") != null ? System.getenv("SL_DESKTOP_RESOLUTION") : System.getProperty("SL_DESKTOP_RESOLUTION");
132+
return System.getenv(EnvironmentConstants.SL_DESKTOP_RESOLUTION) != null ? System.getenv(EnvironmentConstants.SL_DESKTOP_RESOLUTION) : System.getProperty(EnvironmentConstants.SL_DESKTOP_RESOLUTION);
134133
}
135134
}
Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package http.helpers;
22

3+
import environment.EnvironmentConstants;
4+
35
import java.util.Map;
46

57
public class EnvironmentHelper {
@@ -13,29 +15,29 @@ public static void setEnv(Map<String, String> newenv) {
1315
}
1416

1517
private static void clearAllProperties() {
16-
System.clearProperty("IS_LOCAL");
17-
System.clearProperty("IS_MOBILE");
18-
System.clearProperty("IS_REMOTE");
19-
System.clearProperty("IS_HEADLESS");
20-
System.clearProperty("PLATFORM");
21-
System.clearProperty("PHANTOM_JS_PATH");
22-
System.clearProperty("PLATFORM_VERSION");
23-
System.clearProperty("DEVICE");
24-
System.clearProperty("MOBILE_DEVICE_EMULATION");
25-
System.clearProperty("NAME");
26-
System.clearProperty("AUTOMATION_NAME");
27-
System.clearProperty("APP");
28-
System.clearProperty("APP_PACKAGE");
29-
System.clearProperty("APP_ACTIVITY");
30-
System.clearProperty("EXECUTOR");
31-
System.clearProperty("BROWSER");
32-
System.clearProperty("MOBILE_BROWSER");
33-
System.clearProperty("UDID");
34-
System.clearProperty("APPIUM_VERSION");
35-
System.clearProperty("IS_SAUCE");
36-
System.clearProperty("NEW_COMMAND_TIMEOUT");
37-
System.clearProperty("SL_DESKTOP_PLATFORM");
38-
System.clearProperty("SL_BROWSER_VERSION");
39-
System.clearProperty("SL_DESKTOP_RESOLUTION");
18+
System.clearProperty(EnvironmentConstants.IS_LOCAL);
19+
System.clearProperty(EnvironmentConstants.IS_MOBILE);
20+
System.clearProperty(EnvironmentConstants.IS_REMOTE);
21+
System.clearProperty(EnvironmentConstants.IS_HEADLESS);
22+
System.clearProperty(EnvironmentConstants.PLATFORM);
23+
System.clearProperty(EnvironmentConstants.PHANTOM_JS_PATH);
24+
System.clearProperty(EnvironmentConstants.PLATFORM_VERSION);
25+
System.clearProperty(EnvironmentConstants.DEVICE);
26+
System.clearProperty(EnvironmentConstants.MOBILE_DEVICE_EMULATION);
27+
System.clearProperty(EnvironmentConstants.NAME);
28+
System.clearProperty(EnvironmentConstants.AUTOMATION_NAME);
29+
System.clearProperty(EnvironmentConstants.APP);
30+
System.clearProperty(EnvironmentConstants.APP_PACKAGE);
31+
System.clearProperty(EnvironmentConstants.APP_ACTIVITY);
32+
System.clearProperty(EnvironmentConstants.EXECUTOR);
33+
System.clearProperty(EnvironmentConstants.BROWSER);
34+
System.clearProperty(EnvironmentConstants.MOBILE_BROWSER);
35+
System.clearProperty(EnvironmentConstants.UDID);
36+
System.clearProperty(EnvironmentConstants.APPIUM_VERSION);
37+
System.clearProperty(EnvironmentConstants.IS_SAUCE);
38+
System.clearProperty(EnvironmentConstants.NEW_COMMAND_TIMEOUT);
39+
System.clearProperty(EnvironmentConstants.SL_DESKTOP_PLATFORM);
40+
System.clearProperty(EnvironmentConstants.SL_BROWSER_VERSION);
41+
System.clearProperty(EnvironmentConstants.SL_DESKTOP_RESOLUTION);
4042
}
4143
}

src/test/java/EnvironmentFactoryTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import environment.EnvironmentConstants;
12
import environment.EnvironmentFactory;
23
import http.helpers.EnvironmentHelper;
34
import org.junit.Assert;
@@ -11,23 +12,23 @@ public class EnvironmentFactoryTest {
1112
@Test
1213
public void testThatEnvironmentPropertiesCouldBeSet(){
1314
Map<String, String> map = new HashMap<>();
14-
map.put("IS_LOCAL", "TRUE");
15+
map.put(EnvironmentConstants.IS_LOCAL, "TRUE");
1516
EnvironmentHelper.setEnv(map);
1617
Assert.assertTrue(EnvironmentFactory.isLocal());
1718
Assert.assertFalse(EnvironmentFactory.isMobile());
1819
Assert.assertFalse(EnvironmentFactory.isRemote());
1920
Assert.assertFalse(EnvironmentFactory.isHeadless());
2021

2122
map.clear();
22-
map.put("IS_MOBILE", "TRUE");
23+
map.put(EnvironmentConstants.IS_MOBILE, "TRUE");
2324
EnvironmentHelper.setEnv(map);
2425
Assert.assertFalse(EnvironmentFactory.isLocal());
2526
Assert.assertTrue(EnvironmentFactory.isMobile());
2627
Assert.assertFalse(EnvironmentFactory.isRemote());
2728
Assert.assertFalse(EnvironmentFactory.isHeadless());
2829

2930
map.clear();
30-
map.put("IS_REMOTE", "TRUE");
31+
map.put(EnvironmentConstants.IS_REMOTE, "TRUE");
3132
EnvironmentHelper.setEnv(map);
3233
Assert.assertFalse(EnvironmentFactory.isLocal());
3334
Assert.assertFalse(EnvironmentFactory.isMobile());
@@ -36,7 +37,7 @@ public void testThatEnvironmentPropertiesCouldBeSet(){
3637

3738

3839
map.clear();
39-
map.put("IS_HEADLESS", "TRUE");
40+
map.put(EnvironmentConstants.IS_HEADLESS, "TRUE");
4041
EnvironmentHelper.setEnv(map);
4142
Assert.assertFalse(EnvironmentFactory.isLocal());
4243
Assert.assertFalse(EnvironmentFactory.isMobile());

0 commit comments

Comments
 (0)