maestro icon indicating copy to clipboard operation
maestro copied to clipboard

`eraseText` only erases text until the middle if the text is long enough

Open danielferromeral opened this issue 1 year ago • 6 comments

When I tapOn a textInput, the cursors sets in the middle. When I use eraseText, it stats to delete from that point, but if my text was longer that the middle, some letters are not deleted, so I have to tap again and delete it again.

I would like to be able to complete delete the text input with a single command, or to be able to move the cursor to the end.

danielferromeral avatar Jul 05 '24 10:07 danielferromeral

Hey @danielferromeral, thanks for creating the issue. Could you provide some more information? For example:

  • OS, OS version, physical/virtual device?
  • Framework used to build the app (e.g. SwiftUI, UIKit, Flutter, Compose?)
  • screen recording would be great as well

bartekpacia avatar Jul 10 '24 23:07 bartekpacia

Hi @bartekpacia. I have tried in two different devices (both are virtual) and in two different views.

One of the devices was a Virtual iPhone 15 with iOS 17.5, and the views were made with Swift and UIKit. The other device was a Virtual Pixel 8 Pro, and the views are made with Kotlin and Java, but not sure at all, the developer is in PTO.

The flow I used is this:

- runFlow:
    label: "Erase Text"
    commands:
        - tapOn: 
            id: "emailInput"
        - inputText "[email protected]"
        - tapOn: 
            id: "emailInput"
        - eraseText
        - tapOn: 
            id: "emailInput"
        - eraseText

And this is the result: https://github.com/user-attachments/assets/d9ab49ff-39de-48b0-a375-8a32bbf20b01

danielferromeral avatar Jul 12 '24 09:07 danielferromeral

Thanks a ton. If you could also drop an .apk, .app or some sample code in e.g. SwiftUI, that'd be great!

bartekpacia avatar Jul 12 '24 09:07 bartekpacia

Hi, I cannot provide a sample code, sorry, not a mobile dev. But I guess you could use any input text, like the search bar in the settings for Android. In fact, I made this little script with the search bar of the setting app and is the same bahavoiur. Hope it helps.

appId: com.android.settings

---

- launchApp
- tapOn:
    id: "com.android.settings:id/search_action_bar"
- inputText: "Lorem ipsum dolor sit amet"
# Here you would do other actions and the cursor would be no longer at the end of the text
- tapOn:
    id: "com.google.android.settings.intelligence:id/open_search_view_edit_text"
- eraseText
- tapOn:
    id: "com.google.android.settings.intelligence:id/open_search_view_edit_text"
- eraseText
- stopApp

danielferromeral avatar Jul 12 '24 14:07 danielferromeral

Thanks @danielferromeral, I was able to reproduce the problem thanks to your code sample.

Run video

https://github.com/user-attachments/assets/86b8bb36-dc9a-49bf-ae15-15b22ae4dcc9

bartekpacia avatar Jul 17 '24 21:07 bartekpacia

Running into the same problem with Maestro CLI v1.38.1 when executing tests on a physical Android device (OnePlus Nord, Android 12, connected to Windows 11 via USB). Also, this looks like it's a duplicate of #495.

hormesiel avatar Oct 23 '24 06:10 hormesiel

eraseText still place cursor in the middle of text ( only 15 chars) and erase first half... had to make like this to work . any better solution please ?

 - tapOn: 
      id: "stringid"
  - eraseText
  - tapOn: 
      id: "stringid"
  - eraseText
  -  tapOn: 
      id: "stringid"
  - eraseText

alainib avatar Mar 17 '25 15:03 alainib

Here's a utility flow I wrote for one of my projects. It's a little slower (moreso when the text is short and 'Select All' isn't visible), but it's reliable:

appId: ${APP_ID}
jsEngine: graaljs
# Clear a given text field, avoiding flakiness in iOS (https://maestro.mobile.dev/api-reference/commands/erasetext)
# and avoiding issues of not erasing portions of long text already present
env:
  FIELD_ID: ${FIELD_ID}
---
- runFlow:
    when:
      visible:
        id: ${FIELD_ID}
    commands:
      - tapOn:
          id: ${FIELD_ID}
      - longPressOn:
          id: ${FIELD_ID}
      - runFlow:
          label: Select All
          # Sometimes you won't get Select All, but will get Cut, Paste, etc. That's fine - it's probably all selected anyway
          when:
            visible: 'Select All'
          commands:
            - tapOn: 'Select All'
      - eraseText: 1

Fishbowler avatar Mar 26 '25 10:03 Fishbowler

I'm going to close this as a duplicate of #495, but reference it there - there's some good content and conversation here.

Fishbowler avatar Mar 26 '25 10:03 Fishbowler

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 Apr 02 '25 12:04 github-actions[bot]