e2e-testing: no way to register per-navigation page state on the shared Page #49
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
iterative-works/support#49
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found while reviewing an E2E readiness wait in
medeca-modul-poptavky(MEDECA-444 Phase 4).The shape of the problem
PlaywrightTestContextcreates onePageininitialize()andgetPage()returns that sameinstance for the entire Cucumber run
(
e2e-testing/src/main/scala/works/iterative/testing/e2e/PlaywrightTestContext.scala:30,57,60-66).Per-scenario recycling happens only when a video recording directory is configured, which most
suites leave unset.
Playwright has no API to remove an init script. So
page.addInitScript()called from a Cucumberstep body registers for the lifetime of the
Page, not for the current navigation. A step used byN scenarios stacks N identical scripts, and every one of them then re-runs before every later
navigation in the suite — including pages that have nothing to do with the step that registered it.
Concrete instance: a navigation step backing 14 scenarios across 5 feature files registers an init
script that installs a DOM event listener used as a readiness signal. By the end of the run, 14
copies run before every navigation. It happens to be idempotent there (each copy sets the same flag
false, each listener sets it true), so it is untidy rather than wrong — but the next use of the
pattern need not be idempotent.
Why the consumer cannot fix it
A correct one-shot registration needs
Page-keyed state, and a Cucumber step class cannot hold it:Cucumber instantiates a fresh step instance per scenario. The fix belongs in this module.
Suggested direction
Give
e2e-testinga way to registerPage-scoped setup exactly once — aPage-keyed registry, ora hook that runs registrations at
Pagecreation. Then document the rule for consumers: registerper-navigation state with
page.evaluateafter navigating, and reserveaddInitScriptforlisteners that must exist before the page's own scripts run, registered once per
Page.Reference:
medeca-modul-poptavky,project-management/issues/MEDECA-444/LESSONS.md, entry2026-09-03 "
page.addInitScriptaccumulates for the whole run on the suite's single sharedPage".