2017-02-25 38 views
0

我想在执行UiAutomator测试时卸载一个apk。uiDevice.executeShellCommand(“pm uninstall”+ Constants.APP_PACKAGE);不从shell返回输出字符串

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

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

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

回答

0

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

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

确切的代码会给Success在卸载成功的案例。