简体   繁体   English

如何在测试Android studio中用键盘粘贴

[英]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.当我长按文本输入并出现“粘贴”选项时,我试图使用粘贴 function。 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:这不完全是您所要求的,但鉴于我认为不可能使用 Espresso 执行此操作,您可能会考虑在测试中执行 (ctrl + v) 以在 UIAutomator 中执行粘贴:

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.您可能想看看Espresso 和 UIAutomator - 完美的串联文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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