maestro

Maestro UI test: can I perform an action on multiple items identified by a selector?


I have a list on items in my app, e.g:

I would like to be able to perform an action (delete) on a set of matching items (e.g. if the text is "Item 2"). Some items may not be visible on screen when the list is long.

I can see there's an index for selecting among matches and I can also see there's a containsDescendants selector (which I'm thinking might match the parent view, not necessarily the list?) but I'm unclear if I can use some combination of these to iterate zero or more matching items.

The goal is to say: "while there's an element with this text in this screen, possibly out of sight, scroll down until it's visible and perform the delete action".

Ideally I'd like to:

- runFlow:
    when:
      containsDescendants: Item 2 # Keep looping while the list contains any matching items
    commands:
      - scrollUntilVisible:
          element: Item 2 # Scroll down to the item
      - longPressOn: Item 2
      - tapOn: Delete
      

I can see this doesn't work. I'm wondering if it's possible and, if so, what the syntax would be?


Solution

  • I would check out the repeat command. I think that will get you close to what you want; though I'm not sure if it will work if the element is off-screen; for that, you might need to use:

    I think what you'd end up with would probably be something like:

    - repeat:
        while:
          visible: "Item 2"
        commands:
          - longPressOn: "Item 2"
          - tapOn: Delete
    - swipe:
        direction: DOWN
    - runFlow:
        when:
          visible: "Item 2"
        commands:
            - longPressOn: "Item 2"
            - tapOn: Delete