mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.71k stars 260 forks source link

Support tapping on a point within an element #2059

Open tokou opened 1 week ago

tokou commented 1 week ago

[!note] To my surprise, this is documented as working, so maybe this should be a bug https://maestro.mobile.dev/api-reference/commands/tapon#tapping-on-a-specific-point-within-another-element

Use case

Tapping on an element will automatically tap on the center of the element This can lead to issues in cases where the element id refers to a large area that could have specific tap zones

Example: This whole area is tappable and has a single element id. However it contains links in the spannable text. Capture d’écran 2024-09-16 à 14 22 19

Other examples include needing to tap on specific areas of large images: Capture d’écran 2024-09-16 à 14 26 51

Proposal

Make it so that

- tapOn:
    id: 'large_button'
    point: '10%, 50%'

Would tap on the left side of the selected element instead of the current behavior of simply ignoring the id

Anything else?

We might want to add it as a separate field

This is the related code

https://github.com/mobile-dev-inc/maestro/blob/21edc1442aa96d6c435fb88b57bd5e72a65af0c8/maestro-orchestra/src/main/java/maestro/orchestra/yaml/YamlFluentCommand.kt#L472-L497

This should obviously work with any element selector, not just id

Here's an e2e test

appId: com.example.example
tags:
    - passing
---
- launchApp:
    clearState: true
- tapOn: 'Swipe Test'
- tapOn:
    text: 'End here!'
    point: '90%, 90%'

I thought this would do the trick but it does not behave as expected:

appId: com.example.example
tags:
    - passing
---
- launchApp:
    clearState: true
- tapOn: 'Swipe Test'
- tapOn:
    point: '90%, 90%'
    childOf:
      text: 'End here!'
- tapOn:
    text: 'End here!'
    containsChild:
      point: '90%, 90%'