appium-novawindows2-driver 0.1.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 (192) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +97 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +33 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +28 -0
  4. package/.github/workflows/lint-build.yml +30 -0
  5. package/.github/workflows/release.yml +39 -0
  6. package/.releaserc +41 -0
  7. package/CHANGELOG.md +33 -0
  8. package/LICENSE +202 -0
  9. package/README.md +557 -0
  10. package/build/eslint.config.d.mts +3 -0
  11. package/build/eslint.config.d.mts.map +1 -0
  12. package/build/eslint.config.mjs +6 -0
  13. package/build/eslint.config.mjs.map +1 -0
  14. package/build/lib/commands/actions.d.ts +11 -0
  15. package/build/lib/commands/actions.d.ts.map +1 -0
  16. package/build/lib/commands/actions.js +212 -0
  17. package/build/lib/commands/actions.js.map +1 -0
  18. package/build/lib/commands/app.d.ts +12 -0
  19. package/build/lib/commands/app.d.ts.map +1 -0
  20. package/build/lib/commands/app.js +195 -0
  21. package/build/lib/commands/app.js.map +1 -0
  22. package/build/lib/commands/device.d.ts +3 -0
  23. package/build/lib/commands/device.d.ts.map +1 -0
  24. package/build/lib/commands/device.js +31 -0
  25. package/build/lib/commands/device.js.map +1 -0
  26. package/build/lib/commands/element.d.ts +15 -0
  27. package/build/lib/commands/element.d.ts.map +1 -0
  28. package/build/lib/commands/element.js +213 -0
  29. package/build/lib/commands/element.js.map +1 -0
  30. package/build/lib/commands/extension.d.ts +87 -0
  31. package/build/lib/commands/extension.d.ts.map +1 -0
  32. package/build/lib/commands/extension.js +511 -0
  33. package/build/lib/commands/extension.js.map +1 -0
  34. package/build/lib/commands/functions.d.ts +3 -0
  35. package/build/lib/commands/functions.d.ts.map +1 -0
  36. package/build/lib/commands/functions.js +194 -0
  37. package/build/lib/commands/functions.js.map +1 -0
  38. package/build/lib/commands/index.d.ts +126 -0
  39. package/build/lib/commands/index.d.ts.map +1 -0
  40. package/build/lib/commands/index.js +54 -0
  41. package/build/lib/commands/index.js.map +1 -0
  42. package/build/lib/commands/powershell.d.ts +6 -0
  43. package/build/lib/commands/powershell.d.ts.map +1 -0
  44. package/build/lib/commands/powershell.js +204 -0
  45. package/build/lib/commands/powershell.js.map +1 -0
  46. package/build/lib/commands/system.d.ts +4 -0
  47. package/build/lib/commands/system.d.ts.map +1 -0
  48. package/build/lib/commands/system.js +8 -0
  49. package/build/lib/commands/system.js.map +1 -0
  50. package/build/lib/constants.d.ts +2 -0
  51. package/build/lib/constants.d.ts.map +1 -0
  52. package/build/lib/constants.js +5 -0
  53. package/build/lib/constants.js.map +1 -0
  54. package/build/lib/constraints.d.ts +40 -0
  55. package/build/lib/constraints.d.ts.map +1 -0
  56. package/build/lib/constraints.js +42 -0
  57. package/build/lib/constraints.js.map +1 -0
  58. package/build/lib/driver.d.ts +33 -0
  59. package/build/lib/driver.d.ts.map +1 -0
  60. package/build/lib/driver.js +181 -0
  61. package/build/lib/driver.js.map +1 -0
  62. package/build/lib/enums.d.ts +89 -0
  63. package/build/lib/enums.d.ts.map +1 -0
  64. package/build/lib/enums.js +83 -0
  65. package/build/lib/enums.js.map +1 -0
  66. package/build/lib/powershell/common.d.ts +39 -0
  67. package/build/lib/powershell/common.d.ts.map +1 -0
  68. package/build/lib/powershell/common.js +121 -0
  69. package/build/lib/powershell/common.js.map +1 -0
  70. package/build/lib/powershell/conditions.d.ts +24 -0
  71. package/build/lib/powershell/conditions.d.ts.map +1 -0
  72. package/build/lib/powershell/conditions.js +131 -0
  73. package/build/lib/powershell/conditions.js.map +1 -0
  74. package/build/lib/powershell/converter.d.ts +3 -0
  75. package/build/lib/powershell/converter.d.ts.map +1 -0
  76. package/build/lib/powershell/converter.js +273 -0
  77. package/build/lib/powershell/converter.js.map +1 -0
  78. package/build/lib/powershell/core.d.ts +8 -0
  79. package/build/lib/powershell/core.d.ts.map +1 -0
  80. package/build/lib/powershell/core.js +30 -0
  81. package/build/lib/powershell/core.js.map +1 -0
  82. package/build/lib/powershell/elements.d.ts +68 -0
  83. package/build/lib/powershell/elements.d.ts.map +1 -0
  84. package/build/lib/powershell/elements.js +515 -0
  85. package/build/lib/powershell/elements.js.map +1 -0
  86. package/build/lib/powershell/index.d.ts +8 -0
  87. package/build/lib/powershell/index.d.ts.map +1 -0
  88. package/build/lib/powershell/index.js +24 -0
  89. package/build/lib/powershell/index.js.map +1 -0
  90. package/build/lib/powershell/regex.d.ts +19 -0
  91. package/build/lib/powershell/regex.d.ts.map +1 -0
  92. package/build/lib/powershell/regex.js +68 -0
  93. package/build/lib/powershell/regex.js.map +1 -0
  94. package/build/lib/powershell/types.d.ts +155 -0
  95. package/build/lib/powershell/types.d.ts.map +1 -0
  96. package/build/lib/powershell/types.js +141 -0
  97. package/build/lib/powershell/types.js.map +1 -0
  98. package/build/lib/util.d.ts +10 -0
  99. package/build/lib/util.d.ts.map +1 -0
  100. package/build/lib/util.js +51 -0
  101. package/build/lib/util.js.map +1 -0
  102. package/build/lib/winapi/types/index.d.ts +8 -0
  103. package/build/lib/winapi/types/index.d.ts.map +1 -0
  104. package/build/lib/winapi/types/index.js +24 -0
  105. package/build/lib/winapi/types/index.js.map +1 -0
  106. package/build/lib/winapi/types/input.d.ts +11 -0
  107. package/build/lib/winapi/types/input.d.ts.map +1 -0
  108. package/build/lib/winapi/types/input.js +12 -0
  109. package/build/lib/winapi/types/input.js.map +1 -0
  110. package/build/lib/winapi/types/keyeventf.d.ts +13 -0
  111. package/build/lib/winapi/types/keyeventf.d.ts.map +1 -0
  112. package/build/lib/winapi/types/keyeventf.js +14 -0
  113. package/build/lib/winapi/types/keyeventf.js.map +1 -0
  114. package/build/lib/winapi/types/mouseeventf.d.ts +34 -0
  115. package/build/lib/winapi/types/mouseeventf.d.ts.map +1 -0
  116. package/build/lib/winapi/types/mouseeventf.js +37 -0
  117. package/build/lib/winapi/types/mouseeventf.js.map +1 -0
  118. package/build/lib/winapi/types/scancode.d.ts +95 -0
  119. package/build/lib/winapi/types/scancode.d.ts.map +1 -0
  120. package/build/lib/winapi/types/scancode.js +96 -0
  121. package/build/lib/winapi/types/scancode.js.map +1 -0
  122. package/build/lib/winapi/types/systemmetric.d.ts +214 -0
  123. package/build/lib/winapi/types/systemmetric.d.ts.map +1 -0
  124. package/build/lib/winapi/types/systemmetric.js +215 -0
  125. package/build/lib/winapi/types/systemmetric.js.map +1 -0
  126. package/build/lib/winapi/types/virtualkey.d.ts +353 -0
  127. package/build/lib/winapi/types/virtualkey.d.ts.map +1 -0
  128. package/build/lib/winapi/types/virtualkey.js +354 -0
  129. package/build/lib/winapi/types/virtualkey.js.map +1 -0
  130. package/build/lib/winapi/types/xmousebutton.d.ts +7 -0
  131. package/build/lib/winapi/types/xmousebutton.d.ts.map +1 -0
  132. package/build/lib/winapi/types/xmousebutton.js +8 -0
  133. package/build/lib/winapi/types/xmousebutton.js.map +1 -0
  134. package/build/lib/winapi/user32.d.ts +56 -0
  135. package/build/lib/winapi/user32.d.ts.map +1 -0
  136. package/build/lib/winapi/user32.js +591 -0
  137. package/build/lib/winapi/user32.js.map +1 -0
  138. package/build/lib/xpath/core.d.ts +8 -0
  139. package/build/lib/xpath/core.d.ts.map +1 -0
  140. package/build/lib/xpath/core.js +593 -0
  141. package/build/lib/xpath/core.js.map +1 -0
  142. package/build/lib/xpath/functions.d.ts +4 -0
  143. package/build/lib/xpath/functions.d.ts.map +1 -0
  144. package/build/lib/xpath/functions.js +271 -0
  145. package/build/lib/xpath/functions.js.map +1 -0
  146. package/build/lib/xpath/index.d.ts +3 -0
  147. package/build/lib/xpath/index.d.ts.map +1 -0
  148. package/build/lib/xpath/index.js +19 -0
  149. package/build/lib/xpath/index.js.map +1 -0
  150. package/eslint.config.mjs +11 -0
  151. package/examples/C#/CalculatorTest/CalculatorTest/CalculatorSession.cs +44 -0
  152. package/examples/C#/CalculatorTest/CalculatorTest/CalculatorTest.csproj +24 -0
  153. package/examples/C#/CalculatorTest/CalculatorTest/ScenarioStandard.cs +121 -0
  154. package/examples/C#/CalculatorTest/CalculatorTest/ScenarioStandardInvoke.cs +121 -0
  155. package/examples/C#/CalculatorTest/CalculatorTest.sln +16 -0
  156. package/lib/commands/actions.ts +229 -0
  157. package/lib/commands/app.ts +227 -0
  158. package/lib/commands/device.ts +41 -0
  159. package/lib/commands/element.ts +242 -0
  160. package/lib/commands/extension.ts +636 -0
  161. package/lib/commands/functions.ts +192 -0
  162. package/lib/commands/index.ts +28 -0
  163. package/lib/commands/powershell.ts +243 -0
  164. package/lib/commands/system.ts +7 -0
  165. package/lib/constants.ts +1 -0
  166. package/lib/constraints.ts +43 -0
  167. package/lib/driver.ts +247 -0
  168. package/lib/enums.ts +96 -0
  169. package/lib/powershell/common.ts +137 -0
  170. package/lib/powershell/conditions.ts +169 -0
  171. package/lib/powershell/converter.ts +373 -0
  172. package/lib/powershell/core.ts +29 -0
  173. package/lib/powershell/elements.ts +584 -0
  174. package/lib/powershell/index.ts +7 -0
  175. package/lib/powershell/regex.ts +77 -0
  176. package/lib/powershell/types.ts +208 -0
  177. package/lib/util.ts +52 -0
  178. package/lib/winapi/types/index.ts +7 -0
  179. package/lib/winapi/types/input.ts +12 -0
  180. package/lib/winapi/types/keyeventf.ts +14 -0
  181. package/lib/winapi/types/mouseeventf.ts +37 -0
  182. package/lib/winapi/types/scancode.ts +96 -0
  183. package/lib/winapi/types/systemmetric.ts +215 -0
  184. package/lib/winapi/types/virtualkey.ts +354 -0
  185. package/lib/winapi/types/xmousebutton.ts +8 -0
  186. package/lib/winapi/user32.ts +842 -0
  187. package/lib/xpath/core.ts +699 -0
  188. package/lib/xpath/functions.ts +366 -0
  189. package/lib/xpath/index.ts +2 -0
  190. package/package.json +61 -0
  191. package/tsconfig.json +13 -0
  192. package/verify_driver.js +96 -0
@@ -0,0 +1,242 @@
1
+ import { Element, Rect } from '@appium/types';
2
+ import { NovaWindowsDriver } from '../driver';
3
+ import {
4
+ AndCondition,
5
+ AutomationElement,
6
+ ControlType,
7
+ FoundAutomationElement,
8
+ OrCondition,
9
+ Property,
10
+ PropertyCondition,
11
+ PSBoolean,
12
+ PSControlType,
13
+ PSString,
14
+ TreeScope,
15
+ } from '../powershell';
16
+ import { W3C_ELEMENT_KEY } from '@appium/base-driver';
17
+ import { mouseDown, mouseMoveAbsolute, mouseUp } from '../winapi/user32';
18
+ import { Key } from '../enums';
19
+ import { sleep } from '../util';
20
+
21
+ export async function getProperty(this: NovaWindowsDriver, propertyName: string, elementId: string): Promise<string> {
22
+ return await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetPropertyCommand(propertyName));
23
+ }
24
+
25
+ export async function getAttribute(this: NovaWindowsDriver, propertyName: string, elementId: string) {
26
+ this.log.warn('Warning: Use getProperty instead of getAttribute for retrieving element properties.');
27
+ return await this.getProperty(propertyName, elementId);
28
+ }
29
+
30
+ export async function active(this: NovaWindowsDriver): Promise<Element> {
31
+ return { [W3C_ELEMENT_KEY]: await this.sendPowerShellCommand(AutomationElement.focusedElement.buildCommand()) };
32
+ }
33
+
34
+ export async function getName(this: NovaWindowsDriver, elementId: string): Promise<string> {
35
+ return await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetTagNameCommand());
36
+ }
37
+
38
+ export async function getText(this: NovaWindowsDriver, elementId: string): Promise<string> {
39
+ return await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetTextCommand());
40
+ }
41
+
42
+ export async function clear(this: NovaWindowsDriver, elementId: string): Promise<void> {
43
+ await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildSetValueCommand(''));
44
+ }
45
+
46
+ export async function setValue(this: NovaWindowsDriver, value: string | string[], elementId: string): Promise<void> {
47
+ await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildSetFocusCommand());
48
+ const metaKeyStates = {
49
+ shift: false,
50
+ ctrl: false,
51
+ meta: false,
52
+ alt: false,
53
+ };
54
+
55
+ if (!Array.isArray(value)) {
56
+ value = value.split('');
57
+ }
58
+
59
+ let keysToSend: string[] = [];
60
+
61
+ const sendKeysAndResetArray = async () => {
62
+ await this.sendPowerShellCommand(/* ps1 */ `[Windows.Forms.SendKeys]::SendWait(${new PSString(keysToSend.join(''))})`);
63
+ keysToSend = [];
64
+ };
65
+
66
+ for (const char of value) {
67
+ switch (char) {
68
+ case Key.SHIFT:
69
+ case Key.R_SHIFT:
70
+ await sendKeysAndResetArray();
71
+ if (metaKeyStates.shift) {
72
+ metaKeyStates.shift = false;
73
+ await this.handleKeyActionSequence({
74
+ type: 'key',
75
+ id: 'default keyboard',
76
+ actions: [{ type: 'keyUp', value: char }]
77
+ });
78
+ break;
79
+ }
80
+
81
+ metaKeyStates.shift = true;
82
+ await this.handleKeyActionSequence({
83
+ type: 'key',
84
+ id: 'default keyboard',
85
+ actions: [{ type: 'keyDown', value: char }]
86
+ });
87
+ break;
88
+ case Key.CONTROL:
89
+ case Key.R_CONTROL:
90
+ await sendKeysAndResetArray();
91
+ if (metaKeyStates.ctrl) {
92
+ metaKeyStates.ctrl = false;
93
+ await this.handleKeyActionSequence({
94
+ type: 'key',
95
+ id: 'default keyboard',
96
+ actions: [{ type: 'keyUp', value: char }]
97
+ });
98
+ break;
99
+ }
100
+
101
+ metaKeyStates.ctrl = true;
102
+ await this.handleKeyActionSequence({
103
+ type: 'key',
104
+ id: 'default keyboard',
105
+ actions: [{ type: 'keyDown', value: char }]
106
+ });
107
+ break;
108
+ case Key.META:
109
+ case Key.R_META:
110
+ await sendKeysAndResetArray();
111
+ if (metaKeyStates.meta) {
112
+ metaKeyStates.meta = false;
113
+ await this.handleKeyActionSequence({
114
+ type: 'key',
115
+ id: 'default keyboard',
116
+ actions: [{ type: 'keyUp', value: char }]
117
+ });
118
+ break;
119
+ }
120
+
121
+ metaKeyStates.meta = true;
122
+ await this.handleKeyActionSequence({
123
+ type: 'key',
124
+ id: 'default keyboard',
125
+ actions: [{ type: 'keyDown', value: char }]
126
+ });
127
+ break;
128
+ case Key.ALT:
129
+ case Key.R_ALT:
130
+ await sendKeysAndResetArray();
131
+ if (metaKeyStates.alt) {
132
+ metaKeyStates.alt = false;
133
+ await this.handleKeyActionSequence({
134
+ type: 'key',
135
+ id: 'default keyboard',
136
+ actions: [{ type: 'keyUp', value: char }]
137
+ });
138
+ break;
139
+ }
140
+
141
+ metaKeyStates.alt = true;
142
+ await this.handleKeyActionSequence({
143
+ type: 'key',
144
+ id: 'default keyboard',
145
+ actions: [{ type: 'keyDown', value: char }]
146
+ });
147
+ break;
148
+ default:
149
+ if (char.charCodeAt(0) >= 0xE000) {
150
+ await sendKeysAndResetArray();
151
+ await this.handleKeyActionSequence({
152
+ type: 'key',
153
+ id: 'default keyboard',
154
+ actions: [{ type: 'keyDown', value: char }, { type: 'keyUp', value: char }]
155
+ });
156
+ } else {
157
+ keysToSend.push(char.replace(/[+^%~()]/, '{$&}'));
158
+ }
159
+ }
160
+ }
161
+
162
+ await sendKeysAndResetArray();
163
+ }
164
+
165
+ export async function getElementRect(this: NovaWindowsDriver, elementId: string): Promise<Rect> {
166
+ const result = await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetElementRectCommand());
167
+ const rootRectJson = await this.sendPowerShellCommand(AutomationElement.automationRoot.buildGetElementRectCommand());
168
+ const rootRect = JSON.parse(rootRectJson.replaceAll(/(?:infinity)/gi, 0x7FFFFFFF.toString())) as Rect;
169
+ const rect = JSON.parse(result.replaceAll(/(?:infinity)/gi, 0x7FFFFFFF.toString())) as Rect;
170
+ rect.x -= rootRect.x;
171
+ rect.y -= rootRect.y;
172
+ rect.x = Math.min(0x7FFFFFFF, rect.x);
173
+ rect.y = Math.min(0x7FFFFFFF, rect.y);
174
+ return rect;
175
+ }
176
+
177
+ export async function elementDisplayed(this: NovaWindowsDriver, elementId: string): Promise<boolean> {
178
+ const result = await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetPropertyCommand(Property.IS_OFFSCREEN));
179
+ return result.toLowerCase() === 'true' ? false : true;
180
+ }
181
+
182
+ // TODO: find better way to handle whether to use select or toggle
183
+ export async function elementSelected(this: NovaWindowsDriver, elementId: string): Promise<boolean> {
184
+ try {
185
+ const result = await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildIsSelectedCommand());
186
+ return result === 'True';
187
+ } catch {
188
+ const result = await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetToggleStateCommand());
189
+ return result === 'On';
190
+ }
191
+ }
192
+
193
+ export async function elementEnabled(this: NovaWindowsDriver, elementId: string): Promise<boolean> {
194
+ const result = await this.sendPowerShellCommand(new FoundAutomationElement(elementId).buildGetPropertyCommand(Property.IS_ENABLED));
195
+ return result.toLowerCase() === 'true' ? true : false;
196
+ }
197
+
198
+ export async function click(this: NovaWindowsDriver, elementId: string): Promise<void> {
199
+ const easingFunction = this.caps.smoothPointerMove;
200
+ const element = new FoundAutomationElement(elementId);
201
+
202
+ const focusCondition = new AndCondition(
203
+ new PropertyCondition(Property.IS_KEYBOARD_FOCUSABLE, new PSBoolean(true)),
204
+ new OrCondition(
205
+ new PropertyCondition(Property.CONTROL_TYPE, new PSControlType(ControlType.PANE)),
206
+ new PropertyCondition(Property.CONTROL_TYPE, new PSControlType(ControlType.WINDOW)),
207
+ ),
208
+ );
209
+
210
+ try {
211
+ const focusableElementId = await this.sendPowerShellCommand(element.findFirst(TreeScope.ANCESTORS_OR_SELF, focusCondition).buildCommand());
212
+ await this.sendPowerShellCommand(new FoundAutomationElement(focusableElementId.trim()).buildSetFocusCommand());
213
+ } catch {
214
+ // ignore if it fails, focus may fail if there is a forced popup window
215
+ }
216
+
217
+ const coordinates = {
218
+ x: undefined,
219
+ y: undefined,
220
+ } as Partial<Rect>;
221
+
222
+ try {
223
+ const clickablePointJson = await this.sendPowerShellCommand(element.buildGetPropertyCommand(Property.CLICKABLE_POINT));
224
+ const clickablePoint = JSON.parse(clickablePointJson.replaceAll(/(?:infinity)/gi, 0x7FFFFFFF.toString())) as Rect;
225
+ coordinates.x = clickablePoint.x;
226
+ coordinates.y = clickablePoint.y;
227
+ } catch {
228
+ const rectJson = await this.sendPowerShellCommand(element.buildGetElementRectCommand());
229
+ const rect = JSON.parse(rectJson.replaceAll(/(?:infinity)/gi, 0x7FFFFFFF.toString())) as Rect;
230
+ coordinates.x = rect.x + rect.width / 2;
231
+ coordinates.y = rect.y + rect.height / 2;
232
+ }
233
+
234
+ await mouseMoveAbsolute(coordinates.x, coordinates.y, this.caps.delayBeforeClick ?? 0, easingFunction);
235
+
236
+ mouseDown();
237
+ mouseUp();
238
+
239
+ if (this.caps.delayAfterClick) {
240
+ await sleep(this.caps.delayAfterClick ?? 0);
241
+ }
242
+ }