@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.
- package/dist/cucumber/step_definitions/playwright/_.common.d.ts +13 -13
- package/dist/cucumber/step_definitions/playwright/_.common.js +13 -117
- package/dist/cucumber/step_definitions/playwright/base-check-engine.d.ts +13 -13
- package/dist/cucumber/step_definitions/playwright/base-check-engine.js +96 -15
- package/dist/cucumber/step_definitions/playwright/core-engine.d.ts +2 -1
- package/dist/cucumber/step_definitions/playwright/core-engine.js +4 -0
- package/dist/cucumber/step_definitions/playwright/generated/_en-generated-cucumber-steps-definition.js +95 -14
- package/dist/cucumber/step_definitions/playwright/generated/_fr-generated-cucumber-steps-definition.js +95 -14
- package/package.json +2 -2
- package/src/cucumber/step_definitions/playwright/generated/_en-generated-cucumber-steps-definition.ts +279 -180
- package/src/cucumber/step_definitions/playwright/generated/_fr-generated-cucumber-steps-definition.ts +279 -180
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(`I set viewport to preset {string}`, async function(this: World, viewportPreset: string) {
|
|
46
|
-
|
|
47
|
+
await this.page.setViewportSize(devices[viewportPreset].viewport);
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
Given(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
`I set viewport with width {int} and height {int}`, 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(`I visit path {string}`, { timeout: 60 * 1000 }, async function
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
Given(`I visit path {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(`I click`, async function
|
|
62
|
-
|
|
62
|
+
When(`I click`, 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(`Within the element with aria-label {string}`, async function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
When(`Within the element with 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(`I reset context`, async function
|
|
72
|
-
|
|
72
|
+
When(`I reset context`, async function(this: World) {
|
|
73
|
+
await this.context.clearCookies();
|
|
73
74
|
});
|
|
74
75
|
|
|
75
|
-
When(`Within the element with selector {string}`, async function
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
When(`Within the element with selector {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(`I type the sentence {string}`, async function
|
|
81
|
+
When(`I type the sentence {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(`I press {int} times on {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
|
-
|
|
83
|
-
|
|
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(`I
|
|
89
|
-
|
|
99
|
+
When(`I press {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(`I set timeout with value {int}`, async function(this: World, newTimeout: number) {
|
|
106
|
+
await this.testInfo.setTimeout(newTimeout);
|
|
90
107
|
});
|
|
91
108
|
|
|
92
109
|
|
|
93
|
-
When(`Within the element with role {string} and name {string}`, async function
|
|
94
|
-
|
|
110
|
+
When(`Within the element with role {string} and name {string}`, async function(this: World, role: string, name: string) {
|
|
111
|
+
await withinRoleAndName(this, role, name);
|
|
95
112
|
});
|
|
96
113
|
|
|
97
|
-
When(`Within the element with testId {string}`, async function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
114
|
+
When(`Within the element with 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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
`I mock a request {} on url {string} named {string} with content {}`,
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
`I mock a request {} on url {string} named {string} with status code {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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
`I mock a request {} on url {string} named {string} with fixture {}`,
|
|
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(`I should see an element with selector {string}`, async function
|
|
137
|
-
|
|
153
|
+
Then(`I should see an element with selector {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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
158
|
+
`I set header(s) for uri {string} and method {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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
168
|
+
`I set header(s) for 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(`I should see an element with role {string} and name {string}`, async function
|
|
161
|
-
|
|
177
|
+
Then(`I should see an element with role {string} and name {string}`, async function(this: World, role: string, name: string) {
|
|
178
|
+
await findWithRoleAndName(this, role, name);
|
|
162
179
|
});
|
|
163
180
|
|
|
164
|
-
Then(`I should see an element with content {string}`, async function
|
|
165
|
-
|
|
166
|
-
|
|
181
|
+
Then(`I should see an element with content {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(`I should not see an element with content {string}`, async function(this: World, textContent: string) {
|
|
170
|
-
|
|
187
|
+
await getPageOrElement(this).then((element) => expect(element.getByText(textContent, { exact: true })).toHaveCount(0));
|
|
171
188
|
});
|
|
172
189
|
|
|
173
190
|
Then(`I should see an element with testId {string}`, async function(this: World, testId: string) {
|
|
174
|
-
|
|
175
|
-
|
|
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(`I should not see an element with testId {string}`, async function(this: World, testId: string) {
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
201
|
+
`I should not have any accessibility issue`,
|
|
202
|
+
async function(this: World) {
|
|
203
|
+
await injectAxe(this.page as Page);
|
|
204
|
+
await checkA11y(this.page as Page);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
Then(
|
|
208
|
+
`I should not have any accessibility issue with option json fixture {}`,
|
|
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
|
+
`I should not have any accessibility issue with context json fixture {} and option json fixture {}`,
|
|
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
|
+
`I should not have any critical accessibility issue`,
|
|
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
|
+
`I should not have any accessibility issue with {} 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
|
+
`I should not have any accessibility issue with accessibility 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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
262
|
+
`I should not see an element with role {string} and name {string}`,
|
|
263
|
+
async function(this: World, role: string, name: string) {
|
|
264
|
+
await notFoundWithRoleAndName(this, role, name);
|
|
265
|
+
}
|
|
195
266
|
);
|
|
196
267
|
Then(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
268
|
+
`I should see an element with role {string} and name {string} and content {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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
275
|
+
`I should see an element with role {string} and name {string} and content {string} disabled`,
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
282
|
+
`I should see an element with role {string} and name {string} and content {string} not disabled`,
|
|
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(`I should see an element with aria-label {string}`, async function(this: World, expectedAriaLabel: string)
|
|
218
|
-
|
|
219
|
-
|
|
288
|
+
Then(`I should see an element with 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(`I should not see an element with aria-label {string}`, async function(this: World, expectedAriaLabel: string) {
|
|
223
|
-
|
|
224
|
-
|
|
294
|
+
expectedAriaLabel = encodeURIComponent(expectedAriaLabel);
|
|
295
|
+
await getPageOrElement(this).then((element) => expect(element.getByLabel(expectedAriaLabel)).toHaveCount(0));
|
|
225
296
|
});
|
|
226
297
|
|
|
227
|
-
Then(`I should see an element with aria-label {string} and content {string}`, async function(this: World, expectedAriaLabel: string, expectedTextContent: string)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
298
|
+
Then(`I should see an element with aria-label {string} and content {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(`I should consume a mock named {string}`, async function(this: World, name: string) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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(`I wait {int} ms`, async function
|
|
248
|
-
|
|
318
|
+
Then(`I wait {int} ms`, async function(this: World, ms: number) {
|
|
319
|
+
await this.page.waitForTimeout(ms);
|
|
249
320
|
});
|
|
250
321
|
|
|
251
322
|
Then(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
323
|
+
`I should see these attributes with values`,
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
338
|
+
`I should see elements of the list with name {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
|
|