@uuv/playwright 3.37.0 → 3.39.0
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/dist/cucumber/step_definitions/playwright/core-engine.js +0 -1
- package/dist/cucumber/step_definitions/playwright/generated/_en-generated-cucumber-steps-definition.js +40 -0
- package/dist/cucumber/step_definitions/playwright/generated/_fr-generated-cucumber-steps-definition.js +40 -0
- package/dist/cucumber/step_definitions/playwright/generated/enriched/fr/_fr-generated-steps-definition_table.js +8 -8
- package/dist/lib/runner-playwright.d.ts +4 -1
- package/dist/lib/runner-playwright.js +40 -6
- package/dist/lib/watch-test-files.js +10 -7
- package/package.json +2 -2
- package/src/cucumber/step_definitions/playwright/generated/_en-generated-cucumber-steps-definition.ts +53 -3
- package/src/cucumber/step_definitions/playwright/generated/_fr-generated-cucumber-steps-definition.ts +53 -3
- package/src/cucumber/step_definitions/playwright/generated/enriched/fr/_fr-generated-steps-definition_table.ts +8 -8
|
@@ -302,7 +302,6 @@ async function click(world, role, name) {
|
|
|
302
302
|
});
|
|
303
303
|
await (0, test_1.expect)(byRole).toHaveCount(1, { timeout: await getTimeout(world) });
|
|
304
304
|
await byRole.click();
|
|
305
|
-
await world.page.waitForLoadState();
|
|
306
305
|
await deleteCookieByName(world, COOKIE_NAME.SELECTED_ELEMENT);
|
|
307
306
|
});
|
|
308
307
|
}
|
|
@@ -456,6 +456,46 @@ function getConfigDir() {
|
|
|
456
456
|
await (0, test_1.expect)(foundedElement).toEqual(expectedElementsOfList.raw());
|
|
457
457
|
});
|
|
458
458
|
});
|
|
459
|
+
/**
|
|
460
|
+
* Checks that there is a list with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nThen I should see a list named "test-list" and containing\n| First element |\n| Second element |\n| Third element |\n```
|
|
461
|
+
* */
|
|
462
|
+
(0, world_1.Then)(`I should see a grid named {string} and containing`, async function (expectedListName, pExpectedElementsOfList) {
|
|
463
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
464
|
+
await (0, core_engine_1.findWithRoleAndName)(this, "grid", expectedListName);
|
|
465
|
+
await (0, core_engine_1.getPageOrElement)(this).then(async (element) => {
|
|
466
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "gridcell");
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
/**
|
|
470
|
+
* Checks that there is a table with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nThen I should see a list named "test-list" and containing\n| First element |\n| Second element |\n| Third element |\n```
|
|
471
|
+
* */
|
|
472
|
+
(0, world_1.Then)(`I should see a table named {string} and containing`, async function (expectedListName, pExpectedElementsOfList) {
|
|
473
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
474
|
+
await (0, core_engine_1.findWithRoleAndName)(this, "table", expectedListName);
|
|
475
|
+
await (0, core_engine_1.getPageOrElement)(this).then(async (element) => {
|
|
476
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "cell");
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
function removeHeaderSeparatorLine(pExpectedElementsOfList) {
|
|
480
|
+
const expectedElementsOfList = pExpectedElementsOfList.raw();
|
|
481
|
+
if (expectedElementsOfList.length > 1) {
|
|
482
|
+
expectedElementsOfList.splice(1, 1);
|
|
483
|
+
}
|
|
484
|
+
return expectedElementsOfList;
|
|
485
|
+
}
|
|
486
|
+
async function expectTableToHaveContent(element, expectedElementsOfList, pCellAccessibleRole) {
|
|
487
|
+
const rows = await element.getByRole("row", { exact: true }).all();
|
|
488
|
+
return await Promise.all(rows.map(async (row, rowNumber) => {
|
|
489
|
+
const cellAccessibleRole = rowNumber === 0 ? "columnheader" : pCellAccessibleRole;
|
|
490
|
+
const cellsElement = await row.getByRole(cellAccessibleRole, { exact: true }).all();
|
|
491
|
+
let cellNumber = 0;
|
|
492
|
+
return await Promise.all(cellsElement.map((cell) => {
|
|
493
|
+
const expectedValue = expectedElementsOfList[rowNumber][cellNumber];
|
|
494
|
+
(0, test_1.expect)(cell, { message: `${cellAccessibleRole} at index [${rowNumber}, ${cellNumber}] should be ${expectedValue}` }).toHaveAccessibleName(expectedValue);
|
|
495
|
+
cellNumber++;
|
|
496
|
+
}));
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
459
499
|
async function pressKey(world, key) {
|
|
460
500
|
switch (key) {
|
|
461
501
|
case runner_commons_1.KEY_PRESS.TAB:
|
|
@@ -456,6 +456,46 @@ function getConfigDir() {
|
|
|
456
456
|
await (0, test_1.expect)(foundedElement).toEqual(expectedElementsOfList.raw());
|
|
457
457
|
});
|
|
458
458
|
});
|
|
459
|
+
/**
|
|
460
|
+
* Vérifie qu'il existe une liste avec le nom et les éléments de liste spécifiés.<br/> <u>Exemple</u>\n```gherkin\nAlors je dois voir une liste nommée "test-list" et contenant\n| Premier élément |\n| Deuxième élément |\n| Troisième élément |\n```
|
|
461
|
+
* */
|
|
462
|
+
(0, world_1.Then)(`je dois voir une grille nommée {string} et contenant`, async function (expectedListName, pExpectedElementsOfList) {
|
|
463
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
464
|
+
await (0, core_engine_1.findWithRoleAndName)(this, "grid", expectedListName);
|
|
465
|
+
await (0, core_engine_1.getPageOrElement)(this).then(async (element) => {
|
|
466
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "gridcell");
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
/**
|
|
470
|
+
* Vérifie qu'il existe une liste avec le nom et les éléments de liste spécifiés.<br/> <u>Exemple</u>\n```gherkin\nAlors je dois voir une liste nommée "test-list" et contenant\n| Premier élément |\n| Deuxième élément |\n| Troisième élément |\n```
|
|
471
|
+
* */
|
|
472
|
+
(0, world_1.Then)(`je dois voir un tableau nommé {string} et contenant`, async function (expectedListName, pExpectedElementsOfList) {
|
|
473
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
474
|
+
await (0, core_engine_1.findWithRoleAndName)(this, "table", expectedListName);
|
|
475
|
+
await (0, core_engine_1.getPageOrElement)(this).then(async (element) => {
|
|
476
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "cell");
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
function removeHeaderSeparatorLine(pExpectedElementsOfList) {
|
|
480
|
+
const expectedElementsOfList = pExpectedElementsOfList.raw();
|
|
481
|
+
if (expectedElementsOfList.length > 1) {
|
|
482
|
+
expectedElementsOfList.splice(1, 1);
|
|
483
|
+
}
|
|
484
|
+
return expectedElementsOfList;
|
|
485
|
+
}
|
|
486
|
+
async function expectTableToHaveContent(element, expectedElementsOfList, pCellAccessibleRole) {
|
|
487
|
+
const rows = await element.getByRole("row", { exact: true }).all();
|
|
488
|
+
return await Promise.all(rows.map(async (row, rowNumber) => {
|
|
489
|
+
const cellAccessibleRole = rowNumber === 0 ? "columnheader" : pCellAccessibleRole;
|
|
490
|
+
const cellsElement = await row.getByRole(cellAccessibleRole, { exact: true }).all();
|
|
491
|
+
let cellNumber = 0;
|
|
492
|
+
return await Promise.all(cellsElement.map((cell) => {
|
|
493
|
+
const expectedValue = expectedElementsOfList[rowNumber][cellNumber];
|
|
494
|
+
(0, test_1.expect)(cell, { message: `${cellAccessibleRole} at index [${rowNumber}, ${cellNumber}] should be ${expectedValue}` }).toHaveAccessibleName(expectedValue);
|
|
495
|
+
cellNumber++;
|
|
496
|
+
}));
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
459
499
|
async function pressKey(world, key) {
|
|
460
500
|
switch (key) {
|
|
461
501
|
case runner_commons_1.KEY_PRESS.TAB:
|
|
@@ -22,19 +22,19 @@ const test_1 = require("@playwright/test");
|
|
|
22
22
|
/**
|
|
23
23
|
* Sélectionne l'élément ayant le rôle table et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) sont spécifiés <br />⚠ pensez à déselectionner l'élement avec <b>[je reinitialise le contexte](#je-reinitialise-le-contexte)</b> si vous n'agissez plus dessus
|
|
24
24
|
* */
|
|
25
|
-
(0, world_1.When)(`je vais à l'intérieur
|
|
25
|
+
(0, world_1.When)(`je vais à l'intérieur du tableau nommé {string}`, async function (name) {
|
|
26
26
|
return await (0, core_engine_1.withinRoleAndName)(this, "table", name);
|
|
27
27
|
});
|
|
28
28
|
/**
|
|
29
29
|
* Vérifie l'existence d'un élément Html ayant le rôle table et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
|
|
30
30
|
* */
|
|
31
|
-
(0, world_1.Then)(`je dois voir
|
|
31
|
+
(0, world_1.Then)(`je dois voir un tableau nommé {string}`, async function (name) {
|
|
32
32
|
await (0, core_engine_1.findWithRoleAndName)(this, "table", name);
|
|
33
33
|
});
|
|
34
34
|
/**
|
|
35
35
|
* Vérifie l'inexistence d'un élément Html ayant le rôle table et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
|
|
36
36
|
* */
|
|
37
|
-
(0, world_1.Then)(`je ne dois pas voir
|
|
37
|
+
(0, world_1.Then)(`je ne dois pas voir un tableau nommé {string}`, async function (name) {
|
|
38
38
|
await (0, core_engine_1.notFoundWithRoleAndName)(this, "table", name);
|
|
39
39
|
});
|
|
40
40
|
// End of General Section
|
|
@@ -42,7 +42,7 @@ const test_1 = require("@playwright/test");
|
|
|
42
42
|
/**
|
|
43
43
|
* Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire).
|
|
44
44
|
* */
|
|
45
|
-
(0, world_1.When)(`je saisie le(s) mot(s) {string} dans le tableau
|
|
45
|
+
(0, world_1.When)(`je saisie le(s) mot(s) {string} dans le tableau nommé {string}`, async function (textToType, name) {
|
|
46
46
|
await (0, core_engine_1.getPageOrElement)(this).then(async (element) => {
|
|
47
47
|
const byRole = await element.getByRole("table", { name: name, exact: true });
|
|
48
48
|
await (0, test_1.expect)(byRole).toHaveCount(1, { timeout: await (0, core_engine_1.getTimeout)(this) });
|
|
@@ -53,7 +53,7 @@ const test_1 = require("@playwright/test");
|
|
|
53
53
|
/**
|
|
54
54
|
* Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire).
|
|
55
55
|
* */
|
|
56
|
-
(0, world_1.When)(`j'entre la valeur {string} dans le tableau
|
|
56
|
+
(0, world_1.When)(`j'entre la valeur {string} dans le tableau nommé {string}`, async function (textToType, name) {
|
|
57
57
|
await (0, core_engine_1.getPageOrElement)(this).then(async (element) => {
|
|
58
58
|
const byRole = await element.getByRole("table", { name: name, includeHidden: true, exact: true });
|
|
59
59
|
await (0, test_1.expect)(byRole).toHaveCount(1);
|
|
@@ -66,19 +66,19 @@ const test_1 = require("@playwright/test");
|
|
|
66
66
|
/**
|
|
67
67
|
* Vérifie l'existence d'un élément Html ayant le rôle table, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés
|
|
68
68
|
* */
|
|
69
|
-
(0, world_1.Then)(`je dois voir
|
|
69
|
+
(0, world_1.Then)(`je dois voir un tableau nommé {string} et contenant {string}`, async function (name, expectedTextContent) {
|
|
70
70
|
await (0, core_engine_1.findWithRoleAndNameAndContent)(this, "table", name, expectedTextContent);
|
|
71
71
|
});
|
|
72
72
|
/**
|
|
73
73
|
* Vérifie l'existence d'un élément Html ayant le rôle table, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à false
|
|
74
74
|
* */
|
|
75
|
-
(0, world_1.Then)(`je dois voir
|
|
75
|
+
(0, world_1.Then)(`je dois voir un tableau nommé {string} et contenant {string} inactif`, async function (name, expectedTextContent) {
|
|
76
76
|
await (0, core_engine_1.findWithRoleAndNameAndContentDisable)(this, "table", name, expectedTextContent);
|
|
77
77
|
});
|
|
78
78
|
/**
|
|
79
79
|
* Vérifie l'existence d'un élément Html ayant le rôle table, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à true
|
|
80
80
|
* */
|
|
81
|
-
(0, world_1.Then)(`je dois voir
|
|
81
|
+
(0, world_1.Then)(`je dois voir un tableau nommé {string} et contenant {string} actif`, async function (name, expectedTextContent) {
|
|
82
82
|
await (0, core_engine_1.findWithRoleAndNameAndContentEnable)(this, "table", name, expectedTextContent);
|
|
83
83
|
});
|
|
84
84
|
// End of Content Section
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
* understanding English or French.
|
|
12
12
|
*/
|
|
13
13
|
import { UUVCliOptions, UUVCliRunner } from "@uuv/runner-commons";
|
|
14
|
+
import cp from "child_process";
|
|
14
15
|
export declare class UUVCliPlaywrightRunner implements UUVCliRunner {
|
|
15
16
|
projectDir: any;
|
|
16
17
|
private tempDir;
|
|
17
18
|
name: string;
|
|
18
19
|
defaultBrowser: string;
|
|
20
|
+
watchProcess?: cp.ChildProcess | null;
|
|
19
21
|
constructor(projectDir: any, tempDir: any);
|
|
20
22
|
getCurrentVersion(): string;
|
|
21
23
|
prepare(options: Partial<UUVCliOptions>): Promise<void>;
|
|
@@ -26,5 +28,6 @@ export declare class UUVCliPlaywrightRunner implements UUVCliRunner {
|
|
|
26
28
|
private runPlaywright;
|
|
27
29
|
private buildCommand;
|
|
28
30
|
private executeSystemCommand;
|
|
31
|
+
private cleanup;
|
|
29
32
|
}
|
|
30
|
-
export declare function executePreprocessor(projectDir: string):
|
|
33
|
+
export declare function executePreprocessor(projectDir: string): boolean;
|
|
@@ -61,6 +61,7 @@ class UUVCliPlaywrightRunner {
|
|
|
61
61
|
tempDir;
|
|
62
62
|
name = "Playwright";
|
|
63
63
|
defaultBrowser = "chrome";
|
|
64
|
+
watchProcess;
|
|
64
65
|
constructor(projectDir, tempDir) {
|
|
65
66
|
this.projectDir = projectDir;
|
|
66
67
|
this.tempDir = tempDir;
|
|
@@ -72,9 +73,14 @@ class UUVCliPlaywrightRunner {
|
|
|
72
73
|
return JSON.parse(pJsonStr).version;
|
|
73
74
|
}
|
|
74
75
|
async prepare(options) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
try {
|
|
77
|
+
console.log("running preprocessor...");
|
|
78
|
+
this.executeSystemCommand(`npx bddgen -c ${this.projectDir}/playwright.config.ts`);
|
|
79
|
+
console.log("preprocessor executed\n");
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
console.warn(chalk_1.default.redBright("An error occured during preprocessor, please be sure to use existing step definitions"));
|
|
83
|
+
}
|
|
78
84
|
this.setEnvironmentVariables(options);
|
|
79
85
|
}
|
|
80
86
|
setEnvironmentVariables(options) {
|
|
@@ -95,7 +101,20 @@ class UUVCliPlaywrightRunner {
|
|
|
95
101
|
this.runPlaywright(options);
|
|
96
102
|
}
|
|
97
103
|
executeOpenCommand(options) {
|
|
98
|
-
child_process_1.default.fork(path_1.default.join(__dirname, "watch-test-files"), [this.tempDir, this.projectDir]);
|
|
104
|
+
this.watchProcess = child_process_1.default.fork(path_1.default.join(__dirname, "watch-test-files"), [this.tempDir, this.projectDir]);
|
|
105
|
+
process.on("exit", () => this.cleanup(this.watchProcess));
|
|
106
|
+
process.on("SIGINT", () => {
|
|
107
|
+
this.cleanup(this.watchProcess);
|
|
108
|
+
process.exit();
|
|
109
|
+
});
|
|
110
|
+
process.on("SIGTERM", () => {
|
|
111
|
+
this.cleanup(this.watchProcess);
|
|
112
|
+
process.exit();
|
|
113
|
+
});
|
|
114
|
+
process.on("uncaughtException", (err) => {
|
|
115
|
+
this.cleanup(this.watchProcess);
|
|
116
|
+
throw err;
|
|
117
|
+
});
|
|
99
118
|
this.runPlaywright(options);
|
|
100
119
|
}
|
|
101
120
|
getTargetTestFileForPlaywright(targetTestFile) {
|
|
@@ -145,6 +164,14 @@ class UUVCliPlaywrightRunner {
|
|
|
145
164
|
executeSystemCommand(command) {
|
|
146
165
|
executeSystemCommandHelper(command);
|
|
147
166
|
}
|
|
167
|
+
cleanup(watchProcess) {
|
|
168
|
+
if (watchProcess) {
|
|
169
|
+
console.log("Stopping file watcher...");
|
|
170
|
+
watchProcess.kill();
|
|
171
|
+
console.log("File watcher stopped");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
;
|
|
148
175
|
}
|
|
149
176
|
exports.UUVCliPlaywrightRunner = UUVCliPlaywrightRunner;
|
|
150
177
|
function executeSystemCommandHelper(command) {
|
|
@@ -153,6 +180,13 @@ function executeSystemCommandHelper(command) {
|
|
|
153
180
|
}
|
|
154
181
|
function executePreprocessor(projectDir) {
|
|
155
182
|
console.log("running preprocessor...");
|
|
156
|
-
|
|
157
|
-
|
|
183
|
+
try {
|
|
184
|
+
executeSystemCommandHelper(`npx bddgen -c ${projectDir}/playwright.config.ts`);
|
|
185
|
+
console.log("preprocessor executed\n");
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
console.warn(chalk_1.default.redBright("An error occured during preprocessor, please be sure to use existing step definitions"));
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
158
192
|
}
|
|
@@ -29,18 +29,21 @@ chokidar_1.default.watch(`${projectDir}/e2e`, {
|
|
|
29
29
|
ignoreInitial: true,
|
|
30
30
|
ignored: (path, stats) => !!stats && stats.isFile() && !path.endsWith(".feature")
|
|
31
31
|
})
|
|
32
|
-
.on("change",
|
|
32
|
+
.on("change", path => {
|
|
33
33
|
console.log(chalk_1.default.yellowBright("\nRefreshing test files..."));
|
|
34
|
-
(0, runner_playwright_1.executePreprocessor)(projectDir)
|
|
35
|
-
|
|
34
|
+
if ((0, runner_playwright_1.executePreprocessor)(projectDir)) {
|
|
35
|
+
console.log(chalk_1.default.yellowBright(`Test file ${path} refreshed\n`));
|
|
36
|
+
}
|
|
36
37
|
})
|
|
37
38
|
.on("add", path => {
|
|
38
39
|
console.log(chalk_1.default.yellowBright(`\nFile ${path} has been added`));
|
|
39
|
-
(0, runner_playwright_1.executePreprocessor)(projectDir)
|
|
40
|
-
|
|
40
|
+
if ((0, runner_playwright_1.executePreprocessor)(projectDir)) {
|
|
41
|
+
console.log(chalk_1.default.yellowBright(`Test file ${path} refreshed\n`));
|
|
42
|
+
}
|
|
41
43
|
})
|
|
42
44
|
.on("unlink", path => {
|
|
43
45
|
console.log(chalk_1.default.yellowBright(`\nFile ${path} has been removed`));
|
|
44
|
-
(0, runner_playwright_1.executePreprocessor)(projectDir)
|
|
45
|
-
|
|
46
|
+
if ((0, runner_playwright_1.executePreprocessor)(projectDir)) {
|
|
47
|
+
console.log(chalk_1.default.yellowBright(`Test file ${path} refreshed\n`));
|
|
48
|
+
}
|
|
46
49
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uuv/playwright",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.39.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "Louis Fredice NJAKO MOLOM (https://github.com/luifr10) & Stanley SERVICAL (https://github.com/stanlee974)",
|
|
6
6
|
"description": "A solution to facilitate the writing and execution of E2E tests understandable by any human being using cucumber(BDD) and playwright",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@cucumber/tag-expressions": "6.2.0",
|
|
48
48
|
"@playwright/test": "1.52.0",
|
|
49
49
|
"@uuv/a11y": "1.0.0-beta.71",
|
|
50
|
-
"@uuv/runner-commons": "2.
|
|
50
|
+
"@uuv/runner-commons": "2.52.0",
|
|
51
51
|
"axe-core": "4.10.3",
|
|
52
52
|
"axe-playwright": "2.1.0",
|
|
53
53
|
"chalk-table": "1.0.2",
|
|
@@ -34,14 +34,14 @@ import {
|
|
|
34
34
|
findWithRoleAndNameFocused,
|
|
35
35
|
getCookie,
|
|
36
36
|
getPageOrElement,
|
|
37
|
+
getTimeout,
|
|
37
38
|
MockCookie,
|
|
38
39
|
notFoundWithRoleAndName,
|
|
39
40
|
SelectedElementCookie,
|
|
40
41
|
TimeoutCookie,
|
|
41
|
-
withinRoleAndName
|
|
42
|
-
getTimeout
|
|
42
|
+
withinRoleAndName
|
|
43
43
|
} from "../core-engine";
|
|
44
|
-
import {
|
|
44
|
+
import { Given, Then, When, World } from "../../../preprocessor/run/world";
|
|
45
45
|
import { ContextObject, RunOptions } from "axe-core";
|
|
46
46
|
import path from "path";
|
|
47
47
|
|
|
@@ -586,6 +586,56 @@ Then(
|
|
|
586
586
|
}
|
|
587
587
|
);
|
|
588
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Checks that there is a list with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nThen I should see a list named "test-list" and containing\n| First element |\n| Second element |\n| Third element |\n```
|
|
591
|
+
* */
|
|
592
|
+
Then(
|
|
593
|
+
`I should see a grid named {string} and containing`,
|
|
594
|
+
async function(expectedListName: string, pExpectedElementsOfList: DataTable) {
|
|
595
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
596
|
+
await findWithRoleAndName(this, "grid", expectedListName);
|
|
597
|
+
await getPageOrElement(this).then(async (element) => {
|
|
598
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "gridcell");
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Checks that there is a table with the specified [name](https://russmaxdesign.github.io/html-elements-names/) containing list items.<br/> <u>Example</u>\n```gherkin\nThen I should see a list named "test-list" and containing\n| First element |\n| Second element |\n| Third element |\n```
|
|
605
|
+
* */
|
|
606
|
+
Then(
|
|
607
|
+
`I should see a table named {string} and containing`,
|
|
608
|
+
async function(expectedListName: string, pExpectedElementsOfList: DataTable) {
|
|
609
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
610
|
+
await findWithRoleAndName(this, "table", expectedListName);
|
|
611
|
+
await getPageOrElement(this).then(async (element) => {
|
|
612
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "cell");
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
function removeHeaderSeparatorLine(pExpectedElementsOfList: DataTable) {
|
|
618
|
+
const expectedElementsOfList = pExpectedElementsOfList.raw();
|
|
619
|
+
if (expectedElementsOfList.length > 1) {
|
|
620
|
+
expectedElementsOfList.splice(1, 1);
|
|
621
|
+
}
|
|
622
|
+
return expectedElementsOfList;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
async function expectTableToHaveContent(element: Locator, expectedElementsOfList: string[][], pCellAccessibleRole: string) {
|
|
626
|
+
const rows = await element.getByRole("row", { exact: true }).all();
|
|
627
|
+
return await Promise.all(rows.map(async (row: Locator, rowNumber: number) => {
|
|
628
|
+
const cellAccessibleRole = rowNumber === 0 ? "columnheader" : pCellAccessibleRole;
|
|
629
|
+
const cellsElement = await row.getByRole(cellAccessibleRole as any, { exact: true }).all();
|
|
630
|
+
let cellNumber = 0;
|
|
631
|
+
return await Promise.all(cellsElement.map((cell: Locator) => {
|
|
632
|
+
const expectedValue = expectedElementsOfList[rowNumber][cellNumber];
|
|
633
|
+
expect(cell, { message: `${cellAccessibleRole} at index [${rowNumber}, ${cellNumber}] should be ${expectedValue}` }).toHaveAccessibleName(expectedValue);
|
|
634
|
+
cellNumber++;
|
|
635
|
+
}));
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
638
|
+
|
|
589
639
|
async function pressKey(world: World, key: string) {
|
|
590
640
|
switch (key) {
|
|
591
641
|
case KEY_PRESS.TAB:
|
|
@@ -34,14 +34,14 @@ import {
|
|
|
34
34
|
findWithRoleAndNameFocused,
|
|
35
35
|
getCookie,
|
|
36
36
|
getPageOrElement,
|
|
37
|
+
getTimeout,
|
|
37
38
|
MockCookie,
|
|
38
39
|
notFoundWithRoleAndName,
|
|
39
40
|
SelectedElementCookie,
|
|
40
41
|
TimeoutCookie,
|
|
41
|
-
withinRoleAndName
|
|
42
|
-
getTimeout
|
|
42
|
+
withinRoleAndName
|
|
43
43
|
} from "../core-engine";
|
|
44
|
-
import {
|
|
44
|
+
import { Given, Then, When, World } from "../../../preprocessor/run/world";
|
|
45
45
|
import { ContextObject, RunOptions } from "axe-core";
|
|
46
46
|
import path from "path";
|
|
47
47
|
|
|
@@ -586,6 +586,56 @@ Then(
|
|
|
586
586
|
}
|
|
587
587
|
);
|
|
588
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Vérifie qu'il existe une liste avec le nom et les éléments de liste spécifiés.<br/> <u>Exemple</u>\n```gherkin\nAlors je dois voir une liste nommée "test-list" et contenant\n| Premier élément |\n| Deuxième élément |\n| Troisième élément |\n```
|
|
591
|
+
* */
|
|
592
|
+
Then(
|
|
593
|
+
`je dois voir une grille nommée {string} et contenant`,
|
|
594
|
+
async function(expectedListName: string, pExpectedElementsOfList: DataTable) {
|
|
595
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
596
|
+
await findWithRoleAndName(this, "grid", expectedListName);
|
|
597
|
+
await getPageOrElement(this).then(async (element) => {
|
|
598
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "gridcell");
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Vérifie qu'il existe une liste avec le nom et les éléments de liste spécifiés.<br/> <u>Exemple</u>\n```gherkin\nAlors je dois voir une liste nommée "test-list" et contenant\n| Premier élément |\n| Deuxième élément |\n| Troisième élément |\n```
|
|
605
|
+
* */
|
|
606
|
+
Then(
|
|
607
|
+
`je dois voir un tableau nommé {string} et contenant`,
|
|
608
|
+
async function(expectedListName: string, pExpectedElementsOfList: DataTable) {
|
|
609
|
+
const expectedElementsOfList = removeHeaderSeparatorLine(pExpectedElementsOfList);
|
|
610
|
+
await findWithRoleAndName(this, "table", expectedListName);
|
|
611
|
+
await getPageOrElement(this).then(async (element) => {
|
|
612
|
+
await expectTableToHaveContent(element, expectedElementsOfList, "cell");
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
function removeHeaderSeparatorLine(pExpectedElementsOfList: DataTable) {
|
|
618
|
+
const expectedElementsOfList = pExpectedElementsOfList.raw();
|
|
619
|
+
if (expectedElementsOfList.length > 1) {
|
|
620
|
+
expectedElementsOfList.splice(1, 1);
|
|
621
|
+
}
|
|
622
|
+
return expectedElementsOfList;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
async function expectTableToHaveContent(element: Locator, expectedElementsOfList: string[][], pCellAccessibleRole: string) {
|
|
626
|
+
const rows = await element.getByRole("row", { exact: true }).all();
|
|
627
|
+
return await Promise.all(rows.map(async (row: Locator, rowNumber: number) => {
|
|
628
|
+
const cellAccessibleRole = rowNumber === 0 ? "columnheader" : pCellAccessibleRole;
|
|
629
|
+
const cellsElement = await row.getByRole(cellAccessibleRole as any, { exact: true }).all();
|
|
630
|
+
let cellNumber = 0;
|
|
631
|
+
return await Promise.all(cellsElement.map((cell: Locator) => {
|
|
632
|
+
const expectedValue = expectedElementsOfList[rowNumber][cellNumber];
|
|
633
|
+
expect(cell, { message: `${cellAccessibleRole} at index [${rowNumber}, ${cellNumber}] should be ${expectedValue}` }).toHaveAccessibleName(expectedValue);
|
|
634
|
+
cellNumber++;
|
|
635
|
+
}));
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
638
|
+
|
|
589
639
|
async function pressKey(world: World, key: string) {
|
|
590
640
|
switch (key) {
|
|
591
641
|
case KEY_PRESS.TAB:
|
|
@@ -40,14 +40,14 @@ import { expect } from "@playwright/test";
|
|
|
40
40
|
/**
|
|
41
41
|
* Sélectionne l'élément ayant le rôle table et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) sont spécifiés <br />⚠ pensez à déselectionner l'élement avec <b>[je reinitialise le contexte](#je-reinitialise-le-contexte)</b> si vous n'agissez plus dessus
|
|
42
42
|
* */
|
|
43
|
-
When(`je vais à l'intérieur
|
|
43
|
+
When(`je vais à l'intérieur du tableau nommé {string}`, async function(name: string) {
|
|
44
44
|
return await withinRoleAndName(this, "table", name);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Vérifie l'existence d'un élément Html ayant le rôle table et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
|
|
49
49
|
* */
|
|
50
|
-
Then(`je dois voir
|
|
50
|
+
Then(`je dois voir un tableau nommé {string}`, async function(name: string) {
|
|
51
51
|
await findWithRoleAndName(this, "table", name);
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -55,7 +55,7 @@ Then(`je dois voir une tableau nommée {string}`, async function(name: string) {
|
|
|
55
55
|
* Vérifie l'inexistence d'un élément Html ayant le rôle table et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
|
|
56
56
|
* */
|
|
57
57
|
Then(
|
|
58
|
-
`je ne dois pas voir
|
|
58
|
+
`je ne dois pas voir un tableau nommé {string}`,
|
|
59
59
|
async function(name: string) {
|
|
60
60
|
await notFoundWithRoleAndName(this, "table", name);
|
|
61
61
|
}
|
|
@@ -68,7 +68,7 @@ Then(
|
|
|
68
68
|
/**
|
|
69
69
|
* Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire).
|
|
70
70
|
* */
|
|
71
|
-
When(`je saisie le(s) mot(s) {string} dans le tableau
|
|
71
|
+
When(`je saisie le(s) mot(s) {string} dans le tableau nommé {string}`, async function(textToType: string, name: string) {
|
|
72
72
|
await getPageOrElement(this).then(async (element) => {
|
|
73
73
|
const byRole = await element.getByRole("table", { name: name, exact: true });
|
|
74
74
|
await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) });
|
|
@@ -80,7 +80,7 @@ When(`je saisie le(s) mot(s) {string} dans le tableau nommée {string}`, async f
|
|
|
80
80
|
/**
|
|
81
81
|
* Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire).
|
|
82
82
|
* */
|
|
83
|
-
When(`j'entre la valeur {string} dans le tableau
|
|
83
|
+
When(`j'entre la valeur {string} dans le tableau nommé {string}`, async function(textToType: string, name: string) {
|
|
84
84
|
await getPageOrElement(this).then(async (element) => {
|
|
85
85
|
const byRole = await element.getByRole("table", { name: name, includeHidden: true, exact: true });
|
|
86
86
|
await expect(byRole).toHaveCount(1);
|
|
@@ -96,7 +96,7 @@ When(`j'entre la valeur {string} dans le tableau nommée {string}`, async functi
|
|
|
96
96
|
* Vérifie l'existence d'un élément Html ayant le rôle table, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés
|
|
97
97
|
* */
|
|
98
98
|
Then(
|
|
99
|
-
`je dois voir
|
|
99
|
+
`je dois voir un tableau nommé {string} et contenant {string}`,
|
|
100
100
|
async function(name: string, expectedTextContent: string) {
|
|
101
101
|
await findWithRoleAndNameAndContent(this, "table", name, expectedTextContent);
|
|
102
102
|
}
|
|
@@ -106,7 +106,7 @@ Then(
|
|
|
106
106
|
* Vérifie l'existence d'un élément Html ayant le rôle table, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à false
|
|
107
107
|
* */
|
|
108
108
|
Then(
|
|
109
|
-
`je dois voir
|
|
109
|
+
`je dois voir un tableau nommé {string} et contenant {string} inactif`,
|
|
110
110
|
async function(name: string, expectedTextContent: string) {
|
|
111
111
|
await findWithRoleAndNameAndContentDisable(this, "table", name, expectedTextContent);
|
|
112
112
|
}
|
|
@@ -116,7 +116,7 @@ Then(
|
|
|
116
116
|
* Vérifie l'existence d'un élément Html ayant le rôle table, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à true
|
|
117
117
|
* */
|
|
118
118
|
Then(
|
|
119
|
-
`je dois voir
|
|
119
|
+
`je dois voir un tableau nommé {string} et contenant {string} actif`,
|
|
120
120
|
async function(name: string, expectedTextContent: string) {
|
|
121
121
|
await findWithRoleAndNameAndContentEnable(this, "table", name, expectedTextContent);
|
|
122
122
|
}
|