Skip to content

Commit e7f4460

Browse files
asolntsevdiemolharsha509
authored
[java] [ci] upload test reports for Java example (when running tests on GitHub Actions) (#2572)
* upload test report when GitHub Actions build fails Now the report can be downloaded during the next 2 weeks from https://github.com/SeleniumHQ/seleniumhq.github.io/actions * run Gradle tests on GA as well until now, we executed only Maven tests. As a result, build.gradle was outdated. * run Gradle tests as a separate step (probably not needed to run gradle tests with nightly selenium) --------- Co-authored-by: Diego Molina <diemol@users.noreply.github.com> Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com>
1 parent b5a6a55 commit e7f4460

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

.github/workflows/java-examples.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- name: Import test cert Windows
6161
if: matrix.os == 'windows'
6262
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
63-
- name: Run Tests Stable
63+
- name: Run Tests Stable (in Maven)
6464
if: matrix.release == 'stable'
6565
uses: nick-invision/retry@v3.0.2
6666
with:
@@ -69,6 +69,15 @@ jobs:
6969
command: |
7070
cd examples/java
7171
mvn -B test -D"jdk.internal.httpclient.disableHostnameVerification=true"
72+
- name: Run Tests Stable (in Gradle)
73+
if: matrix.release == 'stable'
74+
uses: nick-invision/retry@v3.0.2
75+
with:
76+
timeout_minutes: 40
77+
max_attempts: 3
78+
command: |
79+
cd examples/java
80+
./gradlew test --tests 'dev.selenium.*UsingSeleniumTest'
7281
- name: Run Tests Nightly Linux/macOS
7382
if: matrix.release == 'nightly' && matrix.os != 'windows'
7483
uses: nick-invision/retry@v3.0.2
@@ -109,3 +118,13 @@ jobs:
109118
cd examples/java
110119
mvn -B -U test "-Djdk.internal.httpclient.disableHostnameVerification=true" "-Dselenium.version=$new_version"
111120
}
121+
- name: Upload test report
122+
uses: actions/upload-artifact@v6
123+
if: failure()
124+
with:
125+
name: test-report-${{matrix.os}}-${{matrix.release}}
126+
retention-days: 14
127+
path: |
128+
examples/java/target/surefire-reports
129+
examples/java/build/reports
130+
examples/java/build/test-results

examples/java/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
/build
33
/out
44
/target
5-
/selenium.pdf
6-
/selenium.xml*

examples/java/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ repositories {
99
mavenCentral()
1010
}
1111

12+
ext['seleniumVersion'] = System.getProperty('selenium.version', '4.40.0')
13+
1214
dependencies {
13-
testImplementation 'org.seleniumhq.selenium:selenium-java:4.40.0'
14-
testImplementation 'org.seleniumhq.selenium:selenium-grid:4.40.0'
15-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:6.0.2'
15+
testImplementation "org.seleniumhq.selenium:selenium-java:${seleniumVersion}"
16+
testImplementation "org.seleniumhq.selenium:selenium-grid:${seleniumVersion}"
17+
testImplementation platform("org.junit:junit-bom:6.0.2")
18+
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
19+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
1620
testImplementation 'com.titusfortner:selenium-logger:2.4.0'
1721
}
1822

examples/java/src/test/java/dev/selenium/BaseTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class BaseTest {
3131
protected String username = "admin";
3232
protected String password = "myStrongPassword";
3333
protected String trustStorePassword = "seleniumkeystore";
34+
private final Path artifactsDir = Path.of("target", "surefire-reports");
3435

3536
public WebElement getLocatedElement(WebDriver driver, By by) {
3637
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
@@ -66,6 +67,11 @@ protected static EdgeOptions getDefaultEdgeOptions() {
6667
return new EdgeOptions().addArguments("--no-sandbox");
6768
}
6869

70+
protected Path artifactsDir() throws IOException {
71+
Files.createDirectories(artifactsDir);
72+
return artifactsDir;
73+
}
74+
6975
protected File getTempDirectory(String prefix) {
7076
File tempDirectory = null;
7177
try {
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package dev.selenium.interactions;
22

33
import dev.selenium.BaseChromeTest;
4-
import org.junit.jupiter.api.Assertions;
54
import org.junit.jupiter.api.Test;
6-
import org.openqa.selenium.By;
7-
import org.openqa.selenium.NoSuchElementException;
85
import org.openqa.selenium.print.PrintOptions;
96
import org.openqa.selenium.remote.RemoteWebDriver;
107

118
import java.io.IOException;
129
import java.nio.file.Files;
13-
import java.nio.file.Paths;
1410
import java.util.Base64;
1511

1612
public class SavingTest extends BaseChromeTest {
@@ -20,6 +16,6 @@ public void prints() throws IOException {
2016

2117
String content = ((RemoteWebDriver) driver).print(new PrintOptions()).getContent();
2218
byte[] bytes = Base64.getDecoder().decode(content);
23-
Files.write(Paths.get("selenium.pdf"), bytes);
19+
Files.write(artifactsDir().resolve("selenium.pdf"), bytes);
2420
}
2521
}

examples/java/src/test/java/dev/selenium/troubleshooting/LoggingTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import java.io.IOException;
44
import java.nio.file.Files;
5-
import java.nio.file.Paths;
5+
import java.nio.file.Path;
66
import java.util.Arrays;
77
import java.util.logging.FileHandler;
88
import java.util.logging.Handler;
99
import java.util.logging.Level;
1010
import java.util.logging.Logger;
1111

12+
import dev.selenium.BaseTest;
1213
import org.junit.jupiter.api.AfterEach;
1314
import org.junit.jupiter.api.Assertions;
1415
import org.junit.jupiter.api.Test;
1516
import org.openqa.selenium.manager.SeleniumManager;
1617
import org.openqa.selenium.remote.RemoteWebDriver;
1718

18-
public class LoggingTest {
19+
public class LoggingTest extends BaseTest {
1920

2021
@AfterEach
2122
public void loggingOff() {
@@ -34,7 +35,8 @@ public void logging() throws IOException {
3435
handler.setLevel(Level.FINE);
3536
});
3637

37-
Handler handler = new FileHandler("selenium.xml");
38+
Path output = artifactsDir().resolve("selenium.xml");
39+
Handler handler = new FileHandler(output.toString());
3840
logger.addHandler(handler);
3941

4042
Logger.getLogger(RemoteWebDriver.class.getName()).setLevel(Level.FINEST);
@@ -45,7 +47,7 @@ public void logging() throws IOException {
4547
localLogger.info("this is useful information");
4648
localLogger.fine("this is detailed debug information");
4749

48-
byte[] bytes = Files.readAllBytes(Paths.get("selenium.xml"));
50+
byte[] bytes = Files.readAllBytes(output);
4951
String fileContent = new String(bytes);
5052

5153
Assertions.assertTrue(fileContent.contains("this is a warning"));

0 commit comments

Comments
 (0)