遇到问题
- 在Jenkins定时跑Appium时,屏幕休眠状态时,应用不能启动
解决方法
- 在构建的时候先判断下屏幕是否休眠,如果不休眠,则唤醒屏幕
/** * 判断设备是否休眠
* @return
* @throws IOException
*/
public boolean isScreenLock() throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("cmd.exe /c adb shell dumpsys power | findstr \"Display Power:state=\"");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
String content = "";
boolean flag = false;
while ((line = in.readLine()) != null)
content = content + line;
if (content.contains("Display Power: state=OFF"))
flag = true;
p.destroy();
return flag;
}
if(getUrlFile.isScreenLock()){
// 模拟Power键
Runtime.getRuntime().exec("adb shell input keyevent 26");
// 模拟Home键
Runtime.getRuntime().exec("adb shell input keyevent 3");
}
网友评论