谷歌解释了如何控制安卓仿真器的许多参数,比如电池的当前充电、传感器输入等等:https://developer.android.com/studio/run/emulator-console.html。
我想创建一个Espresso测试,在测试期间更改仿真器的这些参数,这可能吗?我知道有以下方法:
InstrumentationRegistry.getInstrumentation().uiAutomation
.executeShellCommand("someShellCommand")此方法可以在测试期间调用,但要更改模拟器的系统参数,首先必须通过telnet localhost 5554登录,然后才能操作模拟器参数,例如:power capacity 30,它将电池的功率更改为30%。我如何在Espresso测试中做到这一点?
发布于 2018-01-03 17:17:42
你可以试试
InstrumentationRegistry.getInstrumentation().getUiAutomation()
.executeShellCommand("dumpsys battery set level 30");来改变电池的电量。其他值或设置可能需要不同的命令。
注意:阅读完后关闭返回的文件描述符是您的责任。
https://stackoverflow.com/questions/48081847
复制相似问题