From 9d3afa5386a9f316ad017c9da2e83f6283c47677 Mon Sep 17 00:00:00 2001 From: "Grathwohl, Philipp" Date: Fri, 15 Nov 2024 09:45:54 +0100 Subject: [PATCH] feat: Allow specifying the /forcequit argument for WAD --- README.md | 1 + lib/desired-caps.js | 3 +++ lib/winappdriver.js | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1fbb12..7744ab2 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ appium:appWorkingDir | Full path to the folder, which is going to be set as the appium:createSessionTimeout | Timeout in milliseconds used to retry Appium Windows Driver session startup. This capability could be used as a workaround for the long startup times of UWP applications (aka `Failed to locate opened application window with appId: TestCompany.my_app4!App, and processId: 8480`). Default value is `20000`. ms:waitForAppLaunch | Similar to `createSessionTimeout`, but in seconds and is applied on the server side. Enables Appium Windows Driver to wait for a defined amount of time after an app launch is initiated prior to attaching to the application session. The limit for this is 50 seconds. ms:experimental-webdriver | Enables experimental features and optimizations. See Appium Windows Driver release notes for more details on this capability. `false` by default. +ms:forcequit | Defines if the WinAppDriver should be started with the `/forcequit` command line argument. Default `false`. appium:systemPort | The port number to execute Appium Windows Driver server listener on, for example `5556`. The port must not be occupied. The default starting port number for a new Appium Windows Driver session is `4724`. If this port is already busy then the next free port will be automatically selected. appium:prerun | An object containing either `script` or `command` key. The value of each key must be a valid PowerShell script or command to be executed prior to the WinAppDriver session startup. See [Power Shell commands execution](#power-shell-commands-execution) for more details. Example: `{script: 'Get-Process outlook -ErrorAction SilentlyContinue'}` appium:postrun | An object containing either `script` or `command` key. The value of each key must be a valid PowerShell script or command to be executed after WinAppDriver session is stopped. See [Power Shell commands execution](#power-shell-commands-execution) for more details. diff --git a/lib/desired-caps.js b/lib/desired-caps.js index f99a3e3..401ffae 100644 --- a/lib/desired-caps.js +++ b/lib/desired-caps.js @@ -29,6 +29,9 @@ const desiredCapConstraints = /** @type {const} */ ({ 'ms:waitForAppLaunch': { isNumber: true // in seconds }, + 'ms:forcequit': { + isBoolean: true + }, 'ms:experimental-webdriver': { isBoolean: true }, diff --git a/lib/winappdriver.js b/lib/winappdriver.js index b4f8beb..59db3ca 100644 --- a/lib/winappdriver.js +++ b/lib/winappdriver.js @@ -43,6 +43,7 @@ class WADProcess { this.port = opts.port; this.executablePath = opts.executablePath; this.proc = null; + this.forcequit = opts.forcequit; } get isRunning () { @@ -69,6 +70,10 @@ class WADProcess { } const args = [`${this.port}${this.base}`]; + + if (this.forcequit) + args.push('/forcequit'); + this.proc = new SubProcess(this.executablePath, args, { encoding: 'ucs2' }); @@ -120,12 +125,14 @@ class WinAppDriver { async start (caps) { const executablePath = await getWADExecutablePath(); + const forcequit = caps["ms:forcequit"] === true; this.process = new WADProcess(this.log, { // XXXYD TODO: would be better if WinAppDriver didn't require passing in /wd/hub as a param base: DEFAULT_BASE_PATH, port: this.proxyPort, - executablePath, + executablePath: executablePath, + forcequit: forcequit }); await this.process.start();