我的目标是让猴子访问给定 Android 应用程序的所有页面/Activity 。 我目前正在使用 Chimpchat,我的第一步如下:
1 - 连接到设备:
TreeMap<String, String> options = new TreeMap<String, String>();
options.put("backend", "adb");
options.put("adbLocation", ADB);
mChimpchat = ChimpChat.getInstance(options);
mDevice = mChimpchat.waitForConnection(TIMEOUT, ".*");
mDevice.wake();
2 - 获取 View ID 列表:
mDevice.getViewIdList();
3 - 对于每个字符串(使用它的迭代器)ID 包含在 getViewIdList() 返回的列表中,我想访问类、文本(如果有)、边界等......
while (it.hasNext()) {
String s = it.next();
System.out.println(s + " : ");
try {
IChimpView v = mDevice.getView(By.id(s));
System.out.println(v);
System.out.println(v.getViewClass() + " : " );
if (v.getViewClass().toString() == "TextView") {
System.out.print(v.getText());
}
} catch (Exception e) {
e.printStackTrace();
}
}
我得到一个异常(exception)
v.getViewClass()
com.android.chimpchat.core.ChimpException: Node with given ID does not exist
at com.android.chimpchat.ChimpManager.queryView(ChimpManager.java:415)
at com.android.chimpchat.core.ChimpView.queryView(ChimpView.java:53)
at com.android.chimpchat.core.ChimpView.getViewClass(ChimpView.java:96)
at JavaMonkey.listViewsID(JavaMonkey.java:80)
at JavaMonkey.main(JavaMonkey.java:114)
如果有人能指出我的错误或指出另一种方法,将不胜感激!
最佳答案
我认为Robotium会更适合这种类型的测试。根据我的经验,使用 adb/MonkeyRunner 访问远程设备上的 View 不是很可靠。此外,Robotium 具有许多很酷的功能,可以轻松集成到现有的测试套件中。
关于android - Chimpchat 自动旅程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21481057/