Chimpchat自动旅程 [英] Chimpchat automatic journey

查看:764
本文介绍了Chimpchat自动旅程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是让猴子访问特定的Andr​​oid应用程序的所有页/活动。
我目前使用Chimpchat和我的第一个步骤如下:

My goal is to make a monkey visit all pages/activity of a given android application. I am currently using Chimpchat and my first steps are as following :

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 - 获取视图ID列表:

mDevice.getViewIdList();

3 - 对于每一个字符串(使用迭代它)标识中包含由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();
        }


    }

我得到了一个异常

I get an exception on the

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)

如果任何人都可以点我的错(S)或点我到另一种方法,这将是极大的AP preciated!

If anyone can point my mistake(s) or point me to another approach, it would be greatly appreciated !

推荐答案

我认为问题是,有没有运行活动。
正如我上面的评论你也许可以使用 startActivity 开始的。
然而这将需要一些挖掘,以找出所有需要传递的东西。结果
另一种解决方案如下:

I think that the issue is that there is no Activity running. As I commented above you might be able to use startActivity to start one. However that will take some digging to figure out what all needs to be passed in.
Another solution is as follows:

StringBuilder builder = new StringBuilder();
builder.append("am start -a android.intent.action.MAIN -n ");
builder.append(mPackage).append("/").append(mActivity);
String output = mDevice.shell(builder.toString());

这将使用adb shell启动应用程序。
mPackage =包路径(com.company.application)和 mActivity =活动(.MyActivity)。从那里,你应该能够 mDevice.getHierarchyViewer() mDevice.getViewIdList()

This will use the adb shell to launch the application. mPackage = the package path (com.company.application) and mActivity = the activity (.MyActivity). From there you should be able to mDevice.getHierarchyViewer() or mDevice.getViewIdList()

这篇关于Chimpchat自动旅程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆