@react-native-windows/automation 0.3.198 → 0.3.200
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.
- package/lib-commonjs/AutomationClient.d.ts +70 -70
- package/lib-commonjs/AutomationClient.js +65 -65
- package/lib-commonjs/AutomationEnvironment.d.ts +60 -40
- package/lib-commonjs/AutomationEnvironment.js +227 -169
- package/lib-commonjs/AutomationEnvironment.js.map +1 -1
- package/lib-commonjs/index.d.ts +11 -11
- package/lib-commonjs/index.js +16 -16
- package/package.json +7 -7
|
@@ -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,60 @@
|
|
|
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
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
+
* Instead of letting WinAppDriver launch and attach to the app directly,
|
|
20
|
+
* create a Root (Desktop) session and search for the app's window.
|
|
21
|
+
*
|
|
22
|
+
* Note: This is only really necessary to correctly attach to packaged
|
|
23
|
+
* WinAppSDK apps.
|
|
24
|
+
*/
|
|
25
|
+
useRootSession?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* When using a Root (Desktop) session, still launch the test app during setup
|
|
28
|
+
* and close it during cleanup.
|
|
29
|
+
*
|
|
30
|
+
* Defaults to true when using `useRootSession` to mimic the expected test
|
|
31
|
+
* behavior, but can be disabled if you're trying to test an already
|
|
32
|
+
* running app instance.
|
|
33
|
+
*/
|
|
34
|
+
rootLaunchApp?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Arguments to be passed to your application when launched
|
|
37
|
+
*/
|
|
38
|
+
appArguments?: string;
|
|
39
|
+
appWorkingDir?: string;
|
|
40
|
+
enableAutomationChannel?: boolean;
|
|
41
|
+
automationChannelPort?: number;
|
|
42
|
+
winAppDriverBin?: string;
|
|
43
|
+
breakOnStart?: boolean;
|
|
44
|
+
webdriverOptions?: RemoteOptions;
|
|
45
|
+
};
|
|
46
|
+
export default class AutomationEnvironment extends NodeEnvironment {
|
|
47
|
+
private readonly rootWebDriverOptions?;
|
|
48
|
+
private readonly webDriverOptions;
|
|
49
|
+
private readonly channelOptions;
|
|
50
|
+
private readonly winappdriverBin;
|
|
51
|
+
private readonly breakOnStart;
|
|
52
|
+
private readonly useRootSession;
|
|
53
|
+
private readonly rootLaunchApp;
|
|
54
|
+
private winAppDriverProcess;
|
|
55
|
+
private browser;
|
|
56
|
+
private automationClient;
|
|
57
|
+
constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
|
|
58
|
+
setup(): Promise<void>;
|
|
59
|
+
teardown(): Promise<void>;
|
|
60
|
+
}
|
|
@@ -1,170 +1,228 @@
|
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
// Level of logging verbosity: trace | debug | info | warn | error
|
|
61
|
+
logLevel: 'error',
|
|
62
|
+
// Default timeout for all waitFor* commands.
|
|
63
|
+
waitforTimeout: 30000,
|
|
64
|
+
// Default timeout in milliseconds for request
|
|
65
|
+
connectionRetryTimeout: 30000,
|
|
66
|
+
// Default request retries count
|
|
67
|
+
connectionRetryCount: 5,
|
|
68
|
+
};
|
|
69
|
+
this.useRootSession = !!passedOptions.useRootSession;
|
|
70
|
+
this.rootLaunchApp =
|
|
71
|
+
passedOptions.rootLaunchApp === undefined
|
|
72
|
+
? this.useRootSession
|
|
73
|
+
: !!passedOptions.rootLaunchApp;
|
|
74
|
+
if (this.useRootSession) {
|
|
75
|
+
this.rootWebDriverOptions = Object.assign({}, baseOptions, {
|
|
76
|
+
capabilities: {
|
|
77
|
+
app: 'Root',
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
'ms:experimental-webdriver': true,
|
|
80
|
+
},
|
|
81
|
+
}, passedOptions.webdriverOptions);
|
|
82
|
+
this.webDriverOptions = Object.assign({}, baseOptions, {
|
|
83
|
+
capabilities: {
|
|
84
|
+
// Save the name for now, we'll get the handle later
|
|
85
|
+
appTopLevelWindow: passedOptions.app,
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
'ms:experimental-webdriver': true,
|
|
88
|
+
},
|
|
89
|
+
}, passedOptions.webdriverOptions);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.webDriverOptions = Object.assign({}, baseOptions, {
|
|
93
|
+
capabilities: {
|
|
94
|
+
app: resolveAppName(passedOptions.app),
|
|
95
|
+
...(passedOptions.appWorkingDir && {
|
|
96
|
+
appWorkingDir: passedOptions.appWorkingDir,
|
|
97
|
+
}),
|
|
98
|
+
...(passedOptions.appArguments && {
|
|
99
|
+
appArguments: passedOptions.appArguments,
|
|
100
|
+
}),
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
'ms:experimental-webdriver': true,
|
|
103
|
+
},
|
|
104
|
+
}, passedOptions.webdriverOptions);
|
|
105
|
+
}
|
|
106
|
+
this.webDriverOptions.capabilities = Object.assign(this.webDriverOptions.capabilities, (_a = passedOptions.webdriverOptions) === null || _a === void 0 ? void 0 : _a.capabilities);
|
|
107
|
+
this.channelOptions = {
|
|
108
|
+
enable: passedOptions.enableAutomationChannel === true,
|
|
109
|
+
port: passedOptions.automationChannelPort || 8603,
|
|
110
|
+
};
|
|
111
|
+
this.breakOnStart = passedOptions.breakOnStart === true;
|
|
112
|
+
}
|
|
113
|
+
async setup() {
|
|
114
|
+
await super.setup();
|
|
115
|
+
this.winAppDriverProcess = await spawnWinAppDriver(this.winappdriverBin, this.webDriverOptions.port);
|
|
116
|
+
if (this.useRootSession) {
|
|
117
|
+
// Extract out the saved window name
|
|
118
|
+
const appName = this.webDriverOptions.capabilities
|
|
119
|
+
.appTopLevelWindow;
|
|
120
|
+
if (this.rootLaunchApp) {
|
|
121
|
+
const appPackageName = resolveAppName(appName);
|
|
122
|
+
(0, child_process_1.execSync)(`start shell:AppsFolder\\${appPackageName}`);
|
|
123
|
+
}
|
|
124
|
+
// Set up the "Desktop" or Root session
|
|
125
|
+
const rootBrowser = await webdriverio.remote(this.rootWebDriverOptions);
|
|
126
|
+
// Get the list of windows
|
|
127
|
+
const allWindows = await rootBrowser.$$('//Window');
|
|
128
|
+
// Find our target window
|
|
129
|
+
let appWindow;
|
|
130
|
+
for (const window of allWindows) {
|
|
131
|
+
if ((await window.getAttribute('Name')) === appName) {
|
|
132
|
+
appWindow = window;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!appWindow) {
|
|
137
|
+
throw new Error(`Unable to find window with Name === '${appName}'.`);
|
|
138
|
+
}
|
|
139
|
+
// Swap the the window handle for WinAppDriver
|
|
140
|
+
const appWindowHandle = parseInt(await appWindow.getAttribute('NativeWindowHandle'), 10);
|
|
141
|
+
this.webDriverOptions.capabilities.appTopLevelWindow =
|
|
142
|
+
'0x' + appWindowHandle.toString(16);
|
|
143
|
+
await rootBrowser.deleteSession();
|
|
144
|
+
}
|
|
145
|
+
this.browser = await webdriverio.remote(this.webDriverOptions);
|
|
146
|
+
if (this.breakOnStart) {
|
|
147
|
+
readline_sync_1.default.question(chalk_1.default.bold.yellow('Breaking before tests start\n') +
|
|
148
|
+
'Press Enter to resume...');
|
|
149
|
+
}
|
|
150
|
+
if (this.channelOptions.enable) {
|
|
151
|
+
this.automationClient = await (0, automation_channel_1.waitForConnection)({
|
|
152
|
+
port: this.channelOptions.port,
|
|
153
|
+
});
|
|
154
|
+
this.global.automationClient = this.automationClient;
|
|
155
|
+
}
|
|
156
|
+
this.global.remote = webdriverio.remote;
|
|
157
|
+
this.global.browser = this.browser;
|
|
158
|
+
this.global.$ = this.browser.$.bind(this.browser);
|
|
159
|
+
this.global.$$ = this.browser.$$.bind(this.browser);
|
|
160
|
+
}
|
|
161
|
+
async teardown() {
|
|
162
|
+
var _a;
|
|
163
|
+
if (this.automationClient) {
|
|
164
|
+
this.automationClient.close();
|
|
165
|
+
}
|
|
166
|
+
if (this.browser) {
|
|
167
|
+
if (this.rootLaunchApp) {
|
|
168
|
+
// We started the app, so let's close it too
|
|
169
|
+
await this.browser.closeWindow();
|
|
170
|
+
}
|
|
171
|
+
await this.browser.deleteSession();
|
|
172
|
+
}
|
|
173
|
+
(_a = this.winAppDriverProcess) === null || _a === void 0 ? void 0 : _a.kill('SIGINT');
|
|
174
|
+
await super.teardown();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.default = AutomationEnvironment;
|
|
178
|
+
/**
|
|
179
|
+
* Starts a WinAppdriver process and resolves a promise with the process once
|
|
180
|
+
* it is ready to accept commands
|
|
181
|
+
*
|
|
182
|
+
* Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service
|
|
183
|
+
*/
|
|
184
|
+
async function spawnWinAppDriver(winappdriverBin, port) {
|
|
185
|
+
if (!fs_1.default.existsSync(winappdriverBin)) {
|
|
186
|
+
throw new Error(`Could not locate WinAppDriver binary at "${winappdriverBin}"`);
|
|
187
|
+
}
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
const process = (0, child_process_1.spawn)(winappdriverBin, [port.toString()], { stdio: 'pipe' });
|
|
190
|
+
process.stdout.on('data', data => {
|
|
191
|
+
const s = data.toString('utf16le');
|
|
192
|
+
if (s.includes('Press ENTER to exit.')) {
|
|
193
|
+
resolve(process);
|
|
194
|
+
}
|
|
195
|
+
else if (s.includes('Failed to initialize')) {
|
|
196
|
+
reject(new Error('Failed to start WinAppDriver: ' + s));
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
process.stderr.once('data', err => {
|
|
200
|
+
console.warn(err);
|
|
201
|
+
});
|
|
202
|
+
process.once('exit', exitCode => {
|
|
203
|
+
reject(new Error(`WinAppDriver CLI exited before timeout (exit code: ${exitCode})`));
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Convert a package identity or path to exe to the form expected by a WinAppDriver capability
|
|
209
|
+
*/
|
|
210
|
+
function resolveAppName(appName) {
|
|
211
|
+
if (appName.endsWith('.exe')) {
|
|
212
|
+
return appName;
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const packageFamilyName = (0, child_process_1.execSync)(`powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`)
|
|
216
|
+
.toString()
|
|
217
|
+
.trim();
|
|
218
|
+
if (packageFamilyName.length === 0) {
|
|
219
|
+
// Rethrown below
|
|
220
|
+
throw new Error();
|
|
221
|
+
}
|
|
222
|
+
return `${packageFamilyName}!App`;
|
|
223
|
+
}
|
|
224
|
+
catch (_a) {
|
|
225
|
+
throw new Error(`Could not locate a package with identity "${appName}"`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
170
228
|
//# sourceMappingURL=AutomationEnvironment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutomationEnvironment.js","sourceRoot":"","sources":["../src/AutomationEnvironment.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAA0B;AAC1B,iDAA4D;AAC5D,kEAA0C;AAC1C,gDAAwB;AACxB,kEAAyC;AAEzC,kFAAoD;AACpD,yDAA2C;AAI3C,iFAGkD;AA4BlD,MAAqB,qBAAsB,SAAQ,+BAAe;IAShE,YAAY,MAA6B,EAAE,OAA2B;;QACpE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB,MAAM,aAAa,GACjB,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC;QAE9C,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;SACtE;QAED,IAAI,CAAC,eAAe;YAClB,aAAa,CAAC,eAAe;gBAC7B,cAAI,CAAC,IAAI,CACP,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAE,EACjC,8CAA8C,CAC/C,CAAC;QAEJ,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;YACxC,MAAM,IAAI,KAAK,CACb,sDAAsD,IAAI,CAAC,eAAe,GAAG,CAC9E,CAAC;SACH;QAED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,CAAC,MAAM,CAAC,EAAE;QAC5B,OAAO,OAAO,CAAC;KAChB;IAED,IAAI;QACF,MAAM,iBAAiB,GAAG,IAAA,wBAAQ,EAChC,qCAAqC,OAAO,qBAAqB,CAClE;aACE,QAAQ,EAAE;aACV,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,WAAM;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 {execSync, 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 * 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 webDriverOptions: RemoteOptions;\n private readonly channelOptions: AutomationChannelOptions;\n private readonly winappdriverBin: string;\n private readonly breakOnStart: 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 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 // 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.webDriverOptions = Object.assign(\n {},\n baseOptions,\n passedOptions.webdriverOptions,\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 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.browser) {\n await this.browser.deleteSession();\n }\n\n if (this.automationClient) {\n this.automationClient.close();\n }\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 = execSync(\n `powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`,\n )\n .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 ident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AE;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,wBAAQ,EAChC,qCAAqC,OAAO,qBAAqB,CAClE;aACE,QAAQ,EAAE;aACV,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,WAAM;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 {execSync, 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 execSync(`start shell:AppsFolder\\\\${appPackageName}`);\n }\n\n // Set up the \"Desktop\" or Root session\n const rootBrowser = await webdriverio.remote(this.rootWebDriverOptions);\n\n // Get the list of windows\n const allWindows = await rootBrowser.$$('//Window');\n\n // Find our target window\n let appWindow: webdriverio.Element | undefined;\n for (const window of allWindows) {\n if ((await window.getAttribute('Name')) === appName) {\n appWindow = window;\n break;\n }\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 = execSync(\n `powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`,\n )\n .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/lib-commonjs/index.d.ts
CHANGED
|
@@ -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;
|
package/lib-commonjs/index.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.3.200",
|
|
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.
|
|
22
|
-
"@react-native-windows/fs": "^0.0.0-canary.
|
|
21
|
+
"@react-native-windows/automation-channel": "^0.12.118",
|
|
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.
|
|
34
|
-
"@rnw-scripts/just-task": "2.3.
|
|
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": "
|
|
41
|
-
"typescript": "
|
|
40
|
+
"prettier": "2.8.8",
|
|
41
|
+
"typescript": "5.0.4"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"jest": ">=29.0.3",
|