runWebViewScript
Run a JavaScript file in the WebView on screen.
Partial support in Astra Scout
Android only. The step is not available on iOS.
The runWebViewScript command runs a JavaScript file inside the WebView that is on screen, and can keep the result in a variable. Use evalWebViewScript to run an inline snippet instead. It connects to the WebView with the Chrome DevTools protocol, so the WebView must be visible.
Syntax
yaml
- runWebViewScript: scripts/read-cart.js
# or
- runWebViewScript:
file: scripts/read-cart.js
env:
ITEM: shoes
output: CARTParameters
| Parameter | Type | Description |
|---|---|---|
file | String | Required. Path to the JavaScript file. The file is the body of an async function, so use await and return. |
env | Map | Values the script reads from window.__env. |
output | String | Name of a variable that receives the returned value as text. Later steps read it as ${NAME}. |
Behavior
- The script must
returna value to filloutput. Only a string result is stored. - The script is stopped after 10 seconds.
- The step fails with "No WebView CDP connection" if no inspectable WebView is visible.
Usage example
yaml
- runWebViewScript:
file: scripts/read-heading.js
output: HEADING
- assertTrue: ${HEADING == "Welcome"}With scripts/read-heading.js:
js
return document.querySelector('h1').innerText;