Espresso测试许可被拒绝执行shell命令“ geo fix ..”

时间:2019-06-21 10:38:03

标签: android android-espresso

正在寻找一种解决方案,以运行正在发送“地理修复”命令的espresso测试来解决此权限问题。

@Test
public void test_geofix() { 
   // ...throws exception
   InstrumentationRegistry.getInstrumentation().
       getUiAutomation().executeShellCommand("geo fix -70 40 3");
}

引发此异常(出现在日志中,但被UIAutomation捕获):

java.lang.RuntimeException: Error running shell command
    at android.app.UiAutomationConnection$1.run(UiAutomationConnection.java:300)
 Caused by: java.io.IOException: Cannot run program "geo": error=13, Permission denied
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:983)
    at java.lang.Runtime.exec(Runtime.java:691)
    at java.lang.Runtime.exec(Runtime.java:524)
    at java.lang.Runtime.exec(Runtime.java:421)
    at android.app.UiAutomationConnection$1.run(UiAutomationConnection.java:286)
 Caused by: java.io.IOException: error=13, Permission denied
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
    at java.lang.ProcessImpl.start(ProcessImpl.java:128)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:964)
    at java.lang.Runtime.exec(Runtime.java:691) 
    at java.lang.Runtime.exec(Runtime.java:524) 
    at java.lang.Runtime.exec(Runtime.java:421) 
    at android.app.UiAutomationConnection$1.run(UiAutomationConnection.java:286) 

试图将ACCESS_MOCK_LOCATION权限添加到被测应用程序(在调试清单中),但产生了“仅授予系统应用程序权限”。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以获取UIDevice,然后获取device.executeShellCommand("command here")