maestro icon indicating copy to clipboard operation
maestro copied to clipboard

If statement

Open ghasemdev opened this issue 2 years ago • 6 comments

Hi, in my use case, we need to log into the app at first launch, then some other UI test happens. But on the second launch, the login screen doesn't show. In this situation we need an if statement to separate these two work flows.

# flow.yaml

appId: com.example.app
---
- launchApp
- if assertVisible : "Phone Number"
  then :
    - tapOn: "Phone Number"
    - inputText: "+123456789"
    - tapOn: "Confirm"
- elif OTHER_CONDITION
  then :
    - ...
- else :
   - tapOn: "Search"
   - ...
- fi

ghasemdev avatar Sep 13 '22 06:09 ghasemdev

To support this particular use case Maestro offers an initFlow: https://docs.mobile.dev/reference/app-state-restoration

The idea is that you would extract your login flow into a separate file and refer to it in your actual test

dmitry-zaitsev avatar Sep 13 '22 08:09 dmitry-zaitsev

That said, an if statement still has its own use cases and we will consider adding it

dmitry-zaitsev avatar Sep 13 '22 08:09 dmitry-zaitsev

.+1 for this enhancement suggestion, it would be fairly critical in some areas

simon-gilmurray avatar Sep 13 '22 15:09 simon-gilmurray

Adding a +1 here. we have a similar case where there is a flow (or a set of steps) we would like to run if an element is visible/invisible.

In my mind the ideal syntax would be (recalling similar syntax of the extendedWaitUntil):

- runFlow: open-rh.yml
  visible: Element
  notVisible: Element

but I guess the possibility to add elif and/or else would be interesting

carlonzo avatar Sep 28 '22 17:09 carlonzo

I guess this use case is partially covered by https://github.com/mobile-dev-inc/maestro/pull/245 ? without the else

carlonzo avatar Oct 13 '22 06:10 carlonzo

Nice find, looks like it's gone in to 1.10.x although nothing's been announced for it yet

simon-gilmurray avatar Oct 13 '22 08:10 simon-gilmurray

This is indeed covered with the conditional runFlow execution

Leland-Takamine avatar Oct 26 '22 02:10 Leland-Takamine

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue. Thank you for helping keep us our issue tracker clean!

github-actions[bot] avatar Jul 11 '24 18:07 github-actions[bot]