appium-android-driver 7.8.3 → 8.0.0

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 (261) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/lib/commands/app-management.d.ts +129 -5
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +433 -128
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/appearance.d.ts +17 -4
  7. package/build/lib/commands/appearance.d.ts.map +1 -1
  8. package/build/lib/commands/appearance.js +32 -33
  9. package/build/lib/commands/appearance.js.map +1 -1
  10. package/build/lib/commands/context/cache.d.ts +19 -0
  11. package/build/lib/commands/context/cache.d.ts.map +1 -0
  12. package/build/lib/commands/context/cache.js +32 -0
  13. package/build/lib/commands/context/cache.js.map +1 -0
  14. package/build/lib/commands/context/exports.d.ts +141 -0
  15. package/build/lib/commands/context/exports.d.ts.map +1 -0
  16. package/build/lib/commands/context/exports.js +351 -0
  17. package/build/lib/commands/context/exports.js.map +1 -0
  18. package/build/lib/commands/context/helpers.d.ts +98 -0
  19. package/build/lib/commands/context/helpers.d.ts.map +1 -0
  20. package/build/lib/commands/context/helpers.js +715 -0
  21. package/build/lib/commands/context/helpers.js.map +1 -0
  22. package/build/lib/commands/device/common.d.ts +23 -0
  23. package/build/lib/commands/device/common.d.ts.map +1 -0
  24. package/build/lib/commands/device/common.js +230 -0
  25. package/build/lib/commands/device/common.js.map +1 -0
  26. package/build/lib/commands/device/emulator-actions.d.ts +114 -0
  27. package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
  28. package/build/lib/commands/device/emulator-actions.js +197 -0
  29. package/build/lib/commands/device/emulator-actions.js.map +1 -0
  30. package/build/lib/commands/device/emulator-console.d.ts +7 -0
  31. package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
  32. package/build/lib/commands/device/emulator-console.js +24 -0
  33. package/build/lib/commands/device/emulator-console.js.map +1 -0
  34. package/build/lib/commands/device/utils.d.ts +50 -0
  35. package/build/lib/commands/device/utils.d.ts.map +1 -0
  36. package/build/lib/commands/device/utils.js +238 -0
  37. package/build/lib/commands/device/utils.js.map +1 -0
  38. package/build/lib/commands/deviceidle.d.ts +8 -5
  39. package/build/lib/commands/deviceidle.d.ts.map +1 -1
  40. package/build/lib/commands/deviceidle.js +31 -37
  41. package/build/lib/commands/deviceidle.js.map +1 -1
  42. package/build/lib/commands/element.d.ts +99 -5
  43. package/build/lib/commands/element.d.ts.map +1 -1
  44. package/build/lib/commands/element.js +152 -116
  45. package/build/lib/commands/element.js.map +1 -1
  46. package/build/lib/commands/execute.d.ts +12 -4
  47. package/build/lib/commands/execute.d.ts.map +1 -1
  48. package/build/lib/commands/execute.js +83 -78
  49. package/build/lib/commands/execute.js.map +1 -1
  50. package/build/lib/commands/file-actions.d.ts +42 -5
  51. package/build/lib/commands/file-actions.d.ts.map +1 -1
  52. package/build/lib/commands/file-actions.js +230 -194
  53. package/build/lib/commands/file-actions.js.map +1 -1
  54. package/build/lib/commands/find.d.ts +5 -4
  55. package/build/lib/commands/find.d.ts.map +1 -1
  56. package/build/lib/commands/find.js +7 -10
  57. package/build/lib/commands/find.js.map +1 -1
  58. package/build/lib/commands/geolocation.d.ts +45 -0
  59. package/build/lib/commands/geolocation.d.ts.map +1 -0
  60. package/build/lib/commands/geolocation.js +182 -0
  61. package/build/lib/commands/geolocation.js.map +1 -0
  62. package/build/lib/commands/ime.d.ts +25 -5
  63. package/build/lib/commands/ime.d.ts.map +1 -1
  64. package/build/lib/commands/ime.js +59 -42
  65. package/build/lib/commands/ime.js.map +1 -1
  66. package/build/lib/commands/intent.d.ts +56 -5
  67. package/build/lib/commands/intent.d.ts.map +1 -1
  68. package/build/lib/commands/intent.js +135 -83
  69. package/build/lib/commands/intent.js.map +1 -1
  70. package/build/lib/commands/keyboard.d.ts +58 -4
  71. package/build/lib/commands/keyboard.d.ts.map +1 -1
  72. package/build/lib/commands/keyboard.js +119 -17
  73. package/build/lib/commands/keyboard.js.map +1 -1
  74. package/build/lib/commands/lock/exports.d.ts +301 -0
  75. package/build/lib/commands/lock/exports.d.ts.map +1 -0
  76. package/build/lib/commands/lock/exports.js +121 -0
  77. package/build/lib/commands/lock/exports.js.map +1 -0
  78. package/build/lib/commands/lock/helpers.d.ts +349 -0
  79. package/build/lib/commands/lock/helpers.d.ts.map +1 -0
  80. package/build/lib/commands/lock/helpers.js +375 -0
  81. package/build/lib/commands/lock/helpers.js.map +1 -0
  82. package/build/lib/commands/log.d.ts +59 -5
  83. package/build/lib/commands/log.d.ts.map +1 -1
  84. package/build/lib/commands/log.js +150 -140
  85. package/build/lib/commands/log.js.map +1 -1
  86. package/build/lib/commands/media-projection.d.ts +16 -5
  87. package/build/lib/commands/media-projection.d.ts.map +1 -1
  88. package/build/lib/commands/media-projection.js +69 -58
  89. package/build/lib/commands/media-projection.js.map +1 -1
  90. package/build/lib/commands/memory.d.ts +9 -5
  91. package/build/lib/commands/memory.d.ts.map +1 -1
  92. package/build/lib/commands/memory.js +19 -24
  93. package/build/lib/commands/memory.js.map +1 -1
  94. package/build/lib/commands/misc.d.ts +42 -0
  95. package/build/lib/commands/misc.d.ts.map +1 -0
  96. package/build/lib/commands/misc.js +100 -0
  97. package/build/lib/commands/misc.js.map +1 -0
  98. package/build/lib/commands/network.d.ts +61 -5
  99. package/build/lib/commands/network.d.ts.map +1 -1
  100. package/build/lib/commands/network.js +196 -189
  101. package/build/lib/commands/network.js.map +1 -1
  102. package/build/lib/commands/performance.d.ts +67 -27
  103. package/build/lib/commands/performance.d.ts.map +1 -1
  104. package/build/lib/commands/performance.js +105 -80
  105. package/build/lib/commands/performance.js.map +1 -1
  106. package/build/lib/commands/permissions.d.ts +12 -6
  107. package/build/lib/commands/permissions.d.ts.map +1 -1
  108. package/build/lib/commands/permissions.js +65 -62
  109. package/build/lib/commands/permissions.js.map +1 -1
  110. package/build/lib/commands/recordscreen.d.ts +44 -5
  111. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  112. package/build/lib/commands/recordscreen.js +131 -126
  113. package/build/lib/commands/recordscreen.js.map +1 -1
  114. package/build/lib/commands/resources.d.ts +16 -0
  115. package/build/lib/commands/resources.d.ts.map +1 -0
  116. package/build/lib/commands/resources.js +91 -0
  117. package/build/lib/commands/resources.js.map +1 -0
  118. package/build/lib/commands/shell.d.ts +8 -5
  119. package/build/lib/commands/shell.d.ts.map +1 -1
  120. package/build/lib/commands/shell.js +29 -33
  121. package/build/lib/commands/shell.js.map +1 -1
  122. package/build/lib/commands/streamscreen.d.ts +34 -6
  123. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  124. package/build/lib/commands/streamscreen.js +166 -162
  125. package/build/lib/commands/streamscreen.js.map +1 -1
  126. package/build/lib/commands/system-bars.d.ts +18 -13
  127. package/build/lib/commands/system-bars.d.ts.map +1 -1
  128. package/build/lib/commands/system-bars.js +68 -64
  129. package/build/lib/commands/system-bars.js.map +1 -1
  130. package/build/lib/commands/time.d.ts +14 -0
  131. package/build/lib/commands/time.d.ts.map +1 -0
  132. package/build/lib/commands/time.js +39 -0
  133. package/build/lib/commands/time.js.map +1 -0
  134. package/build/lib/commands/touch.d.ts +99 -6
  135. package/build/lib/commands/touch.d.ts.map +1 -1
  136. package/build/lib/commands/touch.js +399 -280
  137. package/build/lib/commands/touch.js.map +1 -1
  138. package/build/lib/commands/types.d.ts +110 -2
  139. package/build/lib/commands/types.d.ts.map +1 -1
  140. package/build/lib/doctor/checks.d.ts.map +1 -1
  141. package/build/lib/doctor/checks.js +4 -4
  142. package/build/lib/doctor/checks.js.map +1 -1
  143. package/build/lib/driver.d.ts +224 -27
  144. package/build/lib/driver.d.ts.map +1 -1
  145. package/build/lib/driver.js +232 -7
  146. package/build/lib/driver.js.map +1 -1
  147. package/build/lib/index.d.ts +1 -4
  148. package/build/lib/index.d.ts.map +1 -1
  149. package/build/lib/index.js +1 -13
  150. package/build/lib/index.js.map +1 -1
  151. package/build/lib/logger.js.map +1 -1
  152. package/build/lib/method-map.d.ts +0 -23
  153. package/build/lib/method-map.d.ts.map +1 -1
  154. package/build/lib/method-map.js +0 -11
  155. package/build/lib/method-map.js.map +1 -1
  156. package/build/lib/utils.d.ts +12 -0
  157. package/build/lib/utils.d.ts.map +1 -1
  158. package/build/lib/utils.js +38 -2
  159. package/build/lib/utils.js.map +1 -1
  160. package/lib/commands/app-management.js +470 -145
  161. package/lib/commands/appearance.js +29 -36
  162. package/lib/commands/context/cache.js +29 -0
  163. package/lib/commands/context/exports.js +379 -0
  164. package/lib/commands/context/helpers.js +802 -0
  165. package/lib/commands/device/common.js +264 -0
  166. package/lib/commands/device/emulator-actions.js +194 -0
  167. package/lib/commands/device/emulator-console.js +24 -0
  168. package/lib/commands/device/utils.js +285 -0
  169. package/lib/commands/deviceidle.js +31 -44
  170. package/lib/commands/element.js +149 -142
  171. package/lib/commands/execute.js +86 -87
  172. package/lib/commands/file-actions.js +249 -222
  173. package/lib/commands/find.ts +13 -19
  174. package/lib/commands/geolocation.js +179 -0
  175. package/lib/commands/ime.js +53 -45
  176. package/lib/commands/intent.js +149 -91
  177. package/lib/commands/keyboard.js +114 -17
  178. package/lib/commands/lock/exports.js +139 -0
  179. package/lib/commands/lock/helpers.js +379 -0
  180. package/lib/commands/log.js +170 -166
  181. package/lib/commands/media-projection.js +75 -70
  182. package/lib/commands/memory.js +17 -29
  183. package/lib/commands/misc.js +94 -0
  184. package/lib/commands/network.js +209 -223
  185. package/lib/commands/performance.js +88 -73
  186. package/lib/commands/permissions.js +83 -84
  187. package/lib/commands/recordscreen.js +171 -170
  188. package/lib/commands/resources.js +96 -0
  189. package/lib/commands/shell.js +28 -42
  190. package/lib/commands/streamscreen.js +207 -206
  191. package/lib/commands/system-bars.js +76 -77
  192. package/lib/commands/time.js +36 -0
  193. package/lib/commands/touch.js +442 -346
  194. package/lib/commands/types.ts +123 -2
  195. package/lib/doctor/checks.js +24 -16
  196. package/lib/driver.ts +454 -12
  197. package/lib/index.ts +1 -13
  198. package/lib/logger.js +1 -1
  199. package/lib/method-map.js +0 -11
  200. package/lib/utils.js +40 -3
  201. package/package.json +1 -1
  202. package/build/lib/commands/actions.d.ts +0 -8
  203. package/build/lib/commands/actions.d.ts.map +0 -1
  204. package/build/lib/commands/actions.js +0 -207
  205. package/build/lib/commands/actions.js.map +0 -1
  206. package/build/lib/commands/alert.d.ts +0 -8
  207. package/build/lib/commands/alert.d.ts.map +0 -1
  208. package/build/lib/commands/alert.js +0 -29
  209. package/build/lib/commands/alert.js.map +0 -1
  210. package/build/lib/commands/context.d.ts +0 -10
  211. package/build/lib/commands/context.d.ts.map +0 -1
  212. package/build/lib/commands/context.js +0 -431
  213. package/build/lib/commands/context.js.map +0 -1
  214. package/build/lib/commands/emu-console.d.ts +0 -7
  215. package/build/lib/commands/emu-console.d.ts.map +0 -1
  216. package/build/lib/commands/emu-console.js +0 -27
  217. package/build/lib/commands/emu-console.js.map +0 -1
  218. package/build/lib/commands/general.d.ts +0 -9
  219. package/build/lib/commands/general.d.ts.map +0 -1
  220. package/build/lib/commands/general.js +0 -293
  221. package/build/lib/commands/general.js.map +0 -1
  222. package/build/lib/commands/index.d.ts +0 -28
  223. package/build/lib/commands/index.d.ts.map +0 -1
  224. package/build/lib/commands/index.js +0 -57
  225. package/build/lib/commands/index.js.map +0 -1
  226. package/build/lib/commands/mixins.d.ts +0 -747
  227. package/build/lib/commands/mixins.d.ts.map +0 -1
  228. package/build/lib/commands/mixins.js +0 -19
  229. package/build/lib/commands/mixins.js.map +0 -1
  230. package/build/lib/helpers/android.d.ts +0 -163
  231. package/build/lib/helpers/android.d.ts.map +0 -1
  232. package/build/lib/helpers/android.js +0 -818
  233. package/build/lib/helpers/android.js.map +0 -1
  234. package/build/lib/helpers/index.d.ts +0 -7
  235. package/build/lib/helpers/index.d.ts.map +0 -1
  236. package/build/lib/helpers/index.js +0 -29
  237. package/build/lib/helpers/index.js.map +0 -1
  238. package/build/lib/helpers/types.d.ts +0 -122
  239. package/build/lib/helpers/types.d.ts.map +0 -1
  240. package/build/lib/helpers/types.js +0 -3
  241. package/build/lib/helpers/types.js.map +0 -1
  242. package/build/lib/helpers/unlock.d.ts +0 -32
  243. package/build/lib/helpers/unlock.d.ts.map +0 -1
  244. package/build/lib/helpers/unlock.js +0 -273
  245. package/build/lib/helpers/unlock.js.map +0 -1
  246. package/build/lib/helpers/webview.d.ts +0 -74
  247. package/build/lib/helpers/webview.d.ts.map +0 -1
  248. package/build/lib/helpers/webview.js +0 -448
  249. package/build/lib/helpers/webview.js.map +0 -1
  250. package/lib/commands/actions.js +0 -244
  251. package/lib/commands/alert.js +0 -34
  252. package/lib/commands/context.js +0 -507
  253. package/lib/commands/emu-console.js +0 -31
  254. package/lib/commands/general.js +0 -343
  255. package/lib/commands/index.ts +0 -54
  256. package/lib/commands/mixins.ts +0 -976
  257. package/lib/helpers/android.ts +0 -1153
  258. package/lib/helpers/index.ts +0 -6
  259. package/lib/helpers/types.ts +0 -136
  260. package/lib/helpers/unlock.ts +0 -329
  261. package/lib/helpers/webview.ts +0 -610
@@ -1,18 +1,227 @@
1
1
  "use strict";
2
- // @ts-check
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.truncateDecimals = exports.doPerformMultiAction = exports.performMultiAction = exports.performTouch = exports.doTouchAction = exports.doTouchDrag = exports.doSwipe = exports.touchMove = exports.touchUp = exports.touchDown = exports.touchLongClick = exports.tap = void 0;
7
8
  const support_1 = require("@appium/support");
8
9
  const driver_1 = require("appium/driver");
9
10
  const asyncbox_1 = require("asyncbox");
10
11
  const bluebird_1 = __importDefault(require("bluebird"));
11
12
  const lodash_1 = __importDefault(require("lodash"));
12
- const android_1 = __importDefault(require("../helpers/android"));
13
- const mixins_1 = require("./mixins");
14
13
  /**
15
- *
14
+ * @deprecated
15
+ * @this {import('../driver').AndroidDriver}
16
+ * @param {string?} [elementId=null]
17
+ * @param {number?} [x=null]
18
+ * @param {number?} [y=null]
19
+ * @param {number} [count=1]
20
+ * @returns {Promise<void>}
21
+ */
22
+ async function tap(elementId = null, x = null, y = null, count = 1) {
23
+ throw new driver_1.errors.NotImplementedError('Not implemented');
24
+ }
25
+ exports.tap = tap;
26
+ /**
27
+ * @deprecated
28
+ * @this {import('../driver').AndroidDriver}
29
+ * @param {string} elementId
30
+ * @param {number} x
31
+ * @param {number} y
32
+ * @param {number} duration
33
+ * @returns {Promise<void>}
34
+ */
35
+ async function touchLongClick(elementId, x, y, duration) {
36
+ throw new driver_1.errors.NotImplementedError('Not implemented');
37
+ }
38
+ exports.touchLongClick = touchLongClick;
39
+ /**
40
+ * @deprecated
41
+ * @this {import('../driver').AndroidDriver}
42
+ * @param {string} elementId
43
+ * @param {number} x
44
+ * @param {number} y
45
+ * @returns {Promise<void>}
46
+ */
47
+ async function touchDown(elementId, x, y) {
48
+ throw new driver_1.errors.NotImplementedError('Not implemented');
49
+ }
50
+ exports.touchDown = touchDown;
51
+ /**
52
+ * @deprecated
53
+ * @this {import('../driver').AndroidDriver}
54
+ * @param {string} elementId
55
+ * @param {number} x
56
+ * @param {number} y
57
+ * @returns {Promise<void>}
58
+ */
59
+ async function touchUp(elementId, x, y) {
60
+ throw new driver_1.errors.NotImplementedError('Not implemented');
61
+ }
62
+ exports.touchUp = touchUp;
63
+ /**
64
+ * @deprecated
65
+ * @this {import('../driver').AndroidDriver}
66
+ * @param {string} elementId
67
+ * @param {number} x
68
+ * @param {number} y
69
+ * @returns {Promise<void>}
70
+ */
71
+ async function touchMove(elementId, x, y) {
72
+ throw new driver_1.errors.NotImplementedError('Not implemented');
73
+ }
74
+ exports.touchMove = touchMove;
75
+ /**
76
+ * @deprecated
77
+ * @this {import('../driver').AndroidDriver}
78
+ * @param {import('./types').SwipeOpts} opts
79
+ * @returns {Promise<void>}
80
+ */
81
+ async function doSwipe(opts) {
82
+ throw new driver_1.errors.NotImplementedError('Not implemented');
83
+ }
84
+ exports.doSwipe = doSwipe;
85
+ /**
86
+ * @deprecated
87
+ * @this {import('../driver').AndroidDriver}
88
+ * @param {import('./types').TouchDragAction} opts
89
+ * @returns {Promise<void>}
90
+ */
91
+ async function doTouchDrag(opts) {
92
+ throw new driver_1.errors.NotImplementedError('Not implemented');
93
+ }
94
+ exports.doTouchDrag = doTouchDrag;
95
+ /**
96
+ * @deprecated
97
+ * @this {import('../driver').AndroidDriver}
98
+ * @param {import('./types').TouchActionKind} action
99
+ * @param {import('./types').TouchActionOpts} [opts={}]
100
+ * @returns {Promise<void>}
101
+ */
102
+ async function doTouchAction(action, opts = {}) {
103
+ const { element, x, y, count, ms, duration } = opts;
104
+ // parseTouch precalculates absolute element positions
105
+ // so there is no need to pass `element` to the affected gestures
106
+ switch (action) {
107
+ case 'tap':
108
+ return await this.tap('', x, y, count);
109
+ case 'press':
110
+ return await this.touchDown('', /** @type {number} */ (x), /** @type {number} */ (y));
111
+ case 'release':
112
+ return await this.touchUp(String(element),
113
+ /** @type {number} */ (x),
114
+ /** @type {number} */ (y));
115
+ case 'moveTo':
116
+ return await this.touchMove('', /** @type {number} */ (x), /** @type {number} */ (y));
117
+ case 'wait':
118
+ return await bluebird_1.default.delay(/** @type {number} */ (ms));
119
+ case 'longPress':
120
+ return await this.touchLongClick('',
121
+ /** @type {number} */ (x),
122
+ /** @type {number} */ (y), duration ?? 1000);
123
+ case 'cancel':
124
+ // TODO: clarify behavior of 'cancel' action and fix this
125
+ this.log.warn('Cancel action currently has no effect');
126
+ break;
127
+ default:
128
+ this.log.errorAndThrow(`unknown action ${action}`);
129
+ }
130
+ }
131
+ exports.doTouchAction = doTouchAction;
132
+ /**
133
+ * @deprecated
134
+ * @this {import('../driver').AndroidDriver}
135
+ * @param {import('./types').TouchAction[]} gestures
136
+ * @returns {Promise<void>}
137
+ */
138
+ async function performTouch(gestures) {
139
+ // press-wait-moveTo-release is `swipe`, so use native method
140
+ if (gestures.length === 4 &&
141
+ gestures[0].action === 'press' &&
142
+ gestures[1].action === 'wait' &&
143
+ gestures[2].action === 'moveTo' &&
144
+ gestures[3].action === 'release') {
145
+ let swipeOpts = await getSwipeOptions.bind(this)(
146
+ /** @type {import('./types').SwipeAction} */ (gestures));
147
+ return await this.doSwipe(swipeOpts);
148
+ }
149
+ let actions = /** @type {(import('./types').TouchActionKind|TouchAction)[]} */ (lodash_1.default.map(gestures, 'action'));
150
+ if (actions[0] === 'longPress' && actions[1] === 'moveTo' && actions[2] === 'release') {
151
+ // some things are special
152
+ return await this.doTouchDrag(/** @type {import('./types').TouchDragAction} */ (gestures));
153
+ }
154
+ else {
155
+ if (actions.length === 2) {
156
+ // `press` without a wait is too slow and gets interpretted as a `longPress`
157
+ if (lodash_1.default.head(actions) === 'press' && lodash_1.default.last(actions) === 'release') {
158
+ actions[0] = 'tap';
159
+ gestures[0].action = 'tap';
160
+ }
161
+ // the `longPress` and `tap` methods release on their own
162
+ if ((lodash_1.default.head(actions) === 'tap' || lodash_1.default.head(actions) === 'longPress') &&
163
+ lodash_1.default.last(actions) === 'release') {
164
+ gestures.pop();
165
+ actions.pop();
166
+ }
167
+ }
168
+ else {
169
+ // longpress followed by anything other than release should become a press and wait
170
+ if (actions[0] === 'longPress') {
171
+ actions = ['press', 'wait', ...actions.slice(1)];
172
+ let press = /** @type {NonReleaseTouchAction} */ (gestures.shift());
173
+ press.action = 'press';
174
+ /** @type {NonReleaseTouchAction} */
175
+ let wait = {
176
+ action: 'wait',
177
+ options: { ms: press.options.duration || 1000 },
178
+ };
179
+ delete press.options.duration;
180
+ gestures = [press, wait, ...gestures];
181
+ }
182
+ }
183
+ let fixedGestures = await parseTouch.bind(this)(gestures, false);
184
+ // fix release action then perform all actions
185
+ if (actions[actions.length - 1] === 'release') {
186
+ actions[actions.length - 1] = /** @type {TouchAction} */ (await fixRelease.bind(this)(gestures));
187
+ }
188
+ for (let g of fixedGestures) {
189
+ await performGesture.bind(this)(g);
190
+ }
191
+ }
192
+ }
193
+ exports.performTouch = performTouch;
194
+ /**
195
+ * @deprecated
196
+ * @this {import('../driver').AndroidDriver}
197
+ * @param {import('./types').TouchAction[]} actions
198
+ * @param {string} elementId
199
+ * @returns {Promise<void>}
200
+ */
201
+ async function performMultiAction(actions, elementId) {
202
+ // Android needs at least two actions to be able to perform a multi pointer gesture
203
+ if (actions.length === 1) {
204
+ throw new Error('Multi Pointer Gestures need at least two actions. ' +
205
+ 'Use Touch Actions for a single action.');
206
+ }
207
+ const states = await (0, asyncbox_1.asyncmap)(actions, async (action) => await parseTouch.bind(this)(action, true), false);
208
+ return await this.doPerformMultiAction(elementId, states);
209
+ }
210
+ exports.performMultiAction = performMultiAction;
211
+ /**
212
+ * @deprecated
213
+ * @this {import('../driver').AndroidDriver}
214
+ * @param {string} elementId
215
+ * @param {import('./types').TouchState[]} states
216
+ * @returns {Promise<void>}
217
+ */
218
+ async function doPerformMultiAction(elementId, states) {
219
+ throw new driver_1.errors.NotImplementedError('Not implemented');
220
+ }
221
+ exports.doPerformMultiAction = doPerformMultiAction;
222
+ // #region Internal helpers
223
+ /**
224
+ * @deprecated
16
225
  * @param {number|null} [val]
17
226
  * @returns {number}
18
227
  */
@@ -23,7 +232,18 @@ function getCoordDefault(val) {
23
232
  return support_1.util.hasValue(val) ? val : 0.5;
24
233
  }
25
234
  /**
26
- *
235
+ * @deprecated
236
+ * @param {number} number
237
+ * @param {number} digits
238
+ * @returns {number}
239
+ */
240
+ function truncateDecimals(number, digits) {
241
+ const multiplier = Math.pow(10, digits), adjustedNum = number * multiplier, truncatedNum = Math[adjustedNum < 0 ? 'ceil' : 'floor'](adjustedNum);
242
+ return truncatedNum / multiplier;
243
+ }
244
+ exports.truncateDecimals = truncateDecimals;
245
+ /**
246
+ * @deprecated
27
247
  * @param {NonReleaseTouchAction} waitGesture
28
248
  * @returns {number}
29
249
  */
@@ -42,304 +262,203 @@ function getSwipeTouchDuration(waitGesture) {
42
262
  return duration;
43
263
  }
44
264
  /**
45
- * @type {import('./mixins').TouchMixin & ThisType<import('../driver').AndroidDriver>}
46
- * @satisfies {import('@appium/types').ExternalDriver}
265
+ * @deprecated
266
+ * @this {import('../driver').AndroidDriver}
267
+ * @param {import('./types').SwipeAction} gestures
268
+ * @param {number} [touchCount=1]
269
+ * @returns {Promise<import('./types').TouchSwipeOpts>}
47
270
  */
48
- const TouchMixin = {
49
- async doTouchAction(action, opts = {}) {
50
- const { element, x, y, count, ms, duration } = opts;
51
- // parseTouch precalculates absolute element positions
52
- // so there is no need to pass `element` to the affected gestures
53
- switch (action) {
54
- case 'tap':
55
- return await this.tap('', x, y, count);
56
- case 'press':
57
- return await this.touchDown('', /** @type {number} */ (x), /** @type {number} */ (y));
58
- case 'release':
59
- return await this.touchUp(String(element),
60
- /** @type {number} */ (x),
61
- /** @type {number} */ (y));
62
- case 'moveTo':
63
- return await this.touchMove('', /** @type {number} */ (x), /** @type {number} */ (y));
64
- case 'wait':
65
- return await bluebird_1.default.delay(/** @type {number} */ (ms));
66
- case 'longPress':
67
- return await this.touchLongClick('',
68
- /** @type {number} */ (x),
69
- /** @type {number} */ (y), duration ?? 1000);
70
- case 'cancel':
71
- // TODO: clarify behavior of 'cancel' action and fix this
72
- this.log.warn('Cancel action currently has no effect');
73
- break;
74
- default:
75
- this.log.errorAndThrow(`unknown action ${action}`);
76
- }
77
- },
78
- async doTouchDrag(gestures) {
79
- let longPress = gestures[0];
80
- let moveTo = gestures[1];
81
- let startX = longPress.options.x || 0, startY = longPress.options.y || 0, endX = moveTo.options.x || 0, endY = moveTo.options.y || 0;
82
- if (longPress.options.element) {
83
- let { x, y } = await this.getLocationInView(longPress.options.element);
84
- startX += x || 0;
85
- startY += y || 0;
271
+ async function getSwipeOptions(gestures, touchCount = 1) {
272
+ let startX = getCoordDefault(gestures[0].options.x), startY = getCoordDefault(gestures[0].options.y), endX = getCoordDefault(gestures[2].options.x), endY = getCoordDefault(gestures[2].options.y), duration = getSwipeTouchDuration(gestures[1]), element = /** @type {string} */ (gestures[0].options.element), destElement = gestures[2].options.element || gestures[0].options.element;
273
+ // there's no destination element handling in bootstrap and since it applies to all platforms, we handle it here
274
+ if (support_1.util.hasValue(destElement)) {
275
+ let locResult = await this.getLocationInView(destElement);
276
+ let sizeResult = await this.getSize(destElement);
277
+ let offsetX = Math.abs(endX) < 1 && Math.abs(endX) > 0 ? sizeResult.width * endX : endX;
278
+ let offsetY = Math.abs(endY) < 1 && Math.abs(endY) > 0 ? sizeResult.height * endY : endY;
279
+ endX = locResult.x + offsetX;
280
+ endY = locResult.y + offsetY;
281
+ // if the target element was provided, the coordinates for the destination need to be relative to it.
282
+ if (support_1.util.hasValue(element)) {
283
+ let firstElLocation = await this.getLocationInView(element);
284
+ endX -= firstElLocation.x;
285
+ endY -= firstElLocation.y;
86
286
  }
87
- if (moveTo.options.element) {
88
- let { x, y } = await this.getLocationInView(moveTo.options.element);
89
- endX += x || 0;
90
- endY += y || 0;
91
- }
92
- let apiLevel = await this.adb.getApiLevel();
93
- // lollipop takes a little longer to get things rolling
94
- let duration = apiLevel >= 5 ? 2 : 1;
95
- // make sure that if the long press has a duration, we use it.
96
- if (longPress.options && longPress.options.duration) {
97
- duration = Math.max(longPress.options.duration / 1000, duration);
98
- }
99
- // `drag` will take care of whether there is an element or not at that level
100
- return await this.drag(startX, startY, endX, endY, duration, 1, longPress.options.element, moveTo.options.element);
101
- },
102
- async fixRelease(gestures) {
103
- let release = /** @type {import('./types').ReleaseTouchAction} */ (lodash_1.default.last(gestures));
104
- // sometimes there are no options
105
- release.options = release.options || {};
106
- // nothing to do if release options are already set
107
- if (release.options.element || (release.options.x && release.options.y)) {
108
- return;
109
- }
110
- // without coordinates, `release` uses the center of the screen, which,
111
- // generally speaking, is not what we want
112
- // therefore: loop backwards and use the last command with an element and/or
113
- // offset coordinates
114
- gestures = lodash_1.default.clone(gestures);
115
- let ref = null;
116
- for (let gesture of /** @type {NonReleaseTouchAction[]} */ (gestures.reverse())) {
117
- let opts = gesture.options;
118
- if (opts.element || (opts.x && opts.y)) {
119
- ref = gesture;
120
- break;
121
- }
122
- }
123
- if (ref) {
124
- let opts = ref.options;
125
- if (opts.element) {
126
- let loc = await this.getLocationInView(opts.element);
127
- if (opts.x && opts.y) {
128
- // this is an offset from the element
129
- release.options = {
130
- x: loc.x + opts.x,
131
- y: loc.y + opts.y,
132
- };
287
+ }
288
+ // clients are responsible to use these options correctly
289
+ return { startX, startY, endX, endY, duration, touchCount, element };
290
+ }
291
+ /**
292
+ * @deprecated
293
+ * @this {import('../driver').AndroidDriver}
294
+ * @param {import('./types').TouchAction[]} gestures
295
+ * @param {boolean} [multi]
296
+ * @returns {Promise<import('./types').TouchState[]>}
297
+ */
298
+ async function parseTouch(gestures, multi) {
299
+ // because multi-touch releases at the end by default
300
+ if (multi && /** @type {TouchAction} */ (lodash_1.default.last(gestures)).action === 'release') {
301
+ gestures.pop();
302
+ }
303
+ let touchStateObjects = await (0, asyncbox_1.asyncmap)(gestures, async (gesture) => {
304
+ let options = gesture.options || {};
305
+ if (lodash_1.default.includes(['press', 'moveTo', 'tap', 'longPress'], gesture.action)) {
306
+ options.offset = false;
307
+ let elementId = gesture.options.element;
308
+ if (elementId) {
309
+ let pos = await this.getLocationInView(elementId);
310
+ if (gesture.options.x || gesture.options.y) {
311
+ options.x = pos.x + (gesture.options.x || 0);
312
+ options.y = pos.y + (gesture.options.y || 0);
133
313
  }
134
314
  else {
135
- // this is the center of the element
136
- let size = await this.getSize(opts.element);
137
- release.options = {
138
- x: loc.x + size.width / 2,
139
- y: loc.y + size.height / 2,
140
- };
315
+ const { width, height } = await this.getSize(elementId);
316
+ options.x = pos.x + width / 2;
317
+ options.y = pos.y + height / 2;
141
318
  }
319
+ let touchStateObject = {
320
+ action: gesture.action,
321
+ options,
322
+ timeOffset: 0.005,
323
+ };
324
+ return touchStateObject;
142
325
  }
143
326
  else {
144
- release.options = lodash_1.default.pick(opts, 'x', 'y');
327
+ options.x = gesture.options.x || 0;
328
+ options.y = gesture.options.y || 0;
329
+ let touchStateObject = {
330
+ action: gesture.action,
331
+ options,
332
+ timeOffset: 0.005,
333
+ };
334
+ return touchStateObject;
145
335
  }
146
336
  }
147
- return release;
148
- },
149
- async performGesture(gesture) {
150
- try {
151
- return await this.doTouchAction(gesture.action, gesture.options || {});
152
- }
153
- catch (e) {
154
- // sometime the element is not available when releasing, retry without it
155
- if ((0, driver_1.isErrorType)(e, driver_1.errors.NoSuchElementError) &&
156
- gesture.action === 'release' &&
157
- gesture.options?.element) {
158
- delete gesture.options.element;
159
- this.log.debug(`retrying release without element opts: ${gesture.options}.`);
160
- return await this.doTouchAction(gesture.action, gesture.options || {});
337
+ else {
338
+ let offset = 0.005;
339
+ if (gesture.action === 'wait') {
340
+ options = gesture.options;
341
+ offset = parseInt(gesture.options.ms, 10) / 1000;
161
342
  }
162
- throw e;
343
+ let touchStateObject = {
344
+ action: gesture.action,
345
+ options,
346
+ timeOffset: offset,
347
+ };
348
+ return touchStateObject;
163
349
  }
164
- },
165
- async getSwipeOptions(gestures, touchCount = 1) {
166
- let startX = getCoordDefault(gestures[0].options.x), startY = getCoordDefault(gestures[0].options.y), endX = getCoordDefault(gestures[2].options.x), endY = getCoordDefault(gestures[2].options.y), duration = getSwipeTouchDuration(gestures[1]), element = /** @type {string} */ (gestures[0].options.element), destElement = gestures[2].options.element || gestures[0].options.element;
167
- // there's no destination element handling in bootstrap and since it applies to all platforms, we handle it here
168
- if (support_1.util.hasValue(destElement)) {
169
- let locResult = await this.getLocationInView(destElement);
170
- let sizeResult = await this.getSize(destElement);
171
- let offsetX = Math.abs(endX) < 1 && Math.abs(endX) > 0 ? sizeResult.width * endX : endX;
172
- let offsetY = Math.abs(endY) < 1 && Math.abs(endY) > 0 ? sizeResult.height * endY : endY;
173
- endX = locResult.x + offsetX;
174
- endY = locResult.y + offsetY;
175
- // if the target element was provided, the coordinates for the destination need to be relative to it.
176
- if (support_1.util.hasValue(element)) {
177
- let firstElLocation = await this.getLocationInView(element);
178
- endX -= firstElLocation.x;
179
- endY -= firstElLocation.y;
180
- }
350
+ }, false);
351
+ // we need to change the time (which is now an offset)
352
+ // and the position (which may be an offset)
353
+ let prevPos = null, time = 0;
354
+ for (let state of touchStateObjects) {
355
+ if (lodash_1.default.isUndefined(state.options.x) && lodash_1.default.isUndefined(state.options.y) && prevPos !== null) {
356
+ // this happens with wait
357
+ state.options.x = prevPos.x;
358
+ state.options.y = prevPos.y;
181
359
  }
182
- // clients are responsible to use these options correctly
183
- return { startX, startY, endX, endY, duration, touchCount, element };
184
- },
185
- async performTouch(gestures) {
186
- // press-wait-moveTo-release is `swipe`, so use native method
187
- if (gestures.length === 4 &&
188
- gestures[0].action === 'press' &&
189
- gestures[1].action === 'wait' &&
190
- gestures[2].action === 'moveTo' &&
191
- gestures[3].action === 'release') {
192
- let swipeOpts = await this.getSwipeOptions(
193
- /** @type {import('./types').SwipeAction} */ (gestures));
194
- return await this.swipe(swipeOpts.startX, swipeOpts.startY, swipeOpts.endX, swipeOpts.endY, swipeOpts.duration, swipeOpts.touchCount, swipeOpts.element);
360
+ if (state.options.offset && prevPos) {
361
+ // the current position is an offset
362
+ state.options.x += prevPos.x;
363
+ state.options.y += prevPos.y;
195
364
  }
196
- let actions = /** @type {(import('./types').TouchActionKind|TouchAction)[]} */ (lodash_1.default.map(gestures, 'action'));
197
- if (actions[0] === 'longPress' && actions[1] === 'moveTo' && actions[2] === 'release') {
198
- // some things are special
199
- return await this.doTouchDrag(/** @type {import('./types').TouchDragAction} */ (gestures));
365
+ delete state.options.offset;
366
+ if (!lodash_1.default.isUndefined(state.options.x) && !lodash_1.default.isUndefined(state.options.y)) {
367
+ prevPos = state.options;
200
368
  }
201
- else {
202
- if (actions.length === 2) {
203
- // `press` without a wait is too slow and gets interpretted as a `longPress`
204
- if (lodash_1.default.head(actions) === 'press' && lodash_1.default.last(actions) === 'release') {
205
- actions[0] = 'tap';
206
- gestures[0].action = 'tap';
207
- }
208
- // the `longPress` and `tap` methods release on their own
209
- if ((lodash_1.default.head(actions) === 'tap' || lodash_1.default.head(actions) === 'longPress') &&
210
- lodash_1.default.last(actions) === 'release') {
211
- gestures.pop();
212
- actions.pop();
213
- }
214
- }
215
- else {
216
- // longpress followed by anything other than release should become a press and wait
217
- if (actions[0] === 'longPress') {
218
- actions = ['press', 'wait', ...actions.slice(1)];
219
- let press = /** @type {NonReleaseTouchAction} */ (gestures.shift());
220
- press.action = 'press';
221
- /** @type {NonReleaseTouchAction} */
222
- let wait = {
223
- action: 'wait',
224
- options: { ms: press.options.duration || 1000 },
225
- };
226
- delete press.options.duration;
227
- gestures = [press, wait, ...gestures];
228
- }
229
- }
230
- let fixedGestures = await this.parseTouch(gestures, false);
231
- // fix release action then perform all actions
232
- if (actions[actions.length - 1] === 'release') {
233
- actions[actions.length - 1] = /** @type {TouchAction} */ (await this.fixRelease(gestures));
234
- }
235
- for (let g of fixedGestures) {
236
- await this.performGesture(g);
369
+ if (multi) {
370
+ let timeOffset = state.timeOffset;
371
+ time += timeOffset;
372
+ state.time = truncateDecimals(time, 3);
373
+ // multi gestures require 'touch' rather than 'options'
374
+ if (!lodash_1.default.isUndefined(state.options.x) && !lodash_1.default.isUndefined(state.options.y)) {
375
+ state.touch = {
376
+ x: state.options.x,
377
+ y: state.options.y,
378
+ };
237
379
  }
380
+ delete state.options;
238
381
  }
239
- },
240
- async parseTouch(gestures, multi) {
241
- // because multi-touch releases at the end by default
242
- if (multi && /** @type {TouchAction} */ (lodash_1.default.last(gestures)).action === 'release') {
243
- gestures.pop();
382
+ delete state.timeOffset;
383
+ }
384
+ return touchStateObjects;
385
+ }
386
+ /**
387
+ * @deprecated
388
+ * @this {import('../driver').AndroidDriver}
389
+ * @param {import('./types').TouchAction[]} gestures
390
+ * @returns {Promise<import('./types').ReleaseTouchAction|undefined>}
391
+ */
392
+ async function fixRelease(gestures) {
393
+ let release = /** @type {import('./types').ReleaseTouchAction} */ (lodash_1.default.last(gestures));
394
+ // sometimes there are no options
395
+ release.options = release.options || {};
396
+ // nothing to do if release options are already set
397
+ if (release.options.element || (release.options.x && release.options.y)) {
398
+ return;
399
+ }
400
+ // without coordinates, `release` uses the center of the screen, which,
401
+ // generally speaking, is not what we want
402
+ // therefore: loop backwards and use the last command with an element and/or
403
+ // offset coordinates
404
+ gestures = lodash_1.default.clone(gestures);
405
+ let ref = null;
406
+ for (let gesture of /** @type {NonReleaseTouchAction[]} */ (gestures.reverse())) {
407
+ let opts = gesture.options;
408
+ if (opts.element || (opts.x && opts.y)) {
409
+ ref = gesture;
410
+ break;
244
411
  }
245
- let touchStateObjects = await (0, asyncbox_1.asyncmap)(gestures, async (gesture) => {
246
- let options = gesture.options || {};
247
- if (lodash_1.default.includes(['press', 'moveTo', 'tap', 'longPress'], gesture.action)) {
248
- options.offset = false;
249
- let elementId = gesture.options.element;
250
- if (elementId) {
251
- let pos = await this.getLocationInView(elementId);
252
- if (gesture.options.x || gesture.options.y) {
253
- options.x = pos.x + (gesture.options.x || 0);
254
- options.y = pos.y + (gesture.options.y || 0);
255
- }
256
- else {
257
- const { width, height } = await this.getSize(elementId);
258
- options.x = pos.x + width / 2;
259
- options.y = pos.y + height / 2;
260
- }
261
- let touchStateObject = {
262
- action: gesture.action,
263
- options,
264
- timeOffset: 0.005,
265
- };
266
- return touchStateObject;
267
- }
268
- else {
269
- options.x = gesture.options.x || 0;
270
- options.y = gesture.options.y || 0;
271
- let touchStateObject = {
272
- action: gesture.action,
273
- options,
274
- timeOffset: 0.005,
275
- };
276
- return touchStateObject;
277
- }
412
+ }
413
+ if (ref) {
414
+ let opts = ref.options;
415
+ if (opts.element) {
416
+ let loc = await this.getLocationInView(opts.element);
417
+ if (opts.x && opts.y) {
418
+ // this is an offset from the element
419
+ release.options = {
420
+ x: loc.x + opts.x,
421
+ y: loc.y + opts.y,
422
+ };
278
423
  }
279
424
  else {
280
- let offset = 0.005;
281
- if (gesture.action === 'wait') {
282
- options = gesture.options;
283
- offset = parseInt(gesture.options.ms, 10) / 1000;
284
- }
285
- let touchStateObject = {
286
- action: gesture.action,
287
- options,
288
- timeOffset: offset,
425
+ // this is the center of the element
426
+ let size = await this.getSize(opts.element);
427
+ release.options = {
428
+ x: loc.x + size.width / 2,
429
+ y: loc.y + size.height / 2,
289
430
  };
290
- return touchStateObject;
291
431
  }
292
- }, false);
293
- // we need to change the time (which is now an offset)
294
- // and the position (which may be an offset)
295
- let prevPos = null, time = 0;
296
- for (let state of touchStateObjects) {
297
- if (lodash_1.default.isUndefined(state.options.x) && lodash_1.default.isUndefined(state.options.y) && prevPos !== null) {
298
- // this happens with wait
299
- state.options.x = prevPos.x;
300
- state.options.y = prevPos.y;
301
- }
302
- if (state.options.offset && prevPos) {
303
- // the current position is an offset
304
- state.options.x += prevPos.x;
305
- state.options.y += prevPos.y;
306
- }
307
- delete state.options.offset;
308
- if (!lodash_1.default.isUndefined(state.options.x) && !lodash_1.default.isUndefined(state.options.y)) {
309
- prevPos = state.options;
310
- }
311
- if (multi) {
312
- let timeOffset = state.timeOffset;
313
- time += timeOffset;
314
- state.time = android_1.default.truncateDecimals(time, 3);
315
- // multi gestures require 'touch' rather than 'options'
316
- if (!lodash_1.default.isUndefined(state.options.x) && !lodash_1.default.isUndefined(state.options.y)) {
317
- state.touch = {
318
- x: state.options.x,
319
- y: state.options.y,
320
- };
321
- }
322
- delete state.options;
323
- }
324
- delete state.timeOffset;
325
432
  }
326
- return touchStateObjects;
327
- },
328
- async performMultiAction(actions, elementId) {
329
- // Android needs at least two actions to be able to perform a multi pointer gesture
330
- if (actions.length === 1) {
331
- throw new Error('Multi Pointer Gestures need at least two actions. ' +
332
- 'Use Touch Actions for a single action.');
433
+ else {
434
+ release.options = lodash_1.default.pick(opts, 'x', 'y');
333
435
  }
334
- const states = await (0, asyncbox_1.asyncmap)(actions, async (action) => await this.parseTouch(action, true), false);
335
- return await this.doPerformMultiAction(elementId, states);
336
- },
337
- async doPerformMultiAction(elementId, states) {
338
- throw new driver_1.errors.NotImplementedError('Not implemented');
339
- },
340
- };
341
- (0, mixins_1.mixin)(TouchMixin);
342
- exports.default = TouchMixin;
436
+ }
437
+ return release;
438
+ }
439
+ /**
440
+ * @deprecated
441
+ * @this {import('../driver').AndroidDriver}
442
+ * @param {import('./types').TouchAction} gesture
443
+ * @returns {Promise<void>}
444
+ */
445
+ async function performGesture(gesture) {
446
+ try {
447
+ return await this.doTouchAction(gesture.action, gesture.options || {});
448
+ }
449
+ catch (e) {
450
+ // sometime the element is not available when releasing, retry without it
451
+ if ((0, driver_1.isErrorType)(e, driver_1.errors.NoSuchElementError) &&
452
+ gesture.action === 'release' &&
453
+ gesture.options?.element) {
454
+ delete gesture.options.element;
455
+ this.log.debug(`retrying release without element opts: ${gesture.options}.`);
456
+ return await this.doTouchAction(gesture.action, gesture.options || {});
457
+ }
458
+ throw e;
459
+ }
460
+ }
461
+ // #endregion
343
462
  /**
344
463
  * @typedef {import('appium-adb').ADB} ADB
345
464
  * @typedef {import('./types').TouchAction} TouchAction