In android phone how to lock and unlock the screen using appium
AndroidDriver provides the following methods to lock and unlock the device - isLocked()
, lockDevice()
and unlockDevice()
. These methods are available in AndroidDriver, so if your driver is of type AppiumDriver then you need to cast it to AndroidDriver -
((AndroidDriver<WebElement>)driver).unlockDevice();
Also, please note that these methods won’t work if you save set up a pin or passcode on the device.
The lock device works for me , but the other direction for unlocking fails every second execution …
[HTTP] --> POST /wd/hub/session/2f2caf8d-1439-4290-b1a9-4a776d8f1d67/appium/device/unlock {}
[debug] [MJSONWP] Calling AppiumDriver.unlock() with args: ["2f2caf8d-1439-4290-b1a9-4a776d8f1d67"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/ie54553/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window"]
[debug] [ADB] Running '/Users/ie54553/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window"]
[MJSONWP] Encountered internal error running command: Error: Error executing adbExec. Original error: 'Command '/Users/ie54553/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys window' timed out after 20000ms'; Stderr: ''; Code: 'null'
at ADB.execFunc$ (../../../lib/tools/system-calls.js:317:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/2f2caf8d-1439-4290-b1a9-4a776d8f1d67/appium/device/unlock 500 40086 ms - 373
Any one else has the same issues ?
Thanks
1 Like