appium-novawindows2-driver 0.1.3 → 0.1.5

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 (103) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +557 -557
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +3 -4
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/app.d.ts.map +1 -1
  7. package/build/lib/commands/app.js +53 -45
  8. package/build/lib/commands/app.js.map +1 -1
  9. package/build/lib/commands/device.d.ts.map +1 -1
  10. package/build/lib/commands/device.js +2 -0
  11. package/build/lib/commands/device.js.map +1 -1
  12. package/build/lib/commands/element.d.ts.map +1 -1
  13. package/build/lib/commands/element.js +42 -12
  14. package/build/lib/commands/element.js.map +1 -1
  15. package/build/lib/commands/extension.d.ts.map +1 -1
  16. package/build/lib/commands/extension.js +29 -17
  17. package/build/lib/commands/extension.js.map +1 -1
  18. package/build/lib/commands/file.d.ts +5 -0
  19. package/build/lib/commands/file.d.ts.map +1 -0
  20. package/build/lib/commands/file.js +49 -0
  21. package/build/lib/commands/file.js.map +1 -0
  22. package/build/lib/commands/functions.d.ts.map +1 -1
  23. package/build/lib/commands/functions.js +189 -187
  24. package/build/lib/commands/functions.js.map +1 -1
  25. package/build/lib/commands/index.d.ts +3 -0
  26. package/build/lib/commands/index.d.ts.map +1 -1
  27. package/build/lib/commands/index.js +2 -0
  28. package/build/lib/commands/index.js.map +1 -1
  29. package/build/lib/commands/powershell.d.ts.map +1 -1
  30. package/build/lib/commands/powershell.js +114 -68
  31. package/build/lib/commands/powershell.js.map +1 -1
  32. package/build/lib/constraints.d.ts +18 -0
  33. package/build/lib/constraints.d.ts.map +1 -1
  34. package/build/lib/constraints.js +18 -0
  35. package/build/lib/constraints.js.map +1 -1
  36. package/build/lib/driver.d.ts.map +1 -1
  37. package/build/lib/driver.js +35 -4
  38. package/build/lib/driver.js.map +1 -1
  39. package/build/lib/powershell/converter.d.ts.map +1 -1
  40. package/build/lib/powershell/converter.js +12 -0
  41. package/build/lib/powershell/converter.js.map +1 -1
  42. package/build/lib/powershell/elements.d.ts.map +1 -1
  43. package/build/lib/powershell/elements.js +270 -265
  44. package/build/lib/powershell/elements.js.map +1 -1
  45. package/build/lib/winapi/user32.js.map +1 -1
  46. package/build/lib/xpath/core.d.ts +2 -2
  47. package/build/lib/xpath/core.d.ts.map +1 -1
  48. package/build/lib/xpath/core.js +32 -26
  49. package/build/lib/xpath/core.js.map +1 -1
  50. package/build/lib/xpath/functions.d.ts +1 -1
  51. package/build/lib/xpath/functions.d.ts.map +1 -1
  52. package/build/lib/xpath/functions.js +2 -2
  53. package/build/lib/xpath/functions.js.map +1 -1
  54. package/build/tsconfig.tsbuildinfo +1 -0
  55. package/package.json +67 -62
  56. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -97
  57. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -33
  58. package/.github/PULL_REQUEST_TEMPLATE.md +0 -28
  59. package/.github/workflows/lint-build.yml +0 -30
  60. package/.github/workflows/release.yml +0 -39
  61. package/.releaserc +0 -41
  62. package/CHANGELOG.md +0 -33
  63. package/eslint.config.mjs +0 -11
  64. package/examples/api_test.js +0 -69
  65. package/examples/concurrency_test.js +0 -82
  66. package/examples/debug_test.js +0 -36
  67. package/examples/stress_test.js +0 -94
  68. package/examples/verify_driver.js +0 -142
  69. package/lib/commands/actions.ts +0 -229
  70. package/lib/commands/app.ts +0 -227
  71. package/lib/commands/device.ts +0 -41
  72. package/lib/commands/element.ts +0 -242
  73. package/lib/commands/extension.ts +0 -640
  74. package/lib/commands/functions.ts +0 -192
  75. package/lib/commands/index.ts +0 -28
  76. package/lib/commands/powershell.ts +0 -256
  77. package/lib/commands/system.ts +0 -7
  78. package/lib/constants.ts +0 -1
  79. package/lib/constraints.ts +0 -43
  80. package/lib/driver.ts +0 -266
  81. package/lib/enums.ts +0 -96
  82. package/lib/powershell/common.ts +0 -137
  83. package/lib/powershell/conditions.ts +0 -169
  84. package/lib/powershell/converter.ts +0 -373
  85. package/lib/powershell/core.ts +0 -29
  86. package/lib/powershell/elements.ts +0 -584
  87. package/lib/powershell/index.ts +0 -7
  88. package/lib/powershell/regex.ts +0 -77
  89. package/lib/powershell/types.ts +0 -208
  90. package/lib/util.ts +0 -52
  91. package/lib/winapi/types/index.ts +0 -7
  92. package/lib/winapi/types/input.ts +0 -12
  93. package/lib/winapi/types/keyeventf.ts +0 -14
  94. package/lib/winapi/types/mouseeventf.ts +0 -37
  95. package/lib/winapi/types/scancode.ts +0 -96
  96. package/lib/winapi/types/systemmetric.ts +0 -215
  97. package/lib/winapi/types/virtualkey.ts +0 -354
  98. package/lib/winapi/types/xmousebutton.ts +0 -8
  99. package/lib/winapi/user32.ts +0 -842
  100. package/lib/xpath/core.ts +0 -699
  101. package/lib/xpath/functions.ts +0 -366
  102. package/lib/xpath/index.ts +0 -2
  103. package/tsconfig.json +0 -13
@@ -1,584 +0,0 @@
1
- import { Enum } from '../enums';
2
- import { pwsh$, PSObject } from './core';
3
- import { PSString } from './common';
4
- import { Condition } from './conditions';
5
-
6
- // TODO: Move the methods to a separate file, some of them are too complicated and are not easy to maintain
7
- const FIND_ALL_ANCESTOR = pwsh$ /* ps1 */ `
8
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
9
- $els = New-Object System.Collections.Generic.List[AutomationElement]
10
-
11
- ${0} | ForEach-Object {
12
- $el = $_
13
- while ($null -ne ($parent = $treeWalker.GetParent($el))) {
14
- $el = $parent
15
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
16
-
17
- if ($null -ne $validEl) {
18
- $els.Add($validEl)
19
- }
20
- }
21
- }
22
-
23
- Write-Output $els
24
- `;
25
-
26
- const FIND_FIRST_ANCESTOR = pwsh$ /* ps1 */ `
27
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
28
-
29
- ${0} | ForEach-Object {
30
- $el = $_
31
- while ($null -ne ($parent = $treeWalker.GetParent($el))) {
32
- $el = $parent
33
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
34
-
35
- if ($null -ne $validEl) {
36
- Write-Output $el
37
- break
38
- }
39
- }
40
- }
41
- `;
42
-
43
- const FIND_ALL_ANCESTOR_OR_SELF = pwsh$ /* ps1 */ `
44
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
45
- $els = New-Object System.Collections.Generic.List[AutomationElement]
46
-
47
- ${0} | ForEach-Object {
48
- $el = $_
49
- while ($null -ne $el) {
50
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
51
-
52
- if ($null -ne $validEl) {
53
- $els.Add($validEl)
54
- }
55
-
56
- $el = $treeWalker.GetParent($el)
57
- }
58
- }
59
-
60
- Write-Output $els
61
- `;
62
-
63
- const FIND_FIRST_ANCESTOR_OR_SELF = pwsh$ /* ps1 */ `
64
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
65
-
66
- ${0} | ForEach-Object {
67
- $el = $_
68
- while ($null -ne $el) {
69
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
70
-
71
- if ($null -ne $validEl) {
72
- Write-Output $el
73
- break
74
- }
75
-
76
- $el = $treeWalker.GetParent($el)
77
- }
78
- }
79
- `;
80
-
81
- const FIND_PARENT = pwsh$ /* ps1 */ `
82
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
83
-
84
- ${0} | ForEach-Object {
85
- $el = $_
86
- $el = $treeWalker.GetParent($el).FindFirst([TreeScope]::Element, ${1})
87
- Write-Output $el
88
- }
89
- `;
90
-
91
- const FIND_FOLLOWING = pwsh$ /* ps1 */ `
92
- $treeWalker = [TreeWalker]::new([AndCondition]::new($cacheRequest.TreeFilter, ${1}))
93
- $els = New-Object System.Collections.Generic.List[AutomationElement]
94
-
95
- ${0} | ForEach-Object {
96
- $el = $_
97
- while ($null -ne $el) {
98
- if ($null -ne ($nextSibling = $treeWalker.GetNextSibling($el))) {
99
- $el = $nextSibling
100
-
101
- Write-Output $el
102
- break
103
- }
104
-
105
- $el = $treeWalker.GetParent($el)
106
- }
107
- }
108
- `;
109
-
110
- const FIND_ALL_FOLLOWING = pwsh$ /* ps1 */ `
111
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
112
- $els = New-Object System.Collections.Generic.List[AutomationElement]
113
-
114
- ${0} | ForEach-Object {
115
- $el = $_
116
- while ($null -ne $el) {
117
- if ($null -ne ($nextSibling = $treeWalker.GetNextSibling($el))) {
118
- $el = $nextSibling
119
- $els.Add($el)
120
- $els.AddRange($el.FindAll([TreeScope]::Children, ${1}))
121
- }
122
-
123
- $el = $treeWalker.GetParent($el)
124
- }
125
- }
126
-
127
- Write-Output $els
128
- `;
129
-
130
- const FIND_FOLLOWING_SIBLING = pwsh$ /* ps1 */ `
131
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
132
-
133
- ${0} | ForEach-Object {
134
- $el = $_
135
- while ($null -ne ($nextSibling = $treeWalker.GetNextSibling($el))) {
136
- $el = $nextSibling
137
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
138
-
139
- if ($null -ne $validEl) {
140
- Write-Output $el
141
- break
142
- }
143
- }
144
- }
145
- `;
146
-
147
- const FIND_ALL_FOLLOWING_SIBLING = pwsh$ /* ps1 */ `
148
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
149
- $els = New-Object System.Collections.Generic.List[AutomationElement]
150
-
151
- ${0} | ForEach-Object {
152
- $el = $_
153
- while ($null -ne ($nextSibling = $treeWalker.GetNextSibling($el))) {
154
- $el = $nextSibling
155
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
156
-
157
- if ($null -ne $validEl) {
158
- $els.Add($validEl)
159
- }
160
- }
161
- }
162
-
163
- Write-Output $els
164
- `;
165
-
166
- const FIND_PRECEDING = pwsh$ /* ps1 */ `
167
- $treeWalker = [TreeWalker]::new([AndCondition]::new($cacheRequest.TreeFilter, ${1}))
168
-
169
- ${0} | ForEach-Object {
170
- $el = $_
171
- while ($null -ne $el) {
172
- if ($null -ne ($previousSibling = $treeWalker.GetPreviousSibling($el))) {
173
- $el = $previousSibling
174
-
175
- Write-Output $el
176
- break
177
- }
178
-
179
- $el = $treeWalker.GetParent($el)
180
- }
181
- }
182
- `;
183
-
184
- const FIND_ALL_PRECEDING = pwsh$ /* ps1 */ `
185
- $treeWalker = [TreeWalker]::new([AndCondition]::new($cacheRequest.TreeFilter, ${1}))
186
- $els = New-Object System.Collections.Generic.List[AutomationElement]
187
-
188
- ${0} | ForEach-Object {
189
- $el = $_
190
- while ($null -ne $el) {
191
- if ($null -ne ($previousSibling = $treeWalker.GetPreviousSibling($el))) {
192
- $el = $previousSibling
193
- $els.Add($el)
194
- $els.AddRange($el.FindAll([TreeScope]::Children, ${1}))
195
- }
196
-
197
- $el = $treeWalker.GetParent($el)
198
- }
199
- }
200
-
201
- Write-Output $els
202
- `;
203
-
204
- const FIND_PRECEDING_SIBLING = pwsh$ /* ps1 */ `
205
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
206
-
207
- ${0} | ForEach-Object {
208
- $el = $_
209
- while ($null -ne ($previousSibling = $treeWalker.GetPreviousSibling($el))) {
210
- $el = $previousSibling
211
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
212
-
213
- if ($null -ne $validEl) {
214
- Write-Output $el
215
- break
216
- }
217
- }
218
- }
219
- `;
220
-
221
- const FIND_ALL_PRECEDING_SIBLING = pwsh$ /* ps1 */ `
222
- $treeWalker = [TreeWalker]::new($cacheRequest.TreeFilter)
223
- $els = New-Object System.Collections.Generic.List[AutomationElement]
224
-
225
- ${0} | ForEach-Object {
226
- $el = $_
227
- while ($null -ne ($previousSibling = $treeWalker.GetPreviousSibling($el))) {
228
- $el = $previousSibling
229
- $validEl = $el.FindFirst([TreeScope]::Element, ${1})
230
-
231
- if ($null -ne $validEl) {
232
- $els.Add($validEl)
233
- }
234
- }
235
- }
236
-
237
- Write-Output $els
238
- `;
239
-
240
- const FIND_CHILDREN_OR_SELF = pwsh$ /* ps1 */ `
241
- $els = New-Object System.Collections.Generic.List[AutomationElement]
242
-
243
- ${0} | ForEach-Object {
244
- $el = $_
245
- $validEl = $el.FindFirst([TreeScope]::Element -bor [TreeScope]::Children, ${1});
246
-
247
- if ($null -ne $validEl) {
248
- $els.Add($validEl)
249
- }
250
- }
251
-
252
- Write-Output $els
253
- `;
254
-
255
- const FIND_ALL_CHILDREN_OR_SELF = pwsh$ /* ps1 */ `
256
- $els = New-Object System.Collections.Generic.List[AutomationElement]
257
-
258
- ${0} | ForEach-Object {
259
- $el = $_
260
- $validEl = $el.FindAll([TreeScope]::Element -bor [TreeScope]::Children, ${1});
261
-
262
- if ($null -ne $validEl) {
263
- $els.Add($validEl)
264
- }
265
- }
266
-
267
- Write-Output $els
268
- `;
269
-
270
- const FIND_DESCENDANTS = pwsh$ /* ps1 */ `Find-ChildrenRecursively -element (${0}) -condition (${1})`;
271
- const FIND_ALL_DESCENDANTS = pwsh$ /* ps1 */ `Find-AllChildrenRecursively -element (${0}) -condition (${1})`;
272
-
273
- const FIND_DESCENDANTS_OR_SELF = pwsh$ /* ps1 */ `Find-ChildrenRecursively -element (${0}) -condition (${1}) -includeSelf $true`;
274
- const FIND_ALL_DESCENDANTS_OR_SELF = pwsh$ /* ps1 */ `Find-AllChildrenRecursively -element (${0}) -condition (${1}) -includeSelf $true`;
275
-
276
- const FIND_FIRST = pwsh$ /* ps1 */ `${0}.FindFirst([TreeScope]::${1}, ${2})`;
277
- const FIND_ALL = pwsh$ /* ps1 */ `${0}.FindAll([TreeScope]::${1}, ${2})`;
278
-
279
- const AUTOMATION_ROOT = /* ps1 */ `$rootElement`;
280
- const FOCUSED_ELEMENT = /* ps1 */ `[AutomationElement]::FocusedElement`;
281
- const ROOT_ELEMENT = /* ps1 */ `[AutomationElement]::RootElement`;
282
-
283
- const SAVE_TO_ELEMENT_TABLE_AND_RETURN_ID = pwsh$ /* ps1 */ `
284
- ${0} | Where-Object { $null -ne $_ } | ForEach-Object {
285
- $runtimeId = $_.GetCurrentPropertyValue([AutomationElement]::RuntimeIdProperty) -join '.';
286
-
287
- if (-not $elementTable.ContainsKey($runtimeId)) {
288
- $elementTable.Add($runtimeId, $_)
289
- };
290
-
291
- $runtimeId
292
- }
293
- `;
294
-
295
- const ELEMENT_TABLE_GET = pwsh$ /* ps1 */ `$elementTable['${0}']`;
296
-
297
- // TODO: maybe encode the result first? Some properties may be on multiple lines, it may cause a problem when returning multiple element results at once
298
- const GET_ELEMENT_PROPERTY = pwsh$ /* ps1 */ `${0}.GetCurrentPropertyValue([AutomationElement]::${1}Property)`;
299
-
300
- const GET_ELEMENT_RUNTIME_ID = pwsh$ /* ps1 */ `
301
- ${0} | ForEach-Object {
302
- $_.GetCurrentPropertyValue([AutomationElement]::RuntimeIdProperty) -join '.'
303
- }
304
- `;
305
-
306
- const GET_ELEMENT_RECT = pwsh$ /* ps1 */ `
307
- ${0}.Current.BoundingRectangle |
308
- Select-Object X, Y, Width, Height |
309
- ForEach-Object { $_ | ConvertTo-Json -Compress } |
310
- ForEach-Object { if ($null -ne $_) { $_.ToLower() } }
311
- `;
312
-
313
- const GET_ELEMENT_TAG_NAME = pwsh$ /* ps1 */ `
314
- ${0}.Current.ControlType.ProgrammaticName |
315
- ForEach-Object { $_.Split('.')[-1] }
316
- `;
317
-
318
- const SET_FOCUS_TO_ELEMENT = pwsh$ /* ps1 */ `${0}.SetFocus()`;
319
-
320
- const GET_ELEMENT_TEXT = pwsh$ /* ps1 */ `
321
- try {
322
- ${0}.GetCurrentPattern([TextPattern]::Pattern).DocumentRange.GetText(-1)
323
- } catch {
324
- try {
325
- ${0}.GetCurrentPattern([SelectionPattern]::Pattern).Current.GetSelection().Current.Name
326
- } catch {
327
- ${0}.Current.Name
328
- }
329
- }
330
- `;
331
-
332
- const INVOKE_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([InvokePattern]::Pattern).Invoke()`;
333
- const EXPAND_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([ExpandCollapsePattern]::Pattern).Expand()`;
334
- const COLLAPSE_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([ExpandCollapsePattern]::Pattern).Collapse()`;
335
- const SCROLL_ELEMENT_INTO_VIEW = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([ScrollItemPattern]::Pattern).ScrollIntoView()`;
336
- const IS_MULTIPLE_SELECT_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([SelectionPattern]::Pattern).Current.CanSelectMultiple`;
337
- const GET_SELECTED_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([SelectionPattern]::Pattern).Current.GetSelection()`;
338
- const IS_ELEMENT_SELECTED = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([SelectionItemPattern]::Pattern).Current.IsSelected`;
339
- const ADD_ELEMENT_TO_SELECTION = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([SelectionItemPattern]::Pattern).AddToSelection()`;
340
- const REMOVE_ELEMENT_FROM_SELECTION = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([SelectionItemPattern]::Pattern).RemoveFromSelection()`;
341
- const SELECT_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([SelectionItemPattern]::Pattern).Select()`;
342
- const TOGGLE_ELEMENT = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([TogglePattern]::Pattern).Toggle()`;
343
- const SET_ELEMENT_VALUE = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([ValuePattern]::Pattern).SetValue(${1})`;
344
- const SET_ELEMENT_RANGE_VALUE = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([RangeValuePattern]::Pattern).SetValue(${1})`;
345
- const GET_ELEMENT_VALUE = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([ValuePattern]::Pattern).Current.Value`;
346
- const GET_ELEMENT_TOGGLE_STATE = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([TogglePattern]::Pattern).Current.ToggleState`;
347
- const MAXIMIZE_WINDOW = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([WindowPattern]::Pattern).SetWindowVisualState([WindowVisualState]::Maximized)`;
348
- const MINIMIZE_WINDOW = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([WindowPattern]::Pattern).SetWindowVisualState([WindowVisualState]::Minimized)`;
349
- const RESTORE_WINDOW = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([WindowPattern]::Pattern).SetWindowVisualState([WindowVisualState]::Normal)`;
350
- const CLOSE_WINDOW = pwsh$ /* ps1 */ `${0}.GetCurrentPattern([WindowPattern]::Pattern).Close()`;
351
-
352
- export const TreeScope = Object.freeze({
353
- ANCESTORS_OR_SELF: 'ancestors-or-self',
354
- FOLLOWING: 'following',
355
- FOLLOWING_SIBLING: 'following-sibling',
356
- PRECEDING: 'preceding',
357
- PRECEDING_SIBLING: 'preceding-sibling',
358
- ANCESTORS: 'ancestors',
359
- CHILDREN_OR_SELF: 'child-or-self',
360
- CHILDREN: 'children',
361
- DESCENDANTS: 'descendants',
362
- ELEMENT: 'element',
363
- SUBTREE: 'subtree',
364
- PARENT: 'parent',
365
- } as const);
366
-
367
- export type TreeScope = Enum<typeof TreeScope>;
368
-
369
- export const AutomationElementMode = Object.freeze({
370
- NONE: 'none',
371
- FULL: 'full',
372
- } as const);
373
-
374
- export type AutomationElementMode = Enum<typeof AutomationElementMode>;
375
-
376
- export class AutomationElement extends PSObject {
377
- constructor(command: string) {
378
- super(command);
379
- }
380
-
381
- static get automationRoot(): AutomationElement {
382
- return new AutomationElement(AUTOMATION_ROOT);
383
- }
384
-
385
- static get rootElement(): AutomationElement {
386
- return new AutomationElement(ROOT_ELEMENT);
387
- }
388
-
389
- static get focusedElement(): AutomationElement {
390
- return new AutomationElement(FOCUSED_ELEMENT);
391
- }
392
-
393
- findFirst(scope: TreeScope, condition: Condition): AutomationElement {
394
- switch (scope) {
395
- case TreeScope.ANCESTORS_OR_SELF:
396
- return new AutomationElement(FIND_FIRST_ANCESTOR_OR_SELF.format(this, condition));
397
- case TreeScope.ANCESTORS:
398
- return new AutomationElement(FIND_FIRST_ANCESTOR.format(this, condition));
399
- case TreeScope.PARENT:
400
- return new AutomationElement(FIND_PARENT.format(this, condition));
401
- case TreeScope.FOLLOWING:
402
- return new AutomationElement(FIND_FOLLOWING.format(this, condition));
403
- case TreeScope.FOLLOWING_SIBLING:
404
- return new AutomationElement(FIND_FOLLOWING_SIBLING.format(this, condition));
405
- case TreeScope.PRECEDING:
406
- return new AutomationElement(FIND_PRECEDING.format(this, condition));
407
- case TreeScope.PRECEDING_SIBLING:
408
- return new AutomationElement(FIND_PRECEDING_SIBLING.format(this, condition));
409
- case TreeScope.CHILDREN_OR_SELF:
410
- return new AutomationElement(FIND_CHILDREN_OR_SELF.format(this, condition));
411
- case TreeScope.DESCENDANTS:
412
- return new AutomationElement(FIND_DESCENDANTS.format(this, condition));
413
- case TreeScope.SUBTREE:
414
- return new AutomationElement(FIND_DESCENDANTS_OR_SELF.format(this, condition));
415
- default:
416
- return new AutomationElement(FIND_FIRST.format(this, scope, condition));
417
- }
418
- }
419
-
420
- findAll(scope: TreeScope, condition: Condition): AutomationElement {
421
- switch (scope) {
422
- case TreeScope.ANCESTORS_OR_SELF:
423
- return new AutomationElement(FIND_ALL_ANCESTOR_OR_SELF.format(this, condition));
424
- case TreeScope.ANCESTORS:
425
- return new AutomationElement(FIND_ALL_ANCESTOR.format(this, condition));
426
- case TreeScope.PARENT:
427
- return new AutomationElement(FIND_PARENT.format(this, condition));
428
- case TreeScope.FOLLOWING:
429
- return new AutomationElement(FIND_ALL_FOLLOWING.format(this, condition));
430
- case TreeScope.FOLLOWING_SIBLING:
431
- return new AutomationElement(FIND_ALL_FOLLOWING_SIBLING.format(this, condition));
432
- case TreeScope.PRECEDING:
433
- return new AutomationElement(FIND_ALL_PRECEDING.format(this, condition));
434
- case TreeScope.PRECEDING_SIBLING:
435
- return new AutomationElement(FIND_ALL_PRECEDING_SIBLING.format(this, condition));
436
- case TreeScope.CHILDREN_OR_SELF:
437
- return new AutomationElement(FIND_ALL_CHILDREN_OR_SELF.format(this, condition));
438
- case TreeScope.DESCENDANTS:
439
- return new AutomationElement(FIND_ALL_DESCENDANTS.format(this, condition));
440
- case TreeScope.SUBTREE:
441
- return new AutomationElement(FIND_ALL_DESCENDANTS_OR_SELF.format(this, condition));
442
- default:
443
- return new AutomationElement(FIND_ALL.format(this, scope, condition));
444
- }
445
- }
446
-
447
- buildGetTagNameCommand(): string {
448
- return GET_ELEMENT_TAG_NAME.format(this);
449
- }
450
-
451
- buildGetPropertyCommand(property: string): string {
452
- if (property.toLowerCase() === 'runtimeid') {
453
- return GET_ELEMENT_RUNTIME_ID.format(this);
454
- }
455
-
456
- if (property.toLowerCase() === 'controltype') {
457
- return GET_ELEMENT_TAG_NAME.format(this);
458
- }
459
-
460
- return GET_ELEMENT_PROPERTY.format(this, property);
461
- }
462
-
463
- buildGetElementRectCommand(): string {
464
- return GET_ELEMENT_RECT.format(this);
465
- }
466
-
467
- buildSetFocusCommand(): string {
468
- return SET_FOCUS_TO_ELEMENT.format(this);
469
- }
470
-
471
- buildCommand(): string {
472
- return SAVE_TO_ELEMENT_TABLE_AND_RETURN_ID.format(this);
473
- }
474
- }
475
-
476
- export class AutomationElementGroup extends AutomationElement {
477
- readonly groups: AutomationElement[];
478
-
479
- constructor(...automationElements: AutomationElement[]) {
480
- super(`@( ${automationElements.map((el) => `(${el.buildCommand()})`).join(', ')} )`);
481
- this.groups = automationElements;
482
- }
483
-
484
- findAllGroups(scope: TreeScope, condition: Condition): AutomationElement[] {
485
- return this.groups.map((el) => el.findAll(scope, condition));
486
- }
487
-
488
- findFirstGroups(scope: TreeScope, condition: Condition): AutomationElement[] {
489
- return this.groups.map((el) => el.findFirst(scope, condition));
490
- }
491
- }
492
-
493
- export class FoundAutomationElement extends AutomationElement {
494
- readonly runtimeId: string;
495
-
496
- constructor(runtimeId: string) {
497
- super(ELEMENT_TABLE_GET.format(runtimeId));
498
- this.runtimeId = runtimeId;
499
- }
500
-
501
- buildGetTextCommand(): string {
502
- return GET_ELEMENT_TEXT.format(this);
503
- }
504
-
505
- buildInvokeCommand(): string {
506
- return INVOKE_ELEMENT.format(this);
507
- }
508
-
509
- buildExpandCommand(): string {
510
- return EXPAND_ELEMENT.format(this);
511
- }
512
-
513
- buildCollapseCommand(): string {
514
- return COLLAPSE_ELEMENT.format(this);
515
- }
516
-
517
- buildScrollIntoViewCommand(): string {
518
- return SCROLL_ELEMENT_INTO_VIEW.format(this);
519
- }
520
-
521
- buildIsMultipleSelectCommand(): string {
522
- return IS_MULTIPLE_SELECT_ELEMENT.format(this);
523
- }
524
-
525
- buildGetSelectionCommand(): string {
526
- return SAVE_TO_ELEMENT_TABLE_AND_RETURN_ID.format(GET_SELECTED_ELEMENT.format(this));
527
- }
528
-
529
- buildIsSelectedCommand(): string {
530
- return IS_ELEMENT_SELECTED.format(this);
531
- }
532
-
533
- buildAddToSelectionCommand(): string {
534
- return ADD_ELEMENT_TO_SELECTION.format(this);
535
- }
536
-
537
- buildRemoveFromSelectionCommand(): string {
538
- return REMOVE_ELEMENT_FROM_SELECTION.format(this);
539
- }
540
-
541
- buildSelectCommand(): string {
542
- return SELECT_ELEMENT.format(this);
543
- }
544
-
545
- buildToggleCommand(): string {
546
- return TOGGLE_ELEMENT.format(this);
547
- }
548
-
549
- buildSetValueCommand(value: string): string {
550
- return SET_ELEMENT_VALUE.format(this, new PSString(value).toString());
551
- }
552
-
553
- buildSetRangeValueCommand(value: string): string {
554
- return SET_ELEMENT_RANGE_VALUE.format(this, Number(value).toString());
555
- }
556
-
557
- buildGetValueCommand(): string {
558
- return GET_ELEMENT_VALUE.format(this);
559
- }
560
-
561
- buildGetToggleStateCommand(): string {
562
- return GET_ELEMENT_TOGGLE_STATE.format(this);
563
- }
564
-
565
- buildMaximizeCommand(): string {
566
- return MAXIMIZE_WINDOW.format(this);
567
- }
568
-
569
- buildMinimizeCommand(): string {
570
- return MINIMIZE_WINDOW.format(this);
571
- }
572
-
573
- buildRestoreCommand(): string {
574
- return RESTORE_WINDOW.format(this);
575
- }
576
-
577
- buildCloseCommand(): string {
578
- return CLOSE_WINDOW.format(this);
579
- }
580
-
581
- override buildCommand(): string {
582
- return this.toString();
583
- }
584
- }
@@ -1,7 +0,0 @@
1
- export * from './core';
2
- export * from './common';
3
- export * from './conditions';
4
- export * from './elements';
5
- export * from './converter';
6
- export * from './regex';
7
- export * from './types';
@@ -1,77 +0,0 @@
1
- import { errors } from '@appium/base-driver';
2
-
3
- const MAGIC_UNICODE_REPLACEMENT_CHAR = '\uF000';
4
- const BEGIN_OF_STATEMENT_REGEX = '(?<![.:-])';
5
-
6
- export class RegexItem {
7
- private value: string;
8
-
9
- constructor(value: string) {
10
- this.value = value;
11
- }
12
-
13
- build(): string {
14
- if (this.value.includes(MAGIC_UNICODE_REPLACEMENT_CHAR)) {
15
- throw new Error(`There are missing parameters in the regex.`);
16
- }
17
-
18
- return this.value;
19
- }
20
-
21
- toRegex(flags?: string): RegExp {
22
- return RegExp(this.build(), flags);
23
- }
24
- }
25
-
26
- export class VarArgsRegexMatcher extends RegexItem {
27
- constructor(value: RegexItem) {
28
- super(`((?:${value.build()})(?:\\s*,\\s*${value.build()})*)`);
29
- }
30
- }
31
-
32
- export class ConstructorRegexMatcher extends RegexItem {
33
- constructor(fullyQualifiedName: string, ...params: RegexItem[]) {
34
- assertCorrectNamespace(fullyQualifiedName);
35
-
36
- const sections = fullyQualifiedName.toLowerCase().split('.');
37
- const mainClass = sections.pop() ?? '';
38
- const parentClass = sections.pop() ?? '';
39
- sections.reverse(); // mutates the actual array
40
-
41
- let regexString = BEGIN_OF_STATEMENT_REGEX +
42
- `(?:(?:(?:(?:\\bnew\\s*)?)(?:(?:\\b${MAGIC_UNICODE_REPLACEMENT_CHAR}${parentClass}\\.)?(?:${mainClass})))` +
43
- `|(?:(?:(?:\\bnew-object\\s*)?)(?:\\[(?:${MAGIC_UNICODE_REPLACEMENT_CHAR}${parentClass}\\]::)?(?:${mainClass})))` +
44
- `|(?:(?:(?:\\[(?:(?:${MAGIC_UNICODE_REPLACEMENT_CHAR}${parentClass}\\.)?${mainClass}\\]::new)))))`;
45
-
46
- sections.forEach((section) => regexString = regexString.replaceAll(MAGIC_UNICODE_REPLACEMENT_CHAR, `(?:${MAGIC_UNICODE_REPLACEMENT_CHAR}${section}\\.)?`));
47
-
48
- super(`${regexString.replaceAll(MAGIC_UNICODE_REPLACEMENT_CHAR, '')}\\(\\s*${params.map((param) => param.build()).join('\\s*,\\s*')}\\s*\\)`);
49
- }
50
- }
51
-
52
- export class PropertyRegexMatcher extends RegexItem {
53
- constructor(namespace: string, ...properties: string[]) {
54
- assertCorrectNamespace(namespace);
55
-
56
- const sections = namespace.toLowerCase().split('.');
57
- const mainClass = sections.pop() ?? '';
58
- sections.reverse(); // mutates the actual array
59
-
60
- let regexString = `${BEGIN_OF_STATEMENT_REGEX}(?:\\b(?:(?:(?:${MAGIC_UNICODE_REPLACEMENT_CHAR}${mainClass}\\.)))|(?:(?:\\[${MAGIC_UNICODE_REPLACEMENT_CHAR}${mainClass}\\]::)))?`;
61
- sections.forEach((section) => regexString = regexString.replaceAll(MAGIC_UNICODE_REPLACEMENT_CHAR, `(?:${MAGIC_UNICODE_REPLACEMENT_CHAR}${section}\\.)?`));
62
-
63
- super(`${regexString.replaceAll(MAGIC_UNICODE_REPLACEMENT_CHAR, '')}(${properties.length > 0 ? `(?<![a-z-.])(?:(?:${properties.join(')|(?:')}))(?![a-z-.])` : '(?:\\b[a-z]+)'}(?![.-]))`.toLowerCase());
64
- }
65
- }
66
-
67
- export class StringRegexMatcher extends RegexItem {
68
- constructor() {
69
- super(`('(?:[^']*(?:''[^']*)?)*')`);
70
- }
71
- }
72
-
73
- function assertCorrectNamespace(namespace: string): void {
74
- if (!/[a-z.()?:]*/i.test(namespace)) {
75
- throw new errors.InvalidArgumentError('namespace parameter should consist of only alphabetical latin letters and dots.');
76
- }
77
- }