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?
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:
scrollUntilVisible
; you can't really scroll until a target that might not be there, without it failing if it isn't, I don't think. You may need to use coordinates and multiple swipes depending on how long your list is. (Though, personally, I'd try to set up your test data such that the length of the list was constant, and just test multiple lengths in multiple tests, if you need to; rather than trying to write a test to account for a list that might be any length.)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