diff --git a/.github/workflows/java-examples.yml b/.github/workflows/java-examples.yml index 73aa3c357866..5cbcc00dd577 100644 --- a/.github/workflows/java-examples.yml +++ b/.github/workflows/java-examples.yml @@ -60,7 +60,7 @@ jobs: - name: Import test cert Windows if: matrix.os == 'windows' run: keytool -import -noprompt -trustcacerts -alias SeleniumHQ -file examples/java/src/test/resources/tls.crt -keystore ${{ steps.java.outputs.path }}/lib/security/cacerts -storepass changeit - - name: Run Tests Stable + - name: Run Tests Stable (in Maven) if: matrix.release == 'stable' uses: nick-invision/retry@v3.0.2 with: @@ -69,6 +69,15 @@ jobs: command: | cd examples/java mvn -B test -D"jdk.internal.httpclient.disableHostnameVerification=true" + - name: Run Tests Stable (in Gradle) + if: matrix.release == 'stable' + uses: nick-invision/retry@v3.0.2 + with: + timeout_minutes: 40 + max_attempts: 3 + command: | + cd examples/java + ./gradlew test --tests 'dev.selenium.*UsingSeleniumTest' - name: Run Tests Nightly Linux/macOS if: matrix.release == 'nightly' && matrix.os != 'windows' uses: nick-invision/retry@v3.0.2 @@ -109,3 +118,13 @@ jobs: cd examples/java mvn -B -U test "-Djdk.internal.httpclient.disableHostnameVerification=true" "-Dselenium.version=$new_version" } + - name: Upload test report + uses: actions/upload-artifact@v6 + if: failure() + with: + name: test-report-${{matrix.os}}-${{matrix.release}} + retention-days: 14 + path: | + examples/java/target/surefire-reports + examples/java/build/reports + examples/java/build/test-results diff --git a/examples/java/.gitignore b/examples/java/.gitignore index 77b33f676e09..f3f6a0bd9eff 100644 --- a/examples/java/.gitignore +++ b/examples/java/.gitignore @@ -2,5 +2,3 @@ /build /out /target -/selenium.pdf -/selenium.xml* diff --git a/examples/java/build.gradle b/examples/java/build.gradle index 3545907b2eba..f9dc4a858d7a 100644 --- a/examples/java/build.gradle +++ b/examples/java/build.gradle @@ -9,10 +9,14 @@ repositories { mavenCentral() } +ext['seleniumVersion'] = System.getProperty('selenium.version', '4.40.0') + dependencies { - testImplementation 'org.seleniumhq.selenium:selenium-java:4.40.0' - testImplementation 'org.seleniumhq.selenium:selenium-grid:4.40.0' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:6.0.2' + testImplementation "org.seleniumhq.selenium:selenium-java:${seleniumVersion}" + testImplementation "org.seleniumhq.selenium:selenium-grid:${seleniumVersion}" + testImplementation platform("org.junit:junit-bom:6.0.2") + testImplementation 'org.junit.jupiter:junit-jupiter-engine' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testImplementation 'com.titusfortner:selenium-logger:2.4.0' } diff --git a/examples/java/src/test/java/dev/selenium/BaseTest.java b/examples/java/src/test/java/dev/selenium/BaseTest.java index 25682d92260b..cb94e65f9c51 100644 --- a/examples/java/src/test/java/dev/selenium/BaseTest.java +++ b/examples/java/src/test/java/dev/selenium/BaseTest.java @@ -31,6 +31,7 @@ public class BaseTest { protected String username = "admin"; protected String password = "myStrongPassword"; protected String trustStorePassword = "seleniumkeystore"; + private final Path artifactsDir = Path.of("target", "surefire-reports"); public WebElement getLocatedElement(WebDriver driver, By by) { WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5)); @@ -66,6 +67,11 @@ protected static EdgeOptions getDefaultEdgeOptions() { return new EdgeOptions().addArguments("--no-sandbox"); } + protected Path artifactsDir() throws IOException { + Files.createDirectories(artifactsDir); + return artifactsDir; + } + protected File getTempDirectory(String prefix) { File tempDirectory = null; try { diff --git a/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java b/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java index 2d0b197fc2c5..41c5769f59da 100644 --- a/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java +++ b/examples/java/src/test/java/dev/selenium/interactions/SavingTest.java @@ -1,16 +1,12 @@ package dev.selenium.interactions; import dev.selenium.BaseChromeTest; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.print.PrintOptions; import org.openqa.selenium.remote.RemoteWebDriver; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Base64; public class SavingTest extends BaseChromeTest { @@ -20,6 +16,6 @@ public void prints() throws IOException { String content = ((RemoteWebDriver) driver).print(new PrintOptions()).getContent(); byte[] bytes = Base64.getDecoder().decode(content); - Files.write(Paths.get("selenium.pdf"), bytes); + Files.write(artifactsDir().resolve("selenium.pdf"), bytes); } } diff --git a/examples/java/src/test/java/dev/selenium/troubleshooting/LoggingTest.java b/examples/java/src/test/java/dev/selenium/troubleshooting/LoggingTest.java index aa24268bcaaa..2cbb7c8e756e 100644 --- a/examples/java/src/test/java/dev/selenium/troubleshooting/LoggingTest.java +++ b/examples/java/src/test/java/dev/selenium/troubleshooting/LoggingTest.java @@ -2,20 +2,21 @@ import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Arrays; import java.util.logging.FileHandler; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; +import dev.selenium.BaseTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.openqa.selenium.manager.SeleniumManager; import org.openqa.selenium.remote.RemoteWebDriver; -public class LoggingTest { +public class LoggingTest extends BaseTest { @AfterEach public void loggingOff() { @@ -34,7 +35,8 @@ public void logging() throws IOException { handler.setLevel(Level.FINE); }); - Handler handler = new FileHandler("selenium.xml"); + Path output = artifactsDir().resolve("selenium.xml"); + Handler handler = new FileHandler(output.toString()); logger.addHandler(handler); Logger.getLogger(RemoteWebDriver.class.getName()).setLevel(Level.FINEST); @@ -45,7 +47,7 @@ public void logging() throws IOException { localLogger.info("this is useful information"); localLogger.fine("this is detailed debug information"); - byte[] bytes = Files.readAllBytes(Paths.get("selenium.xml")); + byte[] bytes = Files.readAllBytes(output); String fileContent = new String(bytes); Assertions.assertTrue(fileContent.contains("this is a warning"));