Skip to content

Commit 84b28d1

Browse files
Merge pull request #1 from testingbot/claude/repo-improvements-review-qjafzq
Modernize build, dependencies, CI, and Selenium API
2 parents 1017484 + 7751052 commit 84b28d1

5 files changed

Lines changed: 45 additions & 52 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@ jobs:
1010
TESTINGBOT_SECRET: ${{ secrets.TESTINGBOT_SECRET }}
1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v4
1414

1515
- name: Set up JDK
16-
uses: actions/setup-java@v2
16+
uses: actions/setup-java@v4
1717
with:
18-
distribution: 'adopt'
18+
distribution: 'temurin'
1919
java-version: '11'
20-
21-
- name: Cache Maven dependencies
22-
uses: actions/cache@v2
23-
with:
24-
path: |
25-
~/.m2/repository
26-
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
27-
restore-keys: |
28-
${{ runner.os }}-maven-
20+
cache: 'maven'
2921

3022
- name: Build and test with Maven
3123
run: mvn clean test

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ steps:
1818
mavenPomFile: 'pom.xml'
1919
mavenOptions: '-Xmx3072m'
2020
javaHomeOption: 'JDKVersion'
21-
jdkVersionOption: '1.8'
21+
jdkVersionOption: '1.11'
2222
jdkArchitectureOption: 'x64'
2323
publishJUnitResults: true
2424
testResultsFiles: '**/TEST-*.xml'

pom.xml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,36 @@
99
<name>testingbot_testng</name>
1010
<description>A Maven project that demonstrates how to integrate TestingBot with WebDriver tests that run using TestNG</description>
1111

12+
<properties>
13+
<maven.compiler.release>11</maven.compiler.release>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
1217
<dependencies>
13-
<dependency>
14-
<groupId>org.hamcrest</groupId>
15-
<artifactId>hamcrest-core</artifactId>
16-
<version>1.3</version>
17-
<scope>test</scope>
18-
</dependency>
1918
<dependency>
2019
<groupId>org.testng</groupId>
2120
<artifactId>testng</artifactId>
22-
<version>7.9.0</version>
21+
<version>7.10.2</version>
2322
<scope>test</scope>
2423
</dependency>
2524
<dependency>
2625
<groupId>org.seleniumhq.selenium</groupId>
2726
<artifactId>selenium-java</artifactId>
28-
<version>4.17.0</version>
29-
<scope>test</scope>
30-
</dependency>
31-
<dependency>
32-
<groupId>commons-lang</groupId>
33-
<artifactId>commons-lang</artifactId>
34-
<version>2.6</version>
27+
<version>4.27.0</version>
3528
<scope>test</scope>
3629
</dependency>
37-
3830
</dependencies>
3931

4032
<build>
4133
<plugins>
4234
<plugin>
4335
<artifactId>maven-compiler-plugin</artifactId>
44-
<version>3.0</version>
45-
<configuration>
46-
<source>1.7</source>
47-
<target>1.7</target>
48-
</configuration>
36+
<version>3.13.0</version>
4937
</plugin>
5038
<plugin>
5139
<groupId>org.apache.maven.plugins</groupId>
5240
<artifactId>maven-surefire-plugin</artifactId>
53-
<version>2.12.4</version>
41+
<version>3.2.5</version>
5442
<configuration>
5543
<parallel>classes</parallel>
5644
<threadCount>40</threadCount>

src/test/java/com/yourcompany/Tests/SimpleTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.yourcompany.Tests;
22

3-
import org.openqa.selenium.InvalidElementStateException;
43
import org.openqa.selenium.WebDriver;
5-
import org.openqa.selenium.By;
6-
import org.openqa.selenium.WebElement;
74
import org.testng.Assert;
85
import org.testng.annotations.Test;
96

107
import java.lang.reflect.Method;
11-
import java.net.MalformedURLException;
12-
import java.rmi.UnexpectedException;
138

149

1510
public class SimpleTest extends TestBase {

src/test/java/com/yourcompany/Tests/TestBase.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.yourcompany.Tests;
22

33
import org.openqa.selenium.JavascriptExecutor;
4+
import org.openqa.selenium.MutableCapabilities;
45
import org.openqa.selenium.WebDriver;
5-
import org.openqa.selenium.remote.CapabilityType;
6-
import org.openqa.selenium.remote.DesiredCapabilities;
6+
import org.openqa.selenium.chrome.ChromeOptions;
7+
import org.openqa.selenium.edge.EdgeOptions;
8+
import org.openqa.selenium.firefox.FirefoxOptions;
79
import org.openqa.selenium.remote.RemoteWebDriver;
810
import org.testng.ITestResult;
911
import org.testng.annotations.AfterMethod;
1012
import org.testng.annotations.DataProvider;
11-
import org.testng.annotations.Listeners;
1213

1314
import java.lang.reflect.Method;
1415
import java.net.MalformedURLException;
15-
import java.net.URL;import java.util.HashMap;
16-
import java.rmi.UnexpectedException;
16+
import java.net.URL;
1717
import java.util.HashMap;
1818
import java.util.Map;
1919

@@ -83,29 +83,47 @@ public String getSessionId() {
8383
* @throws MalformedURLException if an error occurs parsing the url
8484
*/
8585
protected void createDriver(String browser, String version, String os, String testName)
86-
throws MalformedURLException, UnexpectedException {
87-
DesiredCapabilities capabilities = new DesiredCapabilities();
88-
89-
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
90-
capabilities.setCapability(CapabilityType.BROWSER_VERSION, version);
91-
capabilities.setCapability(CapabilityType.PLATFORM_NAME, os);
86+
throws MalformedURLException {
87+
MutableCapabilities options = optionsForBrowser(browser);
88+
options.setCapability("browserVersion", version);
89+
options.setCapability("platformName", os);
9290

9391
Map<String, Object> testingBotOptions = new HashMap<>();
9492
testingBotOptions.put("name", testName);
9593
if (buildTag != null) {
9694
testingBotOptions.put("build", buildTag);
9795
}
98-
capabilities.setCapability("tb:options", testingBotOptions);
96+
options.setCapability("tb:options", testingBotOptions);
9997

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

104102
// set current sessionId
105103
String id = ((RemoteWebDriver) getWebDriver()).getSessionId().toString();
106104
sessionId.set(id);
107105
}
108106

107+
/**
108+
* Returns the Selenium 4 {@link MutableCapabilities} (browser Options) instance
109+
* matching the requested browser name.
110+
*
111+
* @param browser the browser name as supplied by the DataProvider
112+
* @return the matching browser Options instance
113+
*/
114+
private MutableCapabilities optionsForBrowser(String browser) {
115+
switch (browser.toLowerCase()) {
116+
case "chrome":
117+
return new ChromeOptions();
118+
case "firefox":
119+
return new FirefoxOptions();
120+
case "microsoftedge":
121+
return new EdgeOptions();
122+
default:
123+
throw new IllegalArgumentException("Unsupported browser: " + browser);
124+
}
125+
}
126+
109127
/**
110128
* Method that gets invoked after test.
111129
* Dumps browser log and closes the browser

0 commit comments

Comments
 (0)