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,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Lightweight REST testing — distinct from the existing api.steps.js steps
|
|
4
|
+
// Preserves exact step phrasing for compatibility.
|
|
5
|
+
|
|
6
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
7
|
+
const assert = require('assert');
|
|
8
|
+
const axios = require('axios');
|
|
9
|
+
|
|
10
|
+
function ensureState(world) {
|
|
11
|
+
if (!world._rest) world._rest = { headers: {}, response: null };
|
|
12
|
+
return world._rest;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Add an HTTP header to subsequent REST requests.
|
|
17
|
+
*
|
|
18
|
+
* Example #1: Given a REST header "Authorization" with value "Bearer abc123"
|
|
19
|
+
* Example #2: Given a REST header "Accept" with value "application/json"
|
|
20
|
+
* Example #3: And a REST header "X-Request-ID" with value "req-001"
|
|
21
|
+
* Example #4: Given a REST header "Content-Type" with value "application/json"
|
|
22
|
+
* Example #5: Given a REST header "X-API-Key" with value "key-xyz"
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
Given('a REST header {string} with value {string}', async function (name, value) {
|
|
26
|
+
ensureState(this).headers[name] = value;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Send an HTTP request without a body.
|
|
31
|
+
*
|
|
32
|
+
* Example #1: When I send a REST "GET" request to "/api/users"
|
|
33
|
+
* Example #2: When I send a REST "DELETE" request to "/api/orders/1"
|
|
34
|
+
* Example #3: And we send a REST "GET" request to "https://example.com/api/health"
|
|
35
|
+
* Example #4: When I send a REST "GET" request to "/api/me"
|
|
36
|
+
* Example #5: When I send a REST "DELETE" request to "/api/cart/items/42"
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)"$/, async function (pronoun, method, url) {
|
|
40
|
+
const s = ensureState(this);
|
|
41
|
+
const target = url.startsWith('http') ? url : (this.launchUrl || '') + url;
|
|
42
|
+
s.response = await axios.request({
|
|
43
|
+
method, url: target, headers: s.headers, validateStatus: () => true,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Send an HTTP request with a doc-string body (raw text, JSON, or form-encoded).
|
|
49
|
+
*
|
|
50
|
+
* Example #1: When I send a REST "POST" request to "/api/users" with body:
|
|
51
|
+
* """
|
|
52
|
+
* {"name": "Alice"}
|
|
53
|
+
* """
|
|
54
|
+
* Example #2: When I send a REST "PUT" request to "/api/users/1" with body:
|
|
55
|
+
* """
|
|
56
|
+
* {"role": "admin"}
|
|
57
|
+
* """
|
|
58
|
+
* Example #3: And we send a REST "PATCH" request to "/api/orders/1" with body:
|
|
59
|
+
* """
|
|
60
|
+
* {"status": "shipped"}
|
|
61
|
+
* """
|
|
62
|
+
* Example #4: When I send a REST "POST" request to "/api/login" with body:
|
|
63
|
+
* """
|
|
64
|
+
* username=alice&password=s3cret
|
|
65
|
+
* """
|
|
66
|
+
* Example #5: When I send a REST "POST" request to "/webhooks/event" with body:
|
|
67
|
+
* """
|
|
68
|
+
* {"event": "ping"}
|
|
69
|
+
* """
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)" with body:$/, async function (pronoun, method, url, body) {
|
|
73
|
+
const s = ensureState(this);
|
|
74
|
+
const target = url.startsWith('http') ? url : (this.launchUrl || '') + url;
|
|
75
|
+
s.response = await axios.request({
|
|
76
|
+
method, url: target, headers: s.headers, data: body, validateStatus: () => true,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Assert the most recent REST response carried an expected status code.
|
|
82
|
+
*
|
|
83
|
+
* Example #1: Then the REST response status code should be 200
|
|
84
|
+
* Example #2: Then the REST response status code should be 201
|
|
85
|
+
* Example #3: And the REST response status code should be 401
|
|
86
|
+
* Example #4: Then the REST response status code should be 404
|
|
87
|
+
* Example #5: Then the REST response status code should be 500
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
Then('the REST response status code should be {int}', async function (code) {
|
|
91
|
+
const s = ensureState(this);
|
|
92
|
+
assert.ok(s.response, 'No REST response captured.');
|
|
93
|
+
assert.strictEqual(s.response.status, code);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Assert the most recent REST response body contains a substring.
|
|
98
|
+
*
|
|
99
|
+
* Example #1: Then the REST response should contain "Alice"
|
|
100
|
+
* Example #2: Then the REST response should contain "id"
|
|
101
|
+
* Example #3: And the REST response should contain "shipped"
|
|
102
|
+
* Example #4: Then the REST response should contain "ok"
|
|
103
|
+
* Example #5: Then the REST response should contain "Welcome"
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
Then('the REST response should contain {string}', async function (text) {
|
|
107
|
+
const s = ensureState(this);
|
|
108
|
+
assert.ok(s.response, 'No REST response captured.');
|
|
109
|
+
const body = typeof s.response.data === 'string' ? s.response.data : JSON.stringify(s.response.data);
|
|
110
|
+
assert.ok(body.indexOf(text) !== -1, `REST response does not contain "${text}".`);
|
|
111
|
+
});
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
const { When, Then, Before, After, AfterStep, BeforeAll } = require('@cucumber/cucumber');
|
|
28
28
|
const fs = require('fs');
|
|
29
29
|
const path = require('path');
|
|
30
|
+
const { pad } = require('./webship');
|
|
30
31
|
|
|
31
32
|
function pick(envVal, paramVal, fallback) {
|
|
32
33
|
if (envVal !== undefined && envVal !== '') return envVal;
|
|
@@ -70,11 +71,6 @@ function resolveConfig(parameters) {
|
|
|
70
71
|
// ---------------------------------------------------------------------------
|
|
71
72
|
// Filename tokenizer
|
|
72
73
|
// ---------------------------------------------------------------------------
|
|
73
|
-
function pad(n, w) {
|
|
74
|
-
const s = String(n);
|
|
75
|
-
return s.length >= w ? s : '0'.repeat(w - s.length) + s;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
74
|
function formatDate(d, format) {
|
|
79
75
|
const yyyy = d.getFullYear();
|
|
80
76
|
const MM = pad(d.getMonth() + 1, 2);
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// All scroll step definitions live in this file.
|
|
4
|
+
//
|
|
5
|
+
// Vertical: down / up / to top / to bottom (page or scoped element).
|
|
6
|
+
// Horizontal: right / left / to start / to end (page or scoped element).
|
|
7
|
+
//
|
|
8
|
+
// Default delta when no number is supplied is 350 px.
|
|
9
|
+
|
|
10
|
+
const { When } = require('@cucumber/cucumber');
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Vertical scrolling — page
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Scrolls the page down by a custom number of pixels (default 350).
|
|
18
|
+
*
|
|
19
|
+
* Example #1: And I scroll down
|
|
20
|
+
* Example #2: When I scroll down 800
|
|
21
|
+
* Example #3: And we scroll down 500
|
|
22
|
+
* Example #4: When scrolling down 1200
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
When(/^(I scroll|we scroll|scrolling)? down(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
26
|
+
await this.page.evaluate((v) => window.scrollBy(0, v), numValue ? parseInt(numValue, 10) : 350);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Scrolls the page up by a custom number of pixels (default 350).
|
|
31
|
+
*
|
|
32
|
+
* Example #1: And I scroll up
|
|
33
|
+
* Example #2: When I scroll up 1000
|
|
34
|
+
* Example #3: And we scroll up 300
|
|
35
|
+
* Example #4: When scrolling up 750
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
When(/^(I scroll|we scroll|scrolling)? up(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
39
|
+
await this.page.evaluate((v) => window.scrollBy(0, -v), numValue ? parseInt(numValue, 10) : 350);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Scrolls to the very top of the current page.
|
|
44
|
+
*
|
|
45
|
+
* Example #1: When I scroll to top
|
|
46
|
+
* Example #2: And we scroll to the top
|
|
47
|
+
* Example #3: When scrolling to the top of the page
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* top( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
51
|
+
await this.page.evaluate(() => window.scrollTo(0, 0));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Scrolls to the bottom of the current page.
|
|
56
|
+
*
|
|
57
|
+
* Example #1: When I scroll to the bottom
|
|
58
|
+
* Example #2: And we scroll to bottom
|
|
59
|
+
* Example #3: When scrolling to the bottom of the page
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* bottom( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
63
|
+
await this.page.evaluate(() => {
|
|
64
|
+
window.scrollTo(0, document.body.scrollHeight);
|
|
65
|
+
document.querySelectorAll('*').forEach(el => {
|
|
66
|
+
const s = window.getComputedStyle(el);
|
|
67
|
+
if ((s.overflowY === 'scroll' || s.overflowY === 'auto') && el.scrollHeight > el.clientHeight) {
|
|
68
|
+
el.scrollTop = el.scrollHeight;
|
|
69
|
+
el.dispatchEvent(new Event('scroll', { bubbles: true }));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Vertical scrolling — scoped to a CSS selector
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Scrolls to the top of a specific element identified by a CSS selector.
|
|
81
|
+
*
|
|
82
|
+
* Example #1: When I scroll to top of "#off-canvas"
|
|
83
|
+
* Example #2: And we scroll to top of "#sidebar"
|
|
84
|
+
* Example #3: When scrolling to top of "#main-container"
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
88
|
+
await this.page.locator(selector).evaluate(el => {
|
|
89
|
+
el.scrollTop = 0;
|
|
90
|
+
el.dispatchEvent(new Event('scroll', { bubbles: true }));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Scrolls to the bottom of a specific element identified by a CSS selector.
|
|
96
|
+
*
|
|
97
|
+
* Example #1: When I scroll to bottom of "#off-canvas"
|
|
98
|
+
* Example #2: And we scroll to bottom of "#sidebar"
|
|
99
|
+
* Example #3: When scrolling to bottom of "#main-container"
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
103
|
+
await this.page.locator(selector).evaluate(el => {
|
|
104
|
+
el.scrollTop = el.scrollHeight;
|
|
105
|
+
el.dispatchEvent(new Event('scroll', { bubbles: true }));
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Horizontal scrolling — page
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Scrolls the page right by a custom number of pixels (default 350).
|
|
115
|
+
*
|
|
116
|
+
* Example #1: And I scroll right
|
|
117
|
+
* Example #2: When I scroll right 1000
|
|
118
|
+
* Example #3: And we scroll right 300
|
|
119
|
+
* Example #4: When scrolling right 750
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
When(/^(I scroll|we scroll|scrolling)? right(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
123
|
+
await this.page.evaluate((v) => window.scrollBy(v, 0), numValue ? parseInt(numValue, 10) : 350);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Scrolls the page left by a custom number of pixels (default 350).
|
|
128
|
+
*
|
|
129
|
+
* Example #1: And I scroll left
|
|
130
|
+
* Example #2: When I scroll left 800
|
|
131
|
+
* Example #3: And we scroll left 500
|
|
132
|
+
* Example #4: When scrolling left 1200
|
|
133
|
+
*
|
|
134
|
+
*/
|
|
135
|
+
When(/^(I scroll|we scroll|scrolling)? left(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
136
|
+
await this.page.evaluate((v) => window.scrollBy(-v, 0), numValue ? parseInt(numValue, 10) : 350);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Scrolls to the start (horizontal origin) of the page.
|
|
141
|
+
*
|
|
142
|
+
* Example #1: When I scroll to start
|
|
143
|
+
* Example #2: And we scroll to the start
|
|
144
|
+
* Example #3: When scrolling to the start of the page
|
|
145
|
+
*
|
|
146
|
+
*/
|
|
147
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* start( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
148
|
+
await this.page.evaluate(() => window.scrollTo(0, window.scrollY));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Scrolls to the end (horizontal maximum) of the page.
|
|
153
|
+
*
|
|
154
|
+
* Example #1: When I scroll to the end
|
|
155
|
+
* Example #2: And we scroll to end
|
|
156
|
+
* Example #3: When scrolling to the end of the page
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* end( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
160
|
+
await this.page.evaluate(() => window.scrollTo(document.body.scrollWidth, window.scrollY));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Horizontal scrolling — scoped to a CSS selector
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Scrolls to the start of a specific element identified by a CSS selector.
|
|
169
|
+
*
|
|
170
|
+
* Example #1: When I scroll to start of "#off-canvas"
|
|
171
|
+
* Example #2: And we scroll to start of "#sidebar"
|
|
172
|
+
* Example #3: When scrolling to start of "#main-container"
|
|
173
|
+
*
|
|
174
|
+
*/
|
|
175
|
+
When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
176
|
+
await this.page.locator(selector).evaluate(el => { el.scrollLeft = 0; });
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Scrolls to the end of a specific element identified by a CSS selector.
|
|
181
|
+
*
|
|
182
|
+
* Example #1: When I scroll to end of "#off-canvas"
|
|
183
|
+
* Example #2: And we scroll to end of "#sidebar"
|
|
184
|
+
* Example #3: When scrolling to end of "#main-container"
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
188
|
+
await this.page.locator(selector).evaluate(el => { el.scrollLeft = el.scrollWidth; });
|
|
189
|
+
});
|
|
@@ -145,7 +145,42 @@ function resolveSelector(world, name) {
|
|
|
145
145
|
return xp.startsWith('xpath=') ? xp : `xpath=${xp}`;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
// Suggest the closest registered name when one exists. Cheap Levenshtein
|
|
149
|
+
// by character — good enough for short selector names.
|
|
150
|
+
const known = [
|
|
151
|
+
...Object.keys(world.__selectorsCss || {}),
|
|
152
|
+
...Object.keys(world.__selectorsXpath || {}),
|
|
153
|
+
];
|
|
154
|
+
let best = null; let bestDist = Infinity;
|
|
155
|
+
for (const k of known) {
|
|
156
|
+
const dist = (function lev(a, b) {
|
|
157
|
+
const m = a.length, n = b.length;
|
|
158
|
+
if (!m) return n; if (!n) return m;
|
|
159
|
+
const d = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
160
|
+
for (let i = 0; i <= m; i++) d[i][0] = i;
|
|
161
|
+
for (let j = 0; j <= n; j++) d[0][j] = j;
|
|
162
|
+
for (let i = 1; i <= m; i++) for (let j = 1; j <= n; j++) {
|
|
163
|
+
d[i][j] = a[i - 1] === b[j - 1] ? d[i - 1][j - 1] : 1 + Math.min(d[i - 1][j], d[i][j - 1], d[i - 1][j - 1]);
|
|
164
|
+
}
|
|
165
|
+
return d[m][n];
|
|
166
|
+
})(trimmed.toLowerCase(), k.toLowerCase());
|
|
167
|
+
if (dist < bestDist) { bestDist = dist; best = k; }
|
|
168
|
+
}
|
|
169
|
+
const suggestion = best && bestDist <= Math.max(2, Math.floor(trimmed.length / 3))
|
|
170
|
+
? `\n Did you mean "${best}"?`
|
|
171
|
+
: '';
|
|
172
|
+
const examples = known.length
|
|
173
|
+
? `\n Registered names: ${known.slice(0, 8).join(', ')}${known.length > 8 ? ', ...' : ''}`
|
|
174
|
+
: '\n No selectors registered yet.';
|
|
175
|
+
|
|
176
|
+
throw new Error(
|
|
177
|
+
`Unknown selector "${trimmed}".${suggestion}${examples}\n` +
|
|
178
|
+
` Register one with:\n` +
|
|
179
|
+
` Given I define css selectors:\n` +
|
|
180
|
+
` | name | css |\n` +
|
|
181
|
+
` When I add "${trimmed}" selector for "<css>" css selector\n` +
|
|
182
|
+
` or load a JSON preset via worldParameters.selectors.files.`
|
|
183
|
+
);
|
|
149
184
|
}
|
|
150
185
|
|
|
151
186
|
function parseNames(text) {
|
|
@@ -769,16 +804,16 @@ Then(/^(I |we )*(don't|do not) see ([a-zA-Z0-9 ,\-]+)$/, async function (pronoun
|
|
|
769
804
|
/**
|
|
770
805
|
* Assert a named locator has keyboard focus.
|
|
771
806
|
*
|
|
772
|
-
* Example #1: Then search has focus
|
|
773
|
-
* Example #2: Then email input has focus
|
|
774
|
-
* Example #3: Then submit button has focus
|
|
775
|
-
* Example #4: Then username has focus
|
|
776
|
-
* Example #5: Then password has focus
|
|
777
|
-
* Example #6: Then search button has focus
|
|
778
|
-
* Example #7: Then first link has focus
|
|
779
|
-
* Example #8: Then skip link has focus
|
|
780
|
-
* Example #9: Then close button has focus
|
|
781
|
-
* Example #10: Then modal heading has focus
|
|
807
|
+
* Example #1: Then I see search has focus
|
|
808
|
+
* Example #2: Then I see email input has focus
|
|
809
|
+
* Example #3: Then we see submit button has focus
|
|
810
|
+
* Example #4: Then I see username has focus
|
|
811
|
+
* Example #5: Then I see password has focus
|
|
812
|
+
* Example #6: Then we see search button has focus
|
|
813
|
+
* Example #7: Then I see first link has focus
|
|
814
|
+
* Example #8: Then I see skip link has focus
|
|
815
|
+
* Example #9: Then I see close button has focus
|
|
816
|
+
* Example #10: Then I see modal heading has focus
|
|
782
817
|
*/
|
|
783
818
|
Then(/^(I |we )*see ([a-zA-Z0-9 ,\-]+) has focus$/, async function (pronounCase, subjectText) {
|
|
784
819
|
const name = subjectText.trim();
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Cookie / local storage / session storage manipulation steps.
|
|
4
|
+
//
|
|
5
|
+
// Pre-seed per-scenario state without going through the UI. Useful for
|
|
6
|
+
// onboarding flags, A/B-test bucket assignments, feature toggles, language
|
|
7
|
+
// preferences, and any cookie-driven server behaviour.
|
|
8
|
+
//
|
|
9
|
+
// Cookies are scoped to the current page's domain (or `localhost` if no page
|
|
10
|
+
// is loaded yet). Local storage and session storage are scoped to the current
|
|
11
|
+
// page's origin and require a navigated page first.
|
|
12
|
+
|
|
13
|
+
const { Given } = require('@cucumber/cucumber');
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Cookies — context-level
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Set a cookie on the current browser context.
|
|
21
|
+
*
|
|
22
|
+
* Example #1: Given the cookie "session" is set to "abc123"
|
|
23
|
+
* Example #2: Given the cookie "lang" is set to "en"
|
|
24
|
+
* Example #3: Given cookie "ab_bucket" is set to "variant-b"
|
|
25
|
+
* Example #4: Given the cookie "consent" is set to "accepted"
|
|
26
|
+
* And I am on the homepage
|
|
27
|
+
* Example #5: Given the cookie "feature_flag" is set to "enabled"
|
|
28
|
+
* And I am on "/dashboard"
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
Given(/^(?:the cookie|cookie) "([^"]*)" is set to "([^"]*)"$/, async function (name, value) {
|
|
32
|
+
const url = this.page.url() && this.page.url() !== 'about:blank' ? this.page.url() : (this.launchUrl || 'http://localhost');
|
|
33
|
+
const u = new URL(url);
|
|
34
|
+
await this.context.addCookies([{
|
|
35
|
+
name,
|
|
36
|
+
value,
|
|
37
|
+
domain: u.hostname,
|
|
38
|
+
path: '/',
|
|
39
|
+
}]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Remove a single cookie by name (other cookies preserved).
|
|
44
|
+
*
|
|
45
|
+
* Example #1: Given the cookie "session" is removed
|
|
46
|
+
* Example #2: Given the cookie "consent" is removed
|
|
47
|
+
* When I reload the page
|
|
48
|
+
* Then I should see "Accept cookies"
|
|
49
|
+
* Example #3: Given the cookie "ab_bucket" is removed
|
|
50
|
+
* Example #4: Given the cookie "lang" is removed
|
|
51
|
+
* And I am on the homepage
|
|
52
|
+
* Example #5: Given the cookie "feature_flag" is removed
|
|
53
|
+
* When I follow "Pricing"
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
Given(/^the cookie "([^"]*)" is removed$/, async function (name) {
|
|
57
|
+
const cookies = await this.context.cookies();
|
|
58
|
+
const remaining = cookies.filter((c) => c.name !== name);
|
|
59
|
+
await this.context.clearCookies();
|
|
60
|
+
if (remaining.length) await this.context.addCookies(remaining);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Wipe every cookie on the browser context.
|
|
65
|
+
*
|
|
66
|
+
* Example #1: Given all cookies are cleared
|
|
67
|
+
* Example #2: Given all cookies are cleared
|
|
68
|
+
* When I am on the homepage
|
|
69
|
+
* Then I should see "Sign in"
|
|
70
|
+
* Example #3: Given all cookies are cleared
|
|
71
|
+
* And I am an anonymous user
|
|
72
|
+
* Example #4: Given all cookies are cleared
|
|
73
|
+
* And localStorage is cleared
|
|
74
|
+
* And sessionStorage is cleared
|
|
75
|
+
* Example #5: Given all cookies are cleared
|
|
76
|
+
* When I follow "Login"
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
Given(/^all cookies are cleared$/, async function () {
|
|
80
|
+
await this.context.clearCookies();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// localStorage / sessionStorage — page-level
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Set a local storage entry on the current page.
|
|
89
|
+
*
|
|
90
|
+
* The page must be loaded first (local storage is per-origin). Stored value
|
|
91
|
+
* is always a string — JSON-encode complex objects manually.
|
|
92
|
+
*
|
|
93
|
+
* Example #1: Given the local storage "user" is set to "Alice"
|
|
94
|
+
* Example #2: Given I am on the homepage
|
|
95
|
+
* And the local storage "theme" is set to "dark"
|
|
96
|
+
* When I reload the page
|
|
97
|
+
* Then "<body>" should have class "theme-dark"
|
|
98
|
+
* Example #3: Given local storage "lang" is set to "fr"
|
|
99
|
+
* Example #4: Given the local storage "onboarding_complete" is set to "true"
|
|
100
|
+
* And I am on "/dashboard"
|
|
101
|
+
* Then I should not see "Welcome tour"
|
|
102
|
+
* Example #5: Given the local storage "feature_flag" is set to "enabled"
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
Given(/^(?:the )?local storage "([^"]*)" is set to "([^"]*)"$/, async function (key, value) {
|
|
106
|
+
await this.page.evaluate(({ k, v }) => localStorage.setItem(k, v), { k: key, v: value });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Remove a single local storage entry.
|
|
111
|
+
*
|
|
112
|
+
* Example #1: Given the local storage "user" is removed
|
|
113
|
+
* Example #2: Given local storage "theme" is removed
|
|
114
|
+
* When I reload the page
|
|
115
|
+
* Then "<body>" should not have class "theme-dark"
|
|
116
|
+
* Example #3: Given the local storage "onboarding_complete" is removed
|
|
117
|
+
* Example #4: Given the local storage "cart" is removed
|
|
118
|
+
* And I am on "/cart"
|
|
119
|
+
* Then I should see "Your cart is empty"
|
|
120
|
+
* Example #5: Given the local storage "auth_token" is removed
|
|
121
|
+
*
|
|
122
|
+
*/
|
|
123
|
+
Given(/^(?:the )?local storage "([^"]*)" is removed$/, async function (key) {
|
|
124
|
+
await this.page.evaluate((k) => localStorage.removeItem(k), key);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Wipe local storage for the current origin.
|
|
129
|
+
*
|
|
130
|
+
* Example #1: Given local storage is cleared
|
|
131
|
+
* Example #2: Given I am on the homepage
|
|
132
|
+
* And local storage is cleared
|
|
133
|
+
* When I reload the page
|
|
134
|
+
* Example #3: Given local storage is cleared
|
|
135
|
+
* And all cookies are cleared
|
|
136
|
+
* Example #4: Given local storage is cleared
|
|
137
|
+
* And session storage is cleared
|
|
138
|
+
* Example #5: Given local storage is cleared
|
|
139
|
+
* Then I should see "First-time visitor"
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
Given(/^local storage is cleared$/, async function () {
|
|
143
|
+
await this.page.evaluate(() => localStorage.clear());
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Set a session storage entry on the current page.
|
|
148
|
+
*
|
|
149
|
+
* Example #1: Given the session storage "checkout step" is set to "2"
|
|
150
|
+
* Example #2: Given the session storage "temp form" is set to "draft"
|
|
151
|
+
* Example #3: Given session storage "tab id" is set to "tab-1"
|
|
152
|
+
* Example #4: Given the session storage "wizard progress" is set to "3/5"
|
|
153
|
+
* And I am on "/wizard"
|
|
154
|
+
* Example #5: Given the session storage "from checkout" is set to "true"
|
|
155
|
+
* And I am on "/cart"
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
Given(/^(?:the )?session storage "([^"]*)" is set to "([^"]*)"$/, async function (key, value) {
|
|
159
|
+
await this.page.evaluate(({ k, v }) => sessionStorage.setItem(k, v), { k: key, v: value });
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Remove a single session storage entry.
|
|
164
|
+
*
|
|
165
|
+
* Example #1: Given the session storage "checkout step" is removed
|
|
166
|
+
* Example #2: Given session storage "temp form" is removed
|
|
167
|
+
* Example #3: Given the session storage "wizard progress" is removed
|
|
168
|
+
* When I reload the page
|
|
169
|
+
* Then I should see "Step 1"
|
|
170
|
+
* Example #4: Given the session storage "tab id" is removed
|
|
171
|
+
* Example #5: Given the session storage "from checkout" is removed
|
|
172
|
+
*
|
|
173
|
+
*/
|
|
174
|
+
Given(/^(?:the )?session storage "([^"]*)" is removed$/, async function (key) {
|
|
175
|
+
await this.page.evaluate((k) => sessionStorage.removeItem(k), key);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Wipe session storage for the current origin.
|
|
180
|
+
*
|
|
181
|
+
* Example #1: Given session storage is cleared
|
|
182
|
+
* Example #2: Given session storage is cleared
|
|
183
|
+
* And local storage is cleared
|
|
184
|
+
* Example #3: Given session storage is cleared
|
|
185
|
+
* And all cookies are cleared
|
|
186
|
+
* Example #4: Given session storage is cleared
|
|
187
|
+
* When I reload the page
|
|
188
|
+
* Example #5: Given session storage is cleared
|
|
189
|
+
* And I am an anonymous user
|
|
190
|
+
*
|
|
191
|
+
*/
|
|
192
|
+
Given(/^session storage is cleared$/, async function () {
|
|
193
|
+
await this.page.evaluate(() => sessionStorage.clear());
|
|
194
|
+
});
|