简体   繁体   中英

How to paste with keyboard in test Android studio

Im trying to use the paste function when I longclick on a text input and the "paste" option appears. I have tried to click with

onView(withText("Paste"))
            .perform(click(), pressImeActionButton());

using espresso but it does not work. How can i click the little paste prompt that appears?

It's not exactly what you were asking for but given that I don't think it's possible to do this with Espresso you might consider doing (ctrl + v) to perform paste in UIAutomator in your tests:

UiDevice
    .getInstance(InstrumentationRegistry.getInstrumentation())
    .pressKeyCode(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_MASK)

You might want to have a look at the Espresso & UIAutomator - the perfect tandem article.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM