From 0720484dc3e2793690134ce5df6338dd07e21af6 Mon Sep 17 00:00:00 2001 From: jleeh Date: Thu, 20 Aug 2015 11:29:10 +0100 Subject: [PATCH 1/5] Fixed an issue with threading not working correctly. Bumped to version 1.1.1. --- pom.xml | 57 ++++++++++++++++++- .../com/frameworkium/config/DriverSetup.java | 4 +- .../com/frameworkium/config/DriverType.java | 14 +---- .../frameworkium/tests/internal/BaseTest.java | 46 +++++++-------- .../tests/web/TheInternetExampleTest.java | 17 ------ 5 files changed, 79 insertions(+), 59 deletions(-) delete mode 100644 src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java diff --git a/pom.xml b/pom.xml index fcb53a6d..2fe7bdb1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.frameworkium Frameworkium-core - 1.1.0 + 1.1.1 Frameworkium-core Frameworkium core code. Referenced by the com.frameworkium project, with example tests. @@ -27,6 +27,25 @@ + UTF-8 + local + + + + + + + + + + + + + + + + + 1.8.5 1.4.11 @@ -155,7 +174,7 @@ - com.frameworkium-core + selenium-tests true @@ -170,6 +189,40 @@ 1.7 + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + methods + ${threads} + + + ${env.config} + ${browser} + ${project.build.directory}/screenshots + ${seleniumGridURL} + ${platform} + ${platformVersion} + ${browserVersion} + ${device} + ${sauce} + ${browserStack} + ${maximise} + ${build} + ${appPath} + ${jiraURL} + ${jiraResultVersion} + ${allure.issues.tracker.pattern}/browse/%s + + + **/*Test.java + **/*Tests.java + + ${groups} + false + + diff --git a/src/main/java/com/frameworkium/config/DriverSetup.java b/src/main/java/com/frameworkium/config/DriverSetup.java index 55e3de11..776437fe 100644 --- a/src/main/java/com/frameworkium/config/DriverSetup.java +++ b/src/main/java/com/frameworkium/config/DriverSetup.java @@ -41,7 +41,7 @@ public enum SupportedPlatforms { * * @return - Driver Type */ - public static DriverType returnDesiredDriverType() { + public DriverType returnDesiredDriverType() { return initialiseDesiredDriverType(); } @@ -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()) { diff --git a/src/main/java/com/frameworkium/config/DriverType.java b/src/main/java/com/frameworkium/config/DriverType.java index 9ef17c70..5a69a652 100644 --- a/src/main/java/com/frameworkium/config/DriverType.java +++ b/src/main/java/com/frameworkium/config/DriverType.java @@ -14,7 +14,7 @@ public abstract class DriverType { - private static WebDriverWrapper webDriverWrapper; + private WebDriverWrapper webDriverWrapper; protected final static Logger logger = LogManager.getLogger(DriverType.class); @@ -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(); } } } @@ -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(); } /** diff --git a/src/main/java/com/frameworkium/tests/internal/BaseTest.java b/src/main/java/com/frameworkium/tests/internal/BaseTest.java index 57ed20fc..2cda636b 100644 --- a/src/main/java/com/frameworkium/tests/internal/BaseTest.java +++ b/src/main/java/com/frameworkium/tests/internal/BaseTest.java @@ -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; @@ -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}) @@ -48,8 +36,7 @@ public abstract class BaseTest implements SauceOnDemandSessionIdProvider, SauceO private static ThreadLocal requiresReset; private static ThreadLocal capture; private static ThreadLocal driverType; - private static List activeDriverTypes - = Collections.synchronizedList(new ArrayList()); + private static List activeDriverTypes = new ArrayList<>(); private static Logger logger = LogManager.getLogger(BaseTest.class); public static String userAgent; @@ -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() { @Override protected DriverType initialValue() { - DriverType driverType = returnDesiredDriverType(); + DriverType driverType = new DriverSetup() + .returnDesiredDriverType(); driverType.instantiate(); activeDriverTypes.add(driverType); return driverType; @@ -84,7 +72,12 @@ protected ScreenshotCapture initialValue() { return null; } }; + } + + @BeforeMethod + public static void configureBrowserBeforeTest(Method testMethod) { configureDriverBasedOnParams(); + initialiseNewScreenshotCapture(testMethod); } /** @@ -92,8 +85,8 @@ protected ScreenshotCapture initialValue() { * * @param testMethod - Test method passed from the test script */ - @BeforeMethod - public static void initialiseNewScreenshotCapture(Method testMethod) { + private static void initialiseNewScreenshotCapture(Method testMethod) { + configureDriverBasedOnParams(); if (ScreenshotCapture.isRequired()) { String testID = "n/a"; try { @@ -111,7 +104,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())); } } @@ -144,14 +136,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); } } @@ -177,7 +169,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) { diff --git a/src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java b/src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java deleted file mode 100644 index 9607e10f..00000000 --- a/src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.heroku.theinternet.tests.web; - -import static com.google.common.truth.Truth.assertThat; - -import com.frameworkium.tests.internal.BaseTest; -import com.heroku.theinternet.pages.web.WelcomePage; - -import org.testng.annotations.Test; - -public class TheInternetExampleTest extends BaseTest { - - @Test - public void basicAuth() { - - assertThat(WelcomePage.open().then().getTitle()).isEqualTo("The Internet"); - } -} \ No newline at end of file From 77c5e39f9f29fa60ceddaa69b58b414d86fcae75 Mon Sep 17 00:00:00 2001 From: jleeh Date: Thu, 20 Aug 2015 11:32:15 +0100 Subject: [PATCH 2/5] Removed debugging from the pom from looking into threading. --- pom.xml | 63 +++++---------------------------------------------------- 1 file changed, 5 insertions(+), 58 deletions(-) diff --git a/pom.xml b/pom.xml index 2fe7bdb1..f3974f2c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.frameworkium Frameworkium-core - 1.1.1 + 1.1.0 Frameworkium-core Frameworkium core code. Referenced by the com.frameworkium project, with example tests. @@ -27,25 +27,6 @@ - UTF-8 - local - - - - - - - - - - - - - - - - - 1.8.5 1.4.11 @@ -140,9 +121,9 @@ 2.4.0 - joda-time - joda-time - 2.7 + joda-time + joda-time + 2.7 org.aspectj @@ -174,7 +155,7 @@ - selenium-tests + com.frameworkium-core true @@ -189,40 +170,6 @@ 1.7 - - org.apache.maven.plugins - maven-surefire-plugin - 2.18.1 - - methods - ${threads} - - - ${env.config} - ${browser} - ${project.build.directory}/screenshots - ${seleniumGridURL} - ${platform} - ${platformVersion} - ${browserVersion} - ${device} - ${sauce} - ${browserStack} - ${maximise} - ${build} - ${appPath} - ${jiraURL} - ${jiraResultVersion} - ${allure.issues.tracker.pattern}/browse/%s - - - **/*Test.java - **/*Tests.java - - ${groups} - false - - From eac6915fd4f211a2a021a6d960782cfb5629fa2d Mon Sep 17 00:00:00 2001 From: jleeh Date: Thu, 20 Aug 2015 11:35:05 +0100 Subject: [PATCH 3/5] Code cleanup. --- .../java/com/frameworkium/tests/internal/BaseTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/frameworkium/tests/internal/BaseTest.java b/src/main/java/com/frameworkium/tests/internal/BaseTest.java index 2cda636b..2ffe1b39 100644 --- a/src/main/java/com/frameworkium/tests/internal/BaseTest.java +++ b/src/main/java/com/frameworkium/tests/internal/BaseTest.java @@ -74,6 +74,15 @@ protected ScreenshotCapture initialValue() { }; } + /** + * 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(); @@ -86,7 +95,6 @@ public static void configureBrowserBeforeTest(Method testMethod) { * @param testMethod - Test method passed from the test script */ private static void initialiseNewScreenshotCapture(Method testMethod) { - configureDriverBasedOnParams(); if (ScreenshotCapture.isRequired()) { String testID = "n/a"; try { From 8b93191a13b29e8ebc647cc107e541d94981723e Mon Sep 17 00:00:00 2001 From: jleeh Date: Thu, 20 Aug 2015 11:40:18 +0100 Subject: [PATCH 4/5] Re-added the example, basic test. --- .../tests/web/TheInternetExampleTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java diff --git a/src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java b/src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java new file mode 100644 index 00000000..9607e10f --- /dev/null +++ b/src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java @@ -0,0 +1,17 @@ +package com.heroku.theinternet.tests.web; + +import static com.google.common.truth.Truth.assertThat; + +import com.frameworkium.tests.internal.BaseTest; +import com.heroku.theinternet.pages.web.WelcomePage; + +import org.testng.annotations.Test; + +public class TheInternetExampleTest extends BaseTest { + + @Test + public void basicAuth() { + + assertThat(WelcomePage.open().then().getTitle()).isEqualTo("The Internet"); + } +} \ No newline at end of file From ee33b3c7424d14d3c46fa7733ccaf7c6d4673c41 Mon Sep 17 00:00:00 2001 From: jleeh Date: Thu, 20 Aug 2015 11:42:16 +0100 Subject: [PATCH 5/5] Re-bumped the pom to 1.1.1 ready to merge to master. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f3974f2c..4ff20e34 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.frameworkium Frameworkium-core - 1.1.0 + 1.1.1 Frameworkium-core Frameworkium core code. Referenced by the com.frameworkium project, with example tests.