简体   繁体   English

如何使用Robotium测试点击软键盘“搜索”按钮?

[英]How to click on soft keyboard 'search' button with Robotium test?

I want to test next thing with Robotium: enter some text in search field, this I did, and click on soft keyboard 'search' button (android:imeOptions=actionSearch) which I am failing to do. 我想用Robotium测试下一件事:在搜索字段中输入一些文本,我做了,然后点击软键盘'搜索'按钮(android:imeOptions = actionSearch),我没有做到。 I tried with solo.sendKey(Solo.Enter) but no success. 我尝试使用solo.sendKey(Solo.Enter)但没有成功。 I am not sure if this is important, but soft keyboard is not shown at all - I tried to achieve that somehow but without success, also. 我不确定这是否重要,但软键盘根本没有显示 - 我试图以某种方式实现,但也没有成功。

Finally! 最后! Robotium 5.1 proudly presents to you pressSoftKeyboardSearchButton() . Robotium 5.1自豪地向您呈现pressSoftKeyboardSearchButton()

For older versions you can use this code (isn't clean enough, but works): 对于旧版本,您可以使用此代码(不够干净,但有效):

solo.enterText(0, "ItemToSearchFor");
solo.sleep(1000);
solo.clickInList(0); 

Have you tried to send this keycode? 你试过发送这个密码吗? http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_SEARCH something like this http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_SEARCH这样的东西

solo.sendKey(KeyEvent.KEYCODE_HOME); solo.sendKey(KeyEvent.KEYCODE_HOME);

You can not use keycode, what you can do is to know the key position and press it. 您不能使用键码,您可以做的是知道键位置并按下它。 As soft keyboard is a bitmap, not a view. 由于软键盘是位图,而不是视图。

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

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