|
1 | 1 | import { W3C_ELEMENT_KEY, errors } from '@appium/base-driver'; |
2 | 2 | import { Element, Rect } from '@appium/types'; |
3 | 3 | import { tmpdir } from 'node:os'; |
4 | | -import { join, normalize } from 'node:path'; |
| 4 | +import { join } from 'node:path'; |
5 | 5 | import { POWER_SHELL_FEATURE } from '../constants'; |
6 | 6 | import { NovaWindowsDriver } from '../driver'; |
7 | 7 | import { ClickType, Enum, Key } from '../enums'; |
8 | 8 | import { |
9 | 9 | AutomationElement, |
10 | 10 | AutomationElementMode, |
11 | 11 | FoundAutomationElement, |
12 | | - PSInt32, |
13 | 12 | PSInt32Array, |
14 | 13 | Property, |
15 | 14 | PropertyCondition, |
@@ -52,8 +51,8 @@ const EXTENSION_COMMANDS = Object.freeze({ |
52 | 51 | minimize: 'patternMinimize', |
53 | 52 | restore: 'patternRestore', |
54 | 53 | close: 'patternClose', |
55 | | - closeApp: 'closeApp', |
56 | | - launchApp: 'launchApp', |
| 54 | + closeApp: 'windowsCloseApp', |
| 55 | + launchApp: 'windowsLaunchApp', |
57 | 56 | keys: 'executeKeys', |
58 | 57 | click: 'executeClick', |
59 | 58 | hover: 'executeHover', |
@@ -256,69 +255,12 @@ export async function patternClose(this: NovaWindowsDriver, element: Element): P |
256 | 255 | await this.sendPowerShellCommand(new FoundAutomationElement(element[W3C_ELEMENT_KEY]).buildCloseCommand()); |
257 | 256 | } |
258 | 257 |
|
259 | | -export async function closeApp(this: NovaWindowsDriver, args: { |
260 | | - processId?: number, |
261 | | - processName?: string, |
262 | | - windowHandle?: string | number, |
263 | | -}): Promise<void> { |
264 | | - const { processId, processName, windowHandle } = args ?? {}; |
265 | | - const provided = [processId, processName, windowHandle].filter((v) => v != null).length; |
266 | | - |
267 | | - if (provided !== 1) { |
268 | | - throw new errors.InvalidArgumentError( |
269 | | - 'Exactly one of processId, processName, or windowHandle must be provided.' |
270 | | - ); |
271 | | - } |
272 | | - |
273 | | - if (processId != null) { |
274 | | - await this.sendPowerShellCommand(`Stop-Process -Id ${processId}`); |
275 | | - return; |
276 | | - } |
277 | | - |
278 | | - if (processName != null) { |
279 | | - await this.sendPowerShellCommand(`Stop-Process -Name '${processName}'`); |
280 | | - return; |
281 | | - } |
282 | | - |
283 | | - if (windowHandle != null) { |
284 | | - const handle = typeof windowHandle === 'string' ? parseInt(windowHandle, 16) : windowHandle; |
285 | | - const condition = new PropertyCondition(Property.NATIVE_WINDOW_HANDLE, new PSInt32(handle)); |
286 | | - const elementId = await this.sendPowerShellCommand( |
287 | | - AutomationElement.rootElement |
288 | | - .findFirst(TreeScope.CHILDREN_OR_SELF, condition) |
289 | | - .buildCommand() |
290 | | - ); |
291 | | - if (!elementId?.trim()) { |
292 | | - throw new errors.NoSuchWindowError(`No window found with handle ${windowHandle}`); |
293 | | - } |
294 | | - const processId = await this.sendPowerShellCommand( |
295 | | - new FoundAutomationElement(elementId.trim()).buildGetPropertyCommand(Property.PROCESS_ID) |
296 | | - ); |
297 | | - if (!processId?.trim()) { |
298 | | - throw new errors.UnknownError(`Could not get process ID for window handle ${windowHandle}`); |
299 | | - } |
300 | | - await this.sendPowerShellCommand(`Stop-Process -Id ${processId.trim()}`); |
301 | | - } |
| 258 | +export async function windowsCloseApp(this: NovaWindowsDriver): Promise<void> { |
| 259 | + return await this.closeApp(); |
302 | 260 | } |
303 | 261 |
|
304 | | -export async function launchApp(this: NovaWindowsDriver, args: { |
305 | | - app: string, |
306 | | - appArguments?: string, |
307 | | -}): Promise<void> { |
308 | | - if (!args || typeof args !== 'object' || !args.app) { |
309 | | - throw new errors.InvalidArgumentError("'app' must be provided."); |
310 | | - } |
311 | | - |
312 | | - const { app, appArguments } = args; |
313 | | - if (app.includes('!') && app.includes('_') && !(app.includes('/') || app.includes('\\'))) { |
314 | | - this.log.debug('Detected app path to be in the UWP format.'); |
315 | | - await this.sendPowerShellCommand(/* ps1 */ `Start-Process 'explorer.exe' 'shell:AppsFolder\\${app}'${appArguments ? ` -ArgumentList '${appArguments}'` : ''}`); |
316 | | - } else { |
317 | | - this.log.debug('Detected app path to be in the classic format.'); |
318 | | - const normalizedPath = normalize(app); |
319 | | - await this.sendPowerShellCommand(/* ps1 */ `Start-Process '${normalizedPath}'${appArguments ? ` -ArgumentList '${appArguments}'` : ''}`); |
320 | | - } |
321 | | - await sleep(1500); // Wait for the app to start |
| 262 | +export async function windowsLaunchApp(this: NovaWindowsDriver): Promise<void> { |
| 263 | + return await this.launchApp(); |
322 | 264 | } |
323 | 265 |
|
324 | 266 | export async function focusElement(this: NovaWindowsDriver, element: Element): Promise<void> { |
|
0 commit comments