Skip to content

Commit 02ea90d

Browse files
committed
Imported my framework
1 parent 0cb04c9 commit 02ea90d

File tree

81 files changed

+5026
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5026
-124
lines changed

.classpath

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
14+
</attributes>
15+
</classpathentry>
16+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
17+
<attributes>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry kind="con" path="org.jetbrains.kotlin.core.KOTLIN_CONTAINER"/>
27+
<classpathentry kind="output" path="target/classes"/>
28+
</classpath>

.project

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>automated-selenium-tests</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.jetbrains.kotlin.ui.kotlinBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.m2e.core.maven2Builder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.jdt.core.javanature</nature>
26+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
27+
<nature>org.jetbrains.kotlin.core.kotlinNature</nature>
28+
</natures>
29+
<linkedResources>
30+
<link>
31+
<name>kotlin_bin</name>
32+
<type>2</type>
33+
<locationURI>org.jetbrains.kotlin.core.filesystem:/automated-selenium-tests/kotlin_bin</locationURI>
34+
</link>
35+
</linkedResources>
36+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.compliance=1.8
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.release=disabled
6+
org.eclipse.jdt.core.compiler.source=1.8

.settings/org.eclipse.m2e.core.prefs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
codeStyle/codeStyleId=KOTLIN_OFFICIAL
2+
codeStyle/globalsOverridden=true
3+
eclipse.preferences.version=1

Main.kt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package Testng;
2+
3+
import java.util.List;
4+
5+
//import org.testng.TestListenerAdapter;
6+
import org.testng.TestNG;
7+
import org.testng.collections.Lists;
8+
9+
public class Testng {
10+
11+
public static void main(String[] args) {
12+
//TestListenerAdapter tla = new TestListenerAdapter();
13+
TestNG testng = new TestNG();
14+
List<String> suites = Lists.newArrayList();
15+
suites.add("C:/Users/maarten.burrei/workspace/gtbv/src/main/resources/testng.xml");//path to xml..
16+
testng.setTestSuites(suites);
17+
testng.run();
18+
19+
}
20+
21+
}

pom.xml

+37-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,47 @@
1010
<dependency>
1111
<groupId>org.seleniumhq.selenium</groupId>
1212
<artifactId>selenium-java</artifactId>
13-
<version>3.5.2</version>
13+
<version>3.11.0</version>
1414
</dependency>
1515
<dependency>
1616
<groupId>org.testng</groupId>
1717
<artifactId>testng</artifactId>
18-
<version>6.11</version>
18+
<version>6.9.10</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>io.appium</groupId>
22+
<artifactId>java-client</artifactId>
23+
<version>6.0.0-BETA4</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>junit</groupId>
27+
<artifactId>junit</artifactId>
28+
<version>4.12</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.fasterxml.jackson.core</groupId>
32+
<artifactId>jackson-databind</artifactId>
33+
<version>2.8.1</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.apache.pdfbox</groupId>
37+
<artifactId>pdfbox</artifactId>
38+
<version>2.0.5</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.pdfbox</groupId>
42+
<artifactId>fontbox</artifactId>
43+
<version>2.0.5</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.apache.commons</groupId>
47+
<artifactId>commons-text</artifactId>
48+
<version>1.2</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.googlecode.json-simple</groupId>
52+
<artifactId>json-simple</artifactId>
53+
<version>1.1.1</version>
1954
</dependency>
2055
</dependencies>
2156
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.googletest.pom;
2+
3+
import org.openqa.selenium.WebElement;
4+
5+
import com.simonbaars.seleniumframework.core.PageObjectModel;
6+
import com.simonbaars.seleniumframework.reporting.annotations.AlwaysOnPage;
7+
import com.simonbaars.seleniumframework.reporting.annotations.Element;
8+
import com.simonbaars.seleniumframework.reporting.annotations.Page;
9+
import com.simonbaars.seleniumframework.reporting.annotations.TestAction;
10+
11+
import org.openqa.selenium.Keys;
12+
13+
@Page(name = "Homepagina", loadTimeout = 15)
14+
public class Homepagina extends PageObjectModel {
15+
@Element(xpath = "//input[@id=\"lst-ib\"]", name = "Google zoekknop")
16+
17+
WebElement googleZoekknop;
18+
19+
@TestAction(name = "Zoek op \"Hallo\"")
20+
public void zoekOpHallo() {
21+
googleZoekknop.sendKeys("Hallo" + Keys.ENTER);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example.googletest.tests;
2+
3+
import com.simonbaars.seleniumframework.reporting.SeleniumTestcase;
4+
import com.simonbaars.seleniumframework.reporting.annotations.UsesDriver;
5+
6+
import com.example.googletest.pom.Homepagina;
7+
import static com.simonbaars.seleniumframework.core.SeleniumType.BROWSER;
8+
9+
@UsesDriver(type = BROWSER, application = "http://google.nl")
10+
public class GoogleZoeken extends SeleniumTestcase {
11+
@Override
12+
public void run() {
13+
Homepagina pomHomepagina = initPOM(Homepagina.class);
14+
pomHomepagina.zoekOpHallo();
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2018 Simon Baars.
3+
* All rights reserved.
4+
* All code is written by Simon Baars, http://simonbaars.com/.
5+
******************************************************************************/
6+
package com.simonbaars.seleniumframework.core;
7+
8+
import java.lang.reflect.Field;
9+
import java.lang.reflect.Proxy;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
import java.util.Optional;
13+
import java.util.stream.Collectors;
14+
15+
import org.openqa.selenium.By;
16+
import org.openqa.selenium.WebDriver;
17+
import org.openqa.selenium.WebElement;
18+
import org.openqa.selenium.interactions.internal.Locatable;
19+
import org.openqa.selenium.internal.WrapsElement;
20+
21+
import io.appium.java_client.android.AndroidDriver;
22+
import com.simonbaars.seleniumframework.core.common.TestingCommons;
23+
import com.simonbaars.seleniumframework.driver.DriverProvider;
24+
import com.simonbaars.seleniumframework.driver.android.EnhancedAndroidDriver;
25+
import com.simonbaars.seleniumframework.driver.android.enums.AndroidContextType;
26+
import com.simonbaars.seleniumframework.reporting.Logger;
27+
import com.simonbaars.seleniumframework.reporting.annotations.AlwaysOnPage;
28+
import com.simonbaars.seleniumframework.reporting.annotations.Element;
29+
import com.simonbaars.seleniumframework.reporting.annotations.Page;
30+
import com.simonbaars.seleniumframework.reporting.enums.ComparingMethod;
31+
import com.simonbaars.seleniumframework.reporting.interfaces.HasCustomValidation;
32+
import com.simonbaars.seleniumframework.reporting.invocationhandler.ElementInvocationHandler;
33+
34+
public abstract class PageObjectModel {
35+
protected final WebDriver driver;
36+
37+
protected PageObjectModel() {
38+
this.driver = DriverProvider.getDriver();
39+
}
40+
41+
protected PageObjectModel(WebDriver driver) {
42+
this.driver = driver;
43+
}
44+
45+
public boolean validatePage(Class<? extends PageObjectModel> pageObjectModel){
46+
return validatePage(pageObjectModel, getContext(pageObjectModel), getWindow(pageObjectModel));
47+
}
48+
49+
public void waitForPageToValidate(Class<? extends PageObjectModel> pageObjectModel) {
50+
int loadTimeout = getLoadTimeout(pageObjectModel);
51+
new Wait(loadTimeout).until(() -> validatePage(pageObjectModel), "Waiting "+loadTimeout+" seconds for page "+this.getName(pageObjectModel)+" failed.");
52+
}
53+
54+
public boolean validatePage(Class<? extends PageObjectModel> pageObjectModel, String context, String window) {
55+
return validatePage(pageObjectModel, ComparingMethod.CONTAINS, context, window);
56+
}
57+
58+
@SuppressWarnings("unchecked")
59+
private boolean validatePage(Class<? extends PageObjectModel> pageObjectModel, ComparingMethod comparingMethod, String context, String window) {
60+
try {
61+
if(DriverProvider.getDriver() instanceof AndroidDriver) {
62+
try {
63+
if(tryToSeekXPaths(pageObjectModel))
64+
return true;
65+
} catch (Exception e) {}
66+
67+
Logger.log("Context/window switch needed trying to open PageObjectModel "+getName(pageObjectModel));
68+
EnhancedAndroidDriver enhancedAndroidDriver = DriverProvider.getEnhancedAndroidDriver();
69+
if(context!=null && !context.equals("")) {
70+
Optional<String> contextHandle = enhancedAndroidDriver.getContextHandles().stream().filter(e -> comparingMethod.compare((String)e, context)).findAny();
71+
if(!contextHandle.isPresent())
72+
return false;
73+
else
74+
DriverProvider.getAndroidDriver().context(contextHandle.get());
75+
}
76+
77+
System.out.println("CURRENT TYPE = "+enhancedAndroidDriver.getCurrentContextType());
78+
if(window!=null && !window.equals("") && enhancedAndroidDriver.getCurrentContextType() == AndroidContextType.WEBVIEW) {
79+
Optional<String> foundWindow = enhancedAndroidDriver.getAvailableWindows().stream().filter(e -> comparingMethod.compare((String)e, window)).findAny();
80+
if(!foundWindow.isPresent())
81+
return false;
82+
else
83+
enhancedAndroidDriver.switchToWindow(foundWindow.get());
84+
} else {
85+
System.out.println("Scanning window handles.");
86+
if(context!=null && !context.equals("")) {
87+
return scanWindowHandles(pageObjectModel, enhancedAndroidDriver);
88+
} else {
89+
if(enhancedAndroidDriver.getCurrentContextType() == AndroidContextType.WEBVIEW) {
90+
if(scanWindowHandles(pageObjectModel, enhancedAndroidDriver))
91+
return true;
92+
Optional<String> contextHandle = enhancedAndroidDriver.getContextHandles().stream().filter(e -> comparingMethod.compare((String)e, "NATIVE")).findAny();
93+
if(!contextHandle.isPresent())
94+
return false;
95+
else
96+
DriverProvider.getAndroidDriver().context(contextHandle.get());
97+
} else {
98+
Optional<String> contextHandle = enhancedAndroidDriver.getContextHandles().stream().filter(e -> comparingMethod.compare((String)e, "WEBVIEW")).findAny();
99+
if(!contextHandle.isPresent())
100+
return false;
101+
else
102+
DriverProvider.getAndroidDriver().context(contextHandle.get());
103+
return scanWindowHandles(pageObjectModel, enhancedAndroidDriver);
104+
}
105+
}
106+
}
107+
}
108+
return tryToSeekXPaths(pageObjectModel);
109+
} catch (Exception e) {
110+
e.printStackTrace();
111+
Logger.log("Something went wrong while validating page", e);
112+
return false;
113+
}
114+
}
115+
116+
private boolean scanWindowHandles(Class<? extends PageObjectModel> pageObjectModel,
117+
EnhancedAndroidDriver enhancedAndroidDriver) {
118+
System.out.println("AVAILABLE WINDOWS = "+Arrays.toString(enhancedAndroidDriver.getAvailableWindows().toArray()));
119+
for (String windowHandle : enhancedAndroidDriver.getWindowHandles()) {
120+
System.out.println(windowHandle);
121+
enhancedAndroidDriver.switchTo().window(windowHandle);
122+
System.out.println("NOW IN "+enhancedAndroidDriver.getTitle());
123+
if(tryToSeekXPaths(pageObjectModel))
124+
return true;
125+
}
126+
return false;
127+
}
128+
129+
private boolean tryToSeekXPaths(Class<? extends PageObjectModel> pageObjectModel) {
130+
List<String> xpaths = Arrays.asList(pageObjectModel.getDeclaredFields()).stream().filter(f -> f.isAnnotationPresent(AlwaysOnPage.class)).map(f -> f.getAnnotation(Element.class).xpath()).collect(Collectors.toList());
131+
132+
if(this instanceof HasCustomValidation && !((HasCustomValidation)this).executeCustomValidation(xpaths))
133+
return false;
134+
135+
return xpaths.stream().allMatch(xpath -> {
136+
List<WebElement> findElements = driver.findElements(By.xpath(TestingCommons.resolveVariables(xpath)));
137+
System.out.println("In "+driver.getTitle()+ " found "+findElements.size()+ " matching elements with xpath "+xpath);
138+
return !findElements.isEmpty();
139+
});
140+
}
141+
142+
public WebDriver getDriver() {
143+
return driver;
144+
}
145+
146+
public String getContext(Class<? extends PageObjectModel> pomClass) {
147+
return pomClass.getAnnotation(Page.class).context();
148+
}
149+
150+
public String getWindow(Class<? extends PageObjectModel> pomClass) {
151+
return pomClass.getAnnotation(Page.class).window();
152+
}
153+
154+
public String getName(Class<? extends PageObjectModel> pomClass) {
155+
return pomClass.getAnnotation(Page.class).name();
156+
}
157+
158+
public int getLoadTimeout(Class<? extends PageObjectModel> pomClass) {
159+
return pomClass.getAnnotation(Page.class).loadTimeout();
160+
}
161+
162+
public void reproxyElements() {
163+
initElements(driver, (Class<? extends PageObjectModel>)this.getClass());
164+
}
165+
166+
public void initElements(WebDriver driver, Class<? extends PageObjectModel> pomClass) {
167+
List<Field> elements = Arrays.stream(pomClass.getDeclaredFields())
168+
.filter(f -> f.getAnnotation(Element.class) != null).collect(Collectors.toList());
169+
for (Field field : elements) {
170+
field.setAccessible(true);
171+
try {
172+
field.set(this,
173+
(WebElement) Proxy.newProxyInstance(pomClass.getClassLoader(),
174+
new Class[]{WebElement.class, WrapsElement.class, Locatable.class},
175+
new ElementInvocationHandler(driver, field)));
176+
} catch (Exception e) {
177+
Logger.log("Element could not be proxied, and will not work " + field.getName(), e);
178+
}
179+
}
180+
}
181+
}
182+

0 commit comments

Comments
 (0)