正在运行以“ geo fix”命令发送的浓缩咖啡测试来寻找此权限问题的解决方案。
@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权限,但产生了“仅授予系统应用程序权限”。
提前感谢。
您可以获取UIDevice,然后获取device.executeShellCommand(“ command here”)