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 docs-site/docs/guides/trace-viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Selenium Boot generates a standalone, self-contained HTML trace viewer per test

## Enabling Trace Recording

Trace recording is opt-in and configured in `selenium-boot.yml`:
Trace recording is configured in `selenium-boot.yml`. When `tracing.enabled` is not set, traces for **failed tests are recorded automatically in CI** (detected from `CI`, `GITHUB_ACTIONS`, `JENKINS_URL` and similar) and stay off on your machine. An explicit `enabled: true` or `enabled: false` always wins.

```yaml title="selenium-boot.yml"
tracing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean appendSummary(SeleniumBootConfig config,
return false;
}
SeleniumBootConfig.Tracing tracing = config.getTracing();
if (tracing == null || !tracing.isEnabled()) {
if (tracing == null || !tracing.isEffectivelyEnabled()) {
return false;
}
if (timings == null || timings.isEmpty() || summaryFile == null) {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/seleniumboot/config/SeleniumBootConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,18 @@ public static final class Flakiness {
}

public static final class Tracing {
private boolean enabled = false;
/** null = not set in selenium-boot.yml; resolved by {@link #isEffectivelyEnabled(boolean)}. */
private Boolean enabled = null;
private boolean captureOnPass = false;

public boolean isEnabled() { return enabled; }
/** The value set in selenium-boot.yml; false when unset. Prefer {@link #isEffectivelyEnabled()}. */
public boolean isEnabled() { return Boolean.TRUE.equals(enabled); }
public void setEnabled(boolean v) { this.enabled = v; }

/** An explicit {@code tracing.enabled} wins; when unset, tracing is on in CI and off locally. */
public boolean isEffectivelyEnabled() { return isEffectivelyEnabled(com.seleniumboot.ci.CiEnvironmentDetector.isCI()); }
public boolean isEffectivelyEnabled(boolean ci) { return enabled != null ? enabled : ci; }

public boolean isCaptureOnPass() { return captureOnPass; }
public void setCaptureOnPass(boolean v) { this.captureOnPass = v; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static String testId(ExtensionContext context) {
private void saveTraceIfEnabled(String testId, String testName, boolean isPassing) {
try {
SeleniumBootConfig.Tracing tracing = SeleniumBootContext.getConfig().getTracing();
if (tracing == null || !tracing.isEnabled()) return;
if (tracing == null || !tracing.isEffectivelyEnabled()) return;
if (isPassing && !tracing.isCaptureOnPass()) return;
TraceRecorder.save(testId, testName);
} catch (Exception ignored) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private void runAiAnalysisIfEnabled(String testId, String pageUrl, String pageTi
private void saveTraceIfEnabled(String testId, String testName, boolean isPassing) {
try {
SeleniumBootConfig.Tracing tracing = SeleniumBootContext.getConfig().getTracing();
if (tracing == null || !tracing.isEnabled()) return;
if (tracing == null || !tracing.isEffectivelyEnabled()) return;
if (isPassing && !tracing.isCaptureOnPass()) return;
TraceRecorder.save(testId, testName);
} catch (Exception ignored) {}
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/seleniumboot/unit/TracingConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.seleniumboot.unit;

import com.seleniumboot.config.SeleniumBootConfig;
import org.testng.annotations.Test;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class TracingConfigTest {

@Test
public void unsetFollowsCiEnvironment() {
SeleniumBootConfig.Tracing tracing = new SeleniumBootConfig.Tracing();
assertTrue(tracing.isEffectivelyEnabled(true), "unset tracing is on in CI");
assertFalse(tracing.isEffectivelyEnabled(false), "unset tracing stays off locally");
}

@Test
public void explicitFalseWinsInCi() {
SeleniumBootConfig.Tracing tracing = new SeleniumBootConfig.Tracing();
tracing.setEnabled(false);
assertFalse(tracing.isEffectivelyEnabled(true));
}

@Test
public void explicitTrueWinsLocally() {
SeleniumBootConfig.Tracing tracing = new SeleniumBootConfig.Tracing();
tracing.setEnabled(true);
assertTrue(tracing.isEffectivelyEnabled(false));
}

@Test
public void captureOnPassStaysOffByDefault() {
assertFalse(new SeleniumBootConfig.Tracing().isCaptureOnPass());
}
}
Loading