Skip to content

evalWebViewScript ​

Run JavaScript in the WebView on screen.

Partial support in Astra Scout

Android only. The step is not available on iOS.

The evalWebViewScript command runs a JavaScript snippet inside the WebView that is on screen, and can keep the result in a variable. Use runWebViewScript to run a file instead. It connects to the WebView with the Chrome DevTools protocol, so the WebView must be visible.

Syntax ​

yaml
- evalWebViewScript: return document.title
# or
- evalWebViewScript:
    script: return document.title
    output: TITLE

Parameters ​

ParameterTypeDescription
scriptStringRequired. JavaScript to run. It is the body of an async function, so use await and return.
outputStringName of a variable that receives the returned value as text. Later steps read it as ${NAME}.

Behavior ​

  • The script must return a value to fill output. 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
- evalWebViewScript:
    script: return document.querySelector('h1').innerText
    output: HEADING
- assertTrue: ${HEADING == "Welcome"}