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
21 changes: 20 additions & 1 deletion .github/workflows/java-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions examples/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
/build
/out
/target
/selenium.pdf
/selenium.xml*
10 changes: 7 additions & 3 deletions examples/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
6 changes: 6 additions & 0 deletions examples/java/src/test/java/dev/selenium/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand All @@ -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"));
Expand Down