请提供任何建议,但solo.clickOnText()除外。没用
而且我也不想使用enterText(),因为那不是一个好的选择。
最佳答案
[1]在文本框中输入“ a”
[2] solo.sendKey(97); //这里97是字符“ a”的ascii键代码。
在这里我代表一个很好的例子。
public void testAutomation_typetext()
{
solo.clickOnEditText(0);
ch_array = "ashtemp123@gmail.com".toCharArray();
for(int i=0;i<ch_array.length;i++)
{
solo.sendKey( fun_get_android_keycode(ch_array[i]) );
}
}
public int fun_get_android_keycode(char ch)
{
int keycode = ch;//String.valueOf(ch).codePointAt(0);
Log.v(TAG,"in fun : "+ch+" : "+keycode + "");
if(keycode>=97 && keycode <=122)
{
Log.v(TAG,"atoz : "+ch+" : "+keycode + " : " + (keycode-68));
return keycode-68;
}
else if(keycode>=65 && keycode <=90)
{
Log.v(TAG,"atoz : "+ch+" : "+keycode + " : " + (keycode-36));
return keycode-36;
}
else if(keycode>=48 && keycode <=57)
{
Log.v(TAG,"0to9"+ch+" : "+keycode + " : " + (keycode-41));
return keycode-41;
}
else if(keycode==64)
{
Log.v(TAG,"@"+ch+" : "+keycode + " : " + "77");
return KeyEvent.KEYCODE_AT;
}
else if(ch=='.')
{
Log.v(TAG,"DOT "+ch+" : "+keycode + " : " + "158");
return KeyEvent.KEYCODE_PERIOD;
}
else if(ch==',')
{
Log.v(TAG,"comma "+ch+" : "+keycode + " : " + "55");
return KeyEvent.KEYCODE_COMMA;
}
return 62;
}
我希望这将对您最好的自动化测试用例有所帮助。
谢谢。
关于android - 如何在Robotium中从Android键盘(虚拟)键入字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11684346/