Parameters & Constants

Pass parameters and set environment variables in Maestro flows with env and reuse via ${}.

External parameters

There might be cases where you don't want to store certain values in a test file itself (i.e. user name, password, etc.). To solve that, you can pass parameters to Maestro:

maestro test -e [email protected] -e PASSWORD=123 file.yaml

And then refer to them in your flow using ${name} notation:

appId: your.app.id
---
- launchApp
- inputText: ${USERNAME}
- tapOn: Next
- inputText: ${PASSWORD}

In a similar fashion, parameters can be passed to maestro cloud command:

maestro cloud -e [email protected] -e PASSWORD=123 app.apk file.yaml

Inline parameters

Constants can be declared at the flow file level, above the --- marker:

appId: your.app.id
env:
    USERNAME: [email protected]
    PASSWORD: 123
---
- inputText: ${USERNAME}
- inputText: ${PASSWORD}

Alternatively, they can be passed to a runFlow command:

appId: your.app.id
---
- runFlow:
    file: subflow.yaml
    env:
      USERNAME: [email protected]
      PASSWORD: 123
Nested Flows

Constants defined in a nested flow override parameters with the same name in the parent flow.

Accessing variables from the shell

Maestro will automatically read environment variables from the shell prefixed by MAESTRO_ and make them available in your Flows, assuming the environment variable is not manually defined in the Flow or passed as an env parameter.

export MAESTRO_FOO=bar

If you define the variable MAESTRO_FOO as above, you can simply refer to it in your Flows when running maestro test or maestro cloud like a normal environment variable:

- tapOn: ${MAESTRO_FOO}

Parameters and JavaScript

All env parameters are defined as JavaScript variables under the hood and can be accessed from the JavaScript code.

Using JavaScript in Maestro

Setting defaults for parameters in subflows

All env declarations are also JavaScript expressions, which you can use to set a default value. This is especially useful for subflows.

Here's an example login subflow.

appId: com.example
env:
  USERNAME: ${USERNAME || "[email protected]"}
  PASSWORD: ${PASSWORD || "hunter2"}
---
- tapOn: Your Username
- inputText: ${USERNAME}
- tapOn: Your Password
- inputText: ${PASSWORD}
- tapOn: Log In

When you call this with no env vars, you'll get the default USERNAME and PASSWORD, but these can be provided and overridden. This is useful for keeping your tests concise in places where you'd provide the same thing again and again.

# Log in as my-test-user
- runFlow: login.yaml 

# Log in as superuser
- runFlow:
    file: login.yaml
    env:
      USERNAME: [email protected]
      PASSWORD: sup3r_s3cr3t

Of course, since all env declarations are also JavaScript expressions, you can also specify those parameters at call time too, and call your subflow with parameters that were passed into Maestro as environment variables.

# Log in as the provided user
- runFlow:
    file: login.yaml
    env:
      USERNAME: ${MAESTRO_ENV_USER}
      PASSWORD: ${MAESTRO_ENV_PASSWORD}

Built-in parameters

The following parameters are built-in and available in all flows without needing to be defined:

  • MAESTRO_FILENAME: The filename of the current flow (e.g. flow.yaml)

Last updated

Was this helpful?