@react-native-windows/automation 0.3.198 → 0.3.199

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.
@@ -1,70 +1,70 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- *
5
- * @format
6
- */
7
- /// <reference types="webdriverio/webdriverio-core" />
8
- /**
9
- * Projection of a WebDriver Element, with functions corresponding to supported
10
- * WinAppDriver APIs.
11
- *
12
- * See https://github.com/microsoft/WinAppDriver/blob/master/Docs/SupportedAPIs.md
13
- */
14
- export type AutomationElement = Pick<WebdriverIO.Element, 'addValue' | 'clearValue' | 'click' | 'doubleClick' | 'findElements' | 'getAttribute' | 'getLocation' | 'getSize' | 'getText' | 'getValue' | 'isDisplayed' | 'isDisplayedInViewport' | 'isEnabled' | 'isEqual' | 'isSelected' | 'moveTo' | 'saveScreenshot' | 'sendKeys' | 'selectByVisibleText' | 'setValue' | 'touchAction' | 'waitForDisplayed' | 'waitForExist'>;
15
- /**
16
- * A subset of WebDriver functionality that will work with Windows applications
17
- */
18
- export declare const app: {
19
- /**
20
- * Find an element by testID property
21
- */
22
- findElementByTestID: (id: string) => Promise<AutomationElement>;
23
- /**
24
- * Find an element by Automation ID
25
- *
26
- * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.automationid?view=net-6.0
27
- */
28
- findElementByAutomationID: (id: string) => Promise<AutomationElement>;
29
- /**
30
- * Finds an element by the name of its class name (e.g. ListViewItem)
31
- *
32
- * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.classname?view=net-6.0
33
- */
34
- findElementByClassName: (className: string) => Promise<AutomationElement>;
35
- /**
36
- * Find element by ControlType (e.g. Button, CheckBox)
37
- *
38
- * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.controltype?view=net-6.0
39
- */
40
- findElementByControlType: (controlType: string) => Promise<AutomationElement>;
41
- /**
42
- * Find element by a WinAppDriver compatible XPath Selector (e.g. '//Button[@AutomationId=\"MoreButton\"]')
43
- */
44
- findElementByXPath: (xpath: string) => Promise<AutomationElement>;
45
- /**
46
- * Resizes app window outer size according to provided width and height.
47
- */
48
- setWindowSize: (width: number, height: number) => Promise<object | null>;
49
- /**
50
- * Change the position of the current focussed window.
51
- */
52
- setWindowPosition: (x: number, y: number) => Promise<WebDriver.ProtocolCommandResponse>;
53
- /**
54
- * Get the position of the current focussed window.
55
- */
56
- getWindowPosition: () => Promise<WebDriver.ProtocolCommandResponse>;
57
- /**
58
- * Returns app window size.
59
- */
60
- getWindowSize: () => Promise<WebDriver.RectReturn>;
61
- /**
62
- * Switch focus to a particular window.
63
- */
64
- switchWindow: (titleToMatch: string | RegExp) => Promise<void>;
65
- /**
66
- * This wait command is your universal weapon if you want to wait on something. It expects a condition
67
- * and waits until that condition is fulfilled with a truthy value.
68
- */
69
- waitUntil: (condition: () => Promise<boolean>, options?: WebdriverIO.WaitUntilOptions) => Promise<boolean>;
70
- };
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ /// <reference types="webdriverio/webdriverio-core" />
8
+ /**
9
+ * Projection of a WebDriver Element, with functions corresponding to supported
10
+ * WinAppDriver APIs.
11
+ *
12
+ * See https://github.com/microsoft/WinAppDriver/blob/master/Docs/SupportedAPIs.md
13
+ */
14
+ export type AutomationElement = Pick<WebdriverIO.Element, 'addValue' | 'clearValue' | 'click' | 'doubleClick' | 'findElements' | 'getAttribute' | 'getLocation' | 'getSize' | 'getText' | 'getValue' | 'isDisplayed' | 'isDisplayedInViewport' | 'isEnabled' | 'isEqual' | 'isSelected' | 'moveTo' | 'saveScreenshot' | 'sendKeys' | 'selectByVisibleText' | 'setValue' | 'touchAction' | 'waitForDisplayed' | 'waitForExist'>;
15
+ /**
16
+ * A subset of WebDriver functionality that will work with Windows applications
17
+ */
18
+ export declare const app: {
19
+ /**
20
+ * Find an element by testID property
21
+ */
22
+ findElementByTestID: (id: string) => Promise<AutomationElement>;
23
+ /**
24
+ * Find an element by Automation ID
25
+ *
26
+ * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.automationid?view=net-6.0
27
+ */
28
+ findElementByAutomationID: (id: string) => Promise<AutomationElement>;
29
+ /**
30
+ * Finds an element by the name of its class name (e.g. ListViewItem)
31
+ *
32
+ * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.classname?view=net-6.0
33
+ */
34
+ findElementByClassName: (className: string) => Promise<AutomationElement>;
35
+ /**
36
+ * Find element by ControlType (e.g. Button, CheckBox)
37
+ *
38
+ * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.controltype?view=net-6.0
39
+ */
40
+ findElementByControlType: (controlType: string) => Promise<AutomationElement>;
41
+ /**
42
+ * Find element by a WinAppDriver compatible XPath Selector (e.g. '//Button[@AutomationId=\"MoreButton\"]')
43
+ */
44
+ findElementByXPath: (xpath: string) => Promise<AutomationElement>;
45
+ /**
46
+ * Resizes app window outer size according to provided width and height.
47
+ */
48
+ setWindowSize: (width: number, height: number) => Promise<object | null>;
49
+ /**
50
+ * Change the position of the current focussed window.
51
+ */
52
+ setWindowPosition: (x: number, y: number) => Promise<WebDriver.ProtocolCommandResponse>;
53
+ /**
54
+ * Get the position of the current focussed window.
55
+ */
56
+ getWindowPosition: () => Promise<WebDriver.ProtocolCommandResponse>;
57
+ /**
58
+ * Returns app window size.
59
+ */
60
+ getWindowSize: () => Promise<WebDriver.RectReturn>;
61
+ /**
62
+ * Switch focus to a particular window.
63
+ */
64
+ switchWindow: (titleToMatch: string | RegExp) => Promise<void>;
65
+ /**
66
+ * This wait command is your universal weapon if you want to wait on something. It expects a condition
67
+ * and waits until that condition is fulfilled with a truthy value.
68
+ */
69
+ waitUntil: (condition: () => Promise<boolean>, options?: WebdriverIO.WaitUntilOptions) => Promise<boolean>;
70
+ };
@@ -1,66 +1,66 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- *
6
- * @format
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.app = void 0;
10
- /**
11
- * A subset of WebDriver functionality that will work with Windows applications
12
- */
13
- exports.app = {
14
- /**
15
- * Find an element by testID property
16
- */
17
- findElementByTestID: (id) => $(`~${id}`),
18
- /**
19
- * Find an element by Automation ID
20
- *
21
- * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.automationid?view=net-6.0
22
- */
23
- findElementByAutomationID: (id) => $(`~${id}`),
24
- /**
25
- * Finds an element by the name of its class name (e.g. ListViewItem)
26
- *
27
- * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.classname?view=net-6.0
28
- */
29
- findElementByClassName: (className) => $(className),
30
- /**
31
- * Find element by ControlType (e.g. Button, CheckBox)
32
- *
33
- * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.controltype?view=net-6.0
34
- */
35
- findElementByControlType: (controlType) => $(`<${controlType} />`),
36
- /**
37
- * Find element by a WinAppDriver compatible XPath Selector (e.g. '//Button[@AutomationId=\"MoreButton\"]')
38
- */
39
- findElementByXPath: (xpath) => $(xpath),
40
- /**
41
- * Resizes app window outer size according to provided width and height.
42
- */
43
- setWindowSize: (width, height) => browser.setWindowSize(width, height),
44
- /**
45
- * Change the position of the current focussed window.
46
- */
47
- setWindowPosition: (x, y) => browser.setWindowPosition(x, y),
48
- /**
49
- * Get the position of the current focussed window.
50
- */
51
- getWindowPosition: () => browser.getWindowPosition(),
52
- /**
53
- * Returns app window size.
54
- */
55
- getWindowSize: () => browser.getWindowSize(),
56
- /**
57
- * Switch focus to a particular window.
58
- */
59
- switchWindow: (titleToMatch) => browser.switchWindow(titleToMatch),
60
- /**
61
- * This wait command is your universal weapon if you want to wait on something. It expects a condition
62
- * and waits until that condition is fulfilled with a truthy value.
63
- */
64
- waitUntil: (condition, options) => browser.waitUntil(condition, options),
65
- };
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ *
6
+ * @format
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.app = void 0;
10
+ /**
11
+ * A subset of WebDriver functionality that will work with Windows applications
12
+ */
13
+ exports.app = {
14
+ /**
15
+ * Find an element by testID property
16
+ */
17
+ findElementByTestID: (id) => $(`~${id}`),
18
+ /**
19
+ * Find an element by Automation ID
20
+ *
21
+ * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.automationid?view=net-6.0
22
+ */
23
+ findElementByAutomationID: (id) => $(`~${id}`),
24
+ /**
25
+ * Finds an element by the name of its class name (e.g. ListViewItem)
26
+ *
27
+ * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.automationelementinformation.classname?view=net-6.0
28
+ */
29
+ findElementByClassName: (className) => $(className),
30
+ /**
31
+ * Find element by ControlType (e.g. Button, CheckBox)
32
+ *
33
+ * https://docs.microsoft.com/en-us/dotnet/api/system.windows.automation.controltype?view=net-6.0
34
+ */
35
+ findElementByControlType: (controlType) => $(`<${controlType} />`),
36
+ /**
37
+ * Find element by a WinAppDriver compatible XPath Selector (e.g. '//Button[@AutomationId=\"MoreButton\"]')
38
+ */
39
+ findElementByXPath: (xpath) => $(xpath),
40
+ /**
41
+ * Resizes app window outer size according to provided width and height.
42
+ */
43
+ setWindowSize: (width, height) => browser.setWindowSize(width, height),
44
+ /**
45
+ * Change the position of the current focussed window.
46
+ */
47
+ setWindowPosition: (x, y) => browser.setWindowPosition(x, y),
48
+ /**
49
+ * Get the position of the current focussed window.
50
+ */
51
+ getWindowPosition: () => browser.getWindowPosition(),
52
+ /**
53
+ * Returns app window size.
54
+ */
55
+ getWindowSize: () => browser.getWindowSize(),
56
+ /**
57
+ * Switch focus to a particular window.
58
+ */
59
+ switchWindow: (titleToMatch) => browser.switchWindow(titleToMatch),
60
+ /**
61
+ * This wait command is your universal weapon if you want to wait on something. It expects a condition
62
+ * and waits until that condition is fulfilled with a truthy value.
63
+ */
64
+ waitUntil: (condition, options) => browser.waitUntil(condition, options),
65
+ };
66
66
  //# sourceMappingURL=AutomationClient.js.map
@@ -1,40 +1,40 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- *
5
- * @format
6
- */
7
- /// <reference types="webdriverio/webdriverio-core" />
8
- import NodeEnvironment from 'jest-environment-node';
9
- import { RemoteOptions } from 'webdriverio';
10
- import { JestEnvironmentConfig } from '@jest/environment';
11
- import type { EnvironmentContext } from '@jest/environment';
12
- export type EnvironmentOptions = {
13
- /**
14
- * The application to launch. Can be a path to an exe, or a package identity
15
- * name (e.g. Microsoft.WindowsAlarms)
16
- */
17
- app?: string;
18
- /**
19
- * Arguments to be passed to your application when launched
20
- */
21
- appArguments?: string;
22
- appWorkingDir?: string;
23
- enableAutomationChannel?: boolean;
24
- automationChannelPort?: number;
25
- winAppDriverBin?: string;
26
- breakOnStart?: boolean;
27
- webdriverOptions?: RemoteOptions;
28
- };
29
- export default class AutomationEnvironment extends NodeEnvironment {
30
- private readonly webDriverOptions;
31
- private readonly channelOptions;
32
- private readonly winappdriverBin;
33
- private readonly breakOnStart;
34
- private winAppDriverProcess;
35
- private browser;
36
- private automationClient;
37
- constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
38
- setup(): Promise<void>;
39
- teardown(): Promise<void>;
40
- }
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ /// <reference types="webdriverio/webdriverio-core" />
8
+ import NodeEnvironment from 'jest-environment-node';
9
+ import { RemoteOptions } from 'webdriverio';
10
+ import { JestEnvironmentConfig } from '@jest/environment';
11
+ import type { EnvironmentContext } from '@jest/environment';
12
+ export type EnvironmentOptions = {
13
+ /**
14
+ * The application to launch. Can be a path to an exe, or a package identity
15
+ * name (e.g. Microsoft.WindowsAlarms)
16
+ */
17
+ app?: string;
18
+ /**
19
+ * Arguments to be passed to your application when launched
20
+ */
21
+ appArguments?: string;
22
+ appWorkingDir?: string;
23
+ enableAutomationChannel?: boolean;
24
+ automationChannelPort?: number;
25
+ winAppDriverBin?: string;
26
+ breakOnStart?: boolean;
27
+ webdriverOptions?: RemoteOptions;
28
+ };
29
+ export default class AutomationEnvironment extends NodeEnvironment {
30
+ private readonly webDriverOptions;
31
+ private readonly channelOptions;
32
+ private readonly winappdriverBin;
33
+ private readonly breakOnStart;
34
+ private winAppDriverProcess;
35
+ private browser;
36
+ private automationClient;
37
+ constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
38
+ setup(): Promise<void>;
39
+ teardown(): Promise<void>;
40
+ }
@@ -1,170 +1,170 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- *
6
- * @format
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __importDefault = (this && this.__importDefault) || function (mod) {
32
- return (mod && mod.__esModule) ? mod : { "default": mod };
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- const chalk_1 = __importDefault(require("chalk"));
36
- const child_process_1 = require("child_process");
37
- const fs_1 = __importDefault(require("@react-native-windows/fs"));
38
- const path_1 = __importDefault(require("path"));
39
- const readline_sync_1 = __importDefault(require("readline-sync"));
40
- const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
41
- const webdriverio = __importStar(require("webdriverio"));
42
- const automation_channel_1 = require("@react-native-windows/automation-channel");
43
- class AutomationEnvironment extends jest_environment_node_1.default {
44
- constructor(config, context) {
45
- var _a;
46
- super(config, context);
47
- const passedOptions = config.projectConfig.testEnvironmentOptions;
48
- if (!passedOptions.app) {
49
- throw new Error('"app" must be specified in testEnvironmentOptions');
50
- }
51
- this.winappdriverBin =
52
- passedOptions.winAppDriverBin ||
53
- path_1.default.join(process.env['PROGRAMFILES(X86)'], 'Windows Application Driver\\WinAppDriver.exe');
54
- if (!fs_1.default.existsSync(this.winappdriverBin)) {
55
- throw new Error(`Could not find WinAppDriver at searched location: "${this.winappdriverBin}"`);
56
- }
57
- const baseOptions = {
58
- hostname: '127.0.0.1',
59
- port: 4723,
60
- capabilities: {
61
- app: resolveAppName(passedOptions.app),
62
- ...(passedOptions.appWorkingDir && {
63
- appWorkingDir: passedOptions.appWorkingDir,
64
- }),
65
- ...(passedOptions.appArguments && {
66
- appArguments: passedOptions.appArguments,
67
- }),
68
- // @ts-ignore
69
- 'ms:experimental-webdriver': true,
70
- },
71
- // Level of logging verbosity: trace | debug | info | warn | error
72
- logLevel: 'error',
73
- // Default timeout for all waitFor* commands.
74
- waitforTimeout: 30000,
75
- // Default timeout in milliseconds for request
76
- connectionRetryTimeout: 30000,
77
- // Default request retries count
78
- connectionRetryCount: 5,
79
- };
80
- this.webDriverOptions = Object.assign({}, baseOptions, passedOptions.webdriverOptions);
81
- this.webDriverOptions.capabilities = Object.assign(this.webDriverOptions.capabilities, (_a = passedOptions.webdriverOptions) === null || _a === void 0 ? void 0 : _a.capabilities);
82
- this.channelOptions = {
83
- enable: passedOptions.enableAutomationChannel === true,
84
- port: passedOptions.automationChannelPort || 8603,
85
- };
86
- this.breakOnStart = passedOptions.breakOnStart === true;
87
- }
88
- async setup() {
89
- await super.setup();
90
- this.winAppDriverProcess = await spawnWinAppDriver(this.winappdriverBin, this.webDriverOptions.port);
91
- this.browser = await webdriverio.remote(this.webDriverOptions);
92
- if (this.breakOnStart) {
93
- readline_sync_1.default.question(chalk_1.default.bold.yellow('Breaking before tests start\n') +
94
- 'Press Enter to resume...');
95
- }
96
- if (this.channelOptions.enable) {
97
- this.automationClient = await (0, automation_channel_1.waitForConnection)({
98
- port: this.channelOptions.port,
99
- });
100
- this.global.automationClient = this.automationClient;
101
- }
102
- this.global.remote = webdriverio.remote;
103
- this.global.browser = this.browser;
104
- this.global.$ = this.browser.$.bind(this.browser);
105
- this.global.$$ = this.browser.$$.bind(this.browser);
106
- }
107
- async teardown() {
108
- var _a;
109
- if (this.browser) {
110
- await this.browser.deleteSession();
111
- }
112
- if (this.automationClient) {
113
- this.automationClient.close();
114
- }
115
- (_a = this.winAppDriverProcess) === null || _a === void 0 ? void 0 : _a.kill('SIGINT');
116
- await super.teardown();
117
- }
118
- }
119
- exports.default = AutomationEnvironment;
120
- /**
121
- * Starts a WinAppdriver process and resolves a promise with the process once
122
- * it is ready to accept commands
123
- *
124
- * Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service
125
- */
126
- async function spawnWinAppDriver(winappdriverBin, port) {
127
- if (!fs_1.default.existsSync(winappdriverBin)) {
128
- throw new Error(`Could not locate WinAppDriver binary at "${winappdriverBin}"`);
129
- }
130
- return new Promise((resolve, reject) => {
131
- const process = (0, child_process_1.spawn)(winappdriverBin, [port.toString()], { stdio: 'pipe' });
132
- process.stdout.on('data', data => {
133
- const s = data.toString('utf16le');
134
- if (s.includes('Press ENTER to exit.')) {
135
- resolve(process);
136
- }
137
- else if (s.includes('Failed to initialize')) {
138
- reject(new Error('Failed to start WinAppDriver: ' + s));
139
- }
140
- });
141
- process.stderr.once('data', err => {
142
- console.warn(err);
143
- });
144
- process.once('exit', exitCode => {
145
- reject(new Error(`WinAppDriver CLI exited before timeout (exit code: ${exitCode})`));
146
- });
147
- });
148
- }
149
- /**
150
- * Convert a package identity or path to exe to the form expected by a WinAppDriver capability
151
- */
152
- function resolveAppName(appName) {
153
- if (appName.endsWith('.exe')) {
154
- return appName;
155
- }
156
- try {
157
- const packageFamilyName = (0, child_process_1.execSync)(`powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`)
158
- .toString()
159
- .trim();
160
- if (packageFamilyName.length === 0) {
161
- // Rethrown below
162
- throw new Error();
163
- }
164
- return `${packageFamilyName}!App`;
165
- }
166
- catch (_a) {
167
- throw new Error(`Could not locate a package with identity "${appName}"`);
168
- }
169
- }
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ *
6
+ * @format
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const chalk_1 = __importDefault(require("chalk"));
36
+ const child_process_1 = require("child_process");
37
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
38
+ const path_1 = __importDefault(require("path"));
39
+ const readline_sync_1 = __importDefault(require("readline-sync"));
40
+ const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
41
+ const webdriverio = __importStar(require("webdriverio"));
42
+ const automation_channel_1 = require("@react-native-windows/automation-channel");
43
+ class AutomationEnvironment extends jest_environment_node_1.default {
44
+ constructor(config, context) {
45
+ var _a;
46
+ super(config, context);
47
+ const passedOptions = config.projectConfig.testEnvironmentOptions;
48
+ if (!passedOptions.app) {
49
+ throw new Error('"app" must be specified in testEnvironmentOptions');
50
+ }
51
+ this.winappdriverBin =
52
+ passedOptions.winAppDriverBin ||
53
+ path_1.default.join(process.env['PROGRAMFILES(X86)'], 'Windows Application Driver\\WinAppDriver.exe');
54
+ if (!fs_1.default.existsSync(this.winappdriverBin)) {
55
+ throw new Error(`Could not find WinAppDriver at searched location: "${this.winappdriverBin}"`);
56
+ }
57
+ const baseOptions = {
58
+ hostname: '127.0.0.1',
59
+ port: 4723,
60
+ capabilities: {
61
+ app: resolveAppName(passedOptions.app),
62
+ ...(passedOptions.appWorkingDir && {
63
+ appWorkingDir: passedOptions.appWorkingDir,
64
+ }),
65
+ ...(passedOptions.appArguments && {
66
+ appArguments: passedOptions.appArguments,
67
+ }),
68
+ // @ts-ignore
69
+ 'ms:experimental-webdriver': true,
70
+ },
71
+ // Level of logging verbosity: trace | debug | info | warn | error
72
+ logLevel: 'error',
73
+ // Default timeout for all waitFor* commands.
74
+ waitforTimeout: 30000,
75
+ // Default timeout in milliseconds for request
76
+ connectionRetryTimeout: 30000,
77
+ // Default request retries count
78
+ connectionRetryCount: 5,
79
+ };
80
+ this.webDriverOptions = Object.assign({}, baseOptions, passedOptions.webdriverOptions);
81
+ this.webDriverOptions.capabilities = Object.assign(this.webDriverOptions.capabilities, (_a = passedOptions.webdriverOptions) === null || _a === void 0 ? void 0 : _a.capabilities);
82
+ this.channelOptions = {
83
+ enable: passedOptions.enableAutomationChannel === true,
84
+ port: passedOptions.automationChannelPort || 8603,
85
+ };
86
+ this.breakOnStart = passedOptions.breakOnStart === true;
87
+ }
88
+ async setup() {
89
+ await super.setup();
90
+ this.winAppDriverProcess = await spawnWinAppDriver(this.winappdriverBin, this.webDriverOptions.port);
91
+ this.browser = await webdriverio.remote(this.webDriverOptions);
92
+ if (this.breakOnStart) {
93
+ readline_sync_1.default.question(chalk_1.default.bold.yellow('Breaking before tests start\n') +
94
+ 'Press Enter to resume...');
95
+ }
96
+ if (this.channelOptions.enable) {
97
+ this.automationClient = await (0, automation_channel_1.waitForConnection)({
98
+ port: this.channelOptions.port,
99
+ });
100
+ this.global.automationClient = this.automationClient;
101
+ }
102
+ this.global.remote = webdriverio.remote;
103
+ this.global.browser = this.browser;
104
+ this.global.$ = this.browser.$.bind(this.browser);
105
+ this.global.$$ = this.browser.$$.bind(this.browser);
106
+ }
107
+ async teardown() {
108
+ var _a;
109
+ if (this.browser) {
110
+ await this.browser.deleteSession();
111
+ }
112
+ if (this.automationClient) {
113
+ this.automationClient.close();
114
+ }
115
+ (_a = this.winAppDriverProcess) === null || _a === void 0 ? void 0 : _a.kill('SIGINT');
116
+ await super.teardown();
117
+ }
118
+ }
119
+ exports.default = AutomationEnvironment;
120
+ /**
121
+ * Starts a WinAppdriver process and resolves a promise with the process once
122
+ * it is ready to accept commands
123
+ *
124
+ * Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service
125
+ */
126
+ async function spawnWinAppDriver(winappdriverBin, port) {
127
+ if (!fs_1.default.existsSync(winappdriverBin)) {
128
+ throw new Error(`Could not locate WinAppDriver binary at "${winappdriverBin}"`);
129
+ }
130
+ return new Promise((resolve, reject) => {
131
+ const process = (0, child_process_1.spawn)(winappdriverBin, [port.toString()], { stdio: 'pipe' });
132
+ process.stdout.on('data', data => {
133
+ const s = data.toString('utf16le');
134
+ if (s.includes('Press ENTER to exit.')) {
135
+ resolve(process);
136
+ }
137
+ else if (s.includes('Failed to initialize')) {
138
+ reject(new Error('Failed to start WinAppDriver: ' + s));
139
+ }
140
+ });
141
+ process.stderr.once('data', err => {
142
+ console.warn(err);
143
+ });
144
+ process.once('exit', exitCode => {
145
+ reject(new Error(`WinAppDriver CLI exited before timeout (exit code: ${exitCode})`));
146
+ });
147
+ });
148
+ }
149
+ /**
150
+ * Convert a package identity or path to exe to the form expected by a WinAppDriver capability
151
+ */
152
+ function resolveAppName(appName) {
153
+ if (appName.endsWith('.exe')) {
154
+ return appName;
155
+ }
156
+ try {
157
+ const packageFamilyName = (0, child_process_1.execSync)(`powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`)
158
+ .toString()
159
+ .trim();
160
+ if (packageFamilyName.length === 0) {
161
+ // Rethrown below
162
+ throw new Error();
163
+ }
164
+ return `${packageFamilyName}!App`;
165
+ }
166
+ catch (_a) {
167
+ throw new Error(`Could not locate a package with identity "${appName}"`);
168
+ }
169
+ }
170
170
  //# sourceMappingURL=AutomationEnvironment.js.map
@@ -1,11 +1,11 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- *
5
- * @format
6
- */
7
- import AutomationEnvironment from './AutomationEnvironment';
8
- import { app, AutomationElement } from './AutomationClient';
9
- export { app };
10
- export type { AutomationElement };
11
- export default AutomationEnvironment;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ import AutomationEnvironment from './AutomationEnvironment';
8
+ import { app, AutomationElement } from './AutomationClient';
9
+ export { app };
10
+ export type { AutomationElement };
11
+ export default AutomationEnvironment;
@@ -1,17 +1,17 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- *
6
- * @format
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.app = void 0;
13
- const AutomationEnvironment_1 = __importDefault(require("./AutomationEnvironment"));
14
- const AutomationClient_1 = require("./AutomationClient");
15
- Object.defineProperty(exports, "app", { enumerable: true, get: function () { return AutomationClient_1.app; } });
16
- exports.default = AutomationEnvironment_1.default;
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ *
6
+ * @format
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.app = void 0;
13
+ const AutomationEnvironment_1 = __importDefault(require("./AutomationEnvironment"));
14
+ const AutomationClient_1 = require("./AutomationClient");
15
+ Object.defineProperty(exports, "app", { enumerable: true, get: function () { return AutomationClient_1.app; } });
16
+ exports.default = AutomationEnvironment_1.default;
17
17
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/automation",
3
- "version": "0.3.198",
3
+ "version": "0.3.199",
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.12.116",
22
- "@react-native-windows/fs": "^0.0.0-canary.34",
21
+ "@react-native-windows/automation-channel": "^0.12.117",
22
+ "@react-native-windows/fs": "^0.0.0-canary.35",
23
23
  "@typescript-eslint/eslint-plugin": "^5.30.5",
24
24
  "@typescript-eslint/parser": "^5.57.1",
25
25
  "chalk": "^4.1.2",
@@ -30,15 +30,15 @@
30
30
  "@jest/create-cache-key-function": "^29.2.1",
31
31
  "@jest/environment": "^29.3.0",
32
32
  "@jest/types": "^29.2.1",
33
- "@rnw-scripts/eslint-config": "1.2.5",
34
- "@rnw-scripts/just-task": "2.3.21",
33
+ "@rnw-scripts/eslint-config": "1.2.6",
34
+ "@rnw-scripts/just-task": "2.3.22",
35
35
  "@rnw-scripts/ts-config": "2.0.5",
36
36
  "@types/jest": "^29.2.2",
37
37
  "@types/node": "^18.0.0",
38
38
  "@types/readline-sync": "^1.4.4",
39
39
  "eslint": "^8.19.0",
40
- "prettier": "^2.4.1",
41
- "typescript": "^4.9.5"
40
+ "prettier": "2.8.8",
41
+ "typescript": "5.0.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "jest": ">=29.0.3",