【问题标题】:uiDevice.executeShellCommand("pm uninstall " + Constants.APP_PACKAGE); does not return output string from shelluiDevice.executeShellCommand("pm 卸载" + Constants.APP_PACKAGE);不从 shell 返回输出字符串
【发布时间】:2017-02-25 10:16:45
【问题描述】:

我想在执行 UiAutomator 测试时卸载一个 apk。

我正在使用下面的命令,它工作正常。它从设备上卸载应用程序。

String output = uiDevice.executeShellCommand("pm uninstall " + Constants.APP_PACKAGE);

但是,当我检查输出字符串的值时,它是空白的。我想检查应用程序是否已卸载或不执行脚本中的后续步骤。这种情况下如何获取executeShellCommand的输出?

【问题讨论】:

    标签: android android-uiautomator


    【解决方案1】:

    假设您使用的是 Uiautomator2.0 。如果那时我想知道上面的代码是如何毫无例外地工作的。 uiDevice 是仪表实例吗? UiDevice.getInstance(getInstrumentation()) 有一个公共方法 executeShellCommand,它返回一个字符串。 试试下面的代码-

    private UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
    String output = mDevice.executeShellCommand("pm uninstall " + Constants.APP_PACKAGE);
    

    如果卸载成功,确切的代码将给出Success

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多