webship-js 2.0.2 → 2.0.4
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 +7 -31
- package/.drone.yml +68 -0
- package/.harness/webship-js-pipeline.yml +101 -0
- package/.semaphore/semaphore.yml +58 -0
- package/.teamcity/pom.xml +52 -0
- package/.teamcity/settings.kts +92 -0
- package/.travis.yml +24 -3
- package/AGENTS.md +109 -0
- package/CLAUDE.md +317 -0
- package/Jenkinsfile +54 -0
- package/azure-pipelines.yml +82 -0
- package/bamboo-specs/bamboo.yml +131 -0
- package/bin/generate-reports.js +181 -9
- package/buildspec.yml +56 -0
- package/cloudbuild.yaml +49 -0
- package/codefresh.yml +77 -0
- package/cucumber.js +48 -5
- package/docs/00-quick-start.md +102 -0
- package/docs/01-getting-started.md +102 -0
- package/docs/02-bbr-smart-waits.md +77 -0
- package/docs/03-selector-registry.md +95 -0
- package/docs/04-step-reference.md +799 -0
- package/docs/05-web-first-assertions.md +91 -0
- package/docs/06-network-and-dialogs.md +83 -0
- package/docs/07-auth-state.md +75 -0
- package/docs/08-clock-mocking.md +59 -0
- package/docs/09-api-testing.md +114 -0
- package/docs/10-accessibility.md +167 -0
- package/docs/11-debugging.md +129 -0
- package/docs/12-ai-agent-guide.md +338 -0
- package/docs/13-faq.md +236 -0
- package/docs/14-recipes-cookbook.md +255 -0
- package/docs/15-tag-conventions.md +76 -0
- package/docs/16-ci-cd.md +879 -0
- package/docs/README.md +113 -0
- package/docs/advanced-screenshots/then-i-save-fullscreen-screenshot.md +36 -0
- package/docs/advanced-screenshots/then-i-save-width-x-height-screenshot.md +34 -0
- package/docs/advanced-screenshots/when-i-save-screenshot-name-filename.md +45 -0
- package/docs/advanced-screenshots.md +52 -0
- package/docs/advanced-selectors.md +18 -0
- package/docs/api-step-definitions.md +45 -0
- package/docs/diffy-step-definitions/then-compare-diffy-env1-env2.md +30 -0
- package/docs/diffy-step-definitions/then-create-diffy-comparison-name-value.md +21 -0
- package/docs/diffy-step-definitions/then-create-diffy-comparison.md +25 -0
- package/docs/diffy-step-definitions/then-create-diffy-screenshot-environment-name.md +35 -0
- package/docs/diffy-step-definitions/then-i-take-screenshot.md +21 -0
- package/docs/diffy-step-definitions/then-i-take-screenshots-all-breakpoints.md +27 -0
- package/docs/diffy-step-definitions/then-send-screenshots-diffy-name-value.md +27 -0
- package/docs/diffy-step-definitions/then-upload-folder-url-diffy-snapshotname.md +28 -0
- package/docs/diffy-step-definitions/then-wait-diffy-comparison-complete.md +21 -0
- package/docs/diffy-step-definitions/when-i-resize-window-number.md +29 -0
- package/docs/diffy-step-definitions.md +21 -0
- package/docs/global-settings.md +295 -0
- package/docs/install-webship-js/ddev-webship-js.md +52 -0
- package/docs/install-webship-js.md +35 -0
- package/docs/overview.md +41 -0
- package/docs/step-definitions/given-i-am-anonymous-user.md +67 -0
- package/docs/step-definitions/given-i-am-homepage.md +68 -0
- package/docs/step-definitions/given-i-am-specific-page.md +72 -0
- package/docs/step-definitions/then-i-should-be.md +56 -0
- package/docs/step-definitions/then-i-should-see.md +62 -0
- package/docs/step-definitions/then-item-checkbox.md +54 -0
- package/docs/step-definitions/then-item-link-should-contain-url.md +84 -0
- package/docs/step-definitions/then-item-should-contain.md +67 -0
- package/docs/step-definitions/then-radio-button-value-should-be-selected.md +68 -0
- package/docs/step-definitions/then-response-status-code-should-be-number.md +69 -0
- package/docs/step-definitions/then-value-radio-button-selected.md +62 -0
- package/docs/step-definitions/when-i-attach-file-file-name-element.md +71 -0
- package/docs/step-definitions/when-i-check-checkbox.md +60 -0
- package/docs/step-definitions/when-i-click-link.md +51 -0
- package/docs/step-definitions/when-i-click-operation-text-row.md +71 -0
- package/docs/step-definitions/when-i-fill.md +59 -0
- package/docs/step-definitions/when-i-go-homepage.md +60 -0
- package/docs/step-definitions/when-i-go-specific-page.md +67 -0
- package/docs/step-definitions/when-i-move-backward-one-page.md +49 -0
- package/docs/step-definitions/when-i-move-forward-one-page.md +58 -0
- package/docs/step-definitions/when-i-press-button.md +58 -0
- package/docs/step-definitions/when-i-reload-page.md +51 -0
- package/docs/step-definitions/when-i-scroll.md +73 -0
- package/docs/step-definitions/when-i-select-option-select-list.md +53 -0
- package/docs/step-definitions/when-i-select-radio-button-value.md +62 -0
- package/docs/step-definitions/when-i-uncheck-checkbox.md +57 -0
- package/docs/step-definitions/when-i-wait-ajax-finish.md +64 -0
- package/docs/step-definitions/when-i-wait.md +62 -0
- package/docs/step-definitions.md +50 -0
- package/examples/a11y.html +31 -0
- package/examples/cookies.html +10 -0
- package/examples/date.html +12 -0
- package/examples/element.html +11 -0
- package/examples/field.html +24 -0
- package/examples/keyboard.html +11 -0
- package/examples/links.html +9 -0
- package/examples/modal.html +14 -0
- package/examples/path.html +3 -0
- package/examples/table.html +13 -0
- package/examples/video-demo.html +43 -0
- package/package.json +10 -3
- package/playwright.config.ts +3 -2
- package/tests/features/a11y.feature +39 -0
- package/tests/features/cookie.feature +13 -0
- package/tests/features/date.feature +11 -0
- package/tests/features/element.feature +16 -0
- package/tests/features/field.feature +25 -0
- package/tests/features/keyboard.feature +10 -0
- package/tests/features/link.feature +11 -0
- package/tests/features/modal-advanced-example.feature +1 -1
- package/tests/features/modal.feature +11 -0
- package/tests/features/path.feature +16 -0
- package/tests/features/response.feature +8 -0
- package/tests/features/responsive.feature +10 -0
- package/tests/features/table.feature +18 -0
- package/tests/features/video.feature +18 -0
- package/tests/features/wait.feature +7 -0
- package/tests/features/yaml.feature +102 -0
- package/tests/reports/README.md +55 -0
- package/tests/selectors/_canonical-keys.json +113 -0
- package/tests/selectors/back-end-selectors.json +7 -1
- package/tests/selectors/cms-contentful-admin.json +35 -0
- package/tests/selectors/cms-craft-admin.json +39 -0
- package/tests/selectors/cms-drupal-cms-gin.json +56 -0
- package/tests/selectors/cms-drupal-core-claro.json +50 -0
- package/tests/selectors/cms-generic-admin.json +34 -0
- package/tests/selectors/cms-ghost-admin.json +34 -0
- package/tests/selectors/cms-joomla-admin.json +41 -0
- package/tests/selectors/cms-magento2-admin.json +32 -0
- package/tests/selectors/cms-prestashop-admin.json +38 -0
- package/tests/selectors/cms-shopify-admin.json +25 -0
- package/tests/selectors/cms-strapi-admin.json +42 -0
- package/tests/selectors/cms-typo3-admin.json +41 -0
- package/tests/selectors/cms-woocommerce-front.json +50 -0
- package/tests/selectors/cms-wordpress-admin.json +31 -0
- package/tests/selectors/framework-ant-design.json +80 -0
- package/tests/selectors/framework-bootstrap.json +86 -0
- package/tests/selectors/framework-bulma.json +74 -0
- package/tests/selectors/framework-chakra.json +58 -0
- package/tests/selectors/framework-foundation.json +51 -0
- package/tests/selectors/framework-material-ui.json +72 -0
- package/tests/selectors/framework-shadcn.json +51 -0
- package/tests/selectors/framework-tailwind.json +40 -0
- package/tests/selectors/framework-vuetify.json +61 -0
- package/tests/step-definitions/a11y.steps.js +800 -0
- package/tests/step-definitions/action.steps.js +167 -0
- package/tests/step-definitions/{webship-api.js → api.steps.js} +41 -23
- package/tests/step-definitions/assertion.steps.js +352 -0
- package/tests/step-definitions/auth.steps.js +126 -0
- package/tests/step-definitions/clock.steps.js +128 -0
- package/tests/step-definitions/cookie.steps.js +216 -0
- package/tests/step-definitions/debug.steps.js +39 -0
- package/tests/step-definitions/dialog.steps.js +193 -0
- package/tests/step-definitions/element.steps.js +356 -0
- package/tests/step-definitions/field.steps.js +653 -0
- package/tests/step-definitions/file-download.steps.js +211 -0
- package/tests/step-definitions/form.steps.js +333 -0
- package/tests/step-definitions/iframe.steps.js +228 -0
- package/tests/step-definitions/input.steps.js +202 -0
- package/tests/step-definitions/javascript.steps.js +232 -0
- package/tests/step-definitions/keyboard.steps.js +112 -0
- package/tests/step-definitions/link.steps.js +142 -0
- package/tests/step-definitions/metatag.steps.js +91 -0
- package/tests/step-definitions/modal.steps.js +244 -0
- package/tests/step-definitions/navigation.steps.js +218 -0
- package/tests/step-definitions/network.steps.js +280 -0
- package/tests/step-definitions/path.steps.js +141 -0
- package/tests/step-definitions/response.steps.js +98 -0
- package/tests/step-definitions/responsive.steps.js +125 -0
- package/tests/step-definitions/rest.steps.js +111 -0
- package/tests/step-definitions/{webship-screenshot.js → screenshot.steps.js} +1 -5
- package/tests/step-definitions/scroll.steps.js +189 -0
- package/tests/step-definitions/{webship-selectors.js → selectors.steps.js} +64 -27
- package/tests/step-definitions/storage.steps.js +194 -0
- package/tests/step-definitions/table.steps.js +181 -0
- package/tests/step-definitions/video.steps.js +178 -0
- package/tests/step-definitions/wait.steps.js +400 -0
- package/tests/step-definitions/web-first.steps.js +298 -0
- package/tests/step-definitions/webship.js +741 -1477
- package/tests/step-definitions/xml.steps.js +411 -0
- package/tests/step-definitions/yaml.steps.js +913 -0
- package/tests/step-definitions-diffy/webship-diffy.js +0 -13
- package/tsconfig.json +19 -3
- package/videos/README.md +32 -0
- package/.travis-ci.yml +0 -16
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { friendly } = require('./webship');
|
|
4
|
+
|
|
5
|
+
// Web-first assertion steps — each matcher polls the live page until the
|
|
6
|
+
// condition holds or the per-step timeout elapses. The assertion IS the
|
|
7
|
+
// wait, so no `wait for AJAX` is required between an action and its check.
|
|
8
|
+
//
|
|
9
|
+
// Pattern (all steps): "<selector>" should [not] be <state> [within N seconds]
|
|
10
|
+
// Default budget is 5s; override with the trailing "within N seconds" clause.
|
|
11
|
+
|
|
12
|
+
const { Then, When } = require('@cucumber/cucumber');
|
|
13
|
+
const assert = require('assert');
|
|
14
|
+
|
|
15
|
+
function parseTimeout(secondsStr) {
|
|
16
|
+
const n = secondsStr ? parseInt(secondsStr, 10) : 0;
|
|
17
|
+
return n > 0 ? n * 1000 : 5000;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Poll fn() until it returns truthy, or timeout. fn() returns a value;
|
|
21
|
+
// `predicate` decides pass/fail. Returns the last value seen.
|
|
22
|
+
async function poll(fn, predicate, timeout, message) {
|
|
23
|
+
const deadline = Date.now() + timeout;
|
|
24
|
+
let last;
|
|
25
|
+
while (Date.now() < deadline) {
|
|
26
|
+
try {
|
|
27
|
+
last = await fn();
|
|
28
|
+
if (predicate(last)) return last;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
last = e;
|
|
31
|
+
}
|
|
32
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
33
|
+
}
|
|
34
|
+
throw friendly(`${message} (last seen: ${typeof last === 'object' ? JSON.stringify(last) : String(last)})`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function checkState(locator, state) {
|
|
38
|
+
switch (state) {
|
|
39
|
+
case 'visible': return locator.first().isVisible();
|
|
40
|
+
case 'hidden': return !(await locator.first().isVisible().catch(() => false));
|
|
41
|
+
case 'attached': return (await locator.count()) > 0;
|
|
42
|
+
case 'focused': return locator.first().evaluate((el) => el === document.activeElement);
|
|
43
|
+
case 'enabled': return locator.first().isEnabled();
|
|
44
|
+
case 'disabled': return locator.first().isDisabled();
|
|
45
|
+
case 'editable': return locator.first().isEditable();
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// State matchers
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Auto-retrying state assertion. Polls the live page until the matcher passes
|
|
56
|
+
* or the budget elapses. Default budget 5 s.
|
|
57
|
+
*
|
|
58
|
+
* Example #1: Then "#dashboard" should be visible
|
|
59
|
+
* Example #2: Then ".success-banner" should be visible within 10 seconds
|
|
60
|
+
* Example #3: And "[data-testid=signup-cta]" should be focused
|
|
61
|
+
* Example #4: Then "button.submit" should be enabled
|
|
62
|
+
* Example #5: Then "input#email" should be editable
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
Then(/^"([^"]*)" should be (visible|hidden|attached|focused|enabled|disabled|editable)(?: within (\d+) seconds?)?$/, async function (selector, state, sec) {
|
|
66
|
+
const loc = this.page.locator(selector);
|
|
67
|
+
await poll(
|
|
68
|
+
() => checkState(loc, state),
|
|
69
|
+
(v) => v === true,
|
|
70
|
+
parseTimeout(sec),
|
|
71
|
+
`Expected "${selector}" to be ${state}`
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Auto-retrying negated state assertion.
|
|
77
|
+
*
|
|
78
|
+
* Example #1: Then "#loading-spinner" should not be visible
|
|
79
|
+
* Example #2: Then ".error" should not be visible within 5 seconds
|
|
80
|
+
* Example #3: And "button.submit" should not be disabled
|
|
81
|
+
* Example #4: Then "input#email" should not be editable
|
|
82
|
+
* Example #5: Then "[data-testid=password]" should not be focused
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
Then(/^"([^"]*)" should not be (visible|hidden|attached|focused|enabled|disabled|editable)(?: within (\d+) seconds?)?$/, async function (selector, state, sec) {
|
|
86
|
+
const loc = this.page.locator(selector);
|
|
87
|
+
await poll(
|
|
88
|
+
() => checkState(loc, state),
|
|
89
|
+
(v) => v === false,
|
|
90
|
+
parseTimeout(sec),
|
|
91
|
+
`Expected "${selector}" to not be ${state}`
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Assert an element's bounding box overlaps the visible viewport rectangle.
|
|
97
|
+
*
|
|
98
|
+
* Example #1: Then "#hero" should be in the viewport
|
|
99
|
+
* Example #2: Then "[data-testid=cta]" should be in the viewport within 3 seconds
|
|
100
|
+
* Example #3: When I scroll to the element "#footer"
|
|
101
|
+
* Then "#footer" should be in the viewport
|
|
102
|
+
* Example #4: Then "h1" should be in the viewport
|
|
103
|
+
* Example #5: Then ".banner" should be in the viewport
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
Then(/^"([^"]*)" should be in the viewport(?: within (\d+) seconds?)?$/, async function (selector, sec) {
|
|
107
|
+
const loc = this.page.locator(selector).first();
|
|
108
|
+
await poll(
|
|
109
|
+
async () => loc.evaluate((el) => {
|
|
110
|
+
const r = el.getBoundingClientRect();
|
|
111
|
+
return r.bottom > 0 && r.top < (window.innerHeight || 0)
|
|
112
|
+
&& r.right > 0 && r.left < (window.innerWidth || 0);
|
|
113
|
+
}),
|
|
114
|
+
(v) => v === true,
|
|
115
|
+
parseTimeout(sec),
|
|
116
|
+
`Expected "${selector}" to be in viewport`
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Assert an element is OUTSIDE the visible viewport rectangle.
|
|
122
|
+
*
|
|
123
|
+
* Example #1: Then "#footer" should not be in the viewport
|
|
124
|
+
* Example #2: Then "[data-testid=hidden]" should not be in the viewport within 3 seconds
|
|
125
|
+
* Example #3: And ".off-screen" should not be in the viewport
|
|
126
|
+
* Example #4: Then "section.below-fold" should not be in the viewport
|
|
127
|
+
* Example #5: When I scroll to the top
|
|
128
|
+
* Then "#footer" should not be in the viewport
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
Then(/^"([^"]*)" should not be in the viewport(?: within (\d+) seconds?)?$/, async function (selector, sec) {
|
|
132
|
+
const loc = this.page.locator(selector).first();
|
|
133
|
+
await poll(
|
|
134
|
+
async () => loc.evaluate((el) => {
|
|
135
|
+
const r = el.getBoundingClientRect();
|
|
136
|
+
return r.bottom > 0 && r.top < (window.innerHeight || 0)
|
|
137
|
+
&& r.right > 0 && r.left < (window.innerWidth || 0);
|
|
138
|
+
}).catch(() => false),
|
|
139
|
+
(v) => v === false,
|
|
140
|
+
parseTimeout(sec),
|
|
141
|
+
`Expected "${selector}" to not be in viewport`
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Assert exactly N elements match a selector (auto-retry).
|
|
147
|
+
*
|
|
148
|
+
* Example #1: Then ".product-card" should have a count of 12
|
|
149
|
+
* Example #2: Then ".error" should have a count of 0 within 5 seconds
|
|
150
|
+
* Example #3: And "tr" should have a count of 21
|
|
151
|
+
* Example #4: Then "[data-testid=item]" should have a count of 5
|
|
152
|
+
* Example #5: Then ".feed-item" should have a count of 25 within 10 seconds
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
Then(/^"([^"]*)" should have a count of (\d+)(?: within (\d+) seconds?)?$/, async function (selector, count, sec) {
|
|
156
|
+
const expected = parseInt(count, 10);
|
|
157
|
+
const loc = this.page.locator(selector);
|
|
158
|
+
await poll(
|
|
159
|
+
() => loc.count(),
|
|
160
|
+
(v) => v === expected,
|
|
161
|
+
parseTimeout(sec),
|
|
162
|
+
`Expected "${selector}" count to be ${expected}`
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Assert an element's textContent equals an expected string (trimmed).
|
|
168
|
+
*
|
|
169
|
+
* Example #1: Then "h1" should have text "Welcome"
|
|
170
|
+
* Example #2: Then ".badge" should have text "12" within 3 seconds
|
|
171
|
+
* Example #3: And ".total" should have text "$99.00"
|
|
172
|
+
* Example #4: Then "[data-testid=subtitle]" should have text "Premium"
|
|
173
|
+
* Example #5: Then ".alert" should have text "Saved"
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
Then(/^"([^"]*)" should have text "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, text, sec) {
|
|
177
|
+
const loc = this.page.locator(selector).first();
|
|
178
|
+
await poll(
|
|
179
|
+
() => loc.textContent(),
|
|
180
|
+
(v) => (v || '').trim() === text,
|
|
181
|
+
parseTimeout(sec),
|
|
182
|
+
`Expected "${selector}" text to be "${text}"`
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Assert an element's textContent contains an expected substring.
|
|
188
|
+
*
|
|
189
|
+
* Example #1: Then "h1" should contain text "Welcome"
|
|
190
|
+
* Example #2: Then ".badge" should contain text "unread" within 3 seconds
|
|
191
|
+
* Example #3: And ".total" should contain text "$99"
|
|
192
|
+
* Example #4: Then "[data-testid=subtitle]" should contain text "Premium"
|
|
193
|
+
* Example #5: Then ".alert" should contain text "Saved"
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
Then(/^"([^"]*)" should contain text "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, text, sec) {
|
|
197
|
+
const loc = this.page.locator(selector).first();
|
|
198
|
+
await poll(
|
|
199
|
+
() => loc.textContent(),
|
|
200
|
+
(v) => (v || '').includes(text),
|
|
201
|
+
parseTimeout(sec),
|
|
202
|
+
`Expected "${selector}" to contain text "${text}"`
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Assert an input's `value` property equals an expected string.
|
|
208
|
+
*
|
|
209
|
+
* Example #1: Then "#email" should have value "alice@example.com"
|
|
210
|
+
* Example #2: Then "input[name=q]" should have value "laptops"
|
|
211
|
+
* Example #3: And "[data-testid=phone]" should have value "0790000000"
|
|
212
|
+
* Example #4: Then "#bio" should have value "" within 3 seconds
|
|
213
|
+
* Example #5: Then "select#country" should have value "JO"
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
Then(/^"([^"]*)" should have value "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, value, sec) {
|
|
217
|
+
const loc = this.page.locator(selector).first();
|
|
218
|
+
await poll(
|
|
219
|
+
() => loc.inputValue(),
|
|
220
|
+
(v) => v === value,
|
|
221
|
+
parseTimeout(sec),
|
|
222
|
+
`Expected "${selector}" value to be "${value}"`
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Assert an element's attribute equals an expected value.
|
|
228
|
+
*
|
|
229
|
+
* Example #1: Then "#tab-1" should have attribute "aria-selected" with value "true"
|
|
230
|
+
* Example #2: Then "[data-testid=cta]" should have attribute "data-state" with value "open"
|
|
231
|
+
* Example #3: And "img.logo" should have attribute "alt" with value "Webship.co"
|
|
232
|
+
* Example #4: Then "a.signup" should have attribute "href" with value "/signup"
|
|
233
|
+
* Example #5: Then "input#email" should have attribute "type" with value "email"
|
|
234
|
+
*
|
|
235
|
+
*/
|
|
236
|
+
Then(/^"([^"]*)" should have attribute "([^"]*)" with value "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, attr, value, sec) {
|
|
237
|
+
const loc = this.page.locator(selector).first();
|
|
238
|
+
await poll(
|
|
239
|
+
() => loc.getAttribute(attr),
|
|
240
|
+
(v) => v === value,
|
|
241
|
+
parseTimeout(sec),
|
|
242
|
+
`Expected "${selector}" attribute "${attr}" to be "${value}"`
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Assert an element's `class` attribute contains a class token.
|
|
248
|
+
*
|
|
249
|
+
* Example #1: Then "#tab-1" should have class "is-active"
|
|
250
|
+
* Example #2: Then ".modal" should have class "show" within 3 seconds
|
|
251
|
+
* Example #3: And ".dropdown" should have class "open"
|
|
252
|
+
* Example #4: Then "tr.row-1" should have class "selected"
|
|
253
|
+
* Example #5: Then "[data-testid=card]" should have class "highlighted"
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
Then(/^"([^"]*)" should have class "([^"]*)"(?: within (\d+) seconds?)?$/, async function (selector, cls, sec) {
|
|
257
|
+
const loc = this.page.locator(selector).first();
|
|
258
|
+
await poll(
|
|
259
|
+
() => loc.getAttribute('class'),
|
|
260
|
+
(v) => (v || '').split(/\s+/).includes(cls),
|
|
261
|
+
parseTimeout(sec),
|
|
262
|
+
`Expected "${selector}" to have class "${cls}"`
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Click an element by its accessible role + name (Playwright `getByRole`).
|
|
268
|
+
*
|
|
269
|
+
* Example #1: When I click the "Sign in" button
|
|
270
|
+
* Example #2: When I click the "Profile" link
|
|
271
|
+
* Example #3: And we click the "Notifications" tab
|
|
272
|
+
* Example #4: When I click the "Subscribe" checkbox
|
|
273
|
+
* Example #5: When I click the "Premium" radio
|
|
274
|
+
*
|
|
275
|
+
*/
|
|
276
|
+
When(/^(I |we )*click the "([^"]*)" (button|link|tab|menuitem|checkbox|radio|option)$/, async function (pronoun, name, role) {
|
|
277
|
+
await this.page.getByRole(role, { name }).first().click();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Assert a role-addressed element is visible (auto-retry).
|
|
282
|
+
*
|
|
283
|
+
* Example #1: Then the "Save changes" button should be visible
|
|
284
|
+
* Example #2: Then the "Profile" link should be visible within 5 seconds
|
|
285
|
+
* Example #3: And the "Privacy" tab should be visible
|
|
286
|
+
* Example #4: Then the "I agree" checkbox should be visible
|
|
287
|
+
* Example #5: Then the "Premium" radio should be visible
|
|
288
|
+
*
|
|
289
|
+
*/
|
|
290
|
+
Then(/^the "([^"]*)" (button|link|tab|menuitem|checkbox|radio|option) should be visible(?: within (\d+) seconds?)?$/, async function (name, role, sec) {
|
|
291
|
+
const loc = this.page.getByRole(role, { name }).first();
|
|
292
|
+
await poll(
|
|
293
|
+
() => loc.isVisible(),
|
|
294
|
+
(v) => v === true,
|
|
295
|
+
parseTimeout(sec),
|
|
296
|
+
`Expected ${role} "${name}" to be visible`
|
|
297
|
+
);
|
|
298
|
+
});
|