Skip to content

Commit a1e85c5

Browse files
committed
Merge pull request #12 from robertgates55/develop
Fixed threading
2 parents 30f2a9a + ee33b3c commit a1e85c5

File tree

4 files changed

+36
-44
lines changed

4 files changed

+36
-44
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
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.1.0</version>
6+
<version>1.1.1</version>
77

88
<name>Frameworkium-core</name>
99
<description>Frameworkium core code. Referenced by the com.frameworkium project, with example tests.</description>
@@ -121,9 +121,9 @@
121121
<version>2.4.0</version>
122122
</dependency>
123123
<dependency>
124-
<groupId>joda-time</groupId>
125-
<artifactId>joda-time</artifactId>
126-
<version>2.7</version>
124+
<groupId>joda-time</groupId>
125+
<artifactId>joda-time</artifactId>
126+
<version>2.7</version>
127127
</dependency>
128128
<dependency>
129129
<groupId>org.aspectj</groupId>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public enum SupportedPlatforms {
4141
*
4242
* @return - Driver Type
4343
*/
44-
public static DriverType returnDesiredDriverType() {
44+
public DriverType returnDesiredDriverType() {
4545
return initialiseDesiredDriverType();
4646
}
4747

@@ -50,7 +50,7 @@ public static DriverType returnDesiredDriverType() {
5050
*
5151
* @return - The correct driver type based on parameters
5252
*/
53-
private static DriverType initialiseDesiredDriverType() throws NullPointerException {
53+
private DriverType initialiseDesiredDriverType() throws NullPointerException {
5454
DriverType browserDriver = returnBrowserObject();
5555
DesiredCapabilities browserDesiredCapabilities = browserDriver.getDesiredCapabilities();
5656
if (useRemoteDriver()) {

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public abstract class DriverType {
1616

17-
private static WebDriverWrapper webDriverWrapper;
17+
private WebDriverWrapper webDriverWrapper;
1818

1919
protected final static Logger logger = LogManager.getLogger(DriverType.class);
2020

@@ -61,7 +61,7 @@ public static boolean isMobile() {
6161
public void maximiseBrowserWindow() {
6262
if (!MAXIMISE.isSpecified() || Boolean.parseBoolean(MAXIMISE.getValue())) {
6363
if((!useRemoteDriver() && !isNative()) || GRID_URL.isSpecified()) {
64-
webDriverWrapper.getWrappedDriver().manage().window().maximize();
64+
webDriverWrapper.manage().window().maximize();
6565
}
6666
}
6767
}
@@ -70,15 +70,7 @@ public void maximiseBrowserWindow() {
7070
* Method to tear down the driver object, can be overiden
7171
*/
7272
public void tearDownDriver() {
73-
if(isNative()) {
74-
webDriverWrapper.getWrappedAppiumDriver().quit();
75-
}
76-
if(useRemoteDriver()) {
77-
webDriverWrapper.getWrappedRemoteWebDriver().quit();
78-
}
79-
else {
80-
webDriverWrapper.quit();
81-
}
73+
webDriverWrapper.getWrappedDriver().quit();
8274
}
8375

8476
/**

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
package com.frameworkium.tests.internal;
22

33
import java.lang.reflect.Method;
4-
import java.sql.Driver;
54
import java.util.ArrayList;
6-
import java.util.Collections;
75
import java.util.List;
86

7+
import com.frameworkium.config.DriverSetup;
98
import com.frameworkium.config.DriverType;
109
import org.apache.logging.log4j.LogManager;
1110
import org.apache.logging.log4j.Logger;
1211
import org.openqa.selenium.JavascriptExecutor;
13-
import org.openqa.selenium.WebDriver;
14-
import org.openqa.selenium.remote.RemoteWebDriver;
1512
import org.openqa.selenium.remote.SessionId;
16-
import org.openqa.selenium.remote.SessionNotFoundException;
17-
import org.testng.annotations.AfterSuite;
18-
import org.testng.annotations.BeforeMethod;
19-
import org.testng.annotations.BeforeSuite;
20-
import org.testng.annotations.Listeners;
13+
import org.testng.annotations.*;
2114

2215
import ru.yandex.qatools.allure.annotations.Issue;
2316
import ru.yandex.qatools.allure.annotations.TestCaseId;
@@ -35,11 +28,6 @@
3528
import com.saucelabs.common.SauceOnDemandSessionIdProvider;
3629
import com.saucelabs.testng.SauceOnDemandAuthenticationProvider;
3730

38-
import static com.frameworkium.config.DriverSetup.returnDesiredDriverType;
39-
import static com.frameworkium.config.DriverSetup.useRemoteDriver;
40-
import static com.frameworkium.config.DriverType.isMobile;
41-
import static com.frameworkium.config.SystemProperty.MAXIMISE;
42-
4331
@Listeners({CaptureListener.class, ScreenshotListener.class, MethodInterceptor.class, SauceLabsListener.class,
4432
TestListener.class, ResultLoggerListener.class})
4533

@@ -48,8 +36,7 @@ public abstract class BaseTest implements SauceOnDemandSessionIdProvider, SauceO
4836
private static ThreadLocal<Boolean> requiresReset;
4937
private static ThreadLocal<ScreenshotCapture> capture;
5038
private static ThreadLocal<DriverType> driverType;
51-
private static List<DriverType> activeDriverTypes
52-
= Collections.synchronizedList(new ArrayList<DriverType>());
39+
private static List<DriverType> activeDriverTypes = new ArrayList<>();
5340
private static Logger logger = LogManager.getLogger(BaseTest.class);
5441

5542
public static String userAgent;
@@ -61,12 +48,13 @@ public abstract class BaseTest implements SauceOnDemandSessionIdProvider, SauceO
6148
* - Initialise the screenshot capture
6249
* - Configure the browser based on paramaters (maximise window, session resets, user agent)
6350
*/
64-
@BeforeSuite(alwaysRun = true)
51+
@BeforeSuite
6552
public static void instantiateDriverObject() {
6653
driverType = new ThreadLocal<DriverType>() {
6754
@Override
6855
protected DriverType initialValue() {
69-
DriverType driverType = returnDesiredDriverType();
56+
DriverType driverType = new DriverSetup()
57+
.returnDesiredDriverType();
7058
driverType.instantiate();
7159
activeDriverTypes.add(driverType);
7260
return driverType;
@@ -84,16 +72,29 @@ protected ScreenshotCapture initialValue() {
8472
return null;
8573
}
8674
};
75+
}
76+
77+
/**
78+
* The methods which configure the browser once a test runs
79+
* - Maximises browser based on the driver type
80+
* - Initialises screenshot capture if needed
81+
* - Clears the session if another test ran prior
82+
* - Sets the user agent of the browser
83+
*
84+
* @param testMethod - The test method name of the test
85+
*/
86+
@BeforeMethod
87+
public static void configureBrowserBeforeTest(Method testMethod) {
8788
configureDriverBasedOnParams();
89+
initialiseNewScreenshotCapture(testMethod);
8890
}
8991

9092
/**
9193
* Initialise the screenshot capture and link to issue/test case id
9294
*
9395
* @param testMethod - Test method passed from the test script
9496
*/
95-
@BeforeMethod
96-
public static void initialiseNewScreenshotCapture(Method testMethod) {
97+
private static void initialiseNewScreenshotCapture(Method testMethod) {
9798
if (ScreenshotCapture.isRequired()) {
9899
String testID = "n/a";
99100
try {
@@ -111,7 +112,6 @@ public static void initialiseNewScreenshotCapture(Method testMethod) {
111112
} catch (NullPointerException e) {
112113
logger.debug("No Test Case ID defined.");
113114
}
114-
115115
capture.set(new ScreenshotCapture(testID, driverType.get().getDriver()));
116116
}
117117
}
@@ -144,14 +144,14 @@ private static void setUserAgent() {
144144
/**
145145
* Loops through all active driver types and tears down the driver object
146146
*/
147-
@AfterSuite(alwaysRun = true)
147+
@AfterSuite
148148
public static void closeDriverObject() {
149-
for (DriverType driverType : activeDriverTypes) {
150-
try {
149+
try {
150+
for (DriverType driverType : activeDriverTypes) {
151151
driverType.tearDownDriver();
152-
} catch (Exception e) {
153-
logger.warn("Session quit unexpectedly.", e);
154152
}
153+
} catch (Exception e) {
154+
logger.warn("Session quit unexpectedly.", e);
155155
}
156156
}
157157

@@ -177,7 +177,7 @@ public String getSessionId() {
177177
*/
178178
private static String getUserAgent() {
179179
String ua;
180-
JavascriptExecutor js = (JavascriptExecutor)getDriver();
180+
JavascriptExecutor js = getDriver();
181181
try {
182182
ua = (String) js.executeScript("return navigator.userAgent;");
183183
} catch (Exception e) {

0 commit comments

Comments
 (0)