Robotium为Android - solo.searchText()不工作 [英] Robotium for Android - solo.searchText () not working
问题描述
我在与Robotium使用SEARCHTEXT()函数的一个问题。
I'm having a problem with searchText() function used with Robotium.
我在寻找这个字符串:
<string name="provisioning_wizard_title_2">Service Activation Wizard (Step 2)</string>
我在字符串XML定义它,我在寻找这种方式:
I defined it in string xml, and I'm searching it this way:
Activity act=solo.getCurrentActivity();
String string = solo.getString(act.getResources().getIdentifier("provisioning_wizard_title_2", "string", act.getPackageName()));
当我把它称为失败
assertTrue(solo.searchText(string));
和它也失败,如果我打电话:
and it fails also if i call:
assertTrue(solo.searchText("Service Activation Wizard (Step 2)"));
即使这是我看到在聚焦屏幕活动的字符串。
even if that is the string I'm seeing in the focused screen activity.
但奇怪的是,它的作品,如果我使用相同字符串,不最后一个字符:
The strange thing is that it works if I use the same string without last character:
assertTrue(solo.searchText("Service Activation Wizard (Step 2"));
和它的作品,如果我用
assertTrue(solo.searchText(string.substring(0, string.length()-1)));
我希望有人能够帮助我。
I hope someone could help me.
对不起,我的英语!
感谢您。
问题解决了
我感谢解决问题Renas里达(Robotium的创始人和维护者)。
这个问题是由于SEARCHTEXT()正则表达式的支持;一些字符会触发它。
使用Pattern.quote(串)
例如:Pattern.qoute(provisioning_wizard_title_2)和eveything做工不错
PROBLEM SOLVED I solved problem thanks to Renas Reda (Founder and maintainer of Robotium). The problem is due to regex support in searchText(); some characters will trigger it. Use Pattern.quote(string) Example: Pattern.qoute("provisioning_wizard_title_2") and eveything works good!
推荐答案
我通常使用独奏#waitForText(...)
,所以我要确保我没有失去一些竞争状态。
I usually use Solo#waitForText(...)
so I make sure I'm not losing some race condition.
试试这个:
assertTrue(solo.waitForText(solo.getString(R.string provisioning_wizard_title_2));
请确保您输入正确 R.java
从你的生产项目(而不是测试项目)文件。
Make sure you are importing the correct R.java
file from your production project (not the test project).
这篇关于Robotium为Android - solo.searchText()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!