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
2 changes: 1 addition & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ jobs:
git diff > changes.patch
- name: "Upload changes"
if: ${{ always() && inputs.artifact-name != 'ignore-artifacts' }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: ${{ inputs.artifact-name }}
path: changes.patch
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: "Upload changes"
id: upload_changes
if: failure() && steps.check_format.outputs.exit_code == '1' && github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: format-changes
path: changes.patch
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: "Rename binary"
run: mv rust/target/release/selenium-manager.exe selenium-manager-windows.exe
- name: "Upload release binary"
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: selenium-manager-windows
path: selenium-manager-windows.exe
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: "Rename binary"
run: mv rust/target/debug/selenium-manager.exe selenium-manager-windows-debug.exe
- name: "Upload release binary"
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: selenium-manager-windows-debug
path: selenium-manager-windows-debug.exe
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
- name: "Rename binary"
run: mv rust/target/x86_64-unknown-linux-musl/release/selenium-manager selenium-manager-linux
- name: "Upload release binary"
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: selenium-manager-linux
path: selenium-manager-linux
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
tar -cvf ../../../../selenium-manager-linux-debug.tar selenium-manager
working-directory: rust
- name: "Upload release binary"
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: selenium-manager-linux-debug
path: selenium-manager-linux-debug.tar
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
target/x86_64-apple-darwin/release/selenium-manager
working-directory: rust
- name: "Upload release binary"
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: selenium-manager-macos
path: rust/target/selenium-manager-macos
Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
tar -cvf ../../selenium-manager-macos-debug.tar selenium-manager
working-directory: rust
- name: "Upload release binary"
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: selenium-manager-macos-debug
path: selenium-manager-macos-debug.tar
Expand Down
37 changes: 31 additions & 6 deletions common/src/web/blank.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
<html><head><title>blank</title></head><body>
<script>
localStorage.clear();
sessionStorage.clear();
</script>
</body></html>
<html lang="en">
<head>
<title>blank</title>
<style>
body {
background: #f5f5f5;
background: linear-gradient(
109deg,
rgba(245, 245, 245, 1) 0%,
rgba(225, 225, 225, 1) 35%,
rgba(205, 205, 205, 1) 100%
);
}
body {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<h1 id="header">A blank slate</h1>
<script>
localStorage.clear();
sessionStorage.clear();
const params = new URLSearchParams(window.location.search);
const test = params.get('test');
document.getElementById('header').innerText = test;
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/testing/JupiterTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void prepareEnvironment() {

if (driver != null) {
driver.get("about:blank");
driver.get(pages.blankPage);
driver.get(pages.blankPage + "?test=" + seleniumExtension.currentTest());
driver.manage().deleteAllCookies();
}
}
Expand Down
84 changes: 84 additions & 0 deletions java/test/org/openqa/selenium/testing/SeleniumExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

package org.openqa.selenium.testing;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNullElse;
import static java.util.UUID.randomUUID;
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
import static org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.time.Duration;
Expand All @@ -40,6 +46,8 @@
import org.junit.jupiter.api.extension.TestWatcher;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.RemoteWebDriver;
Expand All @@ -57,6 +65,7 @@ public class SeleniumExtension

private static final ThreadLocal<SeleniumExtension.Instances> instances = new ThreadLocal<>();
private static final Logger LOG = Logger.getLogger(SeleniumExtension.class.getName());
protected static final ThreadLocal<String> testName = new ThreadLocal<>();

private final Duration regularWait;
private final Duration shortWait;
Expand All @@ -82,6 +91,7 @@ public SeleniumExtension(Duration regularWait, Duration shortWait) {
public void beforeEach(ExtensionContext context) throws Exception {
captureLoggingRule.startLogCapture();
nullDriver = false;
testName.set(displayName(context));

// ManageDriverRule.starting
Browser current = Objects.requireNonNull(Browser.detect());
Expand Down Expand Up @@ -128,6 +138,8 @@ private static String displayName(ExtensionContext context) {

@Override
public void afterEach(ExtensionContext context) throws Exception {
testName.remove();

// SwitchToTopRule
SwitchToTopRule switchToTopRule = new SwitchToTopRule(context);
switchToTopRule.apply();
Expand Down Expand Up @@ -192,6 +204,8 @@ public void testSuccessful(ExtensionContext context) {
public void testFailed(ExtensionContext context, Throwable cause) {
TestWatcher.super.testFailed(context, cause);

logWebdriverDetails(context);

// ManageDriverRule.failed
Browser current = Objects.requireNonNull(Browser.detect());
Optional<Method> testMethod = context.getTestMethod();
Expand Down Expand Up @@ -309,6 +323,10 @@ public void removeDriver() {
instances.remove();
}

public String currentTest() {
return testName.get();
}

private static class Instances {
public final WebDriver driver;
public final Wait<WebDriver> regularWait;
Expand Down Expand Up @@ -398,4 +416,70 @@ protected void apply() {
}
}
}

private void logWebdriverDetails(ExtensionContext context) {
try {
Optional.ofNullable(instances.get())
.ifPresent(
(Instances current) -> {
System.err.println();
System.err.println("Test failure details:");
System.err.printf(" URL: %s%n", current.driver.getCurrentUrl());
System.err.printf(" Title: %s%n", current.driver.getTitle());
System.err.printf(" Page source: %s%n", savePageSource(current.driver, context));
System.err.printf(" Screenshot: %s%n", saveScreenshot(current.driver, context));
});
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to log webdriver details: " + e.getMessage(), e);
}
}

private File artifact(ExtensionContext context, String suffix, byte[] content)
throws IOException {
File parent = new File("build/failures/java/" + Browser.detect());
File testClassFolder =
new File(parent, context.getTestClass().map(Class::getName).orElse("-").replace('.', '/'));
if (!testClassFolder.exists()) {
if (!testClassFolder.mkdirs()) {
throw new IOException("Cannot create folder " + testClassFolder);
}
}
File result =
new File(
testClassFolder,
context.getTestMethod().map(Method::getName).orElse(randomUUID().toString()) + suffix);
try (FileOutputStream out = new FileOutputStream(result)) {
out.write(content);
}
return result;
}

private String savePageSource(WebDriver driver, ExtensionContext context) {
try {
String pageSource = requireNonNullElse(driver.getPageSource(), "");
return toURL(artifact(context, ".html", pageSource.getBytes(UTF_8)));
} catch (IOException | RuntimeException e) {
return String.format("- (%s)", e);
}
}

private String saveScreenshot(WebDriver driver, ExtensionContext context) {
if (!(driver instanceof TakesScreenshot)) {
return "-";
}
try {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return toURL(artifact(context, ".png", screenshot));
} catch (IOException | RuntimeException e) {
return String.format("- (%s)", e);
}
}

private String toURL(File artifact) {
try {
return artifact.getCanonicalFile().toURI().toURL().toExternalForm();
} catch (IOException e) {
return artifact.getAbsolutePath();
}
}
}
Loading