@react-native-windows/automation 0.83.0 → 0.83.2

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.
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
35
35
  const chalk_1 = __importDefault(require("chalk"));
36
36
  const child_process_1 = require("child_process");
37
37
  const fs_1 = __importDefault(require("@react-native-windows/fs"));
38
+ const find_dotnet_tools_1 = require("@react-native-windows/find-dotnet-tools");
38
39
  const path_1 = __importDefault(require("path"));
39
40
  const readline_sync_1 = __importDefault(require("readline-sync"));
40
41
  const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
@@ -222,8 +223,14 @@ function resolveAppName(appName) {
222
223
  return appName;
223
224
  }
224
225
  try {
225
- const packageFamilyName = (0, child_process_1.spawnSync)('powershell', [
226
- `(Get-AppxPackage -Name ${appName}).PackageFamilyName`,
226
+ const useAppxCompatibility = !!process.env.TF_BUILD;
227
+ const packageFamilyNameCommand = useAppxCompatibility
228
+ ? `& { Import-Module Appx -WarningAction SilentlyContinue; (Get-AppxPackage -Name '${appName}').PackageFamilyName }`
229
+ : `(Get-AppxPackage -Name '${appName}').PackageFamilyName`;
230
+ const packageFamilyName = (0, child_process_1.spawnSync)((0, find_dotnet_tools_1.findPowerShell)(), [
231
+ '-NoProfile',
232
+ '-Command',
233
+ packageFamilyNameCommand,
227
234
  ])
228
235
  .stdout.toString()
229
236
  .trim();
@@ -1 +1 @@
1
- {"version":3,"file":"AutomationEnvironment.js","sourceRoot":"","sources":["../src/AutomationEnvironment.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAA0B;AAC1B,iDAA6D;AAC7D,kEAA0C;AAC1C,gDAAwB;AACxB,kEAAyC;AAEzC,kFAAoD;AACpD,yDAA2C;AAI3C,iFAGkD;AA+ClD,MAAqB,qBAAsB,SAAQ,+BAAe;IAYhE,YAAY,MAA6B,EAAE,OAA2B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M,EAAE,GAAG,CAAC,EAAE;YAChC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;YAC9B,MAAM,CACJ,IAAI,KAAK,CACP,sDAAsD,QAAQ,GAAG,CAClE,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC5B,OAAO,OAAO,CAAC;KAChB;IAED,IAAI;QACF,MAAM,iBAAiB,GAAG,IAAA,yBAAS,EAAC,YAAY,EAAE;YAChD,0BAA0B,OAAO,qBAAqB;SACvD,CAAC;aACC,MAAM,CAAC,QAAQ,EAAE;aACjB,IAAI,EAAE,CAAC;QAEV,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,iBAAiB;YACjB,MAAM,IAAI,KAAK,EAAE,CAAC;SACnB;QAED,OAAO,GAAG,iBAAiB,MAAM,CAAC;KACnC;IAAC,MAAM;QACN,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,GAAG,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport chalk from 'chalk';\nimport {spawnSync, spawn, ChildProcess} from 'child_process';\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\nimport readlineSync from 'readline-sync';\n\nimport NodeEnvironment from 'jest-environment-node';\nimport * as webdriverio from 'webdriverio';\nimport {BrowserObject, RemoteOptions} from 'webdriverio';\nimport {JestEnvironmentConfig} from '@jest/environment';\nimport type {EnvironmentContext} from '@jest/environment';\nimport {\n waitForConnection,\n AutomationClient,\n} from '@react-native-windows/automation-channel';\n\nexport type EnvironmentOptions = {\n /**\n * The application to launch. Can be a path to an exe, or a package identity\n * name (e.g. Microsoft.WindowsAlarms)\n */\n app?: string;\n\n /**\n * Instead of letting WinAppDriver launch and attach to the app directly,\n * create a Root (Desktop) session and search for the app's window.\n *\n * Note: This is only really necessary to correctly attach to packaged\n * WinAppSDK apps.\n */\n useRootSession?: boolean;\n\n /**\n * When using a Root (Desktop) session, still launch the test app during setup\n * and close it during cleanup.\n *\n * Defaults to true when using `useRootSession` to mimic the expected test\n * behavior, but can be disabled if you're trying to test an already\n * running app instance.\n */\n rootLaunchApp?: boolean;\n\n /**\n * Arguments to be passed to your application when launched\n */\n appArguments?: string;\n\n appWorkingDir?: string;\n\n enableAutomationChannel?: boolean;\n automationChannelPort?: number;\n winAppDriverBin?: string;\n breakOnStart?: boolean;\n webdriverOptions?: RemoteOptions;\n};\n\ntype AutomationChannelOptions = {\n enable: boolean;\n port: number;\n};\n\nexport default class AutomationEnvironment extends NodeEnvironment {\n private readonly rootWebDriverOptions?: RemoteOptions;\n private readonly webDriverOptions: RemoteOptions;\n private readonly channelOptions: AutomationChannelOptions;\n private readonly winappdriverBin: string;\n private readonly breakOnStart: boolean;\n private readonly useRootSession: boolean;\n private readonly rootLaunchApp: boolean;\n private winAppDriverProcess: ChildProcess | undefined;\n private browser: BrowserObject | undefined;\n private automationClient: AutomationClient | undefined;\n\n constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {\n super(config, context);\n const passedOptions: EnvironmentOptions =\n config.projectConfig.testEnvironmentOptions;\n\n if (!passedOptions.app) {\n throw new Error('\"app\" must be specified in testEnvironmentOptions');\n }\n\n this.winappdriverBin =\n passedOptions.winAppDriverBin ||\n path.join(\n process.env['PROGRAMFILES(X86)']!,\n 'Windows Application Driver\\\\WinAppDriver.exe',\n );\n\n if (!fs.existsSync(this.winappdriverBin)) {\n throw new Error(\n `Could not find WinAppDriver at searched location: \"${this.winappdriverBin}\"`,\n );\n }\n\n const baseOptions: RemoteOptions = {\n hostname: '127.0.0.1',\n port: 4723,\n\n // Level of logging verbosity: trace | debug | info | warn | error\n logLevel: 'error',\n\n // Default timeout for all waitFor* commands.\n waitforTimeout: 30000,\n\n // Default timeout in milliseconds for request\n connectionRetryTimeout: 30000,\n\n // Default request retries count\n connectionRetryCount: 5,\n };\n\n this.useRootSession = !!passedOptions.useRootSession;\n this.rootLaunchApp =\n passedOptions.rootLaunchApp === undefined\n ? this.useRootSession\n : !!passedOptions.rootLaunchApp;\n\n if (this.useRootSession) {\n this.rootWebDriverOptions = Object.assign(\n {},\n baseOptions,\n {\n capabilities: {\n app: 'Root',\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n },\n passedOptions.webdriverOptions,\n );\n\n this.webDriverOptions = Object.assign(\n {},\n baseOptions,\n {\n capabilities: {\n // Save the name for now, we'll get the handle later\n appTopLevelWindow: passedOptions.app,\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n },\n passedOptions.webdriverOptions,\n );\n } else {\n this.webDriverOptions = Object.assign(\n {},\n baseOptions,\n {\n capabilities: {\n app: resolveAppName(passedOptions.app),\n ...(passedOptions.appWorkingDir && {\n appWorkingDir: passedOptions.appWorkingDir,\n }),\n ...(passedOptions.appArguments && {\n appArguments: passedOptions.appArguments,\n }),\n\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n },\n passedOptions.webdriverOptions,\n );\n }\n\n this.webDriverOptions.capabilities = Object.assign(\n this.webDriverOptions.capabilities!,\n passedOptions.webdriverOptions?.capabilities,\n );\n\n this.channelOptions = {\n enable: passedOptions.enableAutomationChannel === true,\n port: passedOptions.automationChannelPort || 8603,\n };\n\n this.breakOnStart = passedOptions.breakOnStart === true;\n }\n\n async setup() {\n await super.setup();\n this.winAppDriverProcess = await spawnWinAppDriver(\n this.winappdriverBin,\n this.webDriverOptions.port!,\n );\n\n if (this.useRootSession) {\n // Extract out the saved window name\n const appName = (this.webDriverOptions.capabilities! as any)\n .appTopLevelWindow;\n\n if (this.rootLaunchApp) {\n const appPackageName = resolveAppName(appName);\n spawnSync('cmd', [\n '/c',\n 'start',\n `shell:AppsFolder\\\\${appPackageName}`,\n ]);\n }\n\n // Set up the \"Desktop\" or Root session\n const rootBrowser = await webdriverio.remote(this.rootWebDriverOptions);\n\n // Poll for the app window with timeout (cold starts can be slow)\n const windowTimeout = 300000; // 5 minutes\n const pollInterval = 2000;\n const deadline = Date.now() + windowTimeout;\n let appWindow: webdriverio.Element | undefined;\n\n while (Date.now() < deadline) {\n const allWindows = await rootBrowser.$$('//Window');\n for (const window of allWindows) {\n if ((await window.getAttribute('Name')) === appName) {\n appWindow = window;\n break;\n }\n }\n if (appWindow) {\n break;\n }\n await new Promise(resolve => setTimeout(resolve, pollInterval));\n }\n\n if (!appWindow) {\n throw new Error(`Unable to find window with Name === '${appName}'.`);\n }\n\n // Swap the the window handle for WinAppDriver\n const appWindowHandle = parseInt(\n await appWindow!.getAttribute('NativeWindowHandle'),\n 10,\n );\n\n (this.webDriverOptions.capabilities as any).appTopLevelWindow =\n '0x' + appWindowHandle.toString(16);\n\n await rootBrowser.deleteSession();\n }\n\n this.browser = await webdriverio.remote(this.webDriverOptions);\n\n if (this.breakOnStart) {\n readlineSync.question(\n chalk.bold.yellow('Breaking before tests start\\n') +\n 'Press Enter to resume...',\n );\n }\n\n if (this.channelOptions.enable) {\n this.automationClient = await waitForConnection({\n port: this.channelOptions.port,\n });\n this.global.automationClient = this.automationClient;\n }\n\n this.global.remote = webdriverio.remote;\n this.global.browser = this.browser;\n this.global.$ = this.browser.$.bind(this.browser);\n this.global.$$ = this.browser.$$.bind(this.browser);\n }\n\n async teardown() {\n if (this.automationClient) {\n this.automationClient.close();\n }\n\n if (this.browser) {\n if (this.rootLaunchApp) {\n // We started the app, so let's close it too\n await this.browser.closeWindow();\n }\n await this.browser.deleteSession();\n }\n this.winAppDriverProcess?.kill('SIGINT');\n await super.teardown();\n }\n}\n\n/**\n * Starts a WinAppdriver process and resolves a promise with the process once\n * it is ready to accept commands\n *\n * Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service\n */\nasync function spawnWinAppDriver(\n winappdriverBin: string,\n port: number,\n): Promise<ChildProcess> {\n if (!fs.existsSync(winappdriverBin)) {\n throw new Error(\n `Could not locate WinAppDriver binary at \"${winappdriverBin}\"`,\n );\n }\n\n return new Promise((resolve, reject) => {\n const process = spawn(winappdriverBin, [port.toString()], {stdio: 'pipe'});\n\n process.stdout.on('data', data => {\n const s = data.toString('utf16le');\n if (s.includes('Press ENTER to exit.')) {\n resolve(process);\n } else if (s.includes('Failed to initialize')) {\n reject(new Error('Failed to start WinAppDriver: ' + s));\n }\n });\n\n process.stderr.once('data', err => {\n console.warn(err);\n });\n\n process.once('exit', exitCode => {\n reject(\n new Error(\n `WinAppDriver CLI exited before timeout (exit code: ${exitCode})`,\n ),\n );\n });\n });\n}\n\n/**\n * Convert a package identity or path to exe to the form expected by a WinAppDriver capability\n */\nfunction resolveAppName(appName: string): string {\n if (appName.endsWith('.exe')) {\n return appName;\n }\n\n try {\n const packageFamilyName = spawnSync('powershell', [\n `(Get-AppxPackage -Name ${appName}).PackageFamilyName`,\n ])\n .stdout.toString()\n .trim();\n\n if (packageFamilyName.length === 0) {\n // Rethrown below\n throw new Error();\n }\n\n return `${packageFamilyName}!App`;\n } catch {\n throw new Error(`Could not locate a package with identity \"${appName}\"`);\n }\n}\n"]}
1
+ {"version":3,"file":"AutomationEnvironment.js","sourceRoot":"","sources":["../src/AutomationEnvironment.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAA0B;AAC1B,iDAA6D;AAC7D,kEAA0C;AAC1C,+EAAuE;AACvE,gDAAwB;AACxB,kEAAyC;AAEzC,kFAAoD;AACpD,yDAA2C;AAI3C,iFAGkD;AA+ClD,MAAqB,qBAAsB,SAAQ,+BAAe;IAYhE,YAAY,MAA6B,EAAE,OAA2B;QACpE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB,MAAM,aAAa,GACjB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C;QACpB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;YAC9B,MAAM,CACJ,IAAI,KAAK,CACP,sDAAsD,QAAQ,GAAG,CAClE,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC5B,OAAO,OAAO,CAAC;KAChB;IAED,IAAI;QACF,MAAM,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QACpD,MAAM,wBAAwB,GAAG,oBAAoB;YACnD,CAAC,CAAC,mFAAmF,OAAO,wBAAwB;YACpH,CAAC,CAAC,2BAA2B,OAAO,sBAAsB,CAAC;QAC7D,MAAM,iBAAiB,GAAG,IAAA,yBAAS,EAAC,IAAA,kCAAc,GAAE,EAAE;YACpD,YAAY;YACZ,UAAU;YACV,wBAAwB;SACzB,CAAC;aACC,MAAM,CAAC,QAAQ,EAAE;aACjB,IAAI,EAAE,CAAC;QAEV,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,iBAAiB;YACjB,MAAM,IAAI,KAAK,EAAE,CAAC;SACnB;QAED,OAAO,GAAG,iBAAiB,MAAM,CAAC;KACnC;IAAC,MAAM;QACN,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,GAAG,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport chalk from 'chalk';\nimport {spawnSync, spawn, ChildProcess} from 'child_process';\nimport fs from '@react-native-windows/fs';\nimport {findPowerShell} from '@react-native-windows/find-dotnet-tools';\nimport path from 'path';\nimport readlineSync from 'readline-sync';\n\nimport NodeEnvironment from 'jest-environment-node';\nimport * as webdriverio from 'webdriverio';\nimport {BrowserObject, RemoteOptions} from 'webdriverio';\nimport {JestEnvironmentConfig} from '@jest/environment';\nimport type {EnvironmentContext} from '@jest/environment';\nimport {\n waitForConnection,\n AutomationClient,\n} from '@react-native-windows/automation-channel';\n\nexport type EnvironmentOptions = {\n /**\n * The application to launch. Can be a path to an exe, or a package identity\n * name (e.g. Microsoft.WindowsAlarms)\n */\n app?: string;\n\n /**\n * Instead of letting WinAppDriver launch and attach to the app directly,\n * create a Root (Desktop) session and search for the app's window.\n *\n * Note: This is only really necessary to correctly attach to packaged\n * WinAppSDK apps.\n */\n useRootSession?: boolean;\n\n /**\n * When using a Root (Desktop) session, still launch the test app during setup\n * and close it during cleanup.\n *\n * Defaults to true when using `useRootSession` to mimic the expected test\n * behavior, but can be disabled if you're trying to test an already\n * running app instance.\n */\n rootLaunchApp?: boolean;\n\n /**\n * Arguments to be passed to your application when launched\n */\n appArguments?: string;\n\n appWorkingDir?: string;\n\n enableAutomationChannel?: boolean;\n automationChannelPort?: number;\n winAppDriverBin?: string;\n breakOnStart?: boolean;\n webdriverOptions?: RemoteOptions;\n};\n\ntype AutomationChannelOptions = {\n enable: boolean;\n port: number;\n};\n\nexport default class AutomationEnvironment extends NodeEnvironment {\n private readonly rootWebDriverOptions?: RemoteOptions;\n private readonly webDriverOptions: RemoteOptions;\n private readonly channelOptions: AutomationChannelOptions;\n private readonly winappdriverBin: string;\n private readonly breakOnStart: boolean;\n private readonly useRootSession: boolean;\n private readonly rootLaunchApp: boolean;\n private winAppDriverProcess: ChildProcess | undefined;\n private browser: BrowserObject | undefined;\n private automationClient: AutomationClient | undefined;\n\n constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {\n super(config, context);\n const passedOptions: EnvironmentOptions =\n config.projectConfig.testEnvironmentOptions;\n\n if (!passedOptions.app) {\n throw new Error('\"app\" must be specified in testEnvironmentOptions');\n }\n\n this.winappdriverBin =\n passedOptions.winAppDriverBin ||\n path.join(\n process.env['PROGRAMFILES(X86)']!,\n 'Windows Application Driver\\\\WinAppDriver.exe',\n );\n\n if (!fs.existsSync(this.winappdriverBin)) {\n throw new Error(\n `Could not find WinAppDriver at searched location: \"${this.winappdriverBin}\"`,\n );\n }\n\n const baseOptions: RemoteOptions = {\n hostname: '127.0.0.1',\n port: 4723,\n\n // Level of logging verbosity: trace | debug | info | warn | error\n logLevel: 'error',\n\n // Default timeout for all waitFor* commands.\n waitforTimeout: 30000,\n\n // Default timeout in milliseconds for request\n connectionRetryTimeout: 30000,\n\n // Default request retries count\n connectionRetryCount: 5,\n };\n\n this.useRootSession = !!passedOptions.useRootSession;\n this.rootLaunchApp =\n passedOptions.rootLaunchApp === undefined\n ? this.useRootSession\n : !!passedOptions.rootLaunchApp;\n\n if (this.useRootSession) {\n this.rootWebDriverOptions = Object.assign(\n {},\n baseOptions,\n {\n capabilities: {\n app: 'Root',\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n },\n passedOptions.webdriverOptions,\n );\n\n this.webDriverOptions = Object.assign(\n {},\n baseOptions,\n {\n capabilities: {\n // Save the name for now, we'll get the handle later\n appTopLevelWindow: passedOptions.app,\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n },\n passedOptions.webdriverOptions,\n );\n } else {\n this.webDriverOptions = Object.assign(\n {},\n baseOptions,\n {\n capabilities: {\n app: resolveAppName(passedOptions.app),\n ...(passedOptions.appWorkingDir && {\n appWorkingDir: passedOptions.appWorkingDir,\n }),\n ...(passedOptions.appArguments && {\n appArguments: passedOptions.appArguments,\n }),\n\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n },\n passedOptions.webdriverOptions,\n );\n }\n\n this.webDriverOptions.capabilities = Object.assign(\n this.webDriverOptions.capabilities!,\n passedOptions.webdriverOptions?.capabilities,\n );\n\n this.channelOptions = {\n enable: passedOptions.enableAutomationChannel === true,\n port: passedOptions.automationChannelPort || 8603,\n };\n\n this.breakOnStart = passedOptions.breakOnStart === true;\n }\n\n async setup() {\n await super.setup();\n this.winAppDriverProcess = await spawnWinAppDriver(\n this.winappdriverBin,\n this.webDriverOptions.port!,\n );\n\n if (this.useRootSession) {\n // Extract out the saved window name\n const appName = (this.webDriverOptions.capabilities! as any)\n .appTopLevelWindow;\n\n if (this.rootLaunchApp) {\n const appPackageName = resolveAppName(appName);\n spawnSync('cmd', [\n '/c',\n 'start',\n `shell:AppsFolder\\\\${appPackageName}`,\n ]);\n }\n\n // Set up the \"Desktop\" or Root session\n const rootBrowser = await webdriverio.remote(this.rootWebDriverOptions);\n\n // Poll for the app window with timeout (cold starts can be slow)\n const windowTimeout = 300000; // 5 minutes\n const pollInterval = 2000;\n const deadline = Date.now() + windowTimeout;\n let appWindow: webdriverio.Element | undefined;\n\n while (Date.now() < deadline) {\n const allWindows = await rootBrowser.$$('//Window');\n for (const window of allWindows) {\n if ((await window.getAttribute('Name')) === appName) {\n appWindow = window;\n break;\n }\n }\n if (appWindow) {\n break;\n }\n await new Promise(resolve => setTimeout(resolve, pollInterval));\n }\n\n if (!appWindow) {\n throw new Error(`Unable to find window with Name === '${appName}'.`);\n }\n\n // Swap the the window handle for WinAppDriver\n const appWindowHandle = parseInt(\n await appWindow!.getAttribute('NativeWindowHandle'),\n 10,\n );\n\n (this.webDriverOptions.capabilities as any).appTopLevelWindow =\n '0x' + appWindowHandle.toString(16);\n\n await rootBrowser.deleteSession();\n }\n\n this.browser = await webdriverio.remote(this.webDriverOptions);\n\n if (this.breakOnStart) {\n readlineSync.question(\n chalk.bold.yellow('Breaking before tests start\\n') +\n 'Press Enter to resume...',\n );\n }\n\n if (this.channelOptions.enable) {\n this.automationClient = await waitForConnection({\n port: this.channelOptions.port,\n });\n this.global.automationClient = this.automationClient;\n }\n\n this.global.remote = webdriverio.remote;\n this.global.browser = this.browser;\n this.global.$ = this.browser.$.bind(this.browser);\n this.global.$$ = this.browser.$$.bind(this.browser);\n }\n\n async teardown() {\n if (this.automationClient) {\n this.automationClient.close();\n }\n\n if (this.browser) {\n if (this.rootLaunchApp) {\n // We started the app, so let's close it too\n await this.browser.closeWindow();\n }\n await this.browser.deleteSession();\n }\n this.winAppDriverProcess?.kill('SIGINT');\n await super.teardown();\n }\n}\n\n/**\n * Starts a WinAppdriver process and resolves a promise with the process once\n * it is ready to accept commands\n *\n * Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service\n */\nasync function spawnWinAppDriver(\n winappdriverBin: string,\n port: number,\n): Promise<ChildProcess> {\n if (!fs.existsSync(winappdriverBin)) {\n throw new Error(\n `Could not locate WinAppDriver binary at \"${winappdriverBin}\"`,\n );\n }\n\n return new Promise((resolve, reject) => {\n const process = spawn(winappdriverBin, [port.toString()], {stdio: 'pipe'});\n\n process.stdout.on('data', data => {\n const s = data.toString('utf16le');\n if (s.includes('Press ENTER to exit.')) {\n resolve(process);\n } else if (s.includes('Failed to initialize')) {\n reject(new Error('Failed to start WinAppDriver: ' + s));\n }\n });\n\n process.stderr.once('data', err => {\n console.warn(err);\n });\n\n process.once('exit', exitCode => {\n reject(\n new Error(\n `WinAppDriver CLI exited before timeout (exit code: ${exitCode})`,\n ),\n );\n });\n });\n}\n\n/**\n * Convert a package identity or path to exe to the form expected by a WinAppDriver capability\n */\nfunction resolveAppName(appName: string): string {\n if (appName.endsWith('.exe')) {\n return appName;\n }\n\n try {\n const useAppxCompatibility = !!process.env.TF_BUILD;\n const packageFamilyNameCommand = useAppxCompatibility\n ? `& { Import-Module Appx -WarningAction SilentlyContinue; (Get-AppxPackage -Name '${appName}').PackageFamilyName }`\n : `(Get-AppxPackage -Name '${appName}').PackageFamilyName`;\n const packageFamilyName = spawnSync(findPowerShell(), [\n '-NoProfile',\n '-Command',\n packageFamilyNameCommand,\n ])\n .stdout.toString()\n .trim();\n\n if (packageFamilyName.length === 0) {\n // Rethrown below\n throw new Error();\n }\n\n return `${packageFamilyName}!App`;\n } catch {\n throw new Error(`Could not locate a package with identity \"${appName}\"`);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/automation",
3
- "version": "0.83.0",
3
+ "version": "0.83.2",
4
4
  "description": "UI Automation Suite for React Native Windows Applications",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "repository": {
@@ -18,8 +18,8 @@
18
18
  "watch": "rnw-scripts watch"
19
19
  },
20
20
  "dependencies": {
21
- "@react-native-windows/automation-channel": "0.83.0",
22
- "@react-native-windows/fs": "0.83.0",
21
+ "@react-native-windows/automation-channel": "0.83.2",
22
+ "@react-native-windows/fs": "0.83.1",
23
23
  "@typescript-eslint/eslint-plugin": "^7.1.1",
24
24
  "@typescript-eslint/parser": "^7.1.1",
25
25
  "chalk": "^4.1.2",
@@ -49,7 +49,7 @@
49
49
  "README.md"
50
50
  ],
51
51
  "beachball": {
52
- "defaultNpmTag": "latest",
52
+ "defaultNpmTag": "v0.83-stable",
53
53
  "disallowedChangeTypes": [
54
54
  "major",
55
55
  "minor",