webship-js 2.0.2 → 2.0.3
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/AGENTS.md +109 -0
- package/CLAUDE.md +317 -0
- package/bin/generate-reports.js +181 -9
- package/cucumber.js +10 -4
- 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 +728 -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/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 +244 -0
- package/docs/index.md +104 -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/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/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 +798 -0
- package/tests/step-definitions/action.steps.js +167 -0
- package/tests/step-definitions/{webship-api.js → api.steps.js} +24 -7
- package/tests/step-definitions/assertion.steps.js +352 -0
- package/tests/step-definitions/auth.steps.js +124 -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 +31 -0
- package/tests/step-definitions/dialog.steps.js +193 -0
- package/tests/step-definitions/element.steps.js +314 -0
- package/tests/step-definitions/field.steps.js +653 -0
- package/tests/step-definitions/file-download.steps.js +193 -0
- package/tests/step-definitions/form.steps.js +333 -0
- package/tests/step-definitions/iframe.steps.js +178 -0
- package/tests/step-definitions/input.steps.js +163 -0
- package/tests/step-definitions/javascript.steps.js +71 -0
- package/tests/step-definitions/keyboard.steps.js +78 -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 +219 -0
- package/tests/step-definitions/navigation.steps.js +218 -0
- package/tests/step-definitions/network.steps.js +238 -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 +123 -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} +46 -11
- package/tests/step-definitions/storage.steps.js +194 -0
- package/tests/step-definitions/table.steps.js +181 -0
- package/tests/step-definitions/wait.steps.js +400 -0
- package/tests/step-definitions/web-first.steps.js +296 -0
- package/tests/step-definitions/webship.js +552 -1507
- package/tests/step-definitions/xml.steps.js +409 -0
- package/tests/step-definitions/yaml.steps.js +911 -0
- package/tests/step-definitions-diffy/webship-diffy.js +0 -13
- package/tsconfig.json +19 -3
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Network interception and mocking via Playwright's `page.route()` API.
|
|
4
|
+
//
|
|
5
|
+
// Lets BDD scenarios stub external dependencies, simulate slow / offline
|
|
6
|
+
// conditions, and assert what the client actually requested — without
|
|
7
|
+
// leaving the test runner. Patterns use Playwright glob matching: `**/path`,
|
|
8
|
+
// `*.gif`, regex inside parentheses, etc.
|
|
9
|
+
//
|
|
10
|
+
// Order matters: register routes BEFORE the action that triggers the request.
|
|
11
|
+
|
|
12
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
13
|
+
const assert = require('assert');
|
|
14
|
+
|
|
15
|
+
function ensureRequestLog(world) {
|
|
16
|
+
if (world._requestLog) return;
|
|
17
|
+
world._requestLog = [];
|
|
18
|
+
world.page.on('request', (req) => {
|
|
19
|
+
world._requestLog.push({
|
|
20
|
+
url: req.url(),
|
|
21
|
+
method: req.method(),
|
|
22
|
+
resourceType: req.resourceType(),
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Stubbing
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Stub a URL pattern with a JSON response body.
|
|
33
|
+
*
|
|
34
|
+
* Body is sent verbatim with `Content-Type: application/json` and HTTP 200.
|
|
35
|
+
*
|
|
36
|
+
* Example #1: Given the URL "**\/api/users" returns the JSON:
|
|
37
|
+
* """
|
|
38
|
+
* {"users": [{"id": 1, "name": "Alice"}]}
|
|
39
|
+
* """
|
|
40
|
+
* Example #2: Given the URL "**\/api/me" returns the JSON:
|
|
41
|
+
* """
|
|
42
|
+
* {"id": 1, "name": "Alice", "role": "admin"}
|
|
43
|
+
* """
|
|
44
|
+
* Example #3: Given the URL "**\/api/products?*" returns the JSON:
|
|
45
|
+
* """
|
|
46
|
+
* {"items": [], "total": 0}
|
|
47
|
+
* """
|
|
48
|
+
* Example #4: Given the URL "https://api.stripe.com/v1/charges" returns the JSON:
|
|
49
|
+
* """
|
|
50
|
+
* {"id": "ch_test", "status": "succeeded"}
|
|
51
|
+
* """
|
|
52
|
+
* Example #5: Given the URL "**\/api/feature-flags" returns the JSON:
|
|
53
|
+
* """
|
|
54
|
+
* {"darkMode": true, "betaUI": false}
|
|
55
|
+
* """
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
Given(/^the URL "([^"]*)" returns the JSON:$/, async function (urlPattern, body) {
|
|
59
|
+
await this.page.route(urlPattern, async (route) => {
|
|
60
|
+
await route.fulfill({
|
|
61
|
+
status: 200,
|
|
62
|
+
contentType: 'application/json',
|
|
63
|
+
body,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Stub a URL pattern with a status code and plain-text body.
|
|
70
|
+
*
|
|
71
|
+
* Example #1: Given the URL "**\/api/login" returns status 401 with body "Unauthorized"
|
|
72
|
+
* Example #2: Given the URL "**\/api/health" returns status 503
|
|
73
|
+
* Example #3: Given the URL "**\/api/users" returns status 500 with body "Database down"
|
|
74
|
+
* Example #4: Given the URL "**\/api/orders/*" returns status 404
|
|
75
|
+
* Example #5: Given the URL "**\/api/admin/*" returns status 403 with body "Forbidden"
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
Given(/^the URL "([^"]*)" returns status (\d+)(?: with body "([^"]*)")?$/, async function (urlPattern, status, body) {
|
|
79
|
+
await this.page.route(urlPattern, async (route) => {
|
|
80
|
+
await route.fulfill({ status: parseInt(status, 10), body: body || '' });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Block a URL pattern entirely (network failure simulation).
|
|
86
|
+
*
|
|
87
|
+
* Example #1: Given the URL "**\/analytics.js" is blocked
|
|
88
|
+
* Example #2: Given the URL "**\/google-analytics.com/**" is blocked
|
|
89
|
+
* Example #3: Given the URL "**\/sentry.io/**" is blocked
|
|
90
|
+
* Example #4: Given the URL "*.gif" is blocked
|
|
91
|
+
* Example #5: Given the URL "**\/api/tracking" is blocked
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
Given(/^the URL "([^"]*)" is blocked$/, async function (urlPattern) {
|
|
95
|
+
await this.page.route(urlPattern, (route) => route.abort());
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Delay matching requests by N milliseconds (slow-network simulation).
|
|
100
|
+
*
|
|
101
|
+
* The request still completes against the real upstream — only its arrival
|
|
102
|
+
* time at the page is shifted. Useful for verifying loading-state UI.
|
|
103
|
+
*
|
|
104
|
+
* Example #1: Given the URL "**\/api/**" is delayed by 1500 ms
|
|
105
|
+
* Example #2: Given the URL "**\/api/users" is delayed by 3000 ms
|
|
106
|
+
* Example #3: Given the URL "**\/api/heavy-report" is delayed by 5000 ms
|
|
107
|
+
* Example #4: Given the URL "*.png" is delayed by 500 ms
|
|
108
|
+
* Example #5: Given the URL "**\/api/checkout" is delayed by 2000 ms
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
Given(/^the URL "([^"]*)" is delayed by (\d+) ?ms$/, async function (urlPattern, delay) {
|
|
112
|
+
const ms = parseInt(delay, 10);
|
|
113
|
+
await this.page.route(urlPattern, async (route) => {
|
|
114
|
+
await new Promise((r) => setTimeout(r, ms));
|
|
115
|
+
await route.continue();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Simulate offline mode for the rest of the scenario.
|
|
121
|
+
*
|
|
122
|
+
* Example #1: Given the network is offline
|
|
123
|
+
* Example #2: Given I am on the homepage
|
|
124
|
+
* When the network is offline
|
|
125
|
+
* And I follow "Refresh"
|
|
126
|
+
* Then I should see "Offline"
|
|
127
|
+
* Example #3: When the network is offline
|
|
128
|
+
* And I press "Sync"
|
|
129
|
+
* Then I should see "Cannot reach server"
|
|
130
|
+
* Example #4: Given the network is offline
|
|
131
|
+
* And I am on "/dashboard"
|
|
132
|
+
* Example #5: Given the network is offline
|
|
133
|
+
* When I click "Reload"
|
|
134
|
+
* Then "<.error-banner>" should be visible
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
137
|
+
Given(/^the network is offline$/, async function () {
|
|
138
|
+
await this.context.setOffline(true);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Restore network connectivity after `the network is offline`.
|
|
143
|
+
*
|
|
144
|
+
* Example #1: Given the network is online
|
|
145
|
+
* Example #2: When the network is offline
|
|
146
|
+
* And I press "Sync"
|
|
147
|
+
* Then I should see "Cannot reach server"
|
|
148
|
+
* When the network is online
|
|
149
|
+
* And I press "Retry"
|
|
150
|
+
* Then I should see "Synced"
|
|
151
|
+
* Example #3: Given the network is online
|
|
152
|
+
* And I am on the homepage
|
|
153
|
+
* Example #4: When the network is online
|
|
154
|
+
* Example #5: Given the network is online
|
|
155
|
+
* When I follow "Reload"
|
|
156
|
+
* Then I should see "Welcome"
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
Given(/^the network is online$/, async function () {
|
|
160
|
+
await this.context.setOffline(false);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Request logging
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Start recording every outgoing request for later assertion.
|
|
169
|
+
*
|
|
170
|
+
* Example #1: Given I start recording network requests
|
|
171
|
+
* Example #2: Given I start recording network requests
|
|
172
|
+
* When I press "Buy now"
|
|
173
|
+
* Then a POST request to "**\/api/checkout" should have been made
|
|
174
|
+
* Example #3: Given we start recording network requests
|
|
175
|
+
* Example #4: Given I start recording network requests
|
|
176
|
+
* When I follow "Pricing"
|
|
177
|
+
* Then no request to "**\/tracking" should have been made
|
|
178
|
+
* Example #5: Given I start recording network requests
|
|
179
|
+
* When I scroll to the bottom
|
|
180
|
+
* Then a GET request to "**\/api/feed/page=2" should have been made
|
|
181
|
+
*
|
|
182
|
+
*/
|
|
183
|
+
Given(/^(I |we )*start recording network requests$/, function () {
|
|
184
|
+
ensureRequestLog(this);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Assert at least one request matching a URL pattern was recorded.
|
|
189
|
+
*
|
|
190
|
+
* Patterns use simple `*` wildcards (regex internally).
|
|
191
|
+
*
|
|
192
|
+
* Example #1: Then a request to "**\/api/users" should have been made
|
|
193
|
+
* Example #2: Then a request to "**\/api/checkout" should have been made
|
|
194
|
+
* Example #3: Then a request to "**\/api/orders/*" should have been made
|
|
195
|
+
* Example #4: Then a request to "*.css" should have been made
|
|
196
|
+
* Example #5: Then a request to "https://api.example.com/**" should have been made
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
Then(/^a request to "([^"]*)" should have been made$/, function (urlPattern) {
|
|
200
|
+
ensureRequestLog(this);
|
|
201
|
+
const re = new RegExp(urlPattern.replace(/\*/g, '.*'));
|
|
202
|
+
const found = this._requestLog.some((r) => re.test(r.url));
|
|
203
|
+
assert.ok(found, `Expected at least one request matching "${urlPattern}".`);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Assert at least one HTTP-method-specific request was recorded.
|
|
208
|
+
*
|
|
209
|
+
* Example #1: Then a GET request to "**\/api/users" should have been made
|
|
210
|
+
* Example #2: Then a POST request to "**\/api/login" should have been made
|
|
211
|
+
* Example #3: Then a PUT request to "**\/api/users/1" should have been made
|
|
212
|
+
* Example #4: Then a PATCH request to "**\/api/orders/*" should have been made
|
|
213
|
+
* Example #5: Then a DELETE request to "**\/api/cart/items/*" should have been made
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
Then(/^a (GET|POST|PUT|PATCH|DELETE) request to "([^"]*)" should have been made$/, function (method, urlPattern) {
|
|
217
|
+
ensureRequestLog(this);
|
|
218
|
+
const re = new RegExp(urlPattern.replace(/\*/g, '.*'));
|
|
219
|
+
const found = this._requestLog.some((r) => r.method === method && re.test(r.url));
|
|
220
|
+
assert.ok(found, `Expected at least one ${method} request matching "${urlPattern}".`);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Assert NO request matching a URL pattern was recorded.
|
|
225
|
+
*
|
|
226
|
+
* Example #1: Then no request to "**\/tracking" should have been made
|
|
227
|
+
* Example #2: Then no request to "**\/google-analytics.com/**" should have been made
|
|
228
|
+
* Example #3: Then no request to "**\/api/admin/**" should have been made
|
|
229
|
+
* Example #4: Then no request to "*.gif" should have been made
|
|
230
|
+
* Example #5: Then no request to "**\/api/v1/legacy/**" should have been made
|
|
231
|
+
*
|
|
232
|
+
*/
|
|
233
|
+
Then(/^no request to "([^"]*)" should have been made$/, function (urlPattern) {
|
|
234
|
+
ensureRequestLog(this);
|
|
235
|
+
const re = new RegExp(urlPattern.replace(/\*/g, '.*'));
|
|
236
|
+
const found = this._requestLog.some((r) => re.test(r.url));
|
|
237
|
+
assert.ok(!found, `Did not expect any request matching "${urlPattern}".`);
|
|
238
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// URL path and query parameter assertions, basic auth, history navigation.
|
|
4
|
+
|
|
5
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
6
|
+
const assert = require('assert');
|
|
7
|
+
|
|
8
|
+
function currentUrl(page) { return new URL(page.url()); }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Assert the current URL pathname equals an expected string (no query/fragment).
|
|
12
|
+
*
|
|
13
|
+
* Example #1: Then the path should be "/dashboard"
|
|
14
|
+
* Example #2: Then the path should be "/about"
|
|
15
|
+
* Example #3: And the path should be "/checkout/step-2"
|
|
16
|
+
* Example #4: Then the path should be "/admin/users"
|
|
17
|
+
* Example #5: Then the path should be "/"
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
Then('the path should be {string}', async function (path) {
|
|
21
|
+
assert.strictEqual(currentUrl(this.page).pathname, path);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Assert the current URL pathname is NOT equal to an expected string.
|
|
26
|
+
*
|
|
27
|
+
* Example #1: Then the path should not be "/login"
|
|
28
|
+
* Example #2: Then the path should not be "/error"
|
|
29
|
+
* Example #3: And the path should not be "/admin"
|
|
30
|
+
* Example #4: Then the path should not be "/maintenance"
|
|
31
|
+
* Example #5: Then the path should not be "/forbidden"
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
Then('the path should not be {string}', async function (path) {
|
|
35
|
+
assert.notStrictEqual(currentUrl(this.page).pathname, path);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Assert the current URL has the named query parameter (any value).
|
|
40
|
+
*
|
|
41
|
+
* Example #1: Then current url should have the "lang" parameter
|
|
42
|
+
* Example #2: Then current url should have the "page" parameter
|
|
43
|
+
* Example #3: And current url should have the "q" parameter
|
|
44
|
+
* Example #4: Then current url should have the "ref" parameter
|
|
45
|
+
* Example #5: Then current url should have the "sort" parameter
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
Then('current url should have the {string} parameter', async function (param) {
|
|
49
|
+
const u = currentUrl(this.page);
|
|
50
|
+
assert.ok(u.searchParams.has(param), `Query param "${param}" not present in ${u.href}.`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Assert the current URL has the named query parameter with the exact value.
|
|
55
|
+
*
|
|
56
|
+
* Example #1: Then current url should have the "lang" parameter with the "en" value
|
|
57
|
+
* Example #2: Then current url should have the "page" parameter with the "2" value
|
|
58
|
+
* Example #3: And current url should have the "sort" parameter with the "price" value
|
|
59
|
+
* Example #4: Then current url should have the "ref" parameter with the "newsletter" value
|
|
60
|
+
* Example #5: Then current url should have the "q" parameter with the "laptops" value
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
Then('current url should have the {string} parameter with the {string} value', async function (param, value) {
|
|
64
|
+
const u = currentUrl(this.page);
|
|
65
|
+
assert.strictEqual(u.searchParams.get(param), value);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Assert the current URL does NOT carry the named query parameter.
|
|
70
|
+
*
|
|
71
|
+
* Example #1: Then current url should not have the "missing" parameter
|
|
72
|
+
* Example #2: Then current url should not have the "debug" parameter
|
|
73
|
+
* Example #3: And current url should not have the "preview" parameter
|
|
74
|
+
* Example #4: Then current url should not have the "force" parameter
|
|
75
|
+
* Example #5: Then current url should not have the "test" parameter
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
Then('current url should not have the {string} parameter', async function (param) {
|
|
79
|
+
const u = currentUrl(this.page);
|
|
80
|
+
assert.ok(!u.searchParams.has(param), `Query param "${param}" should not be present.`);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Assert the current URL does NOT carry a parameter+value pair.
|
|
85
|
+
*
|
|
86
|
+
* Example #1: Then current url should not have the "lang" parameter with the "fr" value
|
|
87
|
+
* Example #2: Then current url should not have the "page" parameter with the "100" value
|
|
88
|
+
* Example #3: And current url should not have the "sort" parameter with the "old" value
|
|
89
|
+
* Example #4: Then current url should not have the "preview" parameter with the "1" value
|
|
90
|
+
* Example #5: Then current url should not have the "debug" parameter with the "true" value
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
Then('current url should not have the {string} parameter with the {string} value', async function (param, value) {
|
|
94
|
+
const u = currentUrl(this.page);
|
|
95
|
+
assert.notStrictEqual(u.searchParams.get(param), value);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Re-open the browser context with HTTP basic-auth credentials.
|
|
100
|
+
*
|
|
101
|
+
* Example #1: Given the basic authentication with the username "admin" and the password "secret"
|
|
102
|
+
* Example #2: Given the basic authentication with the username "guest" and the password "guest"
|
|
103
|
+
* Example #3: And the basic authentication with the username "alice" and the password "s3cret"
|
|
104
|
+
* Example #4: Given the basic authentication with the username "ci" and the password "ci-token-123"
|
|
105
|
+
* Example #5: Given the basic authentication with the username "tester" and the password ""
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
Given('the basic authentication with the username {string} and the password {string}', async function (user, pass) {
|
|
109
|
+
// Replace context with one that has HTTP basic auth credentials.
|
|
110
|
+
await this.context.close();
|
|
111
|
+
const playwright = require('playwright');
|
|
112
|
+
const playwrightConfig = require(require('path').join(process.cwd(), 'playwright.config'));
|
|
113
|
+
this.context = await this.playwrightBrowser.newContext({
|
|
114
|
+
...playwrightConfig.contextOptions,
|
|
115
|
+
httpCredentials: { username: user, password: pass },
|
|
116
|
+
});
|
|
117
|
+
this.page = await this.context.newPage();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Navigate one step back in the browser history.
|
|
122
|
+
*
|
|
123
|
+
* Equivalent to clicking the browser back button. Throws no error if there
|
|
124
|
+
* is no history (returns null from `page.goBack()`).
|
|
125
|
+
*
|
|
126
|
+
* Example #1: When I go back
|
|
127
|
+
* Example #2: When I follow "About"
|
|
128
|
+
* And I go back
|
|
129
|
+
* Then I should be on the homepage
|
|
130
|
+
* Example #3: And I go back
|
|
131
|
+
* Example #4: When I am on "/cart"
|
|
132
|
+
* When I am on "/checkout"
|
|
133
|
+
* And I go back
|
|
134
|
+
* Then I should be on "/cart"
|
|
135
|
+
* Example #5: When I go back
|
|
136
|
+
* And I wait until the URL contains "/products"
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
When(/^(I |we )*go back$/, async function (pronoun) {
|
|
140
|
+
await this.page.goBack();
|
|
141
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Inspect HTTP response headers using Playwright's request API on the current page URL.
|
|
4
|
+
|
|
5
|
+
const { Then, Before } = require('@cucumber/cucumber');
|
|
6
|
+
const assert = require('assert');
|
|
7
|
+
|
|
8
|
+
// Capture response headers from navigation events, with page.request fallback.
|
|
9
|
+
Before({ order: 100 }, async function () {
|
|
10
|
+
if (!this.page) return;
|
|
11
|
+
this._lastResponseHeaders = null;
|
|
12
|
+
this._lastResponseStatus = null;
|
|
13
|
+
this.page.on('response', (resp) => {
|
|
14
|
+
try {
|
|
15
|
+
if (resp.request().isNavigationRequest() && resp.frame() === this.page.mainFrame()) {
|
|
16
|
+
this._lastResponseHeaders = resp.headers();
|
|
17
|
+
this._lastResponseStatus = resp.status();
|
|
18
|
+
}
|
|
19
|
+
} catch (e) { /* ignore */ }
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
async function getHeaders(world) {
|
|
24
|
+
if (world._lastResponseHeaders) return world._lastResponseHeaders;
|
|
25
|
+
// Fallback: fetch current URL via Playwright request context to get headers.
|
|
26
|
+
const url = world.page.url();
|
|
27
|
+
if (!url || url === 'about:blank') return {};
|
|
28
|
+
try {
|
|
29
|
+
const resp = await world.page.request.get(url);
|
|
30
|
+
return resp.headers();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Assert the most recent navigation response carried a header (case-insensitive).
|
|
38
|
+
*
|
|
39
|
+
* Example #1: Then the response should contain the header "content-type"
|
|
40
|
+
* Example #2: Then the response should contain the header "cache-control"
|
|
41
|
+
* Example #3: And the response should contain the header "x-frame-options"
|
|
42
|
+
* Example #4: Then the response should contain the header "set-cookie"
|
|
43
|
+
* Example #5: Then the response should contain the header "etag"
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
Then('the response should contain the header {string}', async function (name) {
|
|
47
|
+
const h = await getHeaders(this);
|
|
48
|
+
assert.ok(Object.keys(h).map((k) => k.toLowerCase()).includes(name.toLowerCase()), `Header "${name}" not present.`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Assert the most recent navigation response did NOT carry a header.
|
|
53
|
+
*
|
|
54
|
+
* Example #1: Then the response should not contain the header "x-fake-header"
|
|
55
|
+
* Example #2: Then the response should not contain the header "x-powered-by"
|
|
56
|
+
* Example #3: And the response should not contain the header "server"
|
|
57
|
+
* Example #4: Then the response should not contain the header "x-aspnet-version"
|
|
58
|
+
* Example #5: Then the response should not contain the header "x-debug-token"
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
Then('the response should not contain the header {string}', async function (name) {
|
|
62
|
+
const h = await getHeaders(this);
|
|
63
|
+
assert.ok(!Object.keys(h).map((k) => k.toLowerCase()).includes(name.toLowerCase()), `Header "${name}" should not be present.`);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Assert a header's value contains a substring.
|
|
68
|
+
*
|
|
69
|
+
* Example #1: Then the response header "content-type" should contain the value "html"
|
|
70
|
+
* Example #2: Then the response header "cache-control" should contain the value "no-cache"
|
|
71
|
+
* Example #3: And the response header "content-type" should contain the value "charset=utf-8"
|
|
72
|
+
* Example #4: Then the response header "set-cookie" should contain the value "session="
|
|
73
|
+
* Example #5: Then the response header "x-frame-options" should contain the value "DENY"
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
Then('the response header {string} should contain the value {string}', async function (name, value) {
|
|
77
|
+
const h = await getHeaders(this);
|
|
78
|
+
const key = Object.keys(h).find((k) => k.toLowerCase() === name.toLowerCase());
|
|
79
|
+
assert.ok(key, `Header "${name}" not present.`);
|
|
80
|
+
assert.ok(String(h[key]).indexOf(value) !== -1, `Header "${name}"="${h[key]}" does not contain "${value}".`);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Assert a header's value does NOT contain a substring (or the header is absent).
|
|
85
|
+
*
|
|
86
|
+
* Example #1: Then the response header "content-type" should not contain the value "application/json"
|
|
87
|
+
* Example #2: Then the response header "cache-control" should not contain the value "public"
|
|
88
|
+
* Example #3: And the response header "content-type" should not contain the value "xml"
|
|
89
|
+
* Example #4: Then the response header "set-cookie" should not contain the value "Domain=other"
|
|
90
|
+
* Example #5: Then the response header "x-frame-options" should not contain the value "ALLOW"
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
Then('the response header {string} should not contain the value {string}', async function (name, value) {
|
|
94
|
+
const h = await getHeaders(this);
|
|
95
|
+
const key = Object.keys(h).find((k) => k.toLowerCase() === name.toLowerCase());
|
|
96
|
+
if (!key) return;
|
|
97
|
+
assert.ok(String(h[key]).indexOf(value) === -1, `Header "${name}" should not contain "${value}".`);
|
|
98
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Set viewport dimensions and named breakpoints.
|
|
4
|
+
|
|
5
|
+
const { Given, When } = require('@cucumber/cucumber');
|
|
6
|
+
|
|
7
|
+
const DEFAULT_BREAKPOINTS = {
|
|
8
|
+
xs: { width: 375, height: 667 },
|
|
9
|
+
sm: { width: 576, height: 800 },
|
|
10
|
+
md: { width: 768, height: 1024 },
|
|
11
|
+
lg: { width: 992, height: 768 },
|
|
12
|
+
xl: { width: 1200, height: 900 },
|
|
13
|
+
xxl: { width: 1400, height: 900 },
|
|
14
|
+
xxxl: { width: 1920, height: 1080 },
|
|
15
|
+
mobile: { width: 375, height: 667 },
|
|
16
|
+
tablet: { width: 768, height: 1024 },
|
|
17
|
+
desktop: { width: 1200, height: 900 },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function getBreakpoints(world) {
|
|
21
|
+
if (!world._breakpoints) {
|
|
22
|
+
const cfg = (world.parameters && world.parameters.selectors && world.parameters.selectors.breakpoints) || {};
|
|
23
|
+
world._breakpoints = { ...DEFAULT_BREAKPOINTS, ...cfg };
|
|
24
|
+
}
|
|
25
|
+
return world._breakpoints;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Replace the breakpoint registry for the current scenario from a data table.
|
|
30
|
+
*
|
|
31
|
+
* Example #1: Given the following responsive breakpoints:
|
|
32
|
+
* | mobile | 375 | 667 |
|
|
33
|
+
* | tablet | 768 | 1024 |
|
|
34
|
+
* | desktop | 1200 | 900 |
|
|
35
|
+
* Example #2: Given the following responsive breakpoints:
|
|
36
|
+
* | watch | 280 | 280 |
|
|
37
|
+
* | phablet | 414 | 896 |
|
|
38
|
+
* Example #3: And the following responsive breakpoints:
|
|
39
|
+
* | xs | 320 | 480 |
|
|
40
|
+
* | sm | 480 | 800 |
|
|
41
|
+
* Example #4: Given the following responsive breakpoints:
|
|
42
|
+
* | hd | 1280 | 720 |
|
|
43
|
+
* | full-hd | 1920 | 1080 |
|
|
44
|
+
* Example #5: Given the following responsive breakpoints:
|
|
45
|
+
* | a11y | 320 | 480 |
|
|
46
|
+
* | print | 794 | 1123 |
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
Given('the following responsive breakpoints:', async function (table) {
|
|
50
|
+
const map = {};
|
|
51
|
+
for (const row of table.raw()) {
|
|
52
|
+
const [name, w, h] = row;
|
|
53
|
+
map[name] = { width: parseInt(w, 10), height: parseInt(h, 10) };
|
|
54
|
+
}
|
|
55
|
+
this._breakpoints = { ...DEFAULT_BREAKPOINTS, ...map };
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Resize the viewport to a registered named breakpoint.
|
|
60
|
+
*
|
|
61
|
+
* Built-in names: `xs`, `sm`, `md`, `lg`, `xl`, `xxl`, `xxxl`, `mobile`,
|
|
62
|
+
* `tablet`, `desktop`. Project-defined names override built-ins.
|
|
63
|
+
*
|
|
64
|
+
* Example #1: When I set the viewport to the "mobile" breakpoint
|
|
65
|
+
* Example #2: When I set the viewport to the "tablet" breakpoint
|
|
66
|
+
* Example #3: And we set the viewport to the "desktop" breakpoint
|
|
67
|
+
* Example #4: When I set the viewport to the "xl" breakpoint
|
|
68
|
+
* Example #5: When I set the viewport to the "xxxl" breakpoint
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
When(/^(I |we )*set the viewport to the "([^"]*)" breakpoint$/, async function (pronoun, name) {
|
|
72
|
+
const bps = getBreakpoints(this);
|
|
73
|
+
const bp = bps[name];
|
|
74
|
+
if (!bp) throw new Error(`Unknown breakpoint "${name}".`);
|
|
75
|
+
await this.page.setViewportSize({ width: bp.width, height: bp.height });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Resize the viewport width while keeping the current height.
|
|
80
|
+
*
|
|
81
|
+
* Example #1: When I set the viewport width to 1200
|
|
82
|
+
* Example #2: When I set the viewport width to 375
|
|
83
|
+
* Example #3: And we set the viewport width to 1920
|
|
84
|
+
* Example #4: When I set the viewport width to 768
|
|
85
|
+
* Example #5: When I set the viewport width to 1024
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
When(/^(I |we )*set the viewport width to (\d+)$/, async function (pronoun, w) {
|
|
89
|
+
w = parseInt(w, 10);
|
|
90
|
+
const cur = this.page.viewportSize() || { height: 800 };
|
|
91
|
+
await this.page.setViewportSize({ width: w, height: cur.height });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Resize the viewport height while keeping the current width.
|
|
96
|
+
*
|
|
97
|
+
* Example #1: When I set the viewport height to 800
|
|
98
|
+
* Example #2: When I set the viewport height to 1024
|
|
99
|
+
* Example #3: And we set the viewport height to 1080
|
|
100
|
+
* Example #4: When I set the viewport height to 667
|
|
101
|
+
* Example #5: When I set the viewport height to 900
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
When(/^(I |we )*set the viewport height to (\d+)$/, async function (pronoun, h) {
|
|
105
|
+
h = parseInt(h, 10);
|
|
106
|
+
const cur = this.page.viewportSize() || { width: 1200 };
|
|
107
|
+
await this.page.setViewportSize({ width: cur.width, height: h });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Resize the viewport to an explicit width-by-height pair.
|
|
112
|
+
*
|
|
113
|
+
* Example #1: When I set the viewport to 1200 by 800
|
|
114
|
+
* Example #2: When I set the viewport to 375 by 667
|
|
115
|
+
* Example #3: And we set the viewport to 1920 by 1080
|
|
116
|
+
* Example #4: When I set the viewport to 768 by 1024
|
|
117
|
+
* Example #5: When I set the viewport to 1024 by 768
|
|
118
|
+
*
|
|
119
|
+
*/
|
|
120
|
+
When(/^(I |we )*set the viewport to (\d+) by (\d+)$/, async function (pronoun, w, h) {
|
|
121
|
+
w = parseInt(w, 10); h = parseInt(h, 10);
|
|
122
|
+
await this.page.setViewportSize({ width: w, height: h });
|
|
123
|
+
});
|