Skip to content

Commit 1098577

Browse files
committed
2 parents 8e98a87 + 3615620 commit 1098577

File tree

8 files changed

+91
-63
lines changed

8 files changed

+91
-63
lines changed

pom.xml

Lines changed: 9 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.2</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>
@@ -135,6 +135,11 @@
135135
<artifactId>ngwebdriver</artifactId>
136136
<version>0.9.1</version>
137137
</dependency>
138+
<dependency>
139+
<groupId>net.sf.uadetector</groupId>
140+
<artifactId>uadetector-resources</artifactId>
141+
<version>2014.04</version>
142+
</dependency>
138143
</dependencies>
139144

140145
<repositories>

src/main/java/com/frameworkium/capture/model/Browser.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.frameworkium.capture.model;
22

33
import com.frameworkium.config.SystemProperty;
4+
import com.frameworkium.tests.internal.BaseTest;
5+
import net.sf.uadetector.service.UADetectorServiceFactory;
6+
import net.sf.uadetector.UserAgentStringParser;
7+
import net.sf.uadetector.ReadableUserAgent;
48

59
public class Browser {
610
private String name;
@@ -10,20 +14,37 @@ public class Browser {
1014
private String platformVersion;
1115

1216
public Browser() {
13-
if (SystemProperty.BROWSER.isSpecified()) {
14-
this.name = SystemProperty.BROWSER.getValue().toLowerCase();
15-
}
16-
if (SystemProperty.BROWSER_VERSION.isSpecified()) {
17-
this.version = SystemProperty.BROWSER_VERSION.getValue();
18-
}
19-
if (SystemProperty.DEVICE.isSpecified()) {
20-
this.device = SystemProperty.DEVICE.getValue();
21-
}
22-
if (SystemProperty.PLATFORM.isSpecified()) {
23-
this.platform = SystemProperty.PLATFORM.getValue();
24-
}
25-
if (SystemProperty.PLATFORM_VERSION.isSpecified()) {
26-
this.platformVersion = SystemProperty.PLATFORM_VERSION.getValue();
17+
18+
19+
if(!BaseTest.userAgent.isEmpty()) {
20+
// Get an UserAgentStringParser and analyze the requesting client
21+
UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser();
22+
ReadableUserAgent agent = parser.parse(BaseTest.userAgent);
23+
24+
//Set the params based on this agent
25+
this.name = agent.getName();
26+
this.version = agent.getVersionNumber().toVersionString();
27+
this.device = agent.getDeviceCategory().getName();
28+
this.platform = agent.getOperatingSystem().getName();
29+
this.platformVersion = agent.getOperatingSystem().getVersionNumber().toVersionString();
30+
31+
} else {
32+
33+
if (SystemProperty.BROWSER.isSpecified()) {
34+
this.name = SystemProperty.BROWSER.getValue().toLowerCase();
35+
}
36+
if (SystemProperty.BROWSER_VERSION.isSpecified()) {
37+
this.version = SystemProperty.BROWSER_VERSION.getValue();
38+
}
39+
if (SystemProperty.DEVICE.isSpecified()) {
40+
this.device = SystemProperty.DEVICE.getValue();
41+
}
42+
if (SystemProperty.PLATFORM.isSpecified()) {
43+
this.platform = SystemProperty.PLATFORM.getValue();
44+
}
45+
if (SystemProperty.PLATFORM_VERSION.isSpecified()) {
46+
this.platformVersion = SystemProperty.PLATFORM_VERSION.getValue();
47+
}
2748
}
2849
}
2950

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/listeners/CaptureListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public void beforeNavigateTo(String url, WebDriver driver) {
9999

100100
@Override
101101
public void beforeScript(String script, WebDriver driver) {
102-
takeScreenshotAndSendToCapture("script", driver);
102+
if(!script.contains("navigator.userAgent")){
103+
takeScreenshotAndSendToCapture("script", driver);
104+
}
103105
}
104106

105107
/* Test end methods */

src/main/java/com/frameworkium/pages/internal/BasePage.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.concurrent.TimeUnit;
77

8+
import com.paulhammant.ngwebdriver.WaitForAngularRequestsToFinish;
89
import org.apache.commons.lang.StringUtils;
910
import org.apache.logging.log4j.LogManager;
1011
import org.apache.logging.log4j.Logger;
@@ -25,8 +26,6 @@
2526
import com.frameworkium.tests.internal.BaseTest;
2627
import com.google.inject.Inject;
2728

28-
import static com.paulhammant.ngwebdriver.WaitForAngularRequestsToFinish.waitForAngularRequestsToFinish;
29-
3029
public abstract class BasePage<T extends BasePage<T>> {
3130

3231
@Inject
@@ -59,7 +58,7 @@ public T get() {
5958
HtmlElementLoader.populatePageObject(this, driver);
6059
try {
6160
if(isPageAngularJS()) {
62-
waitForAngularRequestsToFinish((JavascriptExecutor) driver);
61+
waitForAngularRequestsToFinish();
6362
}
6463
waitForExpectedVisibleElements(this);
6564
try {
@@ -204,6 +203,15 @@ public Object executeJS(String javascript) {
204203
return returnObj;
205204
}
206205

206+
/**
207+
* Method to wait for AngularJS requests to finish on the page
208+
*/
209+
public void waitForAngularRequestsToFinish() {
210+
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
211+
WaitForAngularRequestsToFinish
212+
.waitForAngularRequestsToFinish((JavascriptExecutor) driver);
213+
}
214+
207215
/**
208216
* Method which executes an async JS call
209217
*

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) {

src/test/java/com/heroku/theinternet/tests/web/TheInternetExampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public void smokeTest() {
1414

1515
assertThat(WelcomePage.open().then().getTitle()).isEqualTo("The Internet");
1616
}
17-
}
17+
}

0 commit comments

Comments
 (0)