Ben
Ben

Reputation: 139

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?

Upvotes: 2

Views: 287

Answers (1)

jeprubio
jeprubio

Reputation: 18012

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.

Upvotes: 2

Related Questions