From 77510526f5ee5b09cee1213ba9443e41290c2c74 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 19 Jun 2026 20:52:55 +0000 Subject: [PATCH] Modernize build, dependencies, CI, and Selenium API - Align Java to 11 across pom.xml (was 1.7), GitHub Actions, and Azure - Bump maven-compiler-plugin (3.13.0) and maven-surefire-plugin (3.2.5) - Update TestNG (7.10.2) and Selenium (4.27.0); drop unused commons-lang and hamcrest-core dependencies - Migrate deprecated DesiredCapabilities to Selenium 4 Options classes (ChromeOptions/FirefoxOptions/EdgeOptions) via an optionsForBrowser helper - Clean up malformed/duplicate/unused imports in TestBase and SimpleTest - Refresh GitHub Actions to v4 with temurin and built-in Maven caching Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01JVTZZXtiK7tSqjtwL5Yd47 --- .github/workflows/test.yml | 16 ++----- azure-pipelines.yml | 2 +- pom.xml | 30 ++++--------- .../com/yourcompany/Tests/SimpleTest.java | 5 --- .../java/com/yourcompany/Tests/TestBase.java | 44 +++++++++++++------ 5 files changed, 45 insertions(+), 52 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b5f69b..fd545fb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 95973d4..75b60c9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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' diff --git a/pom.xml b/pom.xml index f6f7e22..8a5d81f 100644 --- a/pom.xml +++ b/pom.xml @@ -9,48 +9,36 @@ testingbot_testng A Maven project that demonstrates how to integrate TestingBot with WebDriver tests that run using TestNG + + 11 + UTF-8 + + - - org.hamcrest - hamcrest-core - 1.3 - test - org.testng testng - 7.9.0 + 7.10.2 test org.seleniumhq.selenium selenium-java - 4.17.0 - test - - - commons-lang - commons-lang - 2.6 + 4.27.0 test - maven-compiler-plugin - 3.0 - - 1.7 - 1.7 - + 3.13.0 org.apache.maven.plugins maven-surefire-plugin - 2.12.4 + 3.2.5 classes 40 diff --git a/src/test/java/com/yourcompany/Tests/SimpleTest.java b/src/test/java/com/yourcompany/Tests/SimpleTest.java index 383f617..ccbb911 100644 --- a/src/test/java/com/yourcompany/Tests/SimpleTest.java +++ b/src/test/java/com/yourcompany/Tests/SimpleTest.java @@ -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 { diff --git a/src/test/java/com/yourcompany/Tests/TestBase.java b/src/test/java/com/yourcompany/Tests/TestBase.java index d180e5d..d52ad5e 100644 --- a/src/test/java/com/yourcompany/Tests/TestBase.java +++ b/src/test/java/com/yourcompany/Tests/TestBase.java @@ -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; @@ -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 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