Run JavaScript
Last updated
Last updated
Maestro is not a JavaScript testing framework, but we recognize not everything can (or should) be written in YAML. That's why we have JavaScript support.
There are several ways to run JavaScript, depending on your needs.
Right now, Rhino is the default JavaScript engine in Maestro, but we intend to make GraalJS the default soon and then deprecate and remove Rhino. We recommend everyone to opt-in to use GraalJS.
Learn more about GraalJS support.
Everything within ${}
blocks is evaluated as JavaScript, allowing you to insert dynamically computed values into any other Maestro command.
If you want to run a JavaScript file you can use the runScript command:
runScript
accepts env
parameters, in the same way as runFlow
does (see Nested Flows).
Passing a parameter:
Reading a parameter in JavaScript:
For very simple computations (like the one above), creating a new file might be cumbersome. For this use case you can use the evalScript
command:
Whilst the JavaScript environment is limited, there are a few inbuilt things that can be used:
maestro
The maestro
object contains the following properties:
The maestro.platform
value is useful for conditional logic that differs between Android and iOS. For example, you might want to handle location permission differently:
relativePoint
The relativePoint
function converts decimal values to string percentages, which is the format that Maestro commands expect.
The following inbuilt functions are documented in Make HTTP requests:
http.request
http.get
http.post
http.put
http.delete
json
Field Name | Value |
---|---|
copiedText
Results of the copyTextFrom command. See Access element text
platform
The platform the test is running on. Either ios
or android