Add e2etest:debug (`@react-native-windows/automation` option `breakOnStart`) (#9085)

* Add `e2etest:debug`

Adds "break on start` to UI automation infrastructure.

Validated locally that the test is paused with the native app open before hitting enter, and that the test resumes after.

* Change files

* lockfile

* Update packages/@react-native-windows/automation/README.md
This commit is contained in:
Nick Gerleman 2021-11-08 11:59:37 -08:00 коммит произвёл GitHub
Родитель c847ffbdc2
Коммит 3a060ca153
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 56 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Add `breakOnStart` option",
"packageName": "@react-native-windows/automation",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "patch"
}

Просмотреть файл

@ -41,6 +41,10 @@ module.exports = {
⚠ Only the test filename (without the rest of the path) should be included.
> C:\repo\react-native-windows\packages\e2e-test-app> `yarn e2etest visitAllPages.test.ts`
**Break on app start**
> C:\repo\react-native-windows\packages\e2e-test-app> `yarn e2etest:debug visitAllPages.test.ts`
## Debugging E2E Tests in CI
### Increasing verbosity
By default the only messages printed during tests are related to errors returned by WinAppDriver or assertion failures. It is possible to increase verbosity to show individual WebDriver wire commands by editing [`/packages/e2e-test-app/jest.config.js`](../packages/e2e-test-app/jest.config.js).

Просмотреть файл

@ -67,6 +67,9 @@ testEnvironmentOptions: {
// "%PROGRAMFILES(X86)%\Windows Application Driver\WinAppDriver.exe"
winAppDriverBin: 'D:\\WinAppDriver.exe',
// Optional: Whether to break on app launch, before starting tests
breakOnStart: false,
// Optional: Options to be passed to WebDriverIO
// See https://webdriver.io/docs/options/
webdriverOptions: {

Просмотреть файл

@ -15,6 +15,8 @@
},
"dependencies": {
"@react-native-windows/automation-channel": "^0.0.25",
"chalk": "^4.1.2",
"readline-sync": "1.4.10",
"webdriverio": "^6.9.0"
},
"devDependencies": {
@ -24,6 +26,7 @@
"@rnw-scripts/ts-config": "2.0.1",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.22",
"@types/readline-sync": "^1.4.4",
"eslint": "7.12.0",
"just-scripts": "^1.3.3",
"prettier": "1.19.1",

Просмотреть файл

@ -5,9 +5,11 @@
* @format
*/
import chalk from 'chalk';
import {execSync, spawn, ChildProcess} from 'child_process';
import fs from 'fs';
import path from 'path';
import readlineSync from 'readline-sync';
import NodeEnvironment = require('jest-environment-node');
@ -34,6 +36,7 @@ export type EnvironmentOptions = {
enableAutomationChannel?: boolean;
automationChannelPort?: number;
winAppDriverBin?: string;
breakOnStart?: boolean;
webdriverOptions?: RemoteOptions;
};
@ -46,6 +49,7 @@ export default class AutomationEnvironment extends NodeEnvironment {
private readonly webDriverOptions: RemoteOptions;
private readonly channelOptions: AutomationChannelOptions;
private readonly winappdriverBin: string;
private readonly breakOnStart: boolean;
private winAppDriverProcess: ChildProcess | undefined;
private browser: BrowserObject | undefined;
private automationClient: AutomationClient | undefined;
@ -111,17 +115,26 @@ export default class AutomationEnvironment extends NodeEnvironment {
enable: passedOptions.enableAutomationChannel === true,
port: passedOptions.automationChannelPort || 8603,
};
this.breakOnStart = passedOptions.breakOnStart === true;
}
async setup() {
await super.setup();
this.winAppDriverProcess = await spawnWinAppDriver(
this.winappdriverBin,
this.webDriverOptions.port!,
);
this.browser = await webdriverio.remote(this.webDriverOptions);
if (this.breakOnStart) {
readlineSync.question(
chalk.bold.yellow('Breaking before tests start\n') +
'Press Enter to resume...',
);
}
if (this.channelOptions.enable) {
this.automationClient = await waitForConnection({
port: this.channelOptions.port,

Просмотреть файл

@ -0,0 +1,12 @@
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* @format
* @ts-check
*/
const config = require('./jest.config');
config.testEnvironmentOptions.breakOnStart = true;
module.exports = config;

Просмотреть файл

@ -8,7 +8,8 @@
"lint:fix": "rnw-scripts lint:fix",
"watch": "rnw-scripts watch",
"windows": "react-native run-windows",
"e2etest": "jest --color"
"e2etest": "jest --color",
"e2etest:debug": "jest --color --config ./jest.debug.config.js"
},
"dependencies": {
"@react-native-picker/picker": "2.2.0",

Просмотреть файл

@ -2118,6 +2118,11 @@
"@types/scheduler" "*"
csstype "^3.0.2"
"@types/readline-sync@^1.4.4":
version "1.4.4"
resolved "https://registry.yarnpkg.com/@types/readline-sync/-/readline-sync-1.4.4.tgz#8568292efe4ddd94d0ccee958b29cc3f4e0ea140"
integrity sha512-cFjVIoiamX7U6zkO2VPvXyTxbFDdiRo902IarJuPVxBhpDnXhwSaVE86ip+SCuyWBbEioKCkT4C88RNTxBM1Dw==
"@types/responselike@*", "@types/responselike@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29"
@ -3486,7 +3491,7 @@ chai@^4.2.0:
pathval "^1.1.1"
type-detect "^4.0.5"
chalk@*, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1:
chalk@*, chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
@ -9237,6 +9242,11 @@ readdirp@^3.5.0, readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"
readline-sync@1.4.10:
version "1.4.10"
resolved "https://registry.yarnpkg.com/readline-sync/-/readline-sync-1.4.10.tgz#41df7fbb4b6312d673011594145705bf56d8873b"
integrity sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==
readline@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c"