Skip to content

Commit 4fd2b7f

Browse files
committed
Refactored DriverType/DriverSetup to provide a lot more readability and scalability in terms of browsers & remotes.
Included the library ngWebDriver to provide libraries for AngularJS support.
1 parent be04c6a commit 4fd2b7f

File tree

17 files changed

+586
-375
lines changed

17 files changed

+586
-375
lines changed

pom.xml

100755100644
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@
130130
<artifactId>aspectjweaver</artifactId>
131131
<version>1.8.5</version>
132132
</dependency>
133+
<dependency>
134+
<groupId>com.paulhammant</groupId>
135+
<artifactId>ngwebdriver</artifactId>
136+
<version>0.9.1</version>
137+
<scope>test</scope>
138+
</dependency>
133139
</dependencies>
134140

135141
<repositories>

src/main/java/com/frameworkium/capture/ScreenshotCapture.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.URL;
55
import java.net.UnknownHostException;
66

7+
import com.frameworkium.config.DriverSetup;
78
import org.apache.logging.log4j.LogManager;
89
import org.apache.logging.log4j.Logger;
910
import org.openqa.selenium.OutputType;
@@ -74,7 +75,7 @@ private void initExecution(CreateExecution createExecutionMessage) {
7475
private String getNode(WebDriver webdriver) {
7576

7677
String node = "n/a";
77-
if (DriverType.useRemoteWebDriver) {
78+
if (DriverSetup.useRemoteDriver()) {
7879
try {
7980
RemoteWebDriver r = ((WebDriverWrapper) webdriver).getWrappedRemoteWebDriver();
8081
URL gridURL = new URL(SystemProperty.GRID_URL.getValue());
Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,131 @@
11
package com.frameworkium.config;
22

3-
import org.openqa.selenium.WebDriver;
4-
import org.openqa.selenium.remote.DesiredCapabilities;
3+
import com.frameworkium.config.browsers.*;
4+
import com.frameworkium.config.remotes.BrowserStack;
5+
import com.frameworkium.config.remotes.Sauce;
6+
import org.apache.logging.log4j.LogManager;
7+
import org.apache.logging.log4j.Logger;
58

6-
public interface DriverSetup {
9+
import static com.frameworkium.config.SystemProperty.*;
710

8-
WebDriver getWebDriverObject(DesiredCapabilities desiredCapabilities);
11+
public class DriverSetup {
912

10-
DesiredCapabilities getDesiredCapabilities();
13+
private static final SupportedBrowsers DEFAULT_BROWSER = SupportedBrowsers.FIREFOX;
14+
15+
/**
16+
* List of supported browsers
17+
*/
18+
private static enum SupportedBrowsers {
19+
FIREFOX,CHROME,OPERA,IE,PHANTOMJS,SAFARI
20+
}
21+
22+
/**
23+
* List of supported remote grids
24+
*/
25+
private static enum SupportedRemotes {
26+
SAUCE,BROWSERSTACK,GRID
27+
}
28+
29+
/**
30+
* List of supported platforms on remote grids
31+
*/
32+
public static enum SupportedPlatforms {
33+
IOS,ANDROID,BROWSER
34+
}
35+
36+
protected final static Logger logger = LogManager.getLogger(DriverType.class);
37+
38+
/**
39+
* Returns the driver type to the base test, which initialises it
40+
*
41+
* @return - Driver Type
42+
*/
43+
public static DriverType returnDesiredDriverType() {
44+
return initialiseDesiredDriverType();
45+
}
46+
47+
/**
48+
* Uses the paramaters given to determine which browser/remote/platform to use
49+
*
50+
* @return - The correct driver type based on parameters
51+
*/
52+
private static DriverType initialiseDesiredDriverType() {
53+
if (useRemoteDriver()) {
54+
SupportedPlatforms platform = returnPlatformType();
55+
switch(returnRemoteType()) {
56+
case SAUCE:
57+
return new SauceImpl(platform);
58+
case BROWSERSTACK:
59+
return new BrowserStackImpl(platform);
60+
case GRID:
61+
return new GridImpl();
62+
}
63+
}
64+
else {
65+
switch (returnBrowserType()) {
66+
case FIREFOX:
67+
return new FirefoxImpl();
68+
case CHROME:
69+
return new ChromeImpl();
70+
case OPERA:
71+
return new OperaImpl();
72+
case IE:
73+
return new InternetExporerImpl();
74+
case PHANTOMJS:
75+
return new PhantomJSImpl();
76+
case SAFARI:
77+
return new SafariImpl();
78+
}
79+
}
80+
return null;
81+
}
82+
83+
/**
84+
* Checks whether a remote driver is wanting to be used
85+
*
86+
* @return - True/False to whether to use a remote driver
87+
*/
88+
public static boolean useRemoteDriver() {
89+
return GRID_URL.isSpecified() || Sauce.isDesired() || BrowserStack.isDesired();
90+
}
91+
92+
/**
93+
* Returns the platform type, if it's been given
94+
*
95+
* @return - Platform type
96+
*/
97+
private static SupportedPlatforms returnPlatformType() {
98+
return SupportedPlatforms.valueOf(SystemProperty.PLATFORM.getValue().toUpperCase());
99+
}
100+
101+
/**
102+
* Returns the browser type and returns default if not specified
103+
*
104+
* @return - Browser Type
105+
*/
106+
private static SupportedBrowsers returnBrowserType() {
107+
if (!SystemProperty.BROWSER.isSpecified()) {
108+
return DEFAULT_BROWSER;
109+
}
110+
else {
111+
return SupportedBrowsers.valueOf(SystemProperty.BROWSER.getValue().toUpperCase());
112+
}
113+
}
114+
115+
/**
116+
* Returns what type of remote driver has been specified to be used
117+
*
118+
* @return - Remote Driver Type
119+
*/
120+
private static SupportedRemotes returnRemoteType() {
121+
if (Sauce.isDesired()) {
122+
return SupportedRemotes.SAUCE;
123+
}
124+
else if (BrowserStack.isDesired()) {
125+
return SupportedRemotes.BROWSERSTACK;
126+
}
127+
else {
128+
return SupportedRemotes.GRID;
129+
}
130+
}
11131
}

0 commit comments

Comments
 (0)