@uuv/playwright 1.8.2 → 1.10.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.
@@ -29,9 +29,15 @@ const cucumber_1 = require("@cucumber/cucumber");
29
29
  await (0, core_engine_1.deleteCookieByName)(this, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT);
30
30
  await this.page.goto(`${siteUrl}`);
31
31
  });
32
- (0, cucumber_1.When)(`${runner_commons_1.key.when.click}`, async function () {
32
+ (0, cucumber_1.When)(`${runner_commons_1.key.when.click.withContext}`, async function () {
33
33
  await (0, core_engine_1.getPageOrElement)(this).then((element) => element.click({ timeout: runner_commons_1.DEFAULT_TIMEOUT }));
34
34
  });
35
+ (0, cucumber_1.When)(`${runner_commons_1.key.when.click.button}`, async function (name) {
36
+ await click(this, "button", name);
37
+ });
38
+ (0, cucumber_1.When)(`${runner_commons_1.key.when.click.withRole}`, async function (role, name) {
39
+ await click(this, role, name);
40
+ });
35
41
  // TODO : permet de gérer les label accessibles donc pas que les aria : https://playwright.dev/docs/api/class-locator#locator-get-by-label
36
42
  (0, cucumber_1.When)(`${runner_commons_1.key.when.withinElement.ariaLabel}`, async function (expectedAriaLabel) {
37
43
  const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
@@ -269,3 +275,11 @@ async function pressKey(world, element, key) {
269
275
  await (0, core_engine_1.deleteCookieByName)(world, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT);
270
276
  await (0, core_engine_1.addCookieWhenValueIsList)(world, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT, { name: core_engine_1.FILTER_TYPE.SELECTOR_PARENT, value: "*:focus" });
271
277
  }
278
+ async function click(world, role, name) {
279
+ await (0, core_engine_1.getPageOrElement)(world).then(async (element) => {
280
+ const byRole = await element.getByRole(role, { name: name, includeHidden: true, exact: true });
281
+ await (0, test_1.expect)(byRole).toHaveCount(1);
282
+ await byRole.click({ timeout: runner_commons_1.DEFAULT_TIMEOUT });
283
+ await world.context.clearCookies();
284
+ });
285
+ }
@@ -43,10 +43,10 @@ export declare function addCookieWhenValueIsList(world: World, cookieName: COOKI
43
43
  export declare function getCookie(world: World, cookieName: COOKIE_NAME): Promise<Cookie>;
44
44
  export declare function deleteCookieByValue(world: World, cookieName: COOKIE_NAME, node: any): Promise<void>;
45
45
  export declare function deleteCookieByName(world: World, cookieName: COOKIE_NAME): Promise<void>;
46
- export declare function findWithRoleAndName(world: World, role: string, name: string): Promise<void>;
46
+ export declare function findWithRoleAndName(world: World, role: string, name: string): Promise<any>;
47
47
  export declare function withinRoleAndName(world: World, role: string, name: string): Promise<void>;
48
48
  export declare function notFoundWithRoleAndName(world: World, role: string, name: string): Promise<void>;
49
- export declare function findWithRoleAndNameAndContent(world: World, expectedRole: string, name: string, expectedTextContent?: string | undefined): Promise<void>;
49
+ export declare function findWithRoleAndNameAndContent(world: World, expectedRole: string, name: string, expectedTextContent?: string | undefined): Promise<any>;
50
50
  export declare function findWithRoleAndNameAndContentDisable(world: World, expectedRole: string, name: string, expectedTextContent: string): Promise<void>;
51
51
  export declare function findWithRoleAndNameAndContentEnable(world: World, expectedRole: string, name: string, expectedTextContent: string): Promise<void>;
52
52
  export declare function showAttributesInLocator(element: any): Promise<void>;
@@ -35,6 +35,12 @@ const cucumber_1 = require("@cucumber/cucumber");
35
35
  (0, cucumber_1.When)(`I click`, async function () {
36
36
  await (0, core_engine_1.getPageOrElement)(this).then((element) => element.click({ timeout: runner_commons_1.DEFAULT_TIMEOUT }));
37
37
  });
38
+ (0, cucumber_1.When)(`I click on button named {string}`, async function (name) {
39
+ await click(this, "button", name);
40
+ });
41
+ (0, cucumber_1.When)(`I click on element with role {string} and name {string}`, async function (role, name) {
42
+ await click(this, role, name);
43
+ });
38
44
  // TODO : permet de gérer les label accessibles donc pas que les aria : https://playwright.dev/docs/api/class-locator#locator-get-by-label
39
45
  (0, cucumber_1.When)(`Within the element with aria-label {string}`, async function (expectedAriaLabel) {
40
46
  const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
@@ -272,3 +278,11 @@ async function pressKey(world, element, key) {
272
278
  await (0, core_engine_1.deleteCookieByName)(world, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT);
273
279
  await (0, core_engine_1.addCookieWhenValueIsList)(world, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT, { name: core_engine_1.FILTER_TYPE.SELECTOR_PARENT, value: "*:focus" });
274
280
  }
281
+ async function click(world, role, name) {
282
+ await (0, core_engine_1.getPageOrElement)(world).then(async (element) => {
283
+ const byRole = await element.getByRole(role, { name: name, includeHidden: true, exact: true });
284
+ await (0, test_1.expect)(byRole).toHaveCount(1);
285
+ await byRole.click({ timeout: runner_commons_1.DEFAULT_TIMEOUT });
286
+ await world.context.clearCookies();
287
+ });
288
+ }
@@ -35,6 +35,12 @@ const cucumber_1 = require("@cucumber/cucumber");
35
35
  (0, cucumber_1.When)(`je clique`, async function () {
36
36
  await (0, core_engine_1.getPageOrElement)(this).then((element) => element.click({ timeout: runner_commons_1.DEFAULT_TIMEOUT }));
37
37
  });
38
+ (0, cucumber_1.When)(`je clique sur le bouton nommé {string}`, async function (name) {
39
+ await click(this, "button", name);
40
+ });
41
+ (0, cucumber_1.When)(`je clique sur l'élément avec le rôle {string} et le nom {string}`, async function (role, name) {
42
+ await click(this, role, name);
43
+ });
38
44
  // TODO : permet de gérer les label accessibles donc pas que les aria : https://playwright.dev/docs/api/class-locator#locator-get-by-label
39
45
  (0, cucumber_1.When)(`je vais à l'intérieur de l'élément ayant pour aria-label {string}`, async function (expectedAriaLabel) {
40
46
  const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
@@ -272,3 +278,11 @@ async function pressKey(world, element, key) {
272
278
  await (0, core_engine_1.deleteCookieByName)(world, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT);
273
279
  await (0, core_engine_1.addCookieWhenValueIsList)(world, core_engine_1.COOKIE_NAME.SELECTED_ELEMENT, { name: core_engine_1.FILTER_TYPE.SELECTOR_PARENT, value: "*:focus" });
274
280
  }
281
+ async function click(world, role, name) {
282
+ await (0, core_engine_1.getPageOrElement)(world).then(async (element) => {
283
+ const byRole = await element.getByRole(role, { name: name, includeHidden: true, exact: true });
284
+ await (0, test_1.expect)(byRole).toHaveCount(1);
285
+ await byRole.click({ timeout: runner_commons_1.DEFAULT_TIMEOUT });
286
+ await world.context.clearCookies();
287
+ });
288
+ }
@@ -17,4 +17,5 @@ export interface UUVPlaywrightCucumberMapItem {
17
17
  generatedFile: string;
18
18
  }
19
19
  export declare const UUVPlaywrightCucumberMapFile = ".uuv-playwright-cucumber-map.json";
20
+ export declare function executePreprocessor(tempDir: string, configDir: string): Promise<void>;
20
21
  export declare function run(mode: "open" | "e2e", tempDir?: string, configDir?: string, generateHtmlReport?: boolean, env?: any, targetTestFile?: string): Promise<void>;
@@ -13,16 +13,40 @@
13
13
  * understanding English or French.
14
14
  */
15
15
  "use strict";
16
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ var desc = Object.getOwnPropertyDescriptor(m, k);
19
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
+ desc = { enumerable: true, get: function() { return m[k]; } };
21
+ }
22
+ Object.defineProperty(o, k2, desc);
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29
+ }) : function(o, v) {
30
+ o["default"] = v;
31
+ });
32
+ var __importStar = (this && this.__importStar) || function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
16
39
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
40
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
41
  };
19
42
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.run = exports.UUVPlaywrightCucumberMapFile = void 0;
43
+ exports.run = exports.executePreprocessor = exports.UUVPlaywrightCucumberMapFile = void 0;
21
44
  const chalk_1 = __importDefault(require("chalk"));
22
45
  const gen_1 = require("../cucumber/preprocessor/gen");
23
46
  const fs_1 = __importDefault(require("fs"));
24
- const child_process_1 = require("child_process");
47
+ const child_process_1 = __importStar(require("child_process"));
25
48
  const uuv_playwright_reporter_helper_1 = require("../reporter/uuv-playwright-reporter-helper");
49
+ const path_1 = __importDefault(require("path"));
26
50
  exports.UUVPlaywrightCucumberMapFile = ".uuv-playwright-cucumber-map.json";
27
51
  async function bddGen(tempDir) {
28
52
  try {
@@ -123,8 +147,12 @@ async function executePreprocessor(tempDir, configDir) {
123
147
  translateFeatures(tempDir, configDir);
124
148
  console.log("preprocessor executed");
125
149
  }
150
+ exports.executePreprocessor = executePreprocessor;
126
151
  async function run(mode, tempDir = "uuv/.features-gen/e2e", configDir = "uuv", generateHtmlReport = false, env, targetTestFile) {
127
152
  await executePreprocessor(tempDir, configDir);
153
+ if (mode === "open") {
154
+ child_process_1.default.fork(path_1.default.join(__dirname, "watch-test-files"), [tempDir, configDir]);
155
+ }
128
156
  runPlaywright(mode, configDir, generateHtmlReport, env, targetTestFile);
129
157
  }
130
158
  exports.run = run;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Software Name : UUV
3
+ *
4
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2023 Orange
5
+ * SPDX-License-Identifier: MIT
6
+ *
7
+ * This software is distributed under the MIT License,
8
+ * the text of which is available at https://spdx.org/licenses/MIT.html
9
+ * or see the "LICENSE" file for more details.
10
+ *
11
+ * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley
12
+ * Software description: Make test writing fast, understandable by any human
13
+ * understanding English or French.
14
+ */
15
+ export {};
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Software Name : UUV
3
+ *
4
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2023 Orange
5
+ * SPDX-License-Identifier: MIT
6
+ *
7
+ * This software is distributed under the MIT License,
8
+ * the text of which is available at https://spdx.org/licenses/MIT.html
9
+ * or see the "LICENSE" file for more details.
10
+ *
11
+ * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley
12
+ * Software description: Make test writing fast, understandable by any human
13
+ * understanding English or French.
14
+ */
15
+ "use strict";
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ const runner_playwright_1 = require("./runner-playwright");
21
+ const chokidar_1 = __importDefault(require("chokidar"));
22
+ const chalk_1 = __importDefault(require("chalk"));
23
+ const tempDir = process.argv[2];
24
+ const configDir = process.argv[3];
25
+ if (!tempDir || !configDir) {
26
+ console.log(chalk_1.default.redBright("An error occurred during test files watching"));
27
+ process.exit(-1);
28
+ }
29
+ chokidar_1.default.watch(`${configDir}/e2e/**/*.feature`, {
30
+ ignoreInitial: true
31
+ })
32
+ .on("change", async (event, path) => {
33
+ console.log(chalk_1.default.yellowBright("\nRefreshing test files..."));
34
+ await (0, runner_playwright_1.executePreprocessor)(tempDir, configDir);
35
+ console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
36
+ })
37
+ .on("add", async (path) => {
38
+ console.log(chalk_1.default.yellowBright(`\nFile ${path} has been added`));
39
+ await (0, runner_playwright_1.executePreprocessor)(tempDir, configDir);
40
+ console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
41
+ })
42
+ .on("unlink", async (path) => {
43
+ console.log(chalk_1.default.yellowBright(`\nFile ${path} has been removed`));
44
+ await (0, runner_playwright_1.executePreprocessor)(tempDir, configDir);
45
+ console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
46
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uuv/playwright",
3
- "version": "1.8.2",
3
+ "version": "1.10.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 run E2E tests written in cucumber(BDD) with playwright.",
@@ -46,11 +46,12 @@
46
46
  "dependencies": {
47
47
  "@cucumber/cucumber": "9.3.0",
48
48
  "@playwright/test": "1.33.0",
49
- "@uuv/runner-commons": "1.6.5",
49
+ "@uuv/runner-commons": "1.8.0",
50
50
  "axe-core": "4.7.2",
51
51
  "axe-playwright": "1.2.3",
52
52
  "chalk": "4.1.2",
53
53
  "chalk-table": "^1.0.2",
54
+ "chokidar": "3.5.3",
54
55
  "cucumber-json-report-formatter": "0.1.4",
55
56
  "figlet": "1.6.0",
56
57
  "minimist": "1.2.8",
@@ -89,7 +90,7 @@
89
90
  },
90
91
  "devDependencies": {
91
92
  "@types/minimist": "1.2.2",
92
- "@types/node": "16.18.39",
93
+ "@types/node": "16.18.50",
93
94
  "cross-env": "7.0.3",
94
95
  "eslint-plugin-cucumber": "2.0.0",
95
96
  "eslint-plugin-jest": "27.2.3",
@@ -24,7 +24,7 @@ import { devices, expect } from "@playwright/test";
24
24
  import { Page } from "playwright";
25
25
  import { DataTable } from "@cucumber/cucumber";
26
26
  import {
27
- addCookieWhenValueIsList,
27
+ addCookieWhenValueIsList, checkTextContentLocator,
28
28
  COOKIE_NAME, deleteCookieByName,
29
29
  deleteCookieByValue,
30
30
  FILTER_TYPE,
@@ -63,6 +63,15 @@ When(`I click`, async function(this: World) {
63
63
  await getPageOrElement(this).then((element: Locator) => element.click({ timeout: DEFAULT_TIMEOUT }));
64
64
  });
65
65
 
66
+
67
+ When(`I click on button named {string}`, async function(this: World, name: string) {
68
+ await click(this, "button", name);
69
+ });
70
+
71
+ When(`I click on element with role {string} and name {string}`, async function(this: World, role: string, name: string) {
72
+ await click(this, role, name);
73
+ });
74
+
66
75
  // TODO : permet de gérer les label accessibles donc pas que les aria : https://playwright.dev/docs/api/class-locator#locator-get-by-label
67
76
  When(`Within the element with aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
68
77
  const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
@@ -381,4 +390,13 @@ async function pressKey(world: World, element: Locator, key: string) {
381
390
  await addCookieWhenValueIsList(world, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.SELECTOR_PARENT, value: "*:focus" });
382
391
  }
383
392
 
393
+ async function click(world: World, role: any, name: string) {
394
+ await getPageOrElement(world).then(async (element) => {
395
+ const byRole = await element.getByRole(role, { name: name, includeHidden: true, exact: true });
396
+ await expect(byRole).toHaveCount(1);
397
+ await byRole.click({ timeout: DEFAULT_TIMEOUT });
398
+ await world.context.clearCookies();
399
+ });
400
+ }
401
+
384
402
 
@@ -24,7 +24,7 @@ import { devices, expect } from "@playwright/test";
24
24
  import { Page } from "playwright";
25
25
  import { DataTable } from "@cucumber/cucumber";
26
26
  import {
27
- addCookieWhenValueIsList,
27
+ addCookieWhenValueIsList, checkTextContentLocator,
28
28
  COOKIE_NAME, deleteCookieByName,
29
29
  deleteCookieByValue,
30
30
  FILTER_TYPE,
@@ -63,6 +63,15 @@ When(`je clique`, async function(this: World) {
63
63
  await getPageOrElement(this).then((element: Locator) => element.click({ timeout: DEFAULT_TIMEOUT }));
64
64
  });
65
65
 
66
+
67
+ When(`je clique sur le bouton nommé {string}`, async function(this: World, name: string) {
68
+ await click(this, "button", name);
69
+ });
70
+
71
+ When(`je clique sur l'élément avec le rôle {string} et le nom {string}`, async function(this: World, role: string, name: string) {
72
+ await click(this, role, name);
73
+ });
74
+
66
75
  // TODO : permet de gérer les label accessibles donc pas que les aria : https://playwright.dev/docs/api/class-locator#locator-get-by-label
67
76
  When(`je vais à l'intérieur de l'élément ayant pour aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
68
77
  const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
@@ -381,4 +390,13 @@ async function pressKey(world: World, element: Locator, key: string) {
381
390
  await addCookieWhenValueIsList(world, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.SELECTOR_PARENT, value: "*:focus" });
382
391
  }
383
392
 
393
+ async function click(world: World, role: any, name: string) {
394
+ await getPageOrElement(world).then(async (element) => {
395
+ const byRole = await element.getByRole(role, { name: name, includeHidden: true, exact: true });
396
+ await expect(byRole).toHaveCount(1);
397
+ await byRole.click({ timeout: DEFAULT_TIMEOUT });
398
+ await world.context.clearCookies();
399
+ });
400
+ }
401
+
384
402