Skip to content

Commit ee32e58

Browse files
jleehU-SRP_IMPNET\JHuxtable
authored andcommitted
Had to refactor DriverType/DriverSetup further as browser configurations we're being missed on remote.
Fixed a null pointer issue.
1 parent a66f74a commit ee32e58

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

src/main/java/com/frameworkium/config/DriverSetup.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.frameworkium.config.remotes.Sauce;
66
import org.apache.logging.log4j.LogManager;
77
import org.apache.logging.log4j.Logger;
8+
import org.openqa.selenium.remote.DesiredCapabilities;
9+
import sun.security.krb5.internal.crypto.Des;
810

911
import static com.frameworkium.config.SystemProperty.*;
1012

@@ -49,33 +51,40 @@ public static DriverType returnDesiredDriverType() {
4951
*
5052
* @return - The correct driver type based on parameters
5153
*/
52-
private static DriverType initialiseDesiredDriverType() {
54+
private static DriverType initialiseDesiredDriverType() throws NullPointerException {
55+
DriverType browserDriver = returnBrowserObject();
56+
DesiredCapabilities browserDesiredCapabilities = browserDriver.getDesiredCapabilities();
5357
if (useRemoteDriver()) {
5458
SupportedPlatforms platform = returnPlatformType();
5559
switch(returnRemoteType()) {
5660
case SAUCE:
57-
return new SauceImpl(platform);
61+
return new SauceImpl(platform, browserDesiredCapabilities);
5862
case BROWSERSTACK:
59-
return new BrowserStackImpl(platform);
63+
return new BrowserStackImpl(platform, browserDesiredCapabilities);
6064
case GRID:
61-
return new GridImpl();
65+
return new GridImpl(browserDesiredCapabilities);
6266
}
6367
}
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-
}
68+
return browserDriver;
69+
}
70+
71+
/**
72+
* @return the browser driver type object based on the browser passed in
73+
*/
74+
private static DriverType returnBrowserObject() {
75+
switch (returnBrowserType()) {
76+
case FIREFOX:
77+
return new FirefoxImpl();
78+
case CHROME:
79+
return new ChromeImpl();
80+
case OPERA:
81+
return new OperaImpl();
82+
case IE:
83+
return new InternetExporerImpl();
84+
case PHANTOMJS:
85+
return new PhantomJSImpl();
86+
case SAFARI:
87+
return new SafariImpl();
7988
}
8089
return null;
8190
}
@@ -95,7 +104,12 @@ public static boolean useRemoteDriver() {
95104
* @return - Platform type
96105
*/
97106
private static SupportedPlatforms returnPlatformType() {
98-
return SupportedPlatforms.valueOf(SystemProperty.PLATFORM.getValue().toUpperCase());
107+
if (SystemProperty.PLATFORM.isSpecified()) {
108+
return SupportedPlatforms.valueOf(SystemProperty.PLATFORM.getValue().toUpperCase());
109+
}
110+
else {
111+
return null;
112+
}
99113
}
100114

101115
/**

src/main/java/com/frameworkium/config/DriverType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void maximiseBrowserWindow() {
6666
webDriverWrapper.getWrappedAppiumDriver().manage().window().maximize();
6767
}
6868
if(useRemoteDriver()) {
69-
webDriverWrapper.getWrappedRemoteWebDriver().quit();
69+
webDriverWrapper.getWrappedRemoteWebDriver().manage().window().maximize();
7070
}
7171
else {
7272
webDriverWrapper.getWrappedDriver().manage().window().maximize();

src/main/java/com/frameworkium/config/browsers/BrowserStackImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public class BrowserStackImpl extends DriverType {
1818

1919
private static URL remoteURL;
2020
private static SupportedPlatforms supportedPlatform;
21+
private static DesiredCapabilities desiredCapabilities;
2122

22-
public BrowserStackImpl(SupportedPlatforms platform) {
23+
public BrowserStackImpl(SupportedPlatforms platform, DesiredCapabilities browserDesiredCapabilities) {
2324
supportedPlatform = platform;
25+
desiredCapabilities = browserDesiredCapabilities;
2426
try {
2527
remoteURL = BrowserStack.getURL();
2628
}
@@ -30,7 +32,6 @@ public BrowserStackImpl(SupportedPlatforms platform) {
3032
}
3133

3234
public DesiredCapabilities getDesiredCapabilities() {
33-
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
3435
desiredCapabilities = setGeneralRemoteCapabilities(desiredCapabilities);
3536
desiredCapabilities = setCapabilitiesBasedOnPlatform(desiredCapabilities);
3637

src/main/java/com/frameworkium/config/browsers/GridImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
public class GridImpl extends DriverType {
1515

1616
private static URL remoteURL;
17+
private static DesiredCapabilities desiredCapabilities;
1718

18-
public GridImpl() {
19+
public GridImpl(DesiredCapabilities browserDesiredCapabilities) {
20+
desiredCapabilities = browserDesiredCapabilities;
1921
try {
2022
remoteURL = new URL(GRID_URL.getValue());
2123
}
@@ -25,7 +27,6 @@ public GridImpl() {
2527
}
2628

2729
public DesiredCapabilities getDesiredCapabilities() {
28-
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
2930
desiredCapabilities = setGeneralRemoteCapabilities(desiredCapabilities);
3031
return desiredCapabilities;
3132
}

src/main/java/com/frameworkium/config/browsers/SauceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.openqa.selenium.WebDriver;
88
import org.openqa.selenium.remote.DesiredCapabilities;
99
import org.openqa.selenium.remote.RemoteWebDriver;
10+
import sun.security.krb5.internal.crypto.Des;
1011

1112
import java.io.File;
1213
import java.net.MalformedURLException;
@@ -21,9 +22,11 @@ public class SauceImpl extends DriverType {
2122

2223
private static URL remoteURL;
2324
private static SupportedPlatforms supportedPlatforms;
25+
private static DesiredCapabilities desiredCapabilities;
2426

25-
public SauceImpl(SupportedPlatforms platform) {
27+
public SauceImpl(SupportedPlatforms platform, DesiredCapabilities browserDesiredCapabilities) {
2628
supportedPlatforms = platform;
29+
desiredCapabilities = browserDesiredCapabilities;
2730
try {
2831
remoteURL = Sauce.getURL();
2932
}
@@ -33,7 +36,6 @@ public SauceImpl(SupportedPlatforms platform) {
3336
}
3437

3538
public DesiredCapabilities getDesiredCapabilities() {
36-
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
3739
desiredCapabilities = setGeneralRemoteCapabilities(desiredCapabilities);
3840
desiredCapabilities = setCapabilitiesBasedOnPlatform(desiredCapabilities);
3941

src/main/java/com/frameworkium/listeners/ScreenshotListener.java

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

7+
import com.frameworkium.config.WebDriverWrapper;
78
import org.apache.logging.log4j.LogManager;
89
import org.apache.logging.log4j.Logger;
910
import org.openqa.selenium.OutputType;
@@ -68,7 +69,7 @@ private void takeScreenshot(String testName) {
6869
screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + testName + ".png";
6970
File screenshot = new File(absolutePath);
7071
if (createFile(screenshot)) {
71-
WebDriver driver = BaseTest.getDriver();
72+
WebDriverWrapper driver = BaseTest.getDriver();
7273
try {
7374
writeScreenshotToFile(driver, screenshot);
7475
} catch (ClassCastException weNeedToAugmentOurDriverObject) {

src/main/java/com/frameworkium/tests/internal/BaseTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import com.frameworkium.config.DriverType;
1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12+
import org.openqa.selenium.JavascriptExecutor;
1213
import org.openqa.selenium.WebDriver;
14+
import org.openqa.selenium.remote.RemoteWebDriver;
1315
import org.openqa.selenium.remote.SessionId;
1416
import org.openqa.selenium.remote.SessionNotFoundException;
1517
import org.testng.annotations.AfterSuite;
@@ -34,6 +36,8 @@
3436
import com.saucelabs.testng.SauceOnDemandAuthenticationProvider;
3537

3638
import static com.frameworkium.config.DriverSetup.returnDesiredDriverType;
39+
import static com.frameworkium.config.DriverSetup.useRemoteDriver;
40+
import static com.frameworkium.config.DriverType.isMobile;
3741
import static com.frameworkium.config.SystemProperty.MAXIMISE;
3842

3943
@Listeners({CaptureListener.class, ScreenshotListener.class, MethodInterceptor.class, SauceLabsListener.class,
@@ -157,12 +161,11 @@ public static void createAllureProperties() {
157161
AllureProperties.create();
158162
}
159163

160-
/**
161-
* @return the Job id for the current thread
162-
*/
164+
/** @return the Job id for the current thread */
163165
@Override
164166
public String getSessionId() {
165-
SessionId sessionId = getDriver().getWrappedRemoteWebDriver().getSessionId();
167+
WebDriverWrapper driver = getDriver();
168+
SessionId sessionId = driver.getWrappedRemoteWebDriver().getSessionId();
166169
return (sessionId == null) ? null : sessionId.toString();
167170
}
168171

@@ -172,8 +175,9 @@ public String getSessionId() {
172175
*/
173176
private static String getUserAgent() {
174177
String ua;
178+
JavascriptExecutor js = (JavascriptExecutor)getDriver();
175179
try {
176-
ua = (String) getDriver().executeScript("return navigator.userAgent;");
180+
ua = (String) js.executeScript("return navigator.userAgent;");
177181
} catch (Exception e) {
178182
ua = "Unable to fetch UserAgent";
179183
}

0 commit comments

Comments
 (0)