Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.frameworkium</groupId>
<artifactId>Frameworkium-core</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>

<name>Frameworkium-core</name>
<description>Frameworkium core code. Referenced by the com.frameworkium project, with example tests.</description>
Expand Down Expand Up @@ -121,9 +121,9 @@
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/frameworkium/config/DriverSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum SupportedPlatforms {
*
* @return - Driver Type
*/
public static DriverType returnDesiredDriverType() {
public DriverType returnDesiredDriverType() {
return initialiseDesiredDriverType();
}

Expand All @@ -50,7 +50,7 @@ public static DriverType returnDesiredDriverType() {
*
* @return - The correct driver type based on parameters
*/
private static DriverType initialiseDesiredDriverType() throws NullPointerException {
private DriverType initialiseDesiredDriverType() throws NullPointerException {
DriverType browserDriver = returnBrowserObject();
DesiredCapabilities browserDesiredCapabilities = browserDriver.getDesiredCapabilities();
if (useRemoteDriver()) {
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/com/frameworkium/config/DriverType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public abstract class DriverType {

private static WebDriverWrapper webDriverWrapper;
private WebDriverWrapper webDriverWrapper;

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

Expand Down Expand Up @@ -61,7 +61,7 @@ public static boolean isMobile() {
public void maximiseBrowserWindow() {
if (!MAXIMISE.isSpecified() || Boolean.parseBoolean(MAXIMISE.getValue())) {
if((!useRemoteDriver() && !isNative()) || GRID_URL.isSpecified()) {
webDriverWrapper.getWrappedDriver().manage().window().maximize();
webDriverWrapper.manage().window().maximize();
}
}
}
Expand All @@ -70,15 +70,7 @@ public void maximiseBrowserWindow() {
* Method to tear down the driver object, can be overiden
*/
public void tearDownDriver() {
if(isNative()) {
webDriverWrapper.getWrappedAppiumDriver().quit();
}
if(useRemoteDriver()) {
webDriverWrapper.getWrappedRemoteWebDriver().quit();
}
else {
webDriverWrapper.quit();
}
webDriverWrapper.getWrappedDriver().quit();
}

/**
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/com/frameworkium/tests/internal/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package com.frameworkium.tests.internal;

import java.lang.reflect.Method;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.frameworkium.config.DriverSetup;
import com.frameworkium.config.DriverType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.SessionNotFoundException;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.*;

import ru.yandex.qatools.allure.annotations.Issue;
import ru.yandex.qatools.allure.annotations.TestCaseId;
Expand All @@ -35,11 +28,6 @@
import com.saucelabs.common.SauceOnDemandSessionIdProvider;
import com.saucelabs.testng.SauceOnDemandAuthenticationProvider;

import static com.frameworkium.config.DriverSetup.returnDesiredDriverType;
import static com.frameworkium.config.DriverSetup.useRemoteDriver;
import static com.frameworkium.config.DriverType.isMobile;
import static com.frameworkium.config.SystemProperty.MAXIMISE;

@Listeners({CaptureListener.class, ScreenshotListener.class, MethodInterceptor.class, SauceLabsListener.class,
TestListener.class, ResultLoggerListener.class})

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

public static String userAgent;
Expand All @@ -61,12 +48,13 @@ public abstract class BaseTest implements SauceOnDemandSessionIdProvider, SauceO
* - Initialise the screenshot capture
* - Configure the browser based on paramaters (maximise window, session resets, user agent)
*/
@BeforeSuite(alwaysRun = true)
@BeforeSuite
public static void instantiateDriverObject() {
driverType = new ThreadLocal<DriverType>() {
@Override
protected DriverType initialValue() {
DriverType driverType = returnDesiredDriverType();
DriverType driverType = new DriverSetup()
.returnDesiredDriverType();
driverType.instantiate();
activeDriverTypes.add(driverType);
return driverType;
Expand All @@ -84,16 +72,29 @@ protected ScreenshotCapture initialValue() {
return null;
}
};
}

/**
* The methods which configure the browser once a test runs
* - Maximises browser based on the driver type
* - Initialises screenshot capture if needed
* - Clears the session if another test ran prior
* - Sets the user agent of the browser
*
* @param testMethod - The test method name of the test
*/
@BeforeMethod
public static void configureBrowserBeforeTest(Method testMethod) {
configureDriverBasedOnParams();
initialiseNewScreenshotCapture(testMethod);
}

/**
* Initialise the screenshot capture and link to issue/test case id
*
* @param testMethod - Test method passed from the test script
*/
@BeforeMethod
public static void initialiseNewScreenshotCapture(Method testMethod) {
private static void initialiseNewScreenshotCapture(Method testMethod) {
if (ScreenshotCapture.isRequired()) {
String testID = "n/a";
try {
Expand All @@ -111,7 +112,6 @@ public static void initialiseNewScreenshotCapture(Method testMethod) {
} catch (NullPointerException e) {
logger.debug("No Test Case ID defined.");
}

capture.set(new ScreenshotCapture(testID, driverType.get().getDriver()));
}
}
Expand Down Expand Up @@ -144,14 +144,14 @@ private static void setUserAgent() {
/**
* Loops through all active driver types and tears down the driver object
*/
@AfterSuite(alwaysRun = true)
@AfterSuite
public static void closeDriverObject() {
for (DriverType driverType : activeDriverTypes) {
try {
try {
for (DriverType driverType : activeDriverTypes) {
driverType.tearDownDriver();
} catch (Exception e) {
logger.warn("Session quit unexpectedly.", e);
}
} catch (Exception e) {
logger.warn("Session quit unexpectedly.", e);
}
}

Expand All @@ -177,7 +177,7 @@ public String getSessionId() {
*/
private static String getUserAgent() {
String ua;
JavascriptExecutor js = (JavascriptExecutor)getDriver();
JavascriptExecutor js = getDriver();
try {
ua = (String) js.executeScript("return navigator.userAgent;");
} catch (Exception e) {
Expand Down