Skip to content

Commit 15ae78b

Browse files
feat: Improve the documentation on unlock (#979)
1 parent fead5b4 commit 15ae78b

File tree

7 files changed

+103
-7
lines changed

7 files changed

+103
-7
lines changed

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ appium:noSign | Set it to `true` in order to skip application signing. By defaul
154154

155155
Capability Name | Description
156156
--- | ---
157-
appium:skipUnlock | Whether to skip the check for lock screen presence (`true`). By default Espresso driver tries to detect if the device's screen is locked before starting the test and to unlock that (which sometimes might be unstable). Note, that this operation takes some time, so it is highly recommended to set this capability to `false` and disable screen locking on devices under test.
158-
appium:unlockType | Set one of the possible types of Android lock screens to unlock. Read the [Unlock tutorial](https://github.com/appium/appium-android-driver/blob/master/docs/UNLOCK.md) for more details.
159-
appium:unlockKey | Allows to set an unlock key. Read the [Unlock tutorial](https://github.com/appium/appium-android-driver/blob/master/docs/UNLOCK.md) for more details.
160-
appium:unlockStrategy | Either 'locksettings' (default) or 'uiautomator'. Setting it to 'uiautomator' will enforce the driver to avoid using special ADB shortcuts in order to speed up the unlock procedure.
161-
appium:unlockSuccessTimeout | Maximum number of milliseconds to wait until the device is unlocked. `2000` ms by default
157+
appium:skipUnlock | Whether to skip the check for lock screen presence (`true`). By default Espresso driver tries to detect if the device's screen is locked before starting the test and to unlock that (which sometimes might be unstable). Note, that this operation takes some time, so it is recommended to set this capability to `false` and disable screen locking on devices under test. Read the [Unlock tutorial](./docs/unlock/main.md) for more details.
158+
appium:unlockType | Set one of the possible types of Android lock screens to unlock. Read the [Unlock tutorial](./docs/unlock/main.md) for more details.
159+
appium:unlockKey | Allows to set an unlock key. Read the [Unlock tutorial](./docs/unlock/main.md) for more details.
160+
appium:unlockSuccessTimeout | Maximum number of milliseconds to wait until the device is unlocked. `2000` ms by default. Read the [Unlock tutorial](./docs/unlock/main.md) for more details.
162161

163162
### Web Context
164163

@@ -1190,7 +1189,6 @@ Name | Type | Required | Description | Example
11901189
--- | --- | --- | --- | ---
11911190
key | string | yes | The unlock key. See the documentation on [appium:unlockKey](#device-locking) capability for more details | 12345
11921191
type | string | yes | The unlock type. See the documentation on [appium:unlockType](#device-locking) capability for more details | password
1193-
strategy | string | no | Unlock strategy. See the documentation on [appium:unlockStrategy](#device-locking) capability for more details | uiautomator
11941192
timeoutMs | number | no | Unlock timeout. See the documentation on [appium:unlockSuccessTimeout](#device-locking) capability for more details | 5000
11951193

11961194
### mobile: isLocked

docs/unlock/main.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Unlock
2+
3+
Espresso driver allows dealing with the Android lock screen using various APIs.
4+
This article describes the available APIs and their options.
5+
6+
## Unlock On Session Startup
7+
8+
Espresso driver provides the following [capabilities](../../README.md#device-locking) to deal
9+
with the system lock screen:
10+
11+
- appium:unlockSuccessTimeout
12+
- appium:skipUnlock
13+
- appium:unlockType
14+
- appium:unlockKey
15+
16+
These capabilities could be used to unlock the device under test during the driver session initialization
17+
as well as deal with different lock screen types.
18+
19+
### appium:unlockSuccessTimeout
20+
21+
Maximum number of milliseconds to wait until the device is unlocked. `2000` ms by default
22+
23+
### appium:skipUnlock
24+
25+
The `appium:skipUnlock` capability is enabled by default and makes the driver to detect and handle the lock screen
26+
upon session startup _if it is present_. If the lock screen cannot be detected upon session startup then nothing will be
27+
done. By default, it is assumed the device has a "simple" lock screen, which could be removed by waking up the device.
28+
In case the device has a different type of the lock screen configured in its settings then the information about it
29+
must be provided in the below capability values.
30+
31+
### appium:unlockType and appium:unlockKey
32+
33+
This capability supports the following possible values:
34+
35+
#### pin
36+
37+
Assumes the device is protected with a PIN code. Expects the `appium:unlockKey` to contain a valid pin consisting
38+
of digits in range 0-9, for example `1111`.
39+
40+
#### password
41+
42+
Assumes the device is protected with a password. Expects the `appium:unlockKey` to contain a valid password consisting
43+
of latin characters, for example `abcd1234`.
44+
45+
#### pattern
46+
47+
Assumes the device is protected with a secret pattern. Check the example below for more details on the `appium:unlockKey`
48+
value for this particular unlock type.
49+
50+
##### Example
51+
52+
Let say you have a device that is locked with a pattern similar to the one on the image below,
53+
and you want to run a test over that device.
54+
55+
<img src="./screen1.png" />
56+
57+
We treat the pattern pins similarly to numbers on a digital phone dial. So, in this case the *unlockKey* is `729854163`
58+
59+
<img src="./screen2.png" />
60+
61+
and capabilities are:
62+
63+
```json
64+
{
65+
"appium:unlockType": "pattern",
66+
"appium:unlockKey": "729854163"
67+
}
68+
```
69+
70+
## Mid-Session Unlock
71+
72+
There is also a possibility to interact with the device's lock screen while the test session is running.
73+
Use the following mobile extensions for this purpose:
74+
75+
- [mobile: lock](../../README.md#mobile-lock)
76+
- [mobile: unlock](../../README.md#mobile-unlock)
77+
- [mobile: isLocked](../../README.md#mobile-islocked)

docs/unlock/screen1.png

209 KB
Loading

docs/unlock/screen2.png

213 KB
Loading

lib/commands/actions.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @this {import('../driver').EspressoDriver}
3+
* @param {import('@appium/types').StringRecord[]} actions
4+
* @returns {Promise<void>}
5+
*/
6+
export async function performActions(actions) {
7+
this.log.debug(`Received the following W3C actions: ${JSON.stringify(actions, null, ' ')}`);
8+
// This is needed because Selenium API uses MOUSE as the default pointer type
9+
const preprocessedActions = actions.map((action) =>
10+
Object.assign(
11+
{},
12+
action,
13+
action.type === 'pointer' ? {parameters: {pointerType: 'touch'}} : {}
14+
)
15+
);
16+
this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
17+
await this.espresso.jwproxy.command('/actions', 'POST', {actions: preprocessedActions});
18+
}

lib/driver.ts

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as miscCmds from './commands/misc';
2222
import * as servicesCmds from './commands/services';
2323
import * as screenshotCmds from './commands/screenshot';
2424
import * as idlingResourcesCmds from './commands/idling-resources';
25+
import * as actionsCmds from './commands/actions';
2526
import { DEFAULT_ADB_PORT } from 'appium-adb';
2627
import { AndroidDriver, utils } from 'appium-android-driver';
2728
import { SETTINGS_HELPER_ID } from 'io.appium.settings';
@@ -697,6 +698,8 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver<
697698
return !this.opts.app && this.helpers.isPackageOrBundle(this.opts.appPackage!);
698699
}
699700

701+
performActions = actionsCmds.performActions;
702+
700703
executeMobile = executeCmds.executeMobile;
701704

702705
launchApp = appManagementCmds.launchApp;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
],
7474
"dependencies": {
7575
"appium-adb": "^12.0.0",
76-
"appium-android-driver": "^8.1.6",
76+
"appium-android-driver": "^8.3.0",
7777
"asyncbox": "^3.0.0",
7878
"bluebird": "^3.5.0",
7979
"io.appium.settings": "^5.7.2",

0 commit comments

Comments
 (0)