Run JavaScript
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.
Inject
Everything within ${}
blocks is evaluated as JavaScript, allowing you to insert dynamically computed values into any other Maestro command.
Run file
If you want to run a JavaScript file you can use the runScript command:
runScriptPassing parameters
runScript
accepts env
parameters, in the same way as runFlow
does (see Nested Flows).
Passing a parameter:
Reading a parameter in JavaScript:
Inline
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:
Inbuilt functions & properties
Whilst the JavaScript environment is limited, there are a few inbuilt things that can be used:
object maestro
maestro
The maestro
object contains the following properties:
copiedText
Results of the copyTextFrom command. See Access element text
platform
The platform the test is running on. Either ios
or android
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:
function relativePoint
relativePoint
The relativePoint
function converts decimal values to string percentages, which is the format that Maestro commands expect.
Others
The following inbuilt functions are documented in Make HTTP requests:
http.request
http.get
http.post
http.put
http.delete
json
Last updated