appium-xcuitest-driver 10.3.0 → 10.4.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 (257) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/lib/commands/active-app-info.d.ts +9 -0
  3. package/build/lib/commands/active-app-info.d.ts.map +1 -0
  4. package/build/lib/commands/active-app-info.js +14 -0
  5. package/build/lib/commands/active-app-info.js.map +1 -0
  6. package/build/lib/commands/alert.d.ts +42 -45
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +66 -62
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +150 -153
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +300 -286
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/app-strings.d.ts +14 -17
  15. package/build/lib/commands/app-strings.d.ts.map +1 -1
  16. package/build/lib/commands/app-strings.js +23 -24
  17. package/build/lib/commands/app-strings.js.map +1 -1
  18. package/build/lib/commands/appearance.d.ts +19 -22
  19. package/build/lib/commands/appearance.d.ts.map +1 -1
  20. package/build/lib/commands/appearance.js +56 -56
  21. package/build/lib/commands/appearance.js.map +1 -1
  22. package/build/lib/commands/audit.d.ts +22 -17
  23. package/build/lib/commands/audit.d.ts.map +1 -1
  24. package/build/lib/commands/audit.js +17 -18
  25. package/build/lib/commands/audit.js.map +1 -1
  26. package/build/lib/commands/battery.d.ts +11 -14
  27. package/build/lib/commands/battery.d.ts.map +1 -1
  28. package/build/lib/commands/battery.js +36 -37
  29. package/build/lib/commands/battery.js.map +1 -1
  30. package/build/lib/commands/biometric.d.ts +30 -33
  31. package/build/lib/commands/biometric.d.ts.map +1 -1
  32. package/build/lib/commands/biometric.js +42 -41
  33. package/build/lib/commands/biometric.js.map +1 -1
  34. package/build/lib/commands/certificate.d.ts +48 -45
  35. package/build/lib/commands/certificate.d.ts.map +1 -1
  36. package/build/lib/commands/certificate.js +218 -205
  37. package/build/lib/commands/certificate.js.map +1 -1
  38. package/build/lib/commands/clipboard.d.ts +19 -22
  39. package/build/lib/commands/clipboard.d.ts.map +1 -1
  40. package/build/lib/commands/clipboard.js +30 -30
  41. package/build/lib/commands/clipboard.js.map +1 -1
  42. package/build/lib/commands/condition.d.ts +49 -26
  43. package/build/lib/commands/condition.d.ts.map +1 -1
  44. package/build/lib/commands/condition.js +87 -86
  45. package/build/lib/commands/condition.js.map +1 -1
  46. package/build/lib/commands/content-size.d.ts +26 -29
  47. package/build/lib/commands/content-size.d.ts.map +1 -1
  48. package/build/lib/commands/content-size.js +36 -36
  49. package/build/lib/commands/content-size.js.map +1 -1
  50. package/build/lib/commands/context.d.ts +161 -108
  51. package/build/lib/commands/context.d.ts.map +1 -1
  52. package/build/lib/commands/context.js +530 -517
  53. package/build/lib/commands/context.js.map +1 -1
  54. package/build/lib/commands/deviceInfo.d.ts +9 -12
  55. package/build/lib/commands/deviceInfo.d.ts.map +1 -1
  56. package/build/lib/commands/deviceInfo.js +17 -18
  57. package/build/lib/commands/deviceInfo.js.map +1 -1
  58. package/build/lib/commands/element.d.ts +102 -105
  59. package/build/lib/commands/element.d.ts.map +1 -1
  60. package/build/lib/commands/element.js +337 -323
  61. package/build/lib/commands/element.js.map +1 -1
  62. package/build/lib/commands/execute.d.ts +24 -19
  63. package/build/lib/commands/execute.d.ts.map +1 -1
  64. package/build/lib/commands/execute.js +63 -62
  65. package/build/lib/commands/execute.js.map +1 -1
  66. package/build/lib/commands/file-movement.d.ts +77 -80
  67. package/build/lib/commands/file-movement.d.ts.map +1 -1
  68. package/build/lib/commands/file-movement.js +130 -124
  69. package/build/lib/commands/file-movement.js.map +1 -1
  70. package/build/lib/commands/find.d.ts +18 -21
  71. package/build/lib/commands/find.d.ts.map +1 -1
  72. package/build/lib/commands/find.js +158 -156
  73. package/build/lib/commands/find.js.map +1 -1
  74. package/build/lib/commands/general.d.ts +124 -116
  75. package/build/lib/commands/general.d.ts.map +1 -1
  76. package/build/lib/commands/general.js +248 -232
  77. package/build/lib/commands/general.js.map +1 -1
  78. package/build/lib/commands/geolocation.d.ts +43 -46
  79. package/build/lib/commands/geolocation.d.ts.map +1 -1
  80. package/build/lib/commands/geolocation.js +10 -11
  81. package/build/lib/commands/geolocation.js.map +1 -1
  82. package/build/lib/commands/gesture.d.ts +273 -276
  83. package/build/lib/commands/gesture.d.ts.map +1 -1
  84. package/build/lib/commands/gesture.js +506 -492
  85. package/build/lib/commands/gesture.js.map +1 -1
  86. package/build/lib/commands/increase-contrast.d.ts +20 -23
  87. package/build/lib/commands/increase-contrast.d.ts.map +1 -1
  88. package/build/lib/commands/increase-contrast.js +30 -30
  89. package/build/lib/commands/increase-contrast.js.map +1 -1
  90. package/build/lib/commands/iohid.d.ts +1370 -1373
  91. package/build/lib/commands/iohid.d.ts.map +1 -1
  92. package/build/lib/commands/iohid.js +30 -31
  93. package/build/lib/commands/iohid.js.map +1 -1
  94. package/build/lib/commands/keyboard.d.ts +29 -32
  95. package/build/lib/commands/keyboard.d.ts.map +1 -1
  96. package/build/lib/commands/keyboard.js +53 -51
  97. package/build/lib/commands/keyboard.js.map +1 -1
  98. package/build/lib/commands/keychains.d.ts +9 -12
  99. package/build/lib/commands/keychains.d.ts.map +1 -1
  100. package/build/lib/commands/keychains.js +13 -14
  101. package/build/lib/commands/keychains.js.map +1 -1
  102. package/build/lib/commands/localization.d.ts +16 -19
  103. package/build/lib/commands/localization.d.ts.map +1 -1
  104. package/build/lib/commands/localization.js +25 -26
  105. package/build/lib/commands/localization.js.map +1 -1
  106. package/build/lib/commands/location.d.ts +36 -39
  107. package/build/lib/commands/location.d.ts.map +1 -1
  108. package/build/lib/commands/location.js +99 -98
  109. package/build/lib/commands/location.js.map +1 -1
  110. package/build/lib/commands/lock.d.ts +21 -24
  111. package/build/lib/commands/lock.d.ts.map +1 -1
  112. package/build/lib/commands/lock.js +39 -38
  113. package/build/lib/commands/lock.js.map +1 -1
  114. package/build/lib/commands/log.d.ts +43 -37
  115. package/build/lib/commands/log.d.ts.map +1 -1
  116. package/build/lib/commands/log.js +174 -171
  117. package/build/lib/commands/log.js.map +1 -1
  118. package/build/lib/commands/memory.d.ts +9 -12
  119. package/build/lib/commands/memory.d.ts.map +1 -1
  120. package/build/lib/commands/memory.js +37 -38
  121. package/build/lib/commands/memory.js.map +1 -1
  122. package/build/lib/commands/navigation.d.ts +30 -33
  123. package/build/lib/commands/navigation.d.ts.map +1 -1
  124. package/build/lib/commands/navigation.js +92 -92
  125. package/build/lib/commands/navigation.js.map +1 -1
  126. package/build/lib/commands/notifications.d.ts +26 -29
  127. package/build/lib/commands/notifications.d.ts.map +1 -1
  128. package/build/lib/commands/notifications.js +53 -53
  129. package/build/lib/commands/notifications.js.map +1 -1
  130. package/build/lib/commands/pasteboard.d.ts +21 -24
  131. package/build/lib/commands/pasteboard.d.ts.map +1 -1
  132. package/build/lib/commands/pasteboard.js +37 -37
  133. package/build/lib/commands/pasteboard.js.map +1 -1
  134. package/build/lib/commands/pcap.d.ts +39 -26
  135. package/build/lib/commands/pcap.d.ts.map +1 -1
  136. package/build/lib/commands/pcap.js +81 -81
  137. package/build/lib/commands/pcap.js.map +1 -1
  138. package/build/lib/commands/performance.d.ts +63 -44
  139. package/build/lib/commands/performance.d.ts.map +1 -1
  140. package/build/lib/commands/performance.js +105 -105
  141. package/build/lib/commands/performance.js.map +1 -1
  142. package/build/lib/commands/permissions.d.ts +33 -36
  143. package/build/lib/commands/permissions.d.ts.map +1 -1
  144. package/build/lib/commands/permissions.js +66 -65
  145. package/build/lib/commands/permissions.js.map +1 -1
  146. package/build/lib/commands/proxy-helper.d.ts +12 -15
  147. package/build/lib/commands/proxy-helper.d.ts.map +1 -1
  148. package/build/lib/commands/proxy-helper.js +53 -54
  149. package/build/lib/commands/proxy-helper.js.map +1 -1
  150. package/build/lib/commands/record-audio.d.ts +49 -29
  151. package/build/lib/commands/record-audio.d.ts.map +1 -1
  152. package/build/lib/commands/record-audio.js +100 -104
  153. package/build/lib/commands/record-audio.js.map +1 -1
  154. package/build/lib/commands/recordscreen.d.ts +54 -18
  155. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  156. package/build/lib/commands/recordscreen.js +127 -129
  157. package/build/lib/commands/recordscreen.js.map +1 -1
  158. package/build/lib/commands/screenshots.d.ts +14 -17
  159. package/build/lib/commands/screenshots.d.ts.map +1 -1
  160. package/build/lib/commands/screenshots.js +108 -107
  161. package/build/lib/commands/screenshots.js.map +1 -1
  162. package/build/lib/commands/simctl.d.ts +11 -14
  163. package/build/lib/commands/simctl.d.ts.map +1 -1
  164. package/build/lib/commands/simctl.js +23 -26
  165. package/build/lib/commands/simctl.js.map +1 -1
  166. package/build/lib/commands/source.d.ts +14 -17
  167. package/build/lib/commands/source.d.ts.map +1 -1
  168. package/build/lib/commands/source.js +40 -43
  169. package/build/lib/commands/source.js.map +1 -1
  170. package/build/lib/commands/timeouts.d.ts +44 -33
  171. package/build/lib/commands/timeouts.d.ts.map +1 -1
  172. package/build/lib/commands/timeouts.js +65 -63
  173. package/build/lib/commands/timeouts.js.map +1 -1
  174. package/build/lib/commands/web.d.ts +275 -197
  175. package/build/lib/commands/web.d.ts.map +1 -1
  176. package/build/lib/commands/web.js +866 -785
  177. package/build/lib/commands/web.js.map +1 -1
  178. package/build/lib/commands/xctest-record-screen.d.ts +63 -66
  179. package/build/lib/commands/xctest-record-screen.d.ts.map +1 -1
  180. package/build/lib/commands/xctest-record-screen.js +103 -102
  181. package/build/lib/commands/xctest-record-screen.js.map +1 -1
  182. package/build/lib/commands/xctest.d.ts +55 -51
  183. package/build/lib/commands/xctest.d.ts.map +1 -1
  184. package/build/lib/commands/xctest.js +116 -117
  185. package/build/lib/commands/xctest.js.map +1 -1
  186. package/build/lib/driver.d.ts +277 -1597
  187. package/build/lib/driver.d.ts.map +1 -1
  188. package/build/lib/driver.js +318 -235
  189. package/build/lib/driver.js.map +1 -1
  190. package/build/lib/execute-method-map.d.ts.map +1 -1
  191. package/build/lib/execute-method-map.js +9 -0
  192. package/build/lib/execute-method-map.js.map +1 -1
  193. package/lib/commands/active-app-info.js +12 -0
  194. package/lib/commands/alert.js +68 -65
  195. package/lib/commands/app-management.js +308 -301
  196. package/lib/commands/app-strings.js +24 -26
  197. package/lib/commands/appearance.js +54 -56
  198. package/lib/commands/audit.js +18 -20
  199. package/lib/commands/battery.js +35 -37
  200. package/lib/commands/biometric.js +44 -46
  201. package/lib/commands/certificate.js +226 -215
  202. package/lib/commands/clipboard.js +30 -32
  203. package/lib/commands/condition.js +98 -100
  204. package/lib/commands/content-size.js +36 -38
  205. package/lib/commands/context.js +495 -490
  206. package/lib/commands/deviceInfo.js +19 -20
  207. package/lib/commands/element.js +367 -357
  208. package/lib/commands/execute.js +72 -72
  209. package/lib/commands/file-movement.js +132 -134
  210. package/lib/commands/find.js +160 -159
  211. package/lib/commands/general.js +238 -231
  212. package/lib/commands/geolocation.js +6 -14
  213. package/lib/commands/gesture.js +525 -515
  214. package/lib/commands/increase-contrast.js +30 -32
  215. package/lib/commands/iohid.js +32 -34
  216. package/lib/commands/keyboard.js +49 -51
  217. package/lib/commands/keychains.js +12 -14
  218. package/lib/commands/localization.js +24 -26
  219. package/lib/commands/location.js +102 -104
  220. package/lib/commands/lock.js +38 -38
  221. package/lib/commands/log.js +197 -198
  222. package/lib/commands/memory.js +40 -42
  223. package/lib/commands/navigation.js +96 -100
  224. package/lib/commands/notifications.js +57 -59
  225. package/lib/commands/pasteboard.js +37 -39
  226. package/lib/commands/pcap.js +84 -86
  227. package/lib/commands/performance.js +132 -133
  228. package/lib/commands/permissions.js +67 -69
  229. package/lib/commands/proxy-helper.js +60 -61
  230. package/lib/commands/record-audio.js +115 -120
  231. package/lib/commands/recordscreen.js +145 -149
  232. package/lib/commands/screenshots.js +116 -116
  233. package/lib/commands/simctl.js +25 -29
  234. package/lib/commands/source.js +42 -46
  235. package/lib/commands/timeouts.js +59 -63
  236. package/lib/commands/web.js +932 -859
  237. package/lib/commands/xctest-record-screen.js +103 -105
  238. package/lib/commands/xctest.js +134 -139
  239. package/lib/driver.js +286 -235
  240. package/lib/execute-method-map.ts +9 -0
  241. package/npm-shrinkwrap.json +8 -8
  242. package/package.json +1 -1
  243. package/build/lib/commands/activeAppInfo.d.ts +0 -12
  244. package/build/lib/commands/activeAppInfo.d.ts.map +0 -1
  245. package/build/lib/commands/activeAppInfo.js +0 -15
  246. package/build/lib/commands/activeAppInfo.js.map +0 -1
  247. package/build/lib/commands/index.d.ts +0 -96
  248. package/build/lib/commands/index.d.ts.map +0 -1
  249. package/build/lib/commands/index.js +0 -100
  250. package/build/lib/commands/index.js.map +0 -1
  251. package/build/lib/cookies.d.ts +0 -15
  252. package/build/lib/cookies.d.ts.map +0 -1
  253. package/build/lib/cookies.js +0 -84
  254. package/build/lib/cookies.js.map +0 -1
  255. package/lib/commands/activeAppInfo.js +0 -14
  256. package/lib/commands/index.js +0 -95
  257. package/lib/cookies.js +0 -92
@@ -3,9 +3,346 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.elementDisplayed = elementDisplayed;
7
+ exports.elementEnabled = elementEnabled;
8
+ exports.elementSelected = elementSelected;
9
+ exports.getName = getName;
10
+ exports.getNativeAttribute = getNativeAttribute;
11
+ exports.getAttribute = getAttribute;
12
+ exports.getProperty = getProperty;
13
+ exports.getText = getText;
14
+ exports.getElementRect = getElementRect;
15
+ exports.getLocation = getLocation;
16
+ exports.getLocationInView = getLocationInView;
17
+ exports.getSize = getSize;
18
+ exports.setValueImmediate = setValueImmediate;
19
+ exports.setValue = setValue;
20
+ exports.setValueWithWebAtom = setValueWithWebAtom;
21
+ exports.keys = keys;
22
+ exports.clear = clear;
23
+ exports.getContentSize = getContentSize;
24
+ exports.getNativeRect = getNativeRect;
6
25
  const lodash_1 = __importDefault(require("lodash"));
7
26
  const driver_1 = require("appium/driver");
8
27
  const support_1 = require("appium/support");
28
+ /**
29
+ * @this {XCUITestDriver}
30
+ */
31
+ async function elementDisplayed(el) {
32
+ el = support_1.util.unwrapElement(el);
33
+ if (this.isWebContext()) {
34
+ const atomsElement = this.getAtomsElement(el);
35
+ return await this.executeAtom('is_displayed', [atomsElement]);
36
+ }
37
+ return await this.proxyCommand(`/element/${el}/displayed`, 'GET');
38
+ }
39
+ /**
40
+ * @this {XCUITestDriver}
41
+ */
42
+ async function elementEnabled(el) {
43
+ el = support_1.util.unwrapElement(el);
44
+ if (this.isWebContext()) {
45
+ const atomsElement = this.getAtomsElement(el);
46
+ return await this.executeAtom('is_enabled', [atomsElement]);
47
+ }
48
+ return await this.proxyCommand(`/element/${el}/enabled`, 'GET');
49
+ }
50
+ /**
51
+ * @this {XCUITestDriver}
52
+ */
53
+ async function elementSelected(el) {
54
+ el = support_1.util.unwrapElement(el);
55
+ if (this.isWebContext()) {
56
+ const atomsElement = this.getAtomsElement(el);
57
+ return await this.executeAtom('is_selected', [atomsElement]);
58
+ }
59
+ return await this.proxyCommand(`/element/${el}/selected`, 'GET');
60
+ }
61
+ /**
62
+ * @this {XCUITestDriver}
63
+ */
64
+ async function getName(el) {
65
+ el = support_1.util.unwrapElement(el);
66
+ if (this.isWebContext()) {
67
+ const atomsElement = this.getAtomsElement(el);
68
+ const script = 'return arguments[0].tagName.toLowerCase()';
69
+ return await this.executeAtom('execute_script', [script, [atomsElement]]);
70
+ }
71
+ return await this.proxyCommand(`/element/${el}/name`, 'GET');
72
+ }
73
+ /**
74
+ * @this {XCUITestDriver}
75
+ */
76
+ async function getNativeAttribute(attribute, el) {
77
+ if (attribute === 'contentSize') {
78
+ // don't proxy requests for the content size of a scrollable element
79
+ return await this.getContentSize(el);
80
+ }
81
+ el = support_1.util.unwrapElement(el);
82
+ // otherwise let WDA handle attribute requests
83
+ let value = /** @type {string|number|null|undefined|boolean} */ (await this.proxyCommand(`/element/${el}/attribute/${attribute}`, 'GET'));
84
+ // Transform the result for the case when WDA returns an integer representation for a boolean value
85
+ if ([0, 1].includes(/** @type {number} */ (value))) {
86
+ value = !!value;
87
+ }
88
+ // The returned value must be of type string according to https://www.w3.org/TR/webdriver/#get-element-attribute
89
+ return lodash_1.default.isNull(value) || lodash_1.default.isString(value) ? value : JSON.stringify(value);
90
+ }
91
+ /**
92
+ * @this {XCUITestDriver}
93
+ */
94
+ async function getAttribute(attribute, el) {
95
+ el = support_1.util.unwrapElement(el);
96
+ if (!this.isWebContext()) {
97
+ return await this.getNativeAttribute(attribute, el);
98
+ }
99
+ const atomsElement = this.getAtomsElement(el);
100
+ return await this.executeAtom('get_attribute_value', [atomsElement, attribute]);
101
+ }
102
+ /**
103
+ * @this {XCUITestDriver}
104
+ */
105
+ async function getProperty(property, el) {
106
+ el = support_1.util.unwrapElement(el);
107
+ if (!this.isWebContext()) {
108
+ return await this.getNativeAttribute(property, el);
109
+ }
110
+ const atomsElement = this.getAtomsElement(el);
111
+ return await this.executeAtom('get_attribute_value', [atomsElement, property]);
112
+ }
113
+ /**
114
+ * @this {XCUITestDriver}
115
+ */
116
+ async function getText(el) {
117
+ el = support_1.util.unwrapElement(el);
118
+ if (!this.isWebContext()) {
119
+ return await this.proxyCommand(`/element/${el}/text`, 'GET');
120
+ }
121
+ let atomsElement = this.getAtomsElement(el);
122
+ return await this.executeAtom('get_text', [atomsElement]);
123
+ }
124
+ /**
125
+ * @this {XCUITestDriver}
126
+ * @returns {Promise<import('@appium/types').Rect>}
127
+ */
128
+ async function getElementRect(el) {
129
+ if (this.isWebContext()) {
130
+ // Mobile safari doesn't support rect
131
+ const { x, y } = await this.getLocation(el);
132
+ const { width, height } = await this.getSize(el);
133
+ return { x, y, width, height };
134
+ }
135
+ el = support_1.util.unwrapElement(el);
136
+ return await this.getNativeRect(el);
137
+ }
138
+ /**
139
+ * Get the position of an element on screen
140
+ *
141
+ * @param {string|Element} elementId - the element ID
142
+ * @returns {Promise<Position>} The position of the element
143
+ * @deprecated Use {@linkcode XCUITestDriver.getElementRect} instead
144
+ * @this {XCUITestDriver}
145
+ */
146
+ async function getLocation(elementId) {
147
+ const el = support_1.util.unwrapElement(elementId);
148
+ if (this.isWebContext()) {
149
+ const atomsElement = this.getAtomsElement(el);
150
+ let loc = await this.executeAtom('get_top_left_coordinates', [atomsElement]);
151
+ if (this.opts.absoluteWebLocations) {
152
+ const script = 'return [' +
153
+ 'Math.max(window.pageXOffset,document.documentElement.scrollLeft,document.body.scrollLeft),' +
154
+ 'Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop)];';
155
+ const [xOffset, yOffset] = /** @type {[number, number]} */ (await this.execute(script));
156
+ loc.x += xOffset;
157
+ loc.y += yOffset;
158
+ }
159
+ return loc;
160
+ }
161
+ const rect = await this.getElementRect(el);
162
+ return { x: rect.x, y: rect.y };
163
+ }
164
+ /**
165
+ * Alias for {@linkcode XCUITestDriver.getLocation}
166
+ * @param {string|Element} elementId - the element ID
167
+ * @returns {Promise<Position>} The position of the element
168
+ * @deprecated Use {@linkcode XCUITestDriver.getElementRect} instead
169
+ * @this {XCUITestDriver}
170
+ */
171
+ async function getLocationInView(elementId) {
172
+ return await this.getLocation(elementId);
173
+ }
174
+ /**
175
+ * Get the size of an element
176
+ * @param {string|Element} el - the element ID
177
+ * @returns {Promise<Size>} The position of the element
178
+ * @this {XCUITestDriver}
179
+ */
180
+ async function getSize(el) {
181
+ el = support_1.util.unwrapElement(el);
182
+ if (this.isWebContext()) {
183
+ return await this.executeAtom('get_size', [this.getAtomsElement(el)]);
184
+ }
185
+ const rect = await this.getElementRect(el);
186
+ return { width: rect.width, height: rect.height };
187
+ }
188
+ /**
189
+ * Alias for {@linkcode setValue}
190
+ *
191
+ * @param {string} value - the value to set
192
+ * @param {string} el - the element to set the value of
193
+ * @deprecated
194
+ * @this {XCUITestDriver}
195
+ */
196
+ async function setValueImmediate(value, el) {
197
+ // WDA does not provide no way to set the value directly
198
+ this.log.info('There is currently no way to bypass typing using XCUITest. Setting value through keyboard');
199
+ await this.setValue(value, el);
200
+ }
201
+ /**
202
+ * @this {XCUITestDriver}
203
+ */
204
+ async function setValue(value, el) {
205
+ el = support_1.util.unwrapElement(el);
206
+ if (!this.isWebContext()) {
207
+ await this.proxyCommand(`/element/${el}/value`, 'POST', {
208
+ value: prepareInputValue(value),
209
+ });
210
+ return;
211
+ }
212
+ const atomsElement = this.getAtomsElement(el);
213
+ await this.executeAtom('click', [atomsElement]);
214
+ if (this.opts.sendKeyStrategy !== 'oneByOne') {
215
+ await this.setValueWithWebAtom(atomsElement, value);
216
+ return;
217
+ }
218
+ for (const char of prepareInputValue(value)) {
219
+ await this.setValueWithWebAtom(atomsElement, char);
220
+ }
221
+ }
222
+ /**
223
+ * Set value with Atom for Web. This method calls `type` atom only.
224
+ * Expected to be called as part of {@linkcode setValue}.
225
+ * @this {XCUITestDriver}
226
+ * @param {import('./types').AtomsElement<string>} atomsElement A target element to type the given value.
227
+ * @param {string|string[]} value The actual text to type.
228
+ */
229
+ async function setValueWithWebAtom(atomsElement, value) {
230
+ await this.executeAtom('type', [atomsElement, value]);
231
+ if (this.opts.skipTriggerInputEventAfterSendkeys) {
232
+ return;
233
+ }
234
+ function triggerInputEvent(/** @type {EventTarget & {_valueTracker?: any}} */ input) {
235
+ let lastValue = '';
236
+ let event = new Event('input', { bubbles: true });
237
+ let tracker = input._valueTracker;
238
+ if (tracker) {
239
+ tracker.setValue(lastValue);
240
+ }
241
+ input.dispatchEvent(event);
242
+ }
243
+ const scriptAsString = `return (${triggerInputEvent}).apply(null, arguments)`;
244
+ await this.executeAtom('execute_script', [scriptAsString, [atomsElement]]);
245
+ }
246
+ /**
247
+ * Send keys to the app
248
+ * @param {string[]} value - Array of keys to send
249
+ * @this {XCUITestDriver}
250
+ * @deprecated Use {@linkcode XCUITestDriver.setValue} instead
251
+ */
252
+ async function keys(value) {
253
+ await this.proxyCommand('/wda/keys', 'POST', {
254
+ value: prepareInputValue(value),
255
+ });
256
+ }
257
+ /**
258
+ * @this {XCUITestDriver}
259
+ */
260
+ async function clear(el) {
261
+ el = support_1.util.unwrapElement(el);
262
+ if (this.isWebContext()) {
263
+ const atomsElement = this.getAtomsElement(el);
264
+ await this.executeAtom('clear', [atomsElement]);
265
+ return;
266
+ }
267
+ await this.proxyCommand(`/element/${el}/clear`, 'POST');
268
+ }
269
+ /**
270
+ * @this {XCUITestDriver}
271
+ */
272
+ async function getContentSize(el) {
273
+ if (this.isWebContext()) {
274
+ throw new driver_1.errors.NotYetImplementedError('Support for getContentSize for web context is not yet implemented. Please contact an Appium dev');
275
+ }
276
+ const type = await this.getAttribute('type', el);
277
+ if (type !== 'XCUIElementTypeTable' && type !== 'XCUIElementTypeCollectionView') {
278
+ throw new Error(`Can't get content size for type '${type}', only for ` + `tables and collection views`);
279
+ }
280
+ let locator = '*';
281
+ if (type === 'XCUIElementTypeTable') {
282
+ // only find table cells, not just any children
283
+ locator = 'XCUIElementTypeCell';
284
+ }
285
+ let contentHeight = 0;
286
+ const children = await this.findElOrEls(`class chain`, locator, true, el);
287
+ if (children.length === 1) {
288
+ // if we know there's only one element, we can optimize to make just one
289
+ // call to WDA
290
+ const rect = await this.getElementRect(lodash_1.default.head(children));
291
+ contentHeight = rect.height;
292
+ }
293
+ else if (children.length) {
294
+ // otherwise if we have multiple elements, logic differs based on element
295
+ // type
296
+ switch (type) {
297
+ case 'XCUIElementTypeTable': {
298
+ const firstRect = await this.getElementRect(lodash_1.default.head(children));
299
+ const lastRect = await this.getElementRect(lodash_1.default.last(children));
300
+ contentHeight = lastRect.y + lastRect.height - firstRect.y;
301
+ break;
302
+ }
303
+ case 'XCUIElementTypeCollectionView': {
304
+ let elsInRow = 1; // we know there must be at least one element in the row
305
+ let firstRect = await this.getElementRect(lodash_1.default.head(children));
306
+ let initialRects = [firstRect];
307
+ for (let i = 1; i < children.length; i++) {
308
+ const rect = await this.getElementRect(children[i]);
309
+ initialRects.push(rect);
310
+ if (rect.y !== firstRect.y) {
311
+ elsInRow = i;
312
+ break;
313
+ }
314
+ }
315
+ const spaceBetweenEls = initialRects[elsInRow].y -
316
+ initialRects[elsInRow - 1].y -
317
+ initialRects[elsInRow - 1].height;
318
+ const numRows = Math.ceil(children.length / elsInRow);
319
+ // assume all cells are the same height
320
+ contentHeight = numRows * firstRect.height + spaceBetweenEls * (numRows - 1);
321
+ break;
322
+ }
323
+ default:
324
+ throw new Error(`Programming error: type '${type}' was not ` +
325
+ `valid but should have already been rejected`);
326
+ }
327
+ }
328
+ const size = await this.getSize(el);
329
+ const origin = await this.getLocationInView(el);
330
+ // attributes have to be strings, so stringify this up
331
+ return JSON.stringify({
332
+ width: size.width,
333
+ height: size.height,
334
+ top: origin.y,
335
+ left: origin.x,
336
+ scrollableOffset: contentHeight,
337
+ });
338
+ }
339
+ /**
340
+ * @this {XCUITestDriver}
341
+ * @returns {Promise<Rect>}
342
+ */
343
+ async function getNativeRect(el) {
344
+ return /** @type {Rect} */ (await this.proxyCommand(`/element/${el}/rect`, 'GET'));
345
+ }
9
346
  /**
10
347
  * Prepares the input value to be passed as an argument to WDA.
11
348
  *
@@ -48,329 +385,6 @@ function prepareInputValue(inp) {
48
385
  return k;
49
386
  });
50
387
  }
51
- const commands = {
52
- /**
53
- * @this {XCUITestDriver}
54
- */
55
- async elementDisplayed(el) {
56
- el = support_1.util.unwrapElement(el);
57
- if (this.isWebContext()) {
58
- const atomsElement = this.getAtomsElement(el);
59
- return await this.executeAtom('is_displayed', [atomsElement]);
60
- }
61
- return await this.proxyCommand(`/element/${el}/displayed`, 'GET');
62
- },
63
- /**
64
- * @this {XCUITestDriver}
65
- */
66
- async elementEnabled(el) {
67
- el = support_1.util.unwrapElement(el);
68
- if (this.isWebContext()) {
69
- const atomsElement = this.getAtomsElement(el);
70
- return await this.executeAtom('is_enabled', [atomsElement]);
71
- }
72
- return await this.proxyCommand(`/element/${el}/enabled`, 'GET');
73
- },
74
- /**
75
- * @this {XCUITestDriver}
76
- */
77
- async elementSelected(el) {
78
- el = support_1.util.unwrapElement(el);
79
- if (this.isWebContext()) {
80
- const atomsElement = this.getAtomsElement(el);
81
- return await this.executeAtom('is_selected', [atomsElement]);
82
- }
83
- return await this.proxyCommand(`/element/${el}/selected`, 'GET');
84
- },
85
- /**
86
- * @this {XCUITestDriver}
87
- */
88
- async getName(el) {
89
- el = support_1.util.unwrapElement(el);
90
- if (this.isWebContext()) {
91
- const atomsElement = this.getAtomsElement(el);
92
- const script = 'return arguments[0].tagName.toLowerCase()';
93
- return await this.executeAtom('execute_script', [script, [atomsElement]]);
94
- }
95
- return await this.proxyCommand(`/element/${el}/name`, 'GET');
96
- },
97
- /**
98
- * @this {XCUITestDriver}
99
- */
100
- async getNativeAttribute(attribute, el) {
101
- if (attribute === 'contentSize') {
102
- // don't proxy requests for the content size of a scrollable element
103
- return await this.getContentSize(el);
104
- }
105
- el = support_1.util.unwrapElement(el);
106
- // otherwise let WDA handle attribute requests
107
- let value = /** @type {string|number|null|undefined|boolean} */ (await this.proxyCommand(`/element/${el}/attribute/${attribute}`, 'GET'));
108
- // Transform the result for the case when WDA returns an integer representation for a boolean value
109
- if ([0, 1].includes(/** @type {number} */ (value))) {
110
- value = !!value;
111
- }
112
- // The returned value must be of type string according to https://www.w3.org/TR/webdriver/#get-element-attribute
113
- return lodash_1.default.isNull(value) || lodash_1.default.isString(value) ? value : JSON.stringify(value);
114
- },
115
- /**
116
- * @this {XCUITestDriver}
117
- */
118
- async getAttribute(attribute, el) {
119
- el = support_1.util.unwrapElement(el);
120
- if (!this.isWebContext()) {
121
- return await this.getNativeAttribute(attribute, el);
122
- }
123
- const atomsElement = this.getAtomsElement(el);
124
- return await this.executeAtom('get_attribute_value', [atomsElement, attribute]);
125
- },
126
- /**
127
- * @this {XCUITestDriver}
128
- */
129
- async getProperty(property, el) {
130
- el = support_1.util.unwrapElement(el);
131
- if (!this.isWebContext()) {
132
- return await this.getNativeAttribute(property, el);
133
- }
134
- const atomsElement = this.getAtomsElement(el);
135
- return await this.executeAtom('get_attribute_value', [atomsElement, property]);
136
- },
137
- /**
138
- * @this {XCUITestDriver}
139
- */
140
- async getText(el) {
141
- el = support_1.util.unwrapElement(el);
142
- if (!this.isWebContext()) {
143
- return await this.proxyCommand(`/element/${el}/text`, 'GET');
144
- }
145
- let atomsElement = this.getAtomsElement(el);
146
- return await this.executeAtom('get_text', [atomsElement]);
147
- },
148
- /**
149
- * @this {XCUITestDriver}
150
- * @returns {Promise<import('@appium/types').Rect>}
151
- */
152
- async getElementRect(el) {
153
- if (this.isWebContext()) {
154
- // Mobile safari doesn't support rect
155
- const { x, y } = await this.getLocation(el);
156
- const { width, height } = await this.getSize(el);
157
- return { x, y, width, height };
158
- }
159
- el = support_1.util.unwrapElement(el);
160
- return await this.getNativeRect(el);
161
- },
162
- /**
163
- * Get the position of an element on screen
164
- *
165
- * @param {string|Element} elementId - the element ID
166
- * @returns {Promise<Position>} The position of the element
167
- * @deprecated Use {@linkcode XCUITestDriver.getElementRect} instead
168
- * @this {XCUITestDriver}
169
- */
170
- async getLocation(elementId) {
171
- const el = support_1.util.unwrapElement(elementId);
172
- if (this.isWebContext()) {
173
- const atomsElement = this.getAtomsElement(el);
174
- let loc = await this.executeAtom('get_top_left_coordinates', [atomsElement]);
175
- if (this.opts.absoluteWebLocations) {
176
- const script = 'return [' +
177
- 'Math.max(window.pageXOffset,document.documentElement.scrollLeft,document.body.scrollLeft),' +
178
- 'Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop)];';
179
- const [xOffset, yOffset] = /** @type {[number, number]} */ (await this.execute(script));
180
- loc.x += xOffset;
181
- loc.y += yOffset;
182
- }
183
- return loc;
184
- }
185
- const rect = await this.getElementRect(el);
186
- return { x: rect.x, y: rect.y };
187
- },
188
- /**
189
- * Alias for {@linkcode XCUITestDriver.getLocation}
190
- * @param {string|Element} elementId - the element ID
191
- * @returns {Promise<Position>} The position of the element
192
- * @deprecated Use {@linkcode XCUITestDriver.getElementRect} instead
193
- * @this {XCUITestDriver}
194
- */
195
- async getLocationInView(elementId) {
196
- return await this.getLocation(elementId);
197
- },
198
- /**
199
- * Get the size of an element
200
- * @param {string|Element} el - the element ID
201
- * @returns {Promise<Size>} The position of the element
202
- * @this {XCUITestDriver}
203
- */
204
- async getSize(el) {
205
- el = support_1.util.unwrapElement(el);
206
- if (this.isWebContext()) {
207
- return await this.executeAtom('get_size', [this.getAtomsElement(el)]);
208
- }
209
- const rect = await this.getElementRect(el);
210
- return { width: rect.width, height: rect.height };
211
- },
212
- /**
213
- * Alias for {@linkcode setValue}
214
- *
215
- * @param {string} value - the value to set
216
- * @param {string} el - the element to set the value of
217
- * @deprecated
218
- * @this {XCUITestDriver}
219
- */
220
- async setValueImmediate(value, el) {
221
- // WDA does not provide no way to set the value directly
222
- this.log.info('There is currently no way to bypass typing using XCUITest. Setting value through keyboard');
223
- await this.setValue(value, el);
224
- },
225
- /**
226
- * @this {XCUITestDriver}
227
- */
228
- async setValue(value, el) {
229
- el = support_1.util.unwrapElement(el);
230
- if (!this.isWebContext()) {
231
- await this.proxyCommand(`/element/${el}/value`, 'POST', {
232
- value: prepareInputValue(value),
233
- });
234
- return;
235
- }
236
- const atomsElement = this.getAtomsElement(el);
237
- await this.executeAtom('click', [atomsElement]);
238
- if (this.opts.sendKeyStrategy !== 'oneByOne') {
239
- await this.setValueWithWebAtom(atomsElement, value);
240
- return;
241
- }
242
- for (const char of prepareInputValue(value)) {
243
- await this.setValueWithWebAtom(atomsElement, char);
244
- }
245
- },
246
- /**
247
- * Set value with Atom for Web. This method calls `type` atom only.
248
- * Expected to be called as part of {@linkcode setValue}.
249
- * @this {XCUITestDriver}
250
- * @param {import('./types').AtomsElement<string>} atomsElement A target element to type the given value.
251
- * @param {string|string[]} value The actual text to type.
252
- */
253
- async setValueWithWebAtom(atomsElement, value) {
254
- await this.executeAtom('type', [atomsElement, value]);
255
- if (this.opts.skipTriggerInputEventAfterSendkeys) {
256
- return;
257
- }
258
- function triggerInputEvent(/** @type {EventTarget & {_valueTracker?: any}} */ input) {
259
- let lastValue = '';
260
- let event = new Event('input', { bubbles: true });
261
- let tracker = input._valueTracker;
262
- if (tracker) {
263
- tracker.setValue(lastValue);
264
- }
265
- input.dispatchEvent(event);
266
- }
267
- const scriptAsString = `return (${triggerInputEvent}).apply(null, arguments)`;
268
- await this.executeAtom('execute_script', [scriptAsString, [atomsElement]]);
269
- },
270
- /**
271
- * Send keys to the app
272
- * @param {string[]} value - Array of keys to send
273
- * @this {XCUITestDriver}
274
- * @deprecated Use {@linkcode XCUITestDriver.setValue} instead
275
- */
276
- async keys(value) {
277
- await this.proxyCommand('/wda/keys', 'POST', {
278
- value: prepareInputValue(value),
279
- });
280
- },
281
- /**
282
- * @this {XCUITestDriver}
283
- */
284
- async clear(el) {
285
- el = support_1.util.unwrapElement(el);
286
- if (this.isWebContext()) {
287
- const atomsElement = this.getAtomsElement(el);
288
- await this.executeAtom('clear', [atomsElement]);
289
- return;
290
- }
291
- await this.proxyCommand(`/element/${el}/clear`, 'POST');
292
- },
293
- /**
294
- * @this {XCUITestDriver}
295
- */
296
- async getContentSize(el) {
297
- if (this.isWebContext()) {
298
- throw new driver_1.errors.NotYetImplementedError('Support for getContentSize for web context is not yet implemented. Please contact an Appium dev');
299
- }
300
- const type = await this.getAttribute('type', el);
301
- if (type !== 'XCUIElementTypeTable' && type !== 'XCUIElementTypeCollectionView') {
302
- throw new Error(`Can't get content size for type '${type}', only for ` + `tables and collection views`);
303
- }
304
- let locator = '*';
305
- if (type === 'XCUIElementTypeTable') {
306
- // only find table cells, not just any children
307
- locator = 'XCUIElementTypeCell';
308
- }
309
- let contentHeight = 0;
310
- const children = await this.findElOrEls(`class chain`, locator, true, el);
311
- if (children.length === 1) {
312
- // if we know there's only one element, we can optimize to make just one
313
- // call to WDA
314
- const rect = await this.getElementRect(lodash_1.default.head(children));
315
- contentHeight = rect.height;
316
- }
317
- else if (children.length) {
318
- // otherwise if we have multiple elements, logic differs based on element
319
- // type
320
- switch (type) {
321
- case 'XCUIElementTypeTable': {
322
- const firstRect = await this.getElementRect(lodash_1.default.head(children));
323
- const lastRect = await this.getElementRect(lodash_1.default.last(children));
324
- contentHeight = lastRect.y + lastRect.height - firstRect.y;
325
- break;
326
- }
327
- case 'XCUIElementTypeCollectionView': {
328
- let elsInRow = 1; // we know there must be at least one element in the row
329
- let firstRect = await this.getElementRect(lodash_1.default.head(children));
330
- let initialRects = [firstRect];
331
- for (let i = 1; i < children.length; i++) {
332
- const rect = await this.getElementRect(children[i]);
333
- initialRects.push(rect);
334
- if (rect.y !== firstRect.y) {
335
- elsInRow = i;
336
- break;
337
- }
338
- }
339
- const spaceBetweenEls = initialRects[elsInRow].y -
340
- initialRects[elsInRow - 1].y -
341
- initialRects[elsInRow - 1].height;
342
- const numRows = Math.ceil(children.length / elsInRow);
343
- // assume all cells are the same height
344
- contentHeight = numRows * firstRect.height + spaceBetweenEls * (numRows - 1);
345
- break;
346
- }
347
- default:
348
- throw new Error(`Programming error: type '${type}' was not ` +
349
- `valid but should have already been rejected`);
350
- }
351
- }
352
- const size = await this.getSize(el);
353
- const origin = await this.getLocationInView(el);
354
- // attributes have to be strings, so stringify this up
355
- return JSON.stringify({
356
- width: size.width,
357
- height: size.height,
358
- top: origin.y,
359
- left: origin.x,
360
- scrollableOffset: contentHeight,
361
- });
362
- },
363
- };
364
- const extensions = {
365
- /**
366
- * @this {XCUITestDriver}
367
- * @returns {Promise<Rect>}
368
- */
369
- async getNativeRect(el) {
370
- return /** @type {Rect} */ (await this.proxyCommand(`/element/${el}/rect`, 'GET'));
371
- },
372
- };
373
- exports.default = { ...extensions, ...commands };
374
388
  /**
375
389
  * @typedef {import('../driver').XCUITestDriver} XCUITestDriver
376
390
  * @typedef {import('@appium/types').Element} Element