android - 运行 monkeyrunner python 脚本时 EasyMonkeyDevice 未发现错误

标签 android python jython monkeyrunner

我想运行 monkeyrunner python 脚本。

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.android.monkeyrunner.easy import EasyMonkeyDevice
from com.android.monkeyrunner.easy import By
from modjy.modjy_params import INTEGER


# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

easyDevice = EasyMonkeyDevice(device)
MonkeyRunner.sleep(2)
easyDevice.touch(By.id('id/btnSignUp'),MonkeyDevice.DOWN_AND_UP)

下面是我用来运行脚本的命令

c:\path_to_and_sdk_tool> monkeyrunner test.py 

但是当我得到“EasyMonkeyDevice”对象时出现错误。

File "C:\python\test.py", line 19, in <module>
            easyDevice = EasyMonkeyDevice(device)
        java.lang.RuntimeException: Could not connect to the view server
                at com.android.chimpchat.hierarchyviewer.HierarchyViewer.setupViewServer
        (HierarchyViewer.java:57)
                at com.android.chimpchat.hierarchyviewer.HierarchyViewer.<init>(Hierarch
        yViewer.java:43)
                at com.android.chimpchat.adb.AdbChimpDevice.getHierarchyViewer(AdbChimpD
        evice.java:95)
                at com.android.monkeyrunner.easy.EasyMonkeyDevice.<init>(EasyMonkeyDevic
        e.java:64)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
        rce)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at org.python.core.PyReflectedConstructor.make(PyReflectedConstructor.ja
        va:67)
                at org.python.core.PyJavaType$1.new_impl(PyJavaType.java:517)
                at org.python.core.PyType.invokeNew(PyType.java:466)
                at org.python.core.PyType.type___call__(PyType.java:1558)

请分享一些我可以导入 EasyMonkeyDevice 的链接

最佳答案

您必须实现 ViewServer 才能使用 EasyMonkeyDevice : https://github.com/romainguy/ViewServer 因为 easyMonkey 使用 Hierarchy Viewer。

在你的 Activity 中:

像这样为层次结构查看器启用 ViewServer :

public class MyActivity extends Activity {

     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         ViewServer.get(this).addWindow(this);
     }

     public void onDestroy() {
        super.onDestroy();
        ViewServer.get(this).removeWindow(this);
     }

     public void onResume() {
        super.onResume();
        ViewServer.get(this).setFocusedWindow(this);
     }
}

关于android - 运行 monkeyrunner python 脚本时 EasyMonkeyDevice 未发现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27147772/

相关文章:

java - 在具有多个参数类型约束的 Kotlin 中调用具有泛型类型的方法

android - 在 Android 上存储登录信息的最佳实践

python - "Resample"根据其频率的时间戳

python - 我想找到 pandas 数据框中 1 列与所有其他列之间的协方差

java - 在 Jython 中创建 ArrayList 的 ArrayList

java - Jython,从 Java 代码内部停止脚本执行

首次启动 fragment 时,Android ListView 不显示内容

java - Android - 获取加载的类/反射以获取包中的类?

python - 为什么 jupyter 显示 "None not found"?

python - 如何在 python 中的字符串(句子)中打印函数返回的字典输出? (加工)