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
16 changes: 4 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,14 @@ jobs:
TESTINGBOT_SECRET: ${{ secrets.TESTINGBOT_SECRET }}
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'temurin'
java-version: '11'

- name: Cache Maven dependencies
uses: actions/cache@v2
with:
path: |
~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
cache: 'maven'

- name: Build and test with Maven
run: mvn clean test
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ steps:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
Expand Down
30 changes: 9 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,36 @@
<name>testingbot_testng</name>
<description>A Maven project that demonstrates how to integrate TestingBot with WebDriver tests that run using TestNG</description>

<properties>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<version>4.27.0</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<version>3.13.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<version>3.2.5</version>
<configuration>
<parallel>classes</parallel>
<threadCount>40</threadCount>
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/com/yourcompany/Tests/SimpleTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.yourcompany.Tests;

import org.openqa.selenium.InvalidElementStateException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.rmi.UnexpectedException;


public class SimpleTest extends TestBase {
Expand Down
44 changes: 31 additions & 13 deletions src/test/java/com/yourcompany/Tests/TestBase.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.yourcompany.Tests;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;

import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;import java.util.HashMap;
import java.rmi.UnexpectedException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -83,29 +83,47 @@ public String getSessionId() {
* @throws MalformedURLException if an error occurs parsing the url
*/
protected void createDriver(String browser, String version, String os, String testName)
throws MalformedURLException, UnexpectedException {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(CapabilityType.BROWSER_VERSION, version);
capabilities.setCapability(CapabilityType.PLATFORM_NAME, os);
throws MalformedURLException {
MutableCapabilities options = optionsForBrowser(browser);
options.setCapability("browserVersion", version);
options.setCapability("platformName", os);

Map<String, Object> testingBotOptions = new HashMap<>();
testingBotOptions.put("name", testName);
if (buildTag != null) {
testingBotOptions.put("build", buildTag);
}
capabilities.setCapability("tb:options", testingBotOptions);
options.setCapability("tb:options", testingBotOptions);

webDriver.set(new RemoteWebDriver(
new URL("https://" + key + ":" + secret + "@hub.testingbot.com/wd/hub"),
capabilities));
options));

// set current sessionId
String id = ((RemoteWebDriver) getWebDriver()).getSessionId().toString();
sessionId.set(id);
}

/**
* Returns the Selenium 4 {@link MutableCapabilities} (browser Options) instance
* matching the requested browser name.
*
* @param browser the browser name as supplied by the DataProvider
* @return the matching browser Options instance
*/
private MutableCapabilities optionsForBrowser(String browser) {
switch (browser.toLowerCase()) {
case "chrome":
return new ChromeOptions();
case "firefox":
return new FirefoxOptions();
case "microsoftedge":
return new EdgeOptions();
default:
throw new IllegalArgumentException("Unsupported browser: " + browser);
}
}

/**
* Method that gets invoked after test.
* Dumps browser log and closes the browser
Expand Down
Loading