Skip to content

Fix the two defects behind the failing E2E browser smoke suite - #108

Merged
JE-Chen merged 2 commits into
mainfrom
dev
Aug 10, 2026
Merged

Fix the two defects behind the failing E2E browser smoke suite#108
JE-Chen merged 2 commits into
mainfrom
dev

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Aug 10, 2026

Copy link
Copy Markdown
Member

The scheduled E2E Browser Smoke job has failed on every run since it was
added, 3 of 6 tests each time. Two independent causes, verified against a real
headless Chrome.

1. shadow_pierce never returned its result on Selenium

_execute_js built a function body out of an IIFE expression and dropped the
value, so find_first, find_all and assert_pierced_visible resolved to
undefined against every real Selenium driver — not just in CI. The Grid
log shows the tell: execute/sync answering HTTP 200 with {"value":null},
i.e. the script ran fine and returned nothing. The Playwright branch already
returned its expression correctly.

Fixed by wrapping in return ( ... ). Prefixing a bare return is not enough:
the scripts open with a newline, so automatic semicolon insertion turns it into
return; and the result is still undefined.

The existing unit tests could not catch this — they stub execute_script on a
MagicMock, so the JavaScript is never evaluated. Added a guard on the emitted
script shape that rejects both failure modes. This matters because the E2E job
is scheduled-only and does not gate PRs.

2. Storage tests ran on a data: URL

data: URLs are opaque origins; Chrome rejects every localStorage access with
"Storage is disabled inside 'data:' URLs", so capture_state could never
complete. Not a library defect — state_diff builds its script correctly.

Added a storage_origin fixture that parks the shared driver on a genuine http
origin, configurable via WEBRUNNER_E2E_ORIGIN, defaulting to the hub's Grid
console — the one http server the browser container is guaranteed to reach
(localhost:4444 is meaningful to the runner, not to Chrome inside the node
container). It skips rather than fails when no origin is available, and drops
the key afterwards so the session-scoped driver stays clean.

Verification

Check Result
The 4 affected cases against real headless Chrome 4/4 pass
test/unit_test/test_*.py 4345 passed, 3 skipped
pytest test/e2e_test/ -m e2e with no Grid 6 skipped, fixtures intact
Codebase-wide audit for the same missing-return pattern isolated to shadow_pierce; cookie_consent and browser_recorder are correct

The new guard was confirmed to fail on both the original code and the naive
return-prefixed variant, and to pass only on the fix.

🤖 Generated with Claude Code

The shadow-pierce scripts are IIFE expressions, so the Selenium wrapper
built a function body that evaluated the IIFE and discarded it, making
find_first, find_all and assert_pierced_visible resolve to undefined
against every real driver. The Playwright branch already returned its
expression.

Wrap the expression in `return ( ... )` rather than prefixing `return`:
the scripts open with a newline, so a bare `return` would be closed by
automatic semicolon insertion and keep yielding undefined.

The existing unit tests stub execute_script on a MagicMock and never
evaluate the script, so add a guard on the emitted script shape that
rejects both failure modes.
data: URLs are opaque origins, so Chrome rejects every localStorage
access there with "Storage is disabled inside 'data:' URLs" and
capture_state could never complete. Add a storage_origin fixture that
parks the shared driver on a genuine http origin, configurable through
WEBRUNNER_E2E_ORIGIN and defaulting to the hub's Grid console, which is
the one http server the browser container is guaranteed to reach.

Skip instead of failing when no such origin is available, and drop the
key afterwards so the session-scoped driver doesn't leak state into the
tests that follow.
@sonarqubecloud

Copy link
Copy Markdown

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen
JE-Chen merged commit 023d8e6 into main Aug 10, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant