Conditions
Use conditions in Maestro flows to run commands based on visibility, platform, or JavaScript expressions.
By design, Maestro discourages the usage of conditional statements unless absolutely necessary as they could easily ramp up the complexity of your tests.
runFlow conditionally
- runFlow:
when:
visible: 'Some Text'
file: folder/some-flow.yamlOr, if you don't wish to extract your commands into a separate flow file, you can run the commands inline like this:
- runFlow:
when:
visible: 'Some Text'
commands:
- tapOn: 'Some Text'runScript conditionally
- runScript:
when:
visible: 'Some Text'
file: some-script.jsMultiple conditions
- runFlow:
when:
visible: 'Some Text'
platform: iOS
file: folder/some-flow.yamlNote that multiple conditions are applied as AND conditions.
Conditions
Supported conditions include:
visible: { Element matcher } # True if matching element is visible
notVisible: { Element matcher } # True if matching element is not present
true: { Value } # True if given value is true or not empty
platform: { Platform } # True if current platform is given platform (Android|iOS|Web)All of the normal element matchers are supported, e.g.
- runFlow:
when:
visible:
id: 'someId'
text: 'Some Text'
below:
text: 'Some Other Text'
childOf:
id: 'someParentId'
text: 'Some Parent Text'
index: 2
file: folder/some-flow.yamlJavaScript
Usage of JavaScript conditions is possible via true condition:
- runFlow:
when:
true: ${MY_PARAMETER == 'Something'}
file: subflow.yamlIt's also possible to do platform detection in JavaScript:
- runFlow:
when:
true: ${maestro.platform == 'android'}
file: subflow.yamlif (maestro.platform == 'android'){
output.searchTerm = 'robots'
}
if (maestro.platform == 'ios'){
output.searchTerm = 'apples'
}
if (maestro.platform == 'web'){
output.searchTerm = 'spiders'
}Last updated
Was this helpful?
