Repository navigation
Conversation
The script is registered on the active context, so it reaches every page, frame and popup of it, and it is removed when its scope (Test by default, Suite or Global) ends or its context closes. A script from a file is read by Python; with arg, the script must be one function expression, which Node calls with the value. Fixes MarketSquare#5099 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The arg check promises one expression, which is what it checks; a non-function fails in the page like other script errors. The test that a Test-scoped init script does not reach the next test runs its own two-test suite, so it no longer depends on test order. Also drops an unused type export, trims the docstring and comments the new rpcs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5099
Summary
Add Init Script script=None * path=None arg=None scope=Testregisters an init script on the active context: it runs before the page's own scripts in every page, frame and popup of that context. It is always context level; there is no page-level variant (ADR 0015).Corrections to the issue body, found while implementing:
arg, the check is that the source is one expression, not one function expression. An expression that is not a function fails in the page, like any other error in the script.Get Page Errors(Playwrightpageerror), not in the console log.Also: the glossary gets Init script, ADR 0015 records why it is context level with a scope, and the outdated comment in
recorder.tsthat said an init script cannot be removed is reworded (Recorder behaviour unchanged).Evidence
After:
atest/test/05_JS_Tests/init_script.robot, 9 tests: the script runs before an inline page script,arg,path, popups, several scripts, a broken script does not fail the keyword and shows inGet Page Errors, error whenargis used with statements, error when both or neither of script/path are given, aSuitescript reaches every test, andscope=Testfails in Suite Setup.utest/test_init_script_scope.pyruns its own two-test suite: aTest-scoped script does not reach the next test. With the removal at scope end disabled, this test fails.utest/test_python_usage.py: on the Python path the script stays until its context closes; no open context fails.init-script.test.ts:argwrapping, the one-expression check, a file ending in a line comment.inv utest1765 passed,inv utest-node406 passed,inv lintclean, fullinv atest1106 passed, 4 failed. The 4 failures are local to the maintainer's Mac and unrelated: three Firefox launch failures, andWait For Response With OPTIONS Request, which needs Playwright 1.65 while the local wrapper install still has 1.64.1. The new tests also ran on 1.64.1 locally; CI runs them on 1.65.Merge Danger
Door: two-way until released, one-way after: a released keyword is removed only through deprecation.
Blast Radius: small
Purely additive keyword. The only shared path touched is the end of each test and suite, which now also removes the init scripts of that scope; it does nothing when none were added.
🤖 Generated with Claude Code