appium-android-driver 5.14.7 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/lib/commands/actions.d.ts +6 -224
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +306 -405
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/alert.d.ts +7 -9
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +24 -18
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +7 -313
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +135 -293
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/context.d.ts +8 -92
  15. package/build/lib/commands/context.d.ts.map +1 -1
  16. package/build/lib/commands/context.js +381 -439
  17. package/build/lib/commands/context.js.map +1 -1
  18. package/build/lib/commands/element.d.ts +8 -35
  19. package/build/lib/commands/element.d.ts.map +1 -1
  20. package/build/lib/commands/element.js +153 -136
  21. package/build/lib/commands/element.js.map +1 -1
  22. package/build/lib/commands/emu-console.d.ts +6 -48
  23. package/build/lib/commands/emu-console.d.ts.map +1 -1
  24. package/build/lib/commands/emu-console.js +19 -34
  25. package/build/lib/commands/emu-console.js.map +1 -1
  26. package/build/lib/commands/execute.d.ts +6 -5
  27. package/build/lib/commands/execute.d.ts.map +1 -1
  28. package/build/lib/commands/execute.js +77 -66
  29. package/build/lib/commands/execute.js.map +1 -1
  30. package/build/lib/commands/file-actions.d.ts +7 -128
  31. package/build/lib/commands/file-actions.d.ts.map +1 -1
  32. package/build/lib/commands/file-actions.js +183 -219
  33. package/build/lib/commands/file-actions.js.map +1 -1
  34. package/build/lib/commands/find.d.ts +8 -12
  35. package/build/lib/commands/find.d.ts.map +1 -1
  36. package/build/lib/commands/find.js +19 -23
  37. package/build/lib/commands/find.js.map +1 -1
  38. package/build/lib/commands/general.d.ts +9 -132
  39. package/build/lib/commands/general.d.ts.map +1 -1
  40. package/build/lib/commands/general.js +281 -312
  41. package/build/lib/commands/general.js.map +1 -1
  42. package/build/lib/commands/ime.d.ts +7 -10
  43. package/build/lib/commands/ime.d.ts.map +1 -1
  44. package/build/lib/commands/ime.js +47 -35
  45. package/build/lib/commands/ime.js.map +1 -1
  46. package/build/lib/commands/index.d.ts +27 -2
  47. package/build/lib/commands/index.d.ts.map +1 -1
  48. package/build/lib/commands/index.js +41 -19
  49. package/build/lib/commands/index.js.map +1 -1
  50. package/build/lib/commands/intent.d.ts +7 -417
  51. package/build/lib/commands/intent.d.ts.map +1 -1
  52. package/build/lib/commands/intent.js +104 -216
  53. package/build/lib/commands/intent.js.map +1 -1
  54. package/build/lib/commands/keyboard.d.ts +6 -5
  55. package/build/lib/commands/keyboard.d.ts.map +1 -1
  56. package/build/lib/commands/keyboard.js +16 -8
  57. package/build/lib/commands/keyboard.js.map +1 -1
  58. package/build/lib/commands/log.d.ts +7 -44
  59. package/build/lib/commands/log.d.ts.map +1 -1
  60. package/build/lib/commands/log.js +146 -108
  61. package/build/lib/commands/log.js.map +1 -1
  62. package/build/lib/commands/media-projection.d.ts +7 -143
  63. package/build/lib/commands/media-projection.d.ts.map +1 -1
  64. package/build/lib/commands/media-projection.js +113 -140
  65. package/build/lib/commands/media-projection.js.map +1 -1
  66. package/build/lib/commands/mixins.d.ts +740 -0
  67. package/build/lib/commands/mixins.d.ts.map +1 -0
  68. package/build/lib/commands/mixins.js +19 -0
  69. package/build/lib/commands/mixins.js.map +1 -0
  70. package/build/lib/commands/network.d.ts +7 -138
  71. package/build/lib/commands/network.d.ts.map +1 -1
  72. package/build/lib/commands/network.js +212 -254
  73. package/build/lib/commands/network.js.map +1 -1
  74. package/build/lib/commands/performance.d.ts +24 -70
  75. package/build/lib/commands/performance.d.ts.map +1 -1
  76. package/build/lib/commands/performance.js +144 -100
  77. package/build/lib/commands/performance.js.map +1 -1
  78. package/build/lib/commands/permissions.d.ts +8 -92
  79. package/build/lib/commands/permissions.d.ts.map +1 -1
  80. package/build/lib/commands/permissions.js +75 -87
  81. package/build/lib/commands/permissions.js.map +1 -1
  82. package/build/lib/commands/recordscreen.d.ts +7 -193
  83. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  84. package/build/lib/commands/recordscreen.js +151 -182
  85. package/build/lib/commands/recordscreen.js.map +1 -1
  86. package/build/lib/commands/shell.d.ts +7 -7
  87. package/build/lib/commands/shell.d.ts.map +1 -1
  88. package/build/lib/commands/shell.js +40 -33
  89. package/build/lib/commands/shell.js.map +1 -1
  90. package/build/lib/commands/streamscreen.d.ts +9 -103
  91. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  92. package/build/lib/commands/streamscreen.js +261 -218
  93. package/build/lib/commands/streamscreen.js.map +1 -1
  94. package/build/lib/commands/system-bars.d.ts +22 -90
  95. package/build/lib/commands/system-bars.d.ts.map +1 -1
  96. package/build/lib/commands/system-bars.js +76 -74
  97. package/build/lib/commands/system-bars.js.map +1 -1
  98. package/build/lib/commands/touch.d.ts +10 -29
  99. package/build/lib/commands/touch.d.ts.map +1 -1
  100. package/build/lib/commands/touch.js +301 -285
  101. package/build/lib/commands/touch.js.map +1 -1
  102. package/build/lib/commands/types.d.ts +978 -0
  103. package/build/lib/commands/types.d.ts.map +1 -0
  104. package/build/lib/commands/types.js +3 -0
  105. package/build/lib/commands/types.js.map +1 -0
  106. package/build/lib/constraints.d.ts +291 -0
  107. package/build/lib/constraints.d.ts.map +1 -0
  108. package/build/lib/{desired-caps.js → constraints.js} +103 -102
  109. package/build/lib/constraints.js.map +1 -0
  110. package/build/lib/driver.d.ts +68 -37
  111. package/build/lib/driver.d.ts.map +1 -1
  112. package/build/lib/driver.js +123 -80
  113. package/build/lib/driver.js.map +1 -1
  114. package/build/lib/helpers/android.d.ts +164 -0
  115. package/build/lib/helpers/android.d.ts.map +1 -0
  116. package/build/lib/helpers/android.js +819 -0
  117. package/build/lib/helpers/android.js.map +1 -0
  118. package/build/lib/helpers/index.d.ts +7 -0
  119. package/build/lib/helpers/index.d.ts.map +1 -0
  120. package/build/lib/helpers/index.js +29 -0
  121. package/build/lib/helpers/index.js.map +1 -0
  122. package/build/lib/helpers/types.d.ts +121 -0
  123. package/build/lib/helpers/types.d.ts.map +1 -0
  124. package/build/lib/helpers/types.js +3 -0
  125. package/build/lib/helpers/types.js.map +1 -0
  126. package/build/lib/helpers/unlock.d.ts +32 -0
  127. package/build/lib/helpers/unlock.d.ts.map +1 -0
  128. package/build/lib/helpers/unlock.js +273 -0
  129. package/build/lib/helpers/unlock.js.map +1 -0
  130. package/build/lib/helpers/webview.d.ts +74 -0
  131. package/build/lib/helpers/webview.d.ts.map +1 -0
  132. package/build/lib/helpers/webview.js +421 -0
  133. package/build/lib/helpers/webview.js.map +1 -0
  134. package/build/lib/index.d.ts +9 -0
  135. package/build/lib/index.d.ts.map +1 -0
  136. package/build/lib/index.js +37 -0
  137. package/build/lib/index.js.map +1 -0
  138. package/build/lib/method-map.d.ts +0 -8
  139. package/build/lib/method-map.d.ts.map +1 -1
  140. package/build/lib/method-map.js +63 -74
  141. package/build/lib/method-map.js.map +1 -1
  142. package/build/lib/stubs.d.ts +0 -1
  143. package/build/lib/stubs.d.ts.map +1 -1
  144. package/build/lib/stubs.js +1 -0
  145. package/build/lib/stubs.js.map +1 -1
  146. package/build/lib/utils.d.ts +1 -1
  147. package/build/lib/utils.d.ts.map +1 -1
  148. package/lib/commands/actions.js +351 -464
  149. package/lib/commands/alert.js +27 -17
  150. package/lib/commands/app-management.js +156 -314
  151. package/lib/commands/context.js +457 -441
  152. package/lib/commands/element.js +201 -157
  153. package/lib/commands/emu-console.js +25 -45
  154. package/lib/commands/execute.js +106 -90
  155. package/lib/commands/file-actions.js +222 -240
  156. package/lib/commands/find.ts +103 -0
  157. package/lib/commands/general.js +327 -339
  158. package/lib/commands/ime.js +50 -34
  159. package/lib/commands/{index.js → index.ts} +20 -24
  160. package/lib/commands/intent.js +108 -249
  161. package/lib/commands/keyboard.js +20 -8
  162. package/lib/commands/log.js +172 -116
  163. package/lib/commands/media-projection.js +134 -161
  164. package/lib/commands/mixins.ts +966 -0
  165. package/lib/commands/network.js +252 -281
  166. package/lib/commands/performance.js +203 -132
  167. package/lib/commands/permissions.js +108 -109
  168. package/lib/commands/recordscreen.js +212 -209
  169. package/lib/commands/shell.js +51 -40
  170. package/lib/commands/streamscreen.js +355 -289
  171. package/lib/commands/system-bars.js +92 -83
  172. package/lib/commands/touch.js +357 -294
  173. package/lib/commands/types.ts +1097 -0
  174. package/lib/{desired-caps.js → constraints.ts} +106 -103
  175. package/lib/{driver.js → driver.ts} +278 -132
  176. package/lib/helpers/android.ts +1143 -0
  177. package/lib/helpers/index.ts +6 -0
  178. package/lib/helpers/types.ts +134 -0
  179. package/lib/helpers/unlock.ts +329 -0
  180. package/lib/helpers/webview.ts +582 -0
  181. package/lib/index.ts +18 -0
  182. package/lib/method-map.js +87 -98
  183. package/lib/stubs.ts +0 -1
  184. package/package.json +26 -19
  185. package/build/index.js +0 -51
  186. package/build/lib/android-helpers.d.ts +0 -136
  187. package/build/lib/android-helpers.d.ts.map +0 -1
  188. package/build/lib/android-helpers.js +0 -855
  189. package/build/lib/android-helpers.js.map +0 -1
  190. package/build/lib/commands/coverage.d.ts +0 -5
  191. package/build/lib/commands/coverage.d.ts.map +0 -1
  192. package/build/lib/commands/coverage.js +0 -19
  193. package/build/lib/commands/coverage.js.map +0 -1
  194. package/build/lib/desired-caps.d.ts +0 -353
  195. package/build/lib/desired-caps.d.ts.map +0 -1
  196. package/build/lib/desired-caps.js.map +0 -1
  197. package/build/lib/unlock-helpers.d.ts +0 -38
  198. package/build/lib/unlock-helpers.d.ts.map +0 -1
  199. package/build/lib/unlock-helpers.js +0 -266
  200. package/build/lib/unlock-helpers.js.map +0 -1
  201. package/build/lib/webview-helpers.d.ts +0 -224
  202. package/build/lib/webview-helpers.d.ts.map +0 -1
  203. package/build/lib/webview-helpers.js +0 -528
  204. package/build/lib/webview-helpers.js.map +0 -1
  205. package/index.js +0 -24
  206. package/lib/android-helpers.js +0 -983
  207. package/lib/commands/coverage.js +0 -18
  208. package/lib/commands/find.js +0 -82
  209. package/lib/unlock-helpers.js +0 -278
  210. package/lib/webview-helpers.js +0 -602
@@ -1,18 +0,0 @@
1
- const commands = {};
2
-
3
-
4
- commands.endCoverage = async function endCoverage (intentToBroadcast, ecOnDevicePath) {
5
- try {
6
- // ensure the ec we're pulling is newly created as a result of the intent.
7
- await this.adb.rimraf(ecOnDevicePath);
8
- await this.adb.broadcastProcessEnd(intentToBroadcast, this.appProcess);
9
- return await this.pullFile(ecOnDevicePath);
10
- } catch (err) {
11
- this.log.warn(`Error ending test coverage: ${err.message}`);
12
- }
13
- return '';
14
- };
15
-
16
-
17
- export { commands };
18
- export default commands;
@@ -1,82 +0,0 @@
1
- import _ from 'lodash';
2
- import { errors, isErrorType } from 'appium/driver';
3
-
4
-
5
- let helpers = {}, extensions = {};
6
-
7
- /**
8
- * Reason for isolating doFindElementOrEls from findElOrEls is for reusing findElOrEls
9
- * across android-drivers (like appium-uiautomator2-driver) to avoid code duplication.
10
- * Other android-drivers (like appium-uiautomator2-driver) need to override doFindElementOrEls
11
- * to facilitate findElOrEls.
12
- */
13
- helpers.doFindElementOrEls = async function doFindElementOrEls (params) {
14
- return await this.bootstrap.sendAction('find', params);
15
- };
16
-
17
- // stategy: locator strategy
18
- // selector: the actual selector for finding an element
19
- // mult: multiple elements or just one?
20
- // context: finding an element from the root context? or starting from another element
21
- helpers.findElOrEls = async function findElOrEls (strategy, selector, mult, context = '') {
22
- if (!selector) {
23
- throw new Error('Must provide a selector when finding elements');
24
- }
25
-
26
- let params = {
27
- strategy,
28
- selector,
29
- context,
30
- multiple: mult
31
- };
32
-
33
- let element;
34
- let doFind = async () => {
35
- try {
36
- element = await this.doFindElementOrEls(params);
37
- } catch (err) {
38
-
39
- // if the error that comes back is from a proxied request, we need to
40
- // unwrap it to its actual protocol error first
41
- if (isErrorType(err, errors.ProxyRequestError)) {
42
- err = err.getActualError(); // eslint-disable-line no-ex-assign
43
- }
44
-
45
- // now we have to inspect the error to determine if it is a no such
46
- // element error, based on the shape of the error object from
47
- // appium/driver
48
- if (isErrorType(err, errors.NoSuchElementError)) {
49
- // we are fine with this, just indicate a retry
50
- return false;
51
- }
52
- throw err;
53
- }
54
-
55
- // we want to return false if we want to potentially try again
56
- return !_.isEmpty(element);
57
- };
58
-
59
- try {
60
- await this.implicitWaitForCondition(doFind);
61
- } catch (err) {
62
- if (err.message && err.message.match(/Condition unmet/)) {
63
- // only get here if we are looking for multiple elements
64
- // condition was not met setting res to empty array
65
- element = [];
66
- } else {
67
- throw err;
68
- }
69
- }
70
-
71
- if (mult) {
72
- return element;
73
- }
74
- if (_.isEmpty(element)) {
75
- throw new errors.NoSuchElementError();
76
- }
77
- return element;
78
- };
79
-
80
- Object.assign(extensions, helpers);
81
- export { helpers };
82
- export default extensions;
@@ -1,278 +0,0 @@
1
- import logger from './logger';
2
- import { sleep } from 'asyncbox';
3
- import _ from 'lodash';
4
- import { util } from '@appium/support';
5
-
6
- const PIN_UNLOCK = 'pin';
7
- const PIN_UNLOCK_KEY_EVENT = 'pinWithKeyEvent';
8
- const PASSWORD_UNLOCK = 'password';
9
- const PATTERN_UNLOCK = 'pattern';
10
- const FINGERPRINT_UNLOCK = 'fingerprint';
11
- const UNLOCK_TYPES = [
12
- PIN_UNLOCK, PIN_UNLOCK_KEY_EVENT, PASSWORD_UNLOCK,
13
- PATTERN_UNLOCK, FINGERPRINT_UNLOCK
14
- ];
15
- const KEYCODE_NUMPAD_ENTER = 66;
16
- const UNLOCK_WAIT_TIME = 100;
17
- const INPUT_KEYS_WAIT_TIME = 100;
18
- const NUMBER_ZERO_KEYCODE = 7;
19
-
20
- export const helpers = {};
21
-
22
- helpers.validateUnlockCapabilities = function validateUnlockCapabilities (caps = {}) {
23
- const {
24
- unlockKey,
25
- unlockType,
26
- } = caps;
27
- if (_.isNil(unlockKey) || unlockKey === '') {
28
- throw new Error('A non-empty unlock key value must be provided');
29
- }
30
-
31
- if ([PIN_UNLOCK, PIN_UNLOCK_KEY_EVENT, FINGERPRINT_UNLOCK].includes(unlockType)) {
32
- if (!/^[0-9]+$/.test(_.trim(unlockKey))) {
33
- throw new Error(`Unlock key value '${unlockKey}' must only consist of digits`);
34
- }
35
- } else if (unlockType === PATTERN_UNLOCK) {
36
- if (!/^[1-9]{2,9}$/.test(_.trim(unlockKey))) {
37
- throw new Error(`Unlock key value '${unlockKey}' must only include from two to nine digits in range 1..9`);
38
- }
39
- if (/([1-9]).*?\1/.test(_.trim(unlockKey))) {
40
- throw new Error(`Unlock key value '${unlockKey}' must define a valid pattern where repeats are not allowed`);
41
- }
42
- } else if (unlockType === PASSWORD_UNLOCK) {
43
- // Dont trim password key, you can use blank spaces in your android password
44
- // ¯\_(ツ)_/¯
45
- if (!/.{4,}/g.test(unlockKey)) {
46
- throw new Error(`The minimum allowed length of unlock key value '${unlockKey}' is 4 characters`);
47
- }
48
- } else {
49
- throw new Error(`Invalid unlock type '${unlockType}'. ` +
50
- `Only the following unlock types are supported: ${UNLOCK_TYPES}`);
51
- }
52
- return caps;
53
- };
54
-
55
- helpers.fastUnlock = async function fastUnlock (adb, opts = {}) {
56
- const {
57
- credential,
58
- credentialType,
59
- } = opts;
60
- logger.info(`Unlocking the device via ADB using ${credentialType} credential '${credential}'`);
61
- const wasLockEnabled = await adb.isLockEnabled();
62
- if (wasLockEnabled) {
63
- await adb.clearLockCredential(credential);
64
- // not sure why, but the device's screen still remains locked
65
- // if a preliminary wake up cycle has not been performed
66
- await adb.cycleWakeUp();
67
- } else {
68
- logger.info('No active lock has been detected. Proceeding to the keyguard dismissal');
69
- }
70
- try {
71
- await adb.dismissKeyguard();
72
- } finally {
73
- if (wasLockEnabled) {
74
- await adb.setLockCredential(credentialType, credential);
75
- }
76
- }
77
- };
78
-
79
- helpers.encodePassword = function encodePassword (key) {
80
- return `${key}`.replace(/\s/ig, '%s');
81
- };
82
-
83
- helpers.stringKeyToArr = function stringKeyToArr (key) {
84
- return `${key}`.trim().replace(/\s+/g, '').split(/\s*/);
85
- };
86
-
87
- helpers.fingerprintUnlock = async function fingerprintUnlock (adb, driver, capabilities) {
88
- if (await adb.getApiLevel() < 23) {
89
- throw new Error('Fingerprint unlock only works for Android 6+ emulators');
90
- }
91
- await adb.fingerprint(capabilities.unlockKey);
92
- await sleep(UNLOCK_WAIT_TIME);
93
- };
94
-
95
- helpers.pinUnlock = async function pinUnlock (adb, driver, capabilities) {
96
- logger.info(`Trying to unlock device using pin ${capabilities.unlockKey}`);
97
- await adb.dismissKeyguard();
98
- const keys = helpers.stringKeyToArr(capabilities.unlockKey);
99
- if (await adb.getApiLevel() >= 21) {
100
- const els = await driver.findElOrEls('id', 'com.android.systemui:id/digit_text', true);
101
- if (_.isEmpty(els)) {
102
- // fallback to pin with key event
103
- return await helpers.pinUnlockWithKeyEvent(adb, driver, capabilities);
104
- }
105
- const pins = {};
106
- for (const el of els) {
107
- const text = await driver.getAttribute('text', util.unwrapElement(el));
108
- pins[text] = el;
109
- }
110
- for (const pin of keys) {
111
- const el = pins[pin];
112
- await driver.click(util.unwrapElement(el));
113
- }
114
- } else {
115
- for (const pin of keys) {
116
- const el = await driver.findElOrEls('id', `com.android.keyguard:id/key${pin}`, false);
117
- if (el === null) {
118
- // fallback to pin with key event
119
- return await helpers.pinUnlockWithKeyEvent(adb, driver, capabilities);
120
- }
121
- await driver.click(util.unwrapElement(el));
122
- }
123
- }
124
- await waitForUnlock(adb);
125
- };
126
-
127
- /**
128
- * Wait for the display to be unlocked.
129
- * Some devices automatically accept typed 'pin' and 'password' code
130
- * without pressing the Enter key. But some devices need it.
131
- * This method waits a few seconds first for such automatic acceptance case.
132
- * If the device is still locked, then this method will try to send
133
- * the enter key code.
134
- *
135
- * @param {ADB} adb The instance of ADB
136
- */
137
- async function waitForUnlock (adb) {
138
- await sleep(UNLOCK_WAIT_TIME);
139
- if (!await adb.isScreenLocked()) {
140
- return;
141
- }
142
-
143
- await adb.keyevent(KEYCODE_NUMPAD_ENTER);
144
- await sleep(UNLOCK_WAIT_TIME);
145
- }
146
-
147
- helpers.pinUnlockWithKeyEvent = async function pinUnlockWithKeyEvent (adb, driver, capabilities) {
148
- logger.info(`Trying to unlock device using pin with keycode ${capabilities.unlockKey}`);
149
- await adb.dismissKeyguard();
150
- const keys = helpers.stringKeyToArr(capabilities.unlockKey);
151
-
152
- // Some device does not have system key ids like 'com.android.keyguard:id/key'
153
- // Then, sending keyevents are more reliable to unlock the screen.
154
- for (const pin of keys) {
155
- // 'pin' is number (0-9) in string.
156
- // Number '0' is keycode '7'. number '9' is keycode '16'.
157
- await adb.shell(['input', 'keyevent', parseInt(pin, 10) + NUMBER_ZERO_KEYCODE]);
158
- }
159
- await waitForUnlock(adb, driver);
160
- };
161
-
162
- helpers.passwordUnlock = async function passwordUnlock (adb, driver, capabilities) {
163
- const { unlockKey } = capabilities;
164
- logger.info(`Trying to unlock device using password ${unlockKey}`);
165
- await adb.dismissKeyguard();
166
- // Replace blank spaces with %s
167
- const key = helpers.encodePassword(unlockKey);
168
- // Why adb ? It was less flaky
169
- await adb.shell(['input', 'text', key]);
170
- // Why sleeps ? Avoid some flakyness waiting for the input to receive the keys
171
- await sleep(INPUT_KEYS_WAIT_TIME);
172
- await adb.shell(['input', 'keyevent', KEYCODE_NUMPAD_ENTER]);
173
- // Waits a bit for the device to be unlocked
174
- await waitForUnlock(adb, driver);
175
- };
176
-
177
- helpers.getPatternKeyPosition = function getPatternKeyPosition (key, initPos, piece) {
178
- /*
179
- How the math works:
180
- We have 9 buttons divided in 3 columns and 3 rows inside the lockPatternView,
181
- every button has a position on the screen corresponding to the lockPatternView since
182
- it is the parent view right at the middle of each column or row.
183
- */
184
- const cols = 3;
185
- const pins = 9;
186
- const xPos = (key, x, piece) => Math.round(x + ((key % cols) || cols) * piece - piece / 2);
187
- const yPos = (key, y, piece) => Math.round(y + (Math.ceil(((key % pins) || pins) / cols) * piece - piece / 2));
188
- return {
189
- x: xPos(key, initPos.x, piece),
190
- y: yPos(key, initPos.y, piece)
191
- };
192
- };
193
-
194
- helpers.getPatternActions = function getPatternActions (keys, initPos, piece) {
195
- const actions = [];
196
- let lastPos;
197
- for (let key of keys) {
198
- const keyPos = helpers.getPatternKeyPosition(key, initPos, piece);
199
- if (key === keys[0]) {
200
- actions.push({action: 'press', options: {element: null, x: keyPos.x, y: keyPos.y}});
201
- lastPos = keyPos;
202
- continue;
203
- }
204
- const moveTo = {x: 0, y: 0};
205
- const diffX = keyPos.x - lastPos.x;
206
- if (diffX > 0) {
207
- moveTo.x = piece;
208
- if (Math.abs(diffX) > piece) {
209
- moveTo.x += piece;
210
- }
211
- } else if (diffX < 0) {
212
- moveTo.x = -1 * piece;
213
- if (Math.abs(diffX) > piece) {
214
- moveTo.x -= piece;
215
- }
216
- }
217
- const diffY = keyPos.y - lastPos.y;
218
- if (diffY > 0) {
219
- moveTo.y = piece;
220
- if (Math.abs(diffY) > piece) {
221
- moveTo.y += piece;
222
- }
223
- } else if (diffY < 0) {
224
- moveTo.y = -1 * piece;
225
- if (Math.abs(diffY) > piece) {
226
- moveTo.y -= piece;
227
- }
228
- }
229
- actions.push({
230
- action: 'moveTo',
231
- options: {element: null, x: moveTo.x + lastPos.x, y: moveTo.y + lastPos.y}
232
- });
233
- lastPos = keyPos;
234
- }
235
- actions.push({action: 'release'});
236
- return actions;
237
- };
238
-
239
- helpers.patternUnlock = async function patternUnlock (adb, driver, capabilities) {
240
- const { unlockKey } = capabilities;
241
- logger.info(`Trying to unlock device using pattern ${unlockKey}`);
242
- await adb.dismissKeyguard();
243
- const keys = helpers.stringKeyToArr(unlockKey);
244
- /* We set the device pattern buttons as number of a regular phone
245
- * | • • • | | 1 2 3 |
246
- * | • • • | --> | 4 5 6 |
247
- * | • • • | | 7 8 9 |
248
-
249
- The pattern view buttons are not seeing by the uiautomator since they are
250
- included inside a FrameLayout, so we are going to try clicking on the buttons
251
- using the parent view bounds and math.
252
- */
253
- const apiLevel = await adb.getApiLevel();
254
- const el = await driver.findElOrEls('id',
255
- `com.android.${apiLevel >= 21 ? 'systemui' : 'keyguard'}:id/lockPatternView`,
256
- false
257
- );
258
- const initPos = await driver.getLocation(util.unwrapElement(el));
259
- const size = await driver.getSize(util.unwrapElement(el));
260
- // Get actions to perform
261
- const actions = helpers.getPatternActions(keys, initPos, size.width / 3);
262
- // Perform gesture
263
- await driver.performTouch(actions);
264
- // Waits a bit for the device to be unlocked
265
- await sleep(UNLOCK_WAIT_TIME);
266
- };
267
-
268
- helpers.PIN_UNLOCK = PIN_UNLOCK;
269
- helpers.PIN_UNLOCK_KEY_EVENT = PIN_UNLOCK_KEY_EVENT;
270
- helpers.PASSWORD_UNLOCK = PASSWORD_UNLOCK;
271
- helpers.PATTERN_UNLOCK = PATTERN_UNLOCK;
272
- helpers.FINGERPRINT_UNLOCK = FINGERPRINT_UNLOCK;
273
-
274
- export {
275
- PIN_UNLOCK, PIN_UNLOCK_KEY_EVENT, PASSWORD_UNLOCK, PATTERN_UNLOCK,
276
- FINGERPRINT_UNLOCK
277
- };
278
- export default helpers;