MarketSquare / MarketSquare/robotframework-browser
Add `Add Script Tag` keyword to inject a script into the page
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 655
- Forks
- 147
- Avg merge
- 5h 27m
- Merged PRs (30d)
- 59
Description
## Use case
The library already offers `Add Style Tag` for injecting CSS, but there is no counterpart for JavaScript. Users who want to load a helper library by URL (e.g. a test utility from a CDN or the app's own static server), inject a local helper file, or add an ES module `` cannot do so cleanly: `Evaluate JavaScript` evaluates an expression but cannot load an external script by URL and wait for it to load, so the current workaround is fragile hand-written DOM manipulation plus manual load-event polling. Playwright's `page.addScriptTag` does exactly this — adds the tag and resolves once the script has loaded.
## Proposed keyword / arguments
`Add Script Tag *, url=None path=None content=None type=None`
- `url` — URL of a remote script to add.
- `path` — path to a local JavaScript file to inject (content is inlined).
- `content` — raw JavaScript content to inject.
- `type` — script type; use `module` for an ES module. Defaults to a classic script.
Exactly one of `url`/`path`/`content` must be given (mirroring Playwright). Keyword returns once the script has loaded and executed.
```robotframework
Add Script Tag url=${URL}/static/test-helpers.js
Evaluate JavaScript ${None} () => window.testHelpers.reset()
Add Script Tag path=${CURDIR}/helpers/fill-fixtures.js
Add Script Tag content=window.flag = 42; type=module
```
## Playwright API
[`page.addScriptTag`](https://playwright.dev/docs/api/class-page#page-add-script-tag)
## Implementation notes
- New RPC in `protobuf/playwright.proto` (url, content, type — `path` is read Python-side and sent as content, matching how other file arguments are handled).
- Simple pass-through in `node/playwright-wrapper` on the active page (returned ElementHandle is discarded — handles are not part of the keyword model).
- Python keyword next to `add_style_tag` in `Browser/keywords/evaluation.py`, docs, atest loading a script by URL from the test app and by content.
## Backwards compatibility
Purely additive: a new keyword, symmetric to the existing `Add Style Tag`; nothing existing changes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Browser/keywords/evaluation.py next to add_style_tag, then trace the RPC in protobuf/playwright.proto and the pass-through in node/playwright-wrapper. Run the atest coverage for loading scripts by URL and content. Done means the keyword supports the specified sources and type, and returns after the script has loaded and executed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100