webship-js 2.0.11 → 2.0.13
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/.circleci/config.yml +10 -1
- package/.drone.yml +7 -7
- package/.github/workflows/github-actions.yml +48 -0
- package/.gitlab-ci.yml +9 -4
- package/.harness/webship-js-pipeline.yml +5 -6
- package/.semaphore/semaphore.yml +6 -9
- package/.teamcity/settings.kts +7 -6
- package/.travis.yml +6 -1
- package/AGENTS.md +1 -1
- package/CLAUDE.md +65 -23
- package/Jenkinsfile +5 -3
- package/azure-pipelines.yml +17 -8
- package/bamboo-specs/bamboo.yml +9 -15
- package/bin/init-webship.js +53 -10
- package/bitbucket-pipelines.yml +5 -1
- package/buildspec.yml +6 -7
- package/cloudbuild.yaml +28 -12
- package/codefresh.yml +6 -6
- package/cucumber.js +17 -10
- package/docs/00-quick-start.md +8 -0
- package/docs/02-bbr-smart-waits.md +15 -10
- package/docs/03-selector-registry.md +24 -0
- package/docs/04-step-reference.md +51 -25
- package/docs/05-web-first-assertions.md +6 -0
- package/docs/07-auth-state.md +1 -1
- package/docs/08-clock-mocking.md +21 -2
- package/docs/09-api-testing.md +40 -2
- package/docs/10-accessibility.md +2 -0
- package/docs/11-debugging.md +3 -1
- package/docs/12-ai-agent-guide.md +5 -0
- package/docs/13-faq.md +72 -1
- package/docs/14-recipes-cookbook.md +2 -0
- package/docs/15-tag-conventions.md +2 -1
- package/docs/16-ci-cd.md +140 -119
- package/docs/README.md +5 -5
- package/docs/advanced-screenshots.md +3 -1
- package/docs/api-step-definitions.md +16 -2
- package/docs/global-settings.md +69 -17
- package/docs/install-webship-js.md +2 -0
- package/docs/step-definitions/then-i-should-see.md +14 -1
- package/docs/step-definitions/then-item-checkbox.md +2 -0
- package/docs/step-definitions/when-i-fill.md +4 -0
- package/docs/step-definitions/when-i-select-option-select-list.md +2 -0
- package/examples/check-switch.html +37 -0
- package/examples/choice-controls.html +29 -0
- package/examples/click-whitespace.html +37 -0
- package/examples/datetime-fields.html +52 -0
- package/examples/element-selector-hint.html +16 -0
- package/examples/field-states.html +27 -0
- package/examples/fill-in-empty.html +26 -0
- package/examples/fill-unreachable.html +27 -0
- package/examples/follow-hidden-first.html +29 -0
- package/examples/iframe-inner.html +20 -0
- package/examples/iframe-nested.html +16 -0
- package/examples/iframe-outer.html +15 -0
- package/examples/multi-value-fields.html +54 -0
- package/examples/registered-names.html +15 -0
- package/examples/select-by-label.html +33 -0
- package/examples/settle-budget.html +21 -0
- package/examples/sorted-tables.html +38 -0
- package/examples/text-matching.html +48 -0
- package/examples/text-order.html +25 -0
- package/examples/touch.html +22 -0
- package/examples/viewport-top.html +36 -0
- package/package.json +17 -1
- package/playwright.config.ts +3 -1
- package/tests/check-api-launch-url.js +106 -0
- package/tests/check-assets.js +103 -0
- package/tests/check-attachments.js +105 -0
- package/tests/check-breakpoints.js +117 -0
- package/tests/check-clock.js +143 -0
- package/tests/check-config.js +90 -0
- package/tests/check-context.js +215 -0
- package/tests/check-dry-run.js +104 -0
- package/tests/check-examples.js +10 -4
- package/tests/check-exit-report.js +141 -0
- package/tests/check-javascript-errors.js +105 -0
- package/tests/check-must-fail.js +5 -4
- package/tests/check-network-changed.js +137 -0
- package/tests/check-scaffold.js +54 -2
- package/tests/check-screenshots.js +117 -0
- package/tests/check-settle-verbs.js +137 -0
- package/tests/check-time-limit.js +104 -0
- package/tests/check-video.js +156 -0
- package/tests/check-world.js +167 -0
- package/tests/features/api-base-url.feature +25 -0
- package/tests/features/api-form-data.feature +18 -0
- package/tests/features/api-json-paths.feature +24 -0
- package/tests/features/api-response-contains.feature +21 -0
- package/tests/features/api-response-header-presence.feature +17 -0
- package/tests/features/api-response-header.feature +17 -0
- package/tests/features/api-saved-placeholders.feature +37 -0
- package/tests/features/api-step-definitions-individual.feature +1 -1
- package/tests/features/api-tables.feature +40 -0
- package/tests/features/breakpoints.feature +25 -0
- package/tests/features/check-switch.feature +28 -0
- package/tests/features/choice-controls.feature +35 -0
- package/tests/features/click-whitespace.feature +29 -0
- package/tests/features/complete-api-testing-examples.feature +1 -1
- package/tests/features/datetime-field-lookup.feature +29 -0
- package/tests/features/element-selector-hint.feature +14 -0
- package/tests/features/field-state.feature +21 -0
- package/tests/features/fill-in-empty-value.feature +41 -0
- package/tests/features/fill-reachable.feature +13 -0
- package/tests/features/follow-hidden-first.feature +9 -0
- package/tests/features/iframe-nested.feature +43 -0
- package/tests/features/javascript-tolerated-errors.feature +20 -0
- package/tests/features/modal-open.feature +13 -0
- package/tests/features/multi-value-field-lookup.feature +30 -0
- package/tests/features/registered-names.feature +14 -0
- package/tests/features/select-by-label.feature +31 -0
- package/tests/features/selector-files.feature +14 -0
- package/tests/features/selectors-table-header.feature +35 -0
- package/tests/features/settle-budget.feature +11 -0
- package/tests/features/sorted-tables.feature +19 -0
- package/tests/features/storage-quoted-values.feature +26 -0
- package/tests/features/text-matching.feature +38 -0
- package/tests/features/text-order.feature +14 -0
- package/tests/features/touch.feature +21 -0
- package/tests/features/viewport-top.feature +13 -0
- package/tests/features/xml-namespaces.feature +34 -0
- package/tests/must-fail/api-json-paths.feature +21 -0
- package/tests/must-fail/api-response-contains.feature +23 -0
- package/tests/must-fail/api-response-header-presence.feature +17 -0
- package/tests/must-fail/api-response-header.feature +21 -0
- package/tests/must-fail/api-without-base-url.feature +11 -0
- package/tests/must-fail/breakpoints.feature +15 -0
- package/tests/must-fail/choice-controls.feature +25 -0
- package/tests/must-fail/clock.feature +11 -0
- package/tests/must-fail/datetime-field.feature +10 -0
- package/tests/must-fail/element-selector-hint.feature +17 -0
- package/tests/must-fail/field-state.feature +20 -0
- package/tests/must-fail/fill-field.feature +30 -0
- package/tests/must-fail/iframe-text.feature +17 -0
- package/tests/must-fail/modal-open.feature +26 -0
- package/tests/must-fail/multi-value-field.feature +18 -0
- package/tests/must-fail/registered-names.feature +25 -0
- package/tests/must-fail/select-list.feature +15 -0
- package/tests/must-fail/selector-files.feature +10 -0
- package/tests/must-fail/sorted-tables.feature +20 -0
- package/tests/must-fail/storage-before-a-page.feature +13 -0
- package/tests/must-fail/text-matching.feature +16 -0
- package/tests/must-fail/text-order.feature +15 -0
- package/tests/must-fail/viewport-top.feature +20 -0
- package/tests/must-fail/yaml-numbers.feature +48 -0
- package/tests/step-definitions/a11y.steps.js +24 -15
- package/tests/step-definitions/action.steps.js +53 -20
- package/tests/step-definitions/api.steps.js +349 -67
- package/tests/step-definitions/assertion.steps.js +100 -10
- package/tests/step-definitions/auth.steps.js +15 -18
- package/tests/step-definitions/clock.steps.js +22 -0
- package/tests/step-definitions/debug.steps.js +8 -0
- package/tests/step-definitions/dialog.steps.js +7 -0
- package/tests/step-definitions/element.steps.js +132 -17
- package/tests/step-definitions/field.steps.js +412 -96
- package/tests/step-definitions/form.steps.js +88 -37
- package/tests/step-definitions/iframe.steps.js +89 -29
- package/tests/step-definitions/input.steps.js +26 -7
- package/tests/step-definitions/javascript.steps.js +64 -22
- package/tests/step-definitions/modal.steps.js +79 -13
- package/tests/step-definitions/navigation.steps.js +14 -0
- package/tests/step-definitions/network.steps.js +15 -5
- package/tests/step-definitions/response.steps.js +6 -4
- package/tests/step-definitions/responsive.steps.js +26 -33
- package/tests/step-definitions/screenshot.steps.js +25 -8
- package/tests/step-definitions/scroll.steps.js +20 -0
- package/tests/step-definitions/selectors.steps.js +95 -48
- package/tests/step-definitions/storage.steps.js +38 -13
- package/tests/step-definitions/table.steps.js +81 -6
- package/tests/step-definitions/video.steps.js +52 -55
- package/tests/step-definitions/wait.steps.js +88 -23
- package/tests/step-definitions/web-first.steps.js +69 -35
- package/tests/step-definitions/webship.js +741 -145
- package/tests/step-definitions/xml.steps.js +49 -15
- package/tests/step-definitions/yaml.steps.js +45 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { friendly } = require('./webship');
|
|
3
|
+
const { friendly, failure, registeredNameHint } = require('./webship');
|
|
4
4
|
|
|
5
5
|
// Web-first assertion steps — each matcher polls the live page until the
|
|
6
6
|
// condition holds or the per-step timeout elapses. The assertion IS the
|
|
@@ -11,6 +11,7 @@ const { friendly } = require('./webship');
|
|
|
11
11
|
|
|
12
12
|
const { Then, When } = require('@cucumber/cucumber');
|
|
13
13
|
const assert = require('assert');
|
|
14
|
+
const { OWN_LENGTH, withinTimeLimit } = require('./wait.steps');
|
|
14
15
|
|
|
15
16
|
function parseTimeout(secondsStr) {
|
|
16
17
|
const n = secondsStr ? parseInt(secondsStr, 10) : 0;
|
|
@@ -25,20 +26,41 @@ function normalizeText(value) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
// Poll fn() until it returns truthy, or timeout. fn() returns a value;
|
|
28
|
-
// `predicate` decides pass/fail. Returns the last value seen.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
// `predicate` decides pass/fail. Returns the last value seen. The matchers
|
|
30
|
+
// that call it take OWN_LENGTH: "within 60 seconds" runs past the step
|
|
31
|
+
// timeout, bounded by withinTimeLimit. `context.hint`, when the step was given
|
|
32
|
+
// a name of the selector registry, goes into the failure with the page.
|
|
33
|
+
async function poll(fn, predicate, timeout, message, context) {
|
|
34
|
+
return withinTimeLimit(timeout, `The check "${message}"`, async () => {
|
|
35
|
+
const deadline = Date.now() + timeout;
|
|
36
|
+
let last;
|
|
37
|
+
while (Date.now() < deadline) {
|
|
38
|
+
try {
|
|
39
|
+
last = await fn();
|
|
40
|
+
if (predicate(last)) return last;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
last = e;
|
|
43
|
+
}
|
|
44
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
const seen = typeof last === 'object' ? JSON.stringify(last) : String(last);
|
|
47
|
+
if (context && context.hint) {
|
|
48
|
+
throw failure(context.page, `${message}.`, { found: `last seen: ${seen}`, hint: context.hint });
|
|
49
|
+
}
|
|
50
|
+
throw friendly(`${message} (last seen: ${seen})`);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The " within N seconds" a step was given, to repeat it in a hint.
|
|
55
|
+
function within(sec) {
|
|
56
|
+
return sec ? ` within ${sec} seconds` : '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The failure context of a web-first step given a name of the selector
|
|
60
|
+
// registry: the same step with the selector, and the bare-name step that
|
|
61
|
+
// reads the registry when there is one.
|
|
62
|
+
function registryContext(world, selector, sameStep, bare) {
|
|
63
|
+
return { page: world.page, hint: registeredNameHint(world, selector, { bare, withSelector: sameStep }) };
|
|
42
64
|
}
|
|
43
65
|
|
|
44
66
|
async function checkState(locator, state) {
|
|
@@ -69,13 +91,15 @@ async function checkState(locator, state) {
|
|
|
69
91
|
* Example #5: Then "input#email" should be editable
|
|
70
92
|
*
|
|
71
93
|
*/
|
|
72
|
-
Then(/^"([^"]*)" should be (visible|hidden|attached|focused|enabled|disabled|editable)(?: within (\d+) seconds?)?$/, async function (selector, state, sec) {
|
|
94
|
+
Then(/^"([^"]*)" should be (visible|hidden|attached|focused|enabled|disabled|editable)(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, state, sec) {
|
|
73
95
|
const loc = this.page.locator(selector);
|
|
74
96
|
await poll(
|
|
75
97
|
() => checkState(loc, state),
|
|
76
98
|
(v) => v === true,
|
|
77
99
|
parseTimeout(sec),
|
|
78
|
-
`Expected "${selector}" to be ${state}
|
|
100
|
+
`Expected "${selector}" to be ${state}`,
|
|
101
|
+
registryContext(this, selector, (s) => `"${s}" should be ${state}${within(sec)}`,
|
|
102
|
+
{ visible: 'I see visible {name}', hidden: "I don't see {name}", focused: 'I see {name} has focus' }[state])
|
|
79
103
|
);
|
|
80
104
|
});
|
|
81
105
|
|
|
@@ -89,13 +113,15 @@ Then(/^"([^"]*)" should be (visible|hidden|attached|focused|enabled|disabled|edi
|
|
|
89
113
|
* Example #5: Then "[data-testid=password]" should not be focused
|
|
90
114
|
*
|
|
91
115
|
*/
|
|
92
|
-
Then(/^"([^"]*)" should not be (visible|hidden|attached|focused|enabled|disabled|editable)(?: within (\d+) seconds?)?$/, async function (selector, state, sec) {
|
|
116
|
+
Then(/^"([^"]*)" should not be (visible|hidden|attached|focused|enabled|disabled|editable)(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, state, sec) {
|
|
93
117
|
const loc = this.page.locator(selector);
|
|
94
118
|
await poll(
|
|
95
119
|
() => checkState(loc, state),
|
|
96
120
|
(v) => v === false,
|
|
97
121
|
parseTimeout(sec),
|
|
98
|
-
`Expected "${selector}" to not be ${state}
|
|
122
|
+
`Expected "${selector}" to not be ${state}`,
|
|
123
|
+
registryContext(this, selector, (s) => `"${s}" should not be ${state}${within(sec)}`,
|
|
124
|
+
{ visible: "I don't see {name}", hidden: 'I see visible {name}' }[state])
|
|
99
125
|
);
|
|
100
126
|
});
|
|
101
127
|
|
|
@@ -110,7 +136,7 @@ Then(/^"([^"]*)" should not be (visible|hidden|attached|focused|enabled|disabled
|
|
|
110
136
|
* Example #5: Then ".banner" should be in the viewport
|
|
111
137
|
*
|
|
112
138
|
*/
|
|
113
|
-
Then(/^"([^"]*)" should be in the viewport(?: within (\d+) seconds?)?$/, async function (selector, sec) {
|
|
139
|
+
Then(/^"([^"]*)" should be in the viewport(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, sec) {
|
|
114
140
|
const loc = this.page.locator(selector).first();
|
|
115
141
|
await poll(
|
|
116
142
|
async () => loc.evaluate((el) => {
|
|
@@ -120,7 +146,8 @@ Then(/^"([^"]*)" should be in the viewport(?: within (\d+) seconds?)?$/, async f
|
|
|
120
146
|
}),
|
|
121
147
|
(v) => v === true,
|
|
122
148
|
parseTimeout(sec),
|
|
123
|
-
`Expected "${selector}" to be in viewport
|
|
149
|
+
`Expected "${selector}" to be in viewport`,
|
|
150
|
+
registryContext(this, selector, (s) => `"${s}" should be in the viewport${within(sec)}`)
|
|
124
151
|
);
|
|
125
152
|
});
|
|
126
153
|
|
|
@@ -135,7 +162,7 @@ Then(/^"([^"]*)" should be in the viewport(?: within (\d+) seconds?)?$/, async f
|
|
|
135
162
|
* Then "#footer" should not be in the viewport
|
|
136
163
|
*
|
|
137
164
|
*/
|
|
138
|
-
Then(/^"([^"]*)" should not be in the viewport(?: within (\d+) seconds?)?$/, async function (selector, sec) {
|
|
165
|
+
Then(/^"([^"]*)" should not be in the viewport(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, sec) {
|
|
139
166
|
const loc = this.page.locator(selector).first();
|
|
140
167
|
await poll(
|
|
141
168
|
async () => loc.evaluate((el) => {
|
|
@@ -145,7 +172,8 @@ Then(/^"([^"]*)" should not be in the viewport(?: within (\d+) seconds?)?$/, asy
|
|
|
145
172
|
}).catch(() => false),
|
|
146
173
|
(v) => v === false,
|
|
147
174
|
parseTimeout(sec),
|
|
148
|
-
`Expected "${selector}" to not be in viewport
|
|
175
|
+
`Expected "${selector}" to not be in viewport`,
|
|
176
|
+
registryContext(this, selector, (s) => `"${s}" should not be in the viewport${within(sec)}`)
|
|
149
177
|
);
|
|
150
178
|
});
|
|
151
179
|
|
|
@@ -159,14 +187,15 @@ Then(/^"([^"]*)" should not be in the viewport(?: within (\d+) seconds?)?$/, asy
|
|
|
159
187
|
* Example #5: Then ".feed-item" should have a count of 25 within 10 seconds
|
|
160
188
|
*
|
|
161
189
|
*/
|
|
162
|
-
Then(/^"([^"]*)" should have a count of (\d+)(?: within (\d+) seconds?)?$/, async function (selector, count, sec) {
|
|
190
|
+
Then(/^"([^"]*)" should have a count of (\d+)(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, count, sec) {
|
|
163
191
|
const expected = parseInt(count, 10);
|
|
164
192
|
const loc = this.page.locator(selector);
|
|
165
193
|
await poll(
|
|
166
194
|
() => loc.count(),
|
|
167
195
|
(v) => v === expected,
|
|
168
196
|
parseTimeout(sec),
|
|
169
|
-
`Expected "${selector}" count to be ${expected}
|
|
197
|
+
`Expected "${selector}" count to be ${expected}`,
|
|
198
|
+
registryContext(this, selector, (s) => `"${s}" should have a count of ${expected}${within(sec)}`)
|
|
170
199
|
);
|
|
171
200
|
});
|
|
172
201
|
|
|
@@ -180,13 +209,14 @@ Then(/^"([^"]*)" should have a count of (\d+)(?: within (\d+) seconds?)?$/, asyn
|
|
|
180
209
|
* Example #5: Then ".alert" should have text "Saved"
|
|
181
210
|
*
|
|
182
211
|
*/
|
|
183
|
-
Then(/^"([^"]*)" should have text "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, text, sec) {
|
|
212
|
+
Then(/^"([^"]*)" should have text "([^"]*)"(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, text, sec) {
|
|
184
213
|
const loc = this.page.locator(selector).first();
|
|
185
214
|
await poll(
|
|
186
215
|
() => loc.textContent(),
|
|
187
216
|
(v) => (v || '').trim() === text,
|
|
188
217
|
parseTimeout(sec),
|
|
189
|
-
`Expected "${selector}" text to be "${text}"
|
|
218
|
+
`Expected "${selector}" text to be "${text}"`,
|
|
219
|
+
registryContext(this, selector, (s) => `"${s}" should have text "${text}"${within(sec)}`)
|
|
190
220
|
);
|
|
191
221
|
});
|
|
192
222
|
|
|
@@ -203,14 +233,15 @@ Then(/^"([^"]*)" should have text "([^"]*)"(?: within (\d+) seconds?)?$/, async
|
|
|
203
233
|
* Example #5: Then ".alert" should contain text "Saved"
|
|
204
234
|
*
|
|
205
235
|
*/
|
|
206
|
-
Then(/^"([^"]*)" should contain text "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, text, sec) {
|
|
236
|
+
Then(/^"([^"]*)" should contain text "([^"]*)"(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, text, sec) {
|
|
207
237
|
const loc = this.page.locator(selector).first();
|
|
208
238
|
const expected = normalizeText(text);
|
|
209
239
|
await poll(
|
|
210
240
|
async () => normalizeText(await loc.textContent()),
|
|
211
241
|
(v) => v.includes(expected),
|
|
212
242
|
parseTimeout(sec),
|
|
213
|
-
`Expected "${selector}" to contain text "${text}"
|
|
243
|
+
`Expected "${selector}" to contain text "${text}"`,
|
|
244
|
+
registryContext(this, selector, (s) => `"${s}" should contain text "${text}"${within(sec)}`)
|
|
214
245
|
);
|
|
215
246
|
});
|
|
216
247
|
|
|
@@ -224,13 +255,14 @@ Then(/^"([^"]*)" should contain text "([^"]*)"(?: within (\d+) seconds?)?$/, asy
|
|
|
224
255
|
* Example #5: Then "select#country" should have value "JO"
|
|
225
256
|
*
|
|
226
257
|
*/
|
|
227
|
-
Then(/^"([^"]*)" should have value "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, value, sec) {
|
|
258
|
+
Then(/^"([^"]*)" should have value "([^"]*)"(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, value, sec) {
|
|
228
259
|
const loc = this.page.locator(selector).first();
|
|
229
260
|
await poll(
|
|
230
261
|
() => loc.inputValue(),
|
|
231
262
|
(v) => v === value,
|
|
232
263
|
parseTimeout(sec),
|
|
233
|
-
`Expected "${selector}" value to be "${value}"
|
|
264
|
+
`Expected "${selector}" value to be "${value}"`,
|
|
265
|
+
registryContext(this, selector, (s) => `"${s}" should have value "${value}"${within(sec)}`)
|
|
234
266
|
);
|
|
235
267
|
});
|
|
236
268
|
|
|
@@ -244,13 +276,14 @@ Then(/^"([^"]*)" should have value "([^"]*)"(?: within (\d+) seconds?)?$/, async
|
|
|
244
276
|
* Example #5: Then "input#email" should have attribute "type" with value "email"
|
|
245
277
|
*
|
|
246
278
|
*/
|
|
247
|
-
Then(/^"([^"]*)" should have attribute "([^"]*)" with value "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, attr, value, sec) {
|
|
279
|
+
Then(/^"([^"]*)" should have attribute "([^"]*)" with value "([^"]*)"(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, attr, value, sec) {
|
|
248
280
|
const loc = this.page.locator(selector).first();
|
|
249
281
|
await poll(
|
|
250
282
|
() => loc.getAttribute(attr),
|
|
251
283
|
(v) => v === value,
|
|
252
284
|
parseTimeout(sec),
|
|
253
|
-
`Expected "${selector}" attribute "${attr}" to be "${value}"
|
|
285
|
+
`Expected "${selector}" attribute "${attr}" to be "${value}"`,
|
|
286
|
+
registryContext(this, selector, (s) => `"${s}" should have attribute "${attr}" with value "${value}"${within(sec)}`)
|
|
254
287
|
);
|
|
255
288
|
});
|
|
256
289
|
|
|
@@ -264,13 +297,14 @@ Then(/^"([^"]*)" should have attribute "([^"]*)" with value "([^"]*)"(?: within
|
|
|
264
297
|
* Example #5: Then "[data-testid=card]" should have class "highlighted"
|
|
265
298
|
*
|
|
266
299
|
*/
|
|
267
|
-
Then(/^"([^"]*)" should have class "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, cls, sec) {
|
|
300
|
+
Then(/^"([^"]*)" should have class "([^"]*)"(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (selector, cls, sec) {
|
|
268
301
|
const loc = this.page.locator(selector).first();
|
|
269
302
|
await poll(
|
|
270
303
|
() => loc.getAttribute('class'),
|
|
271
304
|
(v) => (v || '').split(/\s+/).includes(cls),
|
|
272
305
|
parseTimeout(sec),
|
|
273
|
-
`Expected "${selector}" to have class "${cls}"
|
|
306
|
+
`Expected "${selector}" to have class "${cls}"`,
|
|
307
|
+
registryContext(this, selector, (s) => `"${s}" should have class "${cls}"${within(sec)}`)
|
|
274
308
|
);
|
|
275
309
|
});
|
|
276
310
|
|
|
@@ -298,7 +332,7 @@ When(/^(I |we )*click the "([^"]*)" (button|link|tab|menuitem|checkbox|radio|opt
|
|
|
298
332
|
* Example #5: Then the "Premium" radio should be visible
|
|
299
333
|
*
|
|
300
334
|
*/
|
|
301
|
-
Then(/^the "([^"]*)" (button|link|tab|menuitem|checkbox|radio|option) should be visible(?: within (\d+) seconds?)?$/, async function (name, role, sec) {
|
|
335
|
+
Then(/^the "([^"]*)" (button|link|tab|menuitem|checkbox|radio|option) should be visible(?: within (\d+) seconds?)?$/, OWN_LENGTH, async function (name, role, sec) {
|
|
302
336
|
const loc = this.page.getByRole(role, { name }).first();
|
|
303
337
|
await poll(
|
|
304
338
|
() => loc.isVisible(),
|