Skip to content

Commit 80f12d8

Browse files
committed
Merge pull request #10 from robertgates55/develop
Full refactor of DriverType/Setup and SauceLabs/BrowserStack Implementation
2 parents 60faaf4 + 3a3da7f commit 80f12d8

20 files changed

+753
-452
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.frameworkium</groupId>
55
<artifactId>Frameworkium-core</artifactId>
6-
<version>1.0.3</version>
6+
<version>1.1.0</version>
77

88
<name>Frameworkium-core</name>
99
<description>Frameworkium core code. Referenced by the com.frameworkium project, with example tests.</description>
@@ -130,6 +130,11 @@
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+
</dependency>
133138
</dependencies>
134139

135140
<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: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,144 @@
11
package com.frameworkium.config;
22

3-
import org.openqa.selenium.WebDriver;
3+
import com.frameworkium.config.drivers.*;
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;
48
import org.openqa.selenium.remote.DesiredCapabilities;
59

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

8-
WebDriver getWebDriverObject(DesiredCapabilities desiredCapabilities);
12+
public class DriverSetup {
913

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

0 commit comments

Comments
 (0)