@uuv/playwright 1.6.1 → 1.7.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.
@@ -3,283 +3,382 @@ NE PAS MODIFIER, FICHIER GENERE
3
3
  *******************************/
4
4
 
5
5
  /**
6
- * Software Name : UUV
7
- *
8
- * SPDX-FileCopyrightText: Copyright (c) 2022-2023 Orange
9
- * SPDX-License-Identifier: MIT
10
- *
11
- * This software is distributed under the MIT License,
12
- * the text of which is available at https://spdx.org/licenses/MIT.html
13
- * or see the "LICENSE" file for more details.
14
- *
15
- * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley
16
- * Software description: Make test writing fast, understandable by any human
17
- * understanding English or French.
18
- */
19
-
20
- import { DEFAULT_TIMEOUT, fs, key } from "@uuv/runner-commons";
21
- import { checkA11y, injectAxe } from "axe-playwright";
6
+ * Software Name : UUV
7
+ *
8
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2023 Orange
9
+ * SPDX-License-Identifier: MIT
10
+ *
11
+ * This software is distributed under the MIT License,
12
+ * the text of which is available at https://spdx.org/licenses/MIT.html
13
+ * or see the "LICENSE" file for more details.
14
+ *
15
+ * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley
16
+ * Software description: Make test writing fast, understandable by any human
17
+ * understanding English or French.
18
+ */
19
+
20
+ import { DEFAULT_TIMEOUT, fs, key, KEY_PRESS } from "@uuv/runner-commons";
21
+ import { checkA11y, configureAxe, injectAxe } from "axe-playwright";
22
22
  import { Locator } from "playwright";
23
23
  import { devices, expect } from "@playwright/test";
24
24
  import { Page } from "playwright";
25
25
  import { DataTable } from "@cucumber/cucumber";
26
26
  import {
27
- addCookieWhenValueIsList,
28
- COOKIE_NAME, deleteCookieByName,
29
- deleteCookieByValue,
30
- FILTER_TYPE,
31
- findWithRoleAndName,
32
- findWithRoleAndNameAndContent,
33
- findWithRoleAndNameAndContentDisable,
34
- findWithRoleAndNameAndContentEnable,
35
- getCookie,
36
- getPageOrElement,
37
- MockType,
38
- notFoundWithRoleAndName,
39
- withinRoleAndName
27
+ addCookieWhenValueIsList,
28
+ COOKIE_NAME, deleteCookieByName,
29
+ deleteCookieByValue,
30
+ FILTER_TYPE,
31
+ findWithRoleAndName,
32
+ findWithRoleAndNameAndContent,
33
+ findWithRoleAndNameAndContentDisable,
34
+ findWithRoleAndNameAndContentEnable,
35
+ getCookie,
36
+ getPageOrElement,
37
+ MockType,
38
+ notFoundWithRoleAndName,
39
+ withinRoleAndName
40
40
  } from "../core-engine";
41
41
 
42
42
  import { Given, When, Then } from "@cucumber/cucumber";
43
43
  import { World } from "../../../preprocessor/run/world";
44
+ import { ContextObject, RunOptions } from "axe-core";
44
45
 
45
46
  Given(`je redimensionne la fenêtre à la vue {string}`, async function(this: World, viewportPreset: string) {
46
- await this.page.setViewportSize(devices[viewportPreset].viewport);
47
+ await this.page.setViewportSize(devices[viewportPreset].viewport);
47
48
  });
48
49
 
49
50
  Given(
50
- `je redimensionne la fenêtre avec une largeur de {int} px et une longueur de {int} px`, async function
51
- (this: World, width: number, height: number) {
52
- await this.page.setViewportSize({ width: width, height: height });
53
- }
51
+ `je redimensionne la fenêtre avec une largeur de {int} px et une longueur de {int} px`, async function
52
+ (this: World, width: number, height: number) {
53
+ await this.page.setViewportSize({ width: width, height: height });
54
+ }
54
55
  );
55
56
 
56
- Given(`je visite l'Url {string}`, { timeout: 60 * 1000 }, async function (this: World, siteUrl: string) {
57
- await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
58
- await this.page.goto(`${siteUrl}`);
57
+ Given(`je visite l'Url {string}`, { timeout: 60 * 1000 }, async function(this: World, siteUrl: string) {
58
+ await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT);
59
+ await this.page.goto(`${siteUrl}`);
59
60
  });
60
61
 
61
- When(`je clique`, async function (this: World) {
62
- await getPageOrElement(this).then((element: Locator) => element.click({ timeout: DEFAULT_TIMEOUT }));
62
+ When(`je clique`, async function(this: World) {
63
+ await getPageOrElement(this).then((element: Locator) => element.click({ timeout: DEFAULT_TIMEOUT }));
63
64
  });
64
65
 
65
66
  // TODO : permet de gérer les label accessibles donc pas que les aria : https://playwright.dev/docs/api/class-locator#locator-get-by-label
66
- When(`je vais à l'intérieur de l'élément ayant pour aria-label {string}`, async function (this: World, expectedAriaLabel: string) {
67
- const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
68
- await getPageOrElement(this).then((element) => expect(element.getByLabel(sanitizedExpectedAriaLabel)).toHaveCount(1));
69
- await addCookieWhenValueIsList(this, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.ARIA_LABEL, value: sanitizedExpectedAriaLabel });
67
+ When(`je vais à l'intérieur de l'élément ayant pour aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
68
+ const sanitizedExpectedAriaLabel = encodeURIComponent(expectedAriaLabel).replaceAll("%20", " ");
69
+ await getPageOrElement(this).then((element) => expect(element.getByLabel(sanitizedExpectedAriaLabel)).toHaveCount(1));
70
+ await addCookieWhenValueIsList(this, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.ARIA_LABEL, value: sanitizedExpectedAriaLabel });
70
71
  });
71
- When(`je reinitialise le contexte`, async function (this: World) {
72
- await this.context.clearCookies();
72
+ When(`je reinitialise le contexte`, async function(this: World) {
73
+ await this.context.clearCookies();
73
74
  });
74
75
 
75
- When(`je vais à l'intérieur de l'élément ayant pour sélecteur {string}`, async function (this: World, selector: string) {
76
- await getPageOrElement(this).then((element) => expect(element.locator(selector)).toHaveCount(1));
77
- await addCookieWhenValueIsList(this, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.SELECTOR, value: selector });
76
+ When(`je vais à l'intérieur de l'élément ayant pour sélecteur {string}`, async function(this: World, selector: string) {
77
+ await getPageOrElement(this).then((element) => expect(element.locator(selector)).toHaveCount(1));
78
+ await addCookieWhenValueIsList(this, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.SELECTOR, value: selector });
78
79
  });
79
80
 
80
- When(`je saisie le(s) mot(s) {string}`, async function (this: World, textToType: string) {
81
+ When(`je saisie le(s) mot(s) {string}`, async function(this: World, textToType: string) {
82
+ await getPageOrElement(this).then(async (element: Locator) => {
83
+ await element.focus({ timeout: 10000 });
84
+ await element.type(textToType);
85
+ // console.debug(await showAttributesInLocator(element));
86
+ });
87
+ });
88
+
89
+
90
+ When(`j'appuie {int} fois sur {string}`, async function(this: World, nbTimes: number, key: string) {
91
+ for (let i = 1; i <= nbTimes; i++) {
81
92
  await getPageOrElement(this).then(async (element: Locator) => {
82
- await element.focus({ timeout: 10000 });
83
- await element.fill(textToType);
84
- // console.debug(await showAttributesInLocator(element));
93
+ await element.focus({ timeout: 10000 });
94
+ await pressKey(this, element, key);
85
95
  });
96
+ }
86
97
  });
87
98
 
88
- When(`je positionne le timeout à {int} secondes`, async function (this: World, newTimeout: number) {
89
- await this.testInfo.setTimeout(newTimeout);
99
+ When(`j'appuie sur {string}`, async function(this: World, key: string) {
100
+ await getPageOrElement(this).then(async (element: Locator) => {
101
+ await element.focus({ timeout: 10000 });
102
+ await pressKey(this, element, key);
103
+ });
104
+ });
105
+ When(`je positionne le timeout à {int} secondes`, async function(this: World, newTimeout: number) {
106
+ await this.testInfo.setTimeout(newTimeout);
90
107
  });
91
108
 
92
109
 
93
- When(`je vais à l'intérieur de l'élément ayant pour rôle {string} et pour nom {string}`, async function (this: World, role: string, name: string) {
94
- await withinRoleAndName(this, role, name);
110
+ When(`je vais à l'intérieur de l'élément ayant pour rôle {string} et pour nom {string}`, async function(this: World, role: string, name: string) {
111
+ await withinRoleAndName(this, role, name);
95
112
  });
96
113
 
97
- When(`je vais à l'intérieur de l'élément ayant pour testId {string}`, async function (this: World, testId: string) {
98
- testId = encodeURIComponent(testId);
99
- await getPageOrElement(this).then(async (element) => await expect(element.getByTestId(testId)).toHaveCount(1));
100
- await addCookieWhenValueIsList(this, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.TEST_ID, value: testId });
114
+ When(`je vais à l'intérieur de l'élément ayant pour testId {string}`, async function(this: World, testId: string) {
115
+ testId = encodeURIComponent(testId);
116
+ await getPageOrElement(this).then(async (element) => await expect(element.getByTestId(testId)).toHaveCount(1));
117
+ await addCookieWhenValueIsList(this, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.TEST_ID, value: testId });
101
118
  });
102
119
 
103
120
 
104
121
  When(
105
- `je simule une requête {} sur l'url {string} nommée {string} avec le contenu suivant {}`,
106
- async function (this: World, verb: string, url: string, name: string, body: any) {
107
- await addCookieWhenValueIsList(this, COOKIE_NAME.MOCK_URL, { name: name, url: url });
108
- await this.page.route(url, async route => {
109
- const json = body;
110
- await route.fulfill({ json });
111
- });
112
- }
122
+ `je simule une requête {} sur l'url {string} nommée {string} avec le contenu suivant {}`,
123
+ async function(this: World, verb: string, url: string, name: string, body: any) {
124
+ await addCookieWhenValueIsList(this, COOKIE_NAME.MOCK_URL, { name: name, url: url });
125
+ await this.page.route(url, async route => {
126
+ const json = body;
127
+ await route.fulfill({ json });
128
+ });
129
+ }
113
130
  );
114
131
 
115
132
  When(
116
- `je simule une requête {} sur l'url {string} nommée {string} avec le code http {int}`,
117
- async function (this: World, verb: string, url: string, name: string, statusCode: number) {
118
- await addCookieWhenValueIsList(this, COOKIE_NAME.MOCK_URL, { name: name, url: url });
119
- await this.page.route(url, async route => {
120
- await route.fulfill({ status: statusCode });
121
- });
122
- }
133
+ `je simule une requête {} sur l'url {string} nommée {string} avec le code http {int}`,
134
+ async function(this: World, verb: string, url: string, name: string, statusCode: number) {
135
+ await addCookieWhenValueIsList(this, COOKIE_NAME.MOCK_URL, { name: name, url: url });
136
+ await this.page.route(url, async route => {
137
+ await route.fulfill({ status: statusCode });
138
+ });
139
+ }
123
140
  );
124
141
 
125
142
  When(
126
- `je simule une requête {} sur l'url {string} nommée {string} avec le fichier suivant {}`,
127
- async function (this: World, verb: string, url: string, name: string, fixture: any) {
128
- await addCookieWhenValueIsList(this, COOKIE_NAME.MOCK_URL, { name: name, url: url });
129
- const data = await fs.readFileSync(`playwright/fixtures/${fixture}`);
130
- await this.page.route(url, async route => {
131
- await route.fulfill({ body: data });
132
- });
133
- }
143
+ `je simule une requête {} sur l'url {string} nommée {string} avec le fichier suivant {}`,
144
+ async function(this: World, verb: string, url: string, name: string, fixture: any) {
145
+ await addCookieWhenValueIsList(this, COOKIE_NAME.MOCK_URL, { name: name, url: url });
146
+ const data = await fs.readFileSync(`playwright/fixtures/${fixture}`);
147
+ await this.page.route(url, async route => {
148
+ await route.fulfill({ body: data });
149
+ });
150
+ }
134
151
  );
135
152
 
136
- Then(`je dois voir un élément ayant pour sélecteur {string}`, async function (this: World, selector: string) {
137
- await getPageOrElement(this).then((element) => expect(element.locator(selector)).toHaveCount(1));
153
+ Then(`je dois voir un élément ayant pour sélecteur {string}`, async function(this: World, selector: string) {
154
+ await getPageOrElement(this).then((element) => expect(element.locator(selector)).toHaveCount(1));
138
155
  });
139
156
 
140
157
  When(
141
- `je saisie le(s) header(s) pour l'Uri {string} et la methode {string}`,
142
- async function (this: World, url: string, method: string, headersToSet: DataTable) {
143
- await this.page.route(url, async route => {
144
- const headers = route.request().headers();
145
- await route.continue({ headers: { ...headers, ...headersToSet.rowsHash() } });
146
- });
147
- }
158
+ `je saisie le(s) header(s) pour l'Uri {string} et la methode {string}`,
159
+ async function(this: World, url: string, method: string, headersToSet: DataTable) {
160
+ await this.page.route(url, async route => {
161
+ const headers = route.request().headers();
162
+ await route.continue({ headers: { ...headers, ...headersToSet.rowsHash() } });
163
+ });
164
+ }
148
165
  );
149
166
 
150
167
  When(
151
- `je saisie le(s) header(s) pour l'Uri {string}`,
152
- async function (this: World, url: string, headersToSet: DataTable) {
153
- await this.page.route(url, async route => {
154
- const headers = route.request().headers();
155
- await route.continue({ headers: { ...headers, ...headersToSet.rowsHash() } });
156
- });
157
- }
168
+ `je saisie le(s) header(s) pour l'Uri {string}`,
169
+ async function(this: World, url: string, headersToSet: DataTable) {
170
+ await this.page.route(url, async route => {
171
+ const headers = route.request().headers();
172
+ await route.continue({ headers: { ...headers, ...headersToSet.rowsHash() } });
173
+ });
174
+ }
158
175
  );
159
176
 
160
- Then(`je dois voir un élément avec le rôle {string} et le nom {string}`, async function (this: World, role: string, name: string) {
161
- await findWithRoleAndName(this, role, name);
177
+ Then(`je dois voir un élément avec le rôle {string} et le nom {string}`, async function(this: World, role: string, name: string) {
178
+ await findWithRoleAndName(this, role, name);
162
179
  });
163
180
 
164
- Then(`je dois voir un élément qui contient {string}`, async function (this: World, textContent: string) {
165
- // TODO partie pris de faire en exactitude. A voir si on doit faire 2 phrases https://playwright.dev/docs/api/class-locator#locator-get-by-text
166
- await getPageOrElement(this).then((element) => expect(element.getByText(textContent, { exact: true })).toHaveCount(1));
181
+ Then(`je dois voir un élément qui contient {string}`, async function(this: World, textContent: string) {
182
+ // TODO partie pris de faire en exactitude. A voir si on doit faire 2 phrases https://playwright.dev/docs/api/class-locator#locator-get-by-text
183
+ await getPageOrElement(this).then((element) => expect(element.getByText(textContent, { exact: true })).toHaveCount(1));
167
184
  });
168
185
 
169
186
  Then(`je ne dois pas voir un élément qui contient {string}`, async function(this: World, textContent: string) {
170
- await getPageOrElement(this).then((element) => expect(element.getByText(textContent, { exact: true })).toHaveCount(0));
187
+ await getPageOrElement(this).then((element) => expect(element.getByText(textContent, { exact: true })).toHaveCount(0));
171
188
  });
172
189
 
173
190
  Then(`je dois voir un élément ayant pour testId {string}`, async function(this: World, testId: string) {
174
- testId = encodeURIComponent(testId);
175
- await getPageOrElement(this).then((element) => expect(element.getByTestId(testId, { exact: true })).toHaveCount(1));
191
+ testId = encodeURIComponent(testId);
192
+ await getPageOrElement(this).then((element) => expect(element.getByTestId(testId, { exact: true })).toHaveCount(1));
176
193
  });
177
194
 
178
195
  Then(`je ne dois pas voir un élément ayant pour testId {string}`, async function(this: World, testId: string) {
179
- testId = encodeURIComponent(testId);
180
- await getPageOrElement(this).then((element) => expect(element.getByTestId(testId, { exact: true })).toHaveCount(0));
196
+ testId = encodeURIComponent(testId);
197
+ await getPageOrElement(this).then((element) => expect(element.getByTestId(testId, { exact: true })).toHaveCount(0));
181
198
  });
182
199
 
183
200
  Then(
184
- `je ne dois pas avoir de problèmes d'accessibilité`,
185
- async function (this: World) {
186
- await injectAxe(this.page as Page);
187
- await checkA11y(this.page as Page);
188
- });
201
+ `je ne dois pas avoir de problèmes d'accessibilité`,
202
+ async function(this: World) {
203
+ await injectAxe(this.page as Page);
204
+ await checkA11y(this.page as Page);
205
+ });
206
+
207
+ Then(
208
+ `je ne dois pas avoir de problèmes d'accessibilité avec le fichier json suivant d'option {}`,
209
+ async function(this: World, option: any) {
210
+ await injectAxe(this.page as Page);
211
+ const optionFile = await fs.readFileSync(`playwright/fixtures/${option}`);
212
+ const optionJson = JSON.parse(optionFile.toString());
213
+ await checkA11y(this.page as Page, undefined, {
214
+ axeOptions: optionJson as RunOptions
215
+ });
216
+ });
217
+
218
+ Then(
219
+ `je ne dois pas avoir de problèmes d'accessibilité sur le fichier json suivant de contexte {} et avec le fichier json suivant d'option {}`,
220
+ async function(this: World, context: any, option: any) {
221
+ await injectAxe(this.page as Page);
222
+ const contextFile = await fs.readFileSync(`playwright/fixtures/${context}`);
223
+ const optionFile = await fs.readFileSync(`playwright/fixtures/${option}`);
224
+ const optionJson = JSON.parse(optionFile.toString());
225
+ await checkA11y(this.page as Page, JSON.parse(contextFile.toString()) as ContextObject, {
226
+ axeOptions: optionJson as RunOptions
227
+ });
228
+ });
229
+
230
+ Then(
231
+ `je ne dois pas avoir de problèmes d'accessibilité de niveau critique`,
232
+ async function(this: World) {
233
+ await injectAxe(this.page as Page);
234
+ await checkA11y(this.page as Page, undefined, {
235
+ includedImpacts: ["critical"]
236
+ });
237
+ });
238
+
239
+ Then(
240
+ `je ne dois pas avoir de problèmes d'accessibilité avec l(es) impact(s) {}`,
241
+ async function(this: World, impacts: any) {
242
+ await injectAxe(this.page as Page);
243
+ await checkA11y(this.page as Page, undefined, {
244
+ includedImpacts: [impacts]
245
+ });
246
+ });
247
+ Then(
248
+ `je ne dois pas avoir de problèmes d'accessibilité avec le(s) standard(s) {}`,
249
+ async function(this: World, tags: any) {
250
+ await injectAxe(this.page as Page);
251
+ await checkA11y(this.page as Page, undefined, {
252
+ axeOptions: {
253
+ runOnly: {
254
+ type: "tag",
255
+ values: [tags]
256
+ }
257
+ }
258
+ });
259
+ });
189
260
 
190
261
  Then(
191
- `je ne dois pas voir un élément avec le rôle {string} et le nom {string}`,
192
- async function(this: World, role: string, name: string) {
193
- await notFoundWithRoleAndName(this, role, name);
194
- }
262
+ `je ne dois pas voir un élément avec le rôle {string} et le nom {string}`,
263
+ async function(this: World, role: string, name: string) {
264
+ await notFoundWithRoleAndName(this, role, name);
265
+ }
195
266
  );
196
267
  Then(
197
- `je dois voir un élément avec le rôle {string} et le nom {string} et pour contenu {string}`,
198
- async function(this: World, expectedRole: string, name: string, expectedTextContent: string) {
199
- await findWithRoleAndNameAndContent(this, expectedRole, name, expectedTextContent);
200
- }
268
+ `je dois voir un élément avec le rôle {string} et le nom {string} et pour contenu {string}`,
269
+ async function(this: World, expectedRole: string, name: string, expectedTextContent: string) {
270
+ await findWithRoleAndNameAndContent(this, expectedRole, name, expectedTextContent);
271
+ }
201
272
  );
202
273
 
203
274
  Then(
204
- `je dois voir un élément avec le rôle {string} et le nom {string} et pour contenu {string} inactif`,
205
- async function(this: World, expectedRole: string, name: string, expectedTextContent: string) {
206
- await findWithRoleAndNameAndContentDisable(this, expectedRole, name, expectedTextContent);
207
- }
275
+ `je dois voir un élément avec le rôle {string} et le nom {string} et pour contenu {string} inactif`,
276
+ async function(this: World, expectedRole: string, name: string, expectedTextContent: string) {
277
+ await findWithRoleAndNameAndContentDisable(this, expectedRole, name, expectedTextContent);
278
+ }
208
279
  );
209
280
 
210
281
  Then(
211
- `je dois voir un élément avec le rôle {string} et le nom {string} et pour contenu {string} actif`,
212
- async function(this: World, expectedRole: string, name: string, expectedTextContent: string) {
213
- await findWithRoleAndNameAndContentEnable(this, expectedRole, name, expectedTextContent);
214
- }
282
+ `je dois voir un élément avec le rôle {string} et le nom {string} et pour contenu {string} actif`,
283
+ async function(this: World, expectedRole: string, name: string, expectedTextContent: string) {
284
+ await findWithRoleAndNameAndContentEnable(this, expectedRole, name, expectedTextContent);
285
+ }
215
286
  );
216
287
 
217
- Then(`je dois voir un élément ayant pour aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
218
- expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
219
- await getPageOrElement(this).then((element) => expect(element.getByLabel(expectedAriaLabel)).toHaveCount(1));
288
+ Then(`je dois voir un élément ayant pour aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
289
+ expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
290
+ await getPageOrElement(this).then((element) => expect(element.getByLabel(expectedAriaLabel)).toHaveCount(1));
220
291
  });
221
292
 
222
293
  Then(`je ne dois pas voir un élément ayant pour aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
223
- expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
224
- await getPageOrElement(this).then((element) => expect(element.getByLabel(expectedAriaLabel)).toHaveCount(0));
294
+ expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
295
+ await getPageOrElement(this).then((element) => expect(element.getByLabel(expectedAriaLabel)).toHaveCount(0));
225
296
  });
226
297
 
227
- Then(`je dois voir un élément ayant pour aria-label {string} et pour contenu {string}`, async function(this: World, expectedAriaLabel: string, expectedTextContent: string) {
228
- expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
229
- await getPageOrElement(this).then(async (element) => {
230
- const byLabel = await element.getByLabel(expectedAriaLabel);
231
- await expect(byLabel).toHaveCount(1);
232
- await expect(byLabel.filter({ hasText: expectedTextContent })).toHaveCount(1);
233
- });
298
+ Then(`je dois voir un élément ayant pour aria-label {string} et pour contenu {string}`, async function(this: World, expectedAriaLabel: string, expectedTextContent: string) {
299
+ expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
300
+ await getPageOrElement(this).then(async (element) => {
301
+ const byLabel = await element.getByLabel(expectedAriaLabel);
302
+ await expect(byLabel).toHaveCount(1);
303
+ await expect(byLabel.filter({ hasText: expectedTextContent })).toHaveCount(1);
304
+ });
234
305
  });
235
306
 
236
307
  Then(`je dois consommer le bouchon nommé {string}`, async function(this: World, name: string) {
237
- const cookie = await getCookie(this, COOKIE_NAME.MOCK_URL);
238
- const mockUrls: MockType[] = JSON.parse(cookie.value);
239
- const mockUrl: MockType | undefined = mockUrls.find(mock => mock.name === name);
240
- await expect(mockUrl).not.toBeUndefined();
241
- const requestPromise = await this.page.waitForResponse(mockUrl?.url);
242
- const request = await requestPromise;
243
- await deleteCookieByValue(this, COOKIE_NAME.MOCK_URL, mockUrl);
244
- // console.debug("request: ", request);
308
+ const cookie = await getCookie(this, COOKIE_NAME.MOCK_URL);
309
+ const mockUrls: MockType[] = JSON.parse(cookie.value);
310
+ const mockUrl: MockType | undefined = mockUrls.find(mock => mock.name === name);
311
+ await expect(mockUrl).not.toBeUndefined();
312
+ const requestPromise = await this.page.waitForResponse(mockUrl?.url);
313
+ const request = await requestPromise;
314
+ await deleteCookieByValue(this, COOKIE_NAME.MOCK_URL, mockUrl);
315
+ // console.debug("request: ", request);
245
316
  });
246
317
  //
247
- Then(`j'attends {int} ms`, async function (this: World, ms: number) {
248
- await this.page.waitForTimeout(ms);
318
+ Then(`j'attends {int} ms`, async function(this: World, ms: number) {
319
+ await this.page.waitForTimeout(ms);
249
320
  });
250
321
 
251
322
  Then(
252
- `je dois voir les attributs avec valeurs suivantes`,
253
- async function (this: World, expectedAttributeList: DataTable) {
254
- await getPageOrElement(this).then(async (element) => {
255
- // console.debug("expectedAttributeList.raw(),", expectedAttributeList.raw())
256
- for (const expectedAttribute of expectedAttributeList.raw()) {
257
- const attributeName = expectedAttribute[0];
258
- const attributeValue = expectedAttribute[1];
259
- // await showAttributesInLocator(element);
260
- expect(await element.getAttribute(attributeName)).toEqual(attributeValue);
261
- }
262
- });
263
- }
323
+ `je dois voir les attributs avec valeurs suivantes`,
324
+ async function(this: World, expectedAttributeList: DataTable) {
325
+ await getPageOrElement(this).then(async (element) => {
326
+ // console.debug("expectedAttributeList.raw(),", expectedAttributeList.raw())
327
+ for (const expectedAttribute of expectedAttributeList.raw()) {
328
+ const attributeName = expectedAttribute[0];
329
+ const attributeValue = expectedAttribute[1];
330
+ // await showAttributesInLocator(element);
331
+ expect(await element.getAttribute(attributeName)).toEqual(attributeValue);
332
+ }
333
+ });
334
+ }
264
335
  );
265
336
 
266
337
  Then(
267
- `je dois voir des elements de la liste ayant pour nom {string}`,
268
- async function(this: World, expectedListName: string, expectedElementsOfList: DataTable) {
269
- await withinRoleAndName(this, "list", expectedListName);
270
- await getPageOrElement(this).then(async (element) => {
271
- const listitem = await element.getByRole("listitem").all();
272
- const foundedElement: any[] = [];
273
- for (const element of listitem) {
274
- const textContent = await element.textContent();
275
- foundedElement.push([textContent]);
276
- }
277
- await expect(foundedElement.length).toBeGreaterThan(0);
278
- // console.debug(`expected [${expectedElementsOfList.raw()}] to be [${foundedElement}]`);
279
- await expect(listitem.length).toEqual(expectedElementsOfList.raw().length);
280
- await expect(foundedElement).toEqual(expectedElementsOfList.raw());
281
- });
282
- }
338
+ `je dois voir des elements de la liste ayant pour nom {string}`,
339
+ async function(this: World, expectedListName: string, expectedElementsOfList: DataTable) {
340
+ await withinRoleAndName(this, "list", expectedListName);
341
+ await getPageOrElement(this).then(async (element) => {
342
+ const listitem = await element.getByRole("listitem").all();
343
+ const foundedElement: any[] = [];
344
+ for (const element of listitem) {
345
+ const textContent = await element.textContent();
346
+ foundedElement.push([textContent]);
347
+ }
348
+ await expect(foundedElement.length).toBeGreaterThan(0);
349
+ // console.debug(`expected [${expectedElementsOfList.raw()}] to be [${foundedElement}]`);
350
+ await expect(listitem.length).toEqual(expectedElementsOfList.raw().length);
351
+ await expect(foundedElement).toEqual(expectedElementsOfList.raw());
352
+ });
353
+ }
283
354
  );
284
355
 
356
+ async function pressKey(world: World, element: Locator, key: string) {
357
+ switch (key) {
358
+ case KEY_PRESS.TAB:
359
+ await element.press("Tab");
360
+ break;
361
+ case KEY_PRESS.REVERSE_TAB:
362
+ await element.press("ShiftLeft+Tab");
363
+ break;
364
+ case KEY_PRESS.UP:
365
+ await element.press("ArrowUp");
366
+ break;
367
+ case KEY_PRESS.DOWN:
368
+ await element.press("ArrowDown");
369
+ break;
370
+ case KEY_PRESS.LEFT:
371
+ await element.press("ArrowLeft");
372
+ break;
373
+ case KEY_PRESS.RIGHT:
374
+ await element.press("ArrowRight");
375
+ break;
376
+ default:
377
+ console.error("the command" + key + " is unrecognized.");
378
+ break;
379
+ }
380
+ await deleteCookieByName(world, COOKIE_NAME.SELECTED_ELEMENT);
381
+ await addCookieWhenValueIsList(world, COOKIE_NAME.SELECTED_ELEMENT, { name: FILTER_TYPE.SELECTOR_PARENT, value: "*:focus" });
382
+ }
383
+
285
384