Skip to content

Latest commit

 

History

History
82 lines (57 loc) · 2.43 KB

runscript.md

File metadata and controls

82 lines (57 loc) · 2.43 KB

runScript

The runScript command runs a provided JavaScript file.

appId: com.example
env:
    MY_NAME: John
---
- launchApp
- runScript: myScript.js
- inputText: ${output.myFlow}

A script would typically perform some action and set an output value that could be accessed later. See outputs.md for more information.

var uppercaseName = MY_NAME.toUpperCase()

output.myFlow = uppercaseName   // returns 'JOHN'

{% hint style="info" %} You can directly access env parameters from within JavaScript. See parameters-and-constants.md for more information. {% endhint %}

For more information regarding JavaScript, please refer to the JavaScript section:

{% content-ref url="../../advanced/javascript/" %} javascript {% endcontent-ref %}

File Paths

Paths can be relative or absolute. Relative paths are required for cloud running. Relative paths are relative to the calling flow, not to the directory running the command.

In a directory structure like this:

├── flows
│   └── test.yaml
└── scripts
    └── uppercase.js

The flow test.yaml would look like this:

appId: com.example
env:
    MY_NAME: John
---
- launchApp
- runScript: ../scripts/uppercase.js

Passing parameters

runScript accepts env parameters, in the same way as runFlow does (see nested-flows.md).

- runScript:
    file: script.js
    env:
       myParameter: 'Parameter'

Running conditionally

You can use conditionals to run a JavaScript file when some condition is true. For more information, please refer to the conditionals documentation.

Console logging

Console logging is supported from the JavaScript files provided in runScript command. Logs from JavaScript are redirected to the console when using Maestro CLI.

{% hint style="warning" %} Remember that when running in the cloud and requiring another file, you must specify a folder on the command line not just the flow file, e.g. maestro cloud myApp.apk ./myTestsFolder else Maestro won't have the files required to run your tests, and you'll receive a 'Failed to parse file' error. {% endhint %}