webship-js 2.0.1 → 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 +363 -0
- package/bin/init-webship.js +343 -0
- package/bin/postinstall.js +8 -74
- package/cucumber.js +66 -2
- 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/diffy/baseline.html +54 -0
- package/examples/diffy/changed.html +63 -0
- package/examples/diffy/index.html +52 -0
- package/examples/element.html +11 -0
- package/examples/field.html +24 -0
- package/examples/index.html +6 -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/test--when--i-additionally-select.html +27 -0
- package/package.json +19 -6
- 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/diffy/test--diffy-01-example-demo.feature +22 -0
- package/tests/features/diffy/test--diffy-02-all-steps.feature +52 -0
- package/tests/features/diffy/test--diffy-03-real-api.feature +21 -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/test--then--i-save-screenshot.feature +33 -0
- package/tests/features/test--then--i-see-locator.feature +320 -0
- package/tests/features/test--then--i-should-see-n-elements.feature +24 -0
- package/tests/features/test--then--print-current-url-and-response.feature +21 -0
- package/tests/features/test--when--i-additionally-select.feature +30 -0
- package/tests/features/test--when--i-follow.feature +22 -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 +19 -0
- 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/selectors/front-end-selectors.json +16 -0
- package/tests/selectors/homepage-selectors.json +13 -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} +254 -44
- 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/screenshot.steps.js +423 -0
- package/tests/step-definitions/scroll.steps.js +189 -0
- package/tests/step-definitions/selectors.steps.js +996 -0
- 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 +567 -923
- package/tests/step-definitions/xml.steps.js +409 -0
- package/tests/step-definitions/yaml.steps.js +911 -0
- package/tests/step-definitions-diffy/README.md +329 -0
- package/tests/step-definitions-diffy/mock-diffy-api/server.js +84 -0
- package/tests/step-definitions-diffy/webship-diffy-mock.js +31 -0
- package/tests/step-definitions-diffy/webship-diffy.js +459 -0
- package/tsconfig.json +19 -3
- package/generate-reports.js +0 -22
- package/required/cucumber.js +0 -37
- package/required/generate-reports.js +0 -22
- package/required/package.json +0 -18
- package/required/playwright.config.ts +0 -37
- package/required/tests/features/README.md +0 -1
- package/required/tests/features/check-homepage.feature +0 -8
- package/required/tests/reports/README.md +0 -1
- package/required/tests/step-definitions/README.md +0 -1
- package/required/tests/step-definitions/custom.js +0 -4
- package/required/tsconfig.json +0 -12
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Assert <meta> tag presence and contents.
|
|
4
|
+
|
|
5
|
+
const { Then } = require('@cucumber/cucumber');
|
|
6
|
+
const assert = require('assert');
|
|
7
|
+
|
|
8
|
+
async function getMetas(page) {
|
|
9
|
+
return await page.evaluate(() => Array.from(document.querySelectorAll('meta')).map((m) => {
|
|
10
|
+
const o = {};
|
|
11
|
+
for (const a of m.attributes) o[a.name] = a.value;
|
|
12
|
+
return o;
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function matchAttrs(meta, attrs) {
|
|
17
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
18
|
+
if (meta[k] !== v) return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Assert at least one `<meta>` tag matches every attribute in the data table.
|
|
25
|
+
*
|
|
26
|
+
* Example #1: Then the meta tag should exist with the following attributes:
|
|
27
|
+
* | name | description |
|
|
28
|
+
* | content | Documentation site |
|
|
29
|
+
* Example #2: Then the meta tag should exist with the following attributes:
|
|
30
|
+
* | property | og:title |
|
|
31
|
+
* | content | Home |
|
|
32
|
+
* Example #3: And the meta tag should exist with the following attributes:
|
|
33
|
+
* | name | viewport |
|
|
34
|
+
* | content | width=device-width, initial-scale=1 |
|
|
35
|
+
* Example #4: Then the meta tag should exist with the following attributes:
|
|
36
|
+
* | name | robots |
|
|
37
|
+
* | content | noindex,nofollow |
|
|
38
|
+
* Example #5: Then the meta tag should exist with the following attributes:
|
|
39
|
+
* | charset | UTF-8 |
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
Then('the meta tag should exist with the following attributes:', async function (table) {
|
|
43
|
+
const want = Object.fromEntries(table.raw());
|
|
44
|
+
const metas = await getMetas(this.page);
|
|
45
|
+
assert.ok(metas.some((m) => matchAttrs(m, want)), `No meta tag matching ${JSON.stringify(want)} was found.`);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Assert NO `<meta>` tag matches every attribute in the data table.
|
|
50
|
+
*
|
|
51
|
+
* Example #1: Then the meta tag should not exist with the following attributes:
|
|
52
|
+
* | name | description |
|
|
53
|
+
* | content | Coming soon |
|
|
54
|
+
* Example #2: Then the meta tag should not exist with the following attributes:
|
|
55
|
+
* | name | robots |
|
|
56
|
+
* | content | noindex |
|
|
57
|
+
* Example #3: And the meta tag should not exist with the following attributes:
|
|
58
|
+
* | property | og:title |
|
|
59
|
+
* | content | Placeholder |
|
|
60
|
+
* Example #4: Then the meta tag should not exist with the following attributes:
|
|
61
|
+
* | http-equiv | refresh |
|
|
62
|
+
* | content | 5 |
|
|
63
|
+
* Example #5: Then the meta tag should not exist with the following attributes:
|
|
64
|
+
* | name | author |
|
|
65
|
+
* | content | Anonymous |
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
Then('the meta tag should not exist with the following attributes:', async function (table) {
|
|
69
|
+
const want = Object.fromEntries(table.raw());
|
|
70
|
+
const metas = await getMetas(this.page);
|
|
71
|
+
assert.ok(!metas.some((m) => matchAttrs(m, want)), `Meta tag matching ${JSON.stringify(want)} should not exist.`);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Assert the `content` attribute of a named meta tag contains no HTML markup.
|
|
76
|
+
* Useful for description / open-graph fields that should render as plain text.
|
|
77
|
+
*
|
|
78
|
+
* Example #1: Then the "description" meta tag should not contain any HTML tags
|
|
79
|
+
* Example #2: Then the "og:title" meta tag should not contain any HTML tags
|
|
80
|
+
* Example #3: And the "twitter:description" meta tag should not contain any HTML tags
|
|
81
|
+
* Example #4: Then the "keywords" meta tag should not contain any HTML tags
|
|
82
|
+
* Example #5: Then the "author" meta tag should not contain any HTML tags
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
Then('the {string} meta tag should not contain any HTML tags', async function (metaName) {
|
|
86
|
+
const metas = await getMetas(this.page);
|
|
87
|
+
const m = metas.find((x) => x.name === metaName || x.property === metaName);
|
|
88
|
+
assert.ok(m, `Meta tag "${metaName}" not found.`);
|
|
89
|
+
const content = m.content || '';
|
|
90
|
+
assert.ok(!/<[a-z][\s\S]*>/i.test(content), `Meta tag "${metaName}" contains HTML: ${content}`);
|
|
91
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// All modal / dialog step definitions live in this file.
|
|
4
|
+
//
|
|
5
|
+
// Modal element resolution priority:
|
|
6
|
+
// 1. world.__selectorsCss['modal'] (set via the named-selector registry
|
|
7
|
+
// or the active CMS / framework selector preset)
|
|
8
|
+
// 2. fallback to "[role=\"dialog\"], dialog"
|
|
9
|
+
//
|
|
10
|
+
// Visibility is derived from computed style (display, visibility, opacity)
|
|
11
|
+
// rather than offsetParent — that check is unreliable for fixed-position
|
|
12
|
+
// modal containers. The wait step lives in wait.steps.js.
|
|
13
|
+
|
|
14
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
15
|
+
const assert = require('assert');
|
|
16
|
+
const {
|
|
17
|
+
getModalLocator,
|
|
18
|
+
findVisibleModal,
|
|
19
|
+
isAnyModalVisible,
|
|
20
|
+
waitForModalState,
|
|
21
|
+
} = require('./webship');
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Visibility
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Assert that a modal dialog is visible or not visible on the page.
|
|
29
|
+
*
|
|
30
|
+
* Example #1: Then I should see a modal
|
|
31
|
+
* Example #2: Then I should see the modal
|
|
32
|
+
* Example #3: Then we should see a modal dialog
|
|
33
|
+
* Example #4: Then I should not see a modal
|
|
34
|
+
* Example #5: Then I should not see the modal dialog
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
Then(/^(I |we )*should( not)* see (a |the )*modal( dialog)*$/, async function (pronounCase, notCase, aTheCase, dialogCase) {
|
|
38
|
+
const visible = await isAnyModalVisible(this.page, this);
|
|
39
|
+
if (notCase) {
|
|
40
|
+
assert.ok(!visible, 'Modal dialog is visible, but it should not be.');
|
|
41
|
+
} else {
|
|
42
|
+
assert.ok(visible, 'Modal dialog is not visible, but it should be.');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Assert that a modal dialog with a given title is visible or not visible.
|
|
48
|
+
*
|
|
49
|
+
* Example #1: Then I should see a modal with title "Confirm Action"
|
|
50
|
+
* Example #2: Then I should see the modal with title "Welcome"
|
|
51
|
+
* Example #3: Then we should see a modal with title "Welcome Message"
|
|
52
|
+
* Example #4: Then I should not see a modal with title "Error"
|
|
53
|
+
* Example #5: Then I should not see the modal with title "Validation Error"
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
Then(/^(I |we )*should( not)* see (a |the )*modal with title "([^"]*)?"$/, async function (pronounCase, notCase, aTheCase, title) {
|
|
57
|
+
const modal = getModalLocator(this.page, this);
|
|
58
|
+
const byHeading = modal.locator('.modal-title, .dialog-title, h1, h2, h3').filter({ hasText: title });
|
|
59
|
+
const byAttr = modal.locator(`[title*="${title}"], [aria-label*="${title}"]`);
|
|
60
|
+
const found = await byHeading.count() > 0 || await byAttr.count() > 0;
|
|
61
|
+
if (notCase) {
|
|
62
|
+
assert.ok(!found, `Modal with title "${title}" is visible, but it should not be.`);
|
|
63
|
+
} else {
|
|
64
|
+
assert.ok(found, `Modal with title "${title}" is not visible or not found.`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Assert that a specific modal by id/class/data-modal is visible or not.
|
|
70
|
+
*
|
|
71
|
+
* Example #1: Then I should see a "confirmation-modal" modal
|
|
72
|
+
* Example #2: Then I should see the "#delete-modal" modal
|
|
73
|
+
* Example #3: Then we should see a "settings-modal" modal
|
|
74
|
+
* Example #4: Then I should not see a "error-modal" modal
|
|
75
|
+
* Example #5: Then I should not see the "#success-modal" modal
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
Then(/^(I |we )*should( not)* see (a |the )*"([^"]*)?" modal$/, async function (pronounCase, notCase, aTheCase, identifier) {
|
|
79
|
+
const selector = (identifier.startsWith('#') || identifier.startsWith('.'))
|
|
80
|
+
? identifier
|
|
81
|
+
: `#${identifier}, .${identifier}, [data-modal="${identifier}"]`;
|
|
82
|
+
const visible = await this.page.locator(selector).first().isVisible();
|
|
83
|
+
if (notCase) {
|
|
84
|
+
assert.ok(!visible, `Modal "${identifier}" is visible, but it should not be.`);
|
|
85
|
+
} else {
|
|
86
|
+
assert.ok(visible, `Modal "${identifier}" is not visible or not found.`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Text content
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Assert that a modal contains or does not contain specific text.
|
|
96
|
+
*
|
|
97
|
+
* Example #1: Then I should see "Are you sure?" in the modal
|
|
98
|
+
* Example #2: Then I should see "Delete this item" in the modal
|
|
99
|
+
* Example #3: Then we should see "Confirmation required" in the modal dialog
|
|
100
|
+
* Example #4: Then I should not see "Error occurred" in the modal
|
|
101
|
+
*
|
|
102
|
+
*/
|
|
103
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* modal( dialog)*$/, async function (pronounCase, notCase, expectedText, theCase, dialogCase) {
|
|
104
|
+
const found = await getModalLocator(this.page, this).filter({ hasText: expectedText }).count() > 0;
|
|
105
|
+
if (notCase) {
|
|
106
|
+
assert.ok(!found, `Found "${expectedText}" in modal, but it should not be there.`);
|
|
107
|
+
} else {
|
|
108
|
+
assert.ok(found, `Could not find "${expectedText}" in modal.`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Assert that the modal contains the given text (alternate phrasing).
|
|
114
|
+
*
|
|
115
|
+
* Distinct from "I should see :text in the modal" — checks plain
|
|
116
|
+
* `innerText`, ignoring nested layout. Use when the text is part of the
|
|
117
|
+
* modal body rather than a specific element.
|
|
118
|
+
*
|
|
119
|
+
* Example #1: Then the modal should contain "Welcome modal text"
|
|
120
|
+
* Example #2: Then the modal should contain "Are you sure"
|
|
121
|
+
* Example #3: And the modal should contain "Order #1234"
|
|
122
|
+
* Example #4: When I press "Show details"
|
|
123
|
+
* Then the modal should contain "Address"
|
|
124
|
+
* Example #5: Given I am on "/dashboard"
|
|
125
|
+
* When I click "Open settings"
|
|
126
|
+
* And I wait for the modal to appear
|
|
127
|
+
* Then the modal should contain "Preferences"
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
Then('the modal should contain {string}', async function (text) {
|
|
131
|
+
const inner = await getModalLocator(this.page, this).first().innerText();
|
|
132
|
+
assert.ok(inner.indexOf(text) !== -1, `Modal does not contain "${text}". Got: ${inner}`);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Assert that the modal does NOT contain the given text.
|
|
137
|
+
*
|
|
138
|
+
* Passes when no modal exists OR when the modal exists but lacks the text.
|
|
139
|
+
*
|
|
140
|
+
* Example #1: Then the modal should not contain "Goodbye"
|
|
141
|
+
* Example #2: Then the modal should not contain "Error"
|
|
142
|
+
* Example #3: And the modal should not contain "Payment failed"
|
|
143
|
+
* Example #4: When I close the modal
|
|
144
|
+
* Then the modal should not contain "Welcome"
|
|
145
|
+
* Example #5: When I press "Refresh"
|
|
146
|
+
* Then the modal should not contain "Loading"
|
|
147
|
+
*
|
|
148
|
+
*/
|
|
149
|
+
Then('the modal should not contain {string}', async function (text) {
|
|
150
|
+
const loc = getModalLocator(this.page, this);
|
|
151
|
+
const count = await loc.count();
|
|
152
|
+
if (count === 0) return;
|
|
153
|
+
const inner = await loc.first().innerText();
|
|
154
|
+
assert.ok(inner.indexOf(text) === -1, `Modal should not contain "${text}".`);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// Interactions
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Click a button or link inside a modal dialog by its visible text.
|
|
163
|
+
*
|
|
164
|
+
* Example #1: When I click "Confirm" in the modal
|
|
165
|
+
* Example #2: When I click "Cancel" in the modal dialog
|
|
166
|
+
* Example #3: When we click "OK" button in the modal
|
|
167
|
+
* Example #4: And I click "Close" in the modal
|
|
168
|
+
*
|
|
169
|
+
*/
|
|
170
|
+
When(/^(I |we )*click "([^"]*)?"( button)* in( the)* modal( dialog)*$/, async function (pronounCase, buttonText, buttonCase, theCase, dialogCase) {
|
|
171
|
+
await waitForModalState(this.page, 'visible', 10000, this);
|
|
172
|
+
const modal = await findVisibleModal(this.page, this);
|
|
173
|
+
await modal.locator('button, a, [role="button"], input[type="button"], input[type="submit"], .btn')
|
|
174
|
+
.filter({ hasText: buttonText })
|
|
175
|
+
.first()
|
|
176
|
+
.click();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Click a CSS-selector-addressed element inside the active modal.
|
|
181
|
+
*
|
|
182
|
+
* Distinct from "click :text in the modal" which uses visible button text.
|
|
183
|
+
* Use this variant when the target lacks readable text (icon button) or
|
|
184
|
+
* when text is ambiguous across multiple buttons in the modal.
|
|
185
|
+
*
|
|
186
|
+
* Example #1: When I click on "#close-btn" in the modal
|
|
187
|
+
* Example #2: When I click on ".confirm-delete" in the modal
|
|
188
|
+
* Example #3: And I click on "[data-testid=accept]" in the modal
|
|
189
|
+
* Example #4: When I click on "button[aria-label=Close]" in the modal
|
|
190
|
+
* Example #5: When I press "Open settings"
|
|
191
|
+
* And I wait for the modal to appear
|
|
192
|
+
* Then I click on "#tab-notifications" in the modal
|
|
193
|
+
*
|
|
194
|
+
*/
|
|
195
|
+
When(/^(I |we )*click on "([^"]*)" in the modal$/, async function (pronoun, selector) {
|
|
196
|
+
await getModalLocator(this.page, this).locator(selector).first().click();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Close or dismiss a modal dialog (uses close button, or Escape fallback).
|
|
201
|
+
*
|
|
202
|
+
* Example #1: When I close the modal
|
|
203
|
+
* Example #2: When I dismiss the modal dialog
|
|
204
|
+
* Example #3: When we close the modal
|
|
205
|
+
* Example #4: And I dismiss the modal
|
|
206
|
+
*
|
|
207
|
+
*/
|
|
208
|
+
When(/^(I |we )*(close|dismiss)( the)* modal( dialog)*$/, async function (pronounCase, closeOrDismiss, theCase, dialogCase) {
|
|
209
|
+
await waitForModalState(this.page, 'visible', 10000, this);
|
|
210
|
+
const modal = await findVisibleModal(this.page, this);
|
|
211
|
+
const closeBtn = modal.locator('.close, .modal-close, [data-dismiss="modal"], [aria-label="Close"], .btn-close, button[class*="close"]').first();
|
|
212
|
+
if (await closeBtn.isVisible()) {
|
|
213
|
+
await closeBtn.click();
|
|
214
|
+
} else {
|
|
215
|
+
await modal.press('Escape');
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// "When I wait for the modal to appear/disappear" is defined in wait.steps.js.
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// All navigation step definitions live in this file: anonymous user, going
|
|
4
|
+
// to the homepage / a specific path, browser history (back/forward), reload,
|
|
5
|
+
// and URL/path assertions.
|
|
6
|
+
|
|
7
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
8
|
+
const assert = require('assert');
|
|
9
|
+
const { gotoUrl, waitForPageLoad, smartSettle } = require('./webship');
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Sessions / visits
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Clear cookies and navigate to the launch URL as an anonymous visitor.
|
|
17
|
+
*
|
|
18
|
+
* Example #1: Given I am an anonymous user
|
|
19
|
+
* Example #2: Given we are an anonymous user
|
|
20
|
+
* Example #3: Given an anonymous user
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
Given(/^(I am |we are )?an anonymous user$/, async function (pronounCase) {
|
|
24
|
+
await this.context.clearCookies();
|
|
25
|
+
await gotoUrl(this.page, this.launchUrl);
|
|
26
|
+
await waitForPageLoad(this.page, this.minWaitTime.page || 3000);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Open the homepage.
|
|
31
|
+
*
|
|
32
|
+
* Example #1: Given I am on homepage
|
|
33
|
+
* Example #2: Given I am on the homepage
|
|
34
|
+
* Example #3: Given I am on frontpage
|
|
35
|
+
* Example #4: Given I am on the frontpage
|
|
36
|
+
* Example #5: Given we are on homepage
|
|
37
|
+
* Example #6: Given we are on the frontpage
|
|
38
|
+
* Example #7: Given on homepage
|
|
39
|
+
* Example #8: Given on the homepage
|
|
40
|
+
* Example #9: Given on frontpage
|
|
41
|
+
* Example #10: Given on the frontpage
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, async function (pronounCase, theCase, pageCase) {
|
|
45
|
+
const defaultTime = this.minWaitTime.page || 3000;
|
|
46
|
+
await gotoUrl(this.page, this.launchUrl);
|
|
47
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
48
|
+
await waitForPageLoad(this.page, defaultTime);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Open a specific page under the launch URL.
|
|
53
|
+
*
|
|
54
|
+
* Example #1: Given I am on "/about-us.html"
|
|
55
|
+
* Example #2: Given I am on the "/about-us.html" page
|
|
56
|
+
* Example #3: Given we are on "/user/login"
|
|
57
|
+
* Example #4: Given we are on the "/contact-us.html" page
|
|
58
|
+
* Example #5: Given on "/about-us.html"
|
|
59
|
+
* Example #6: Given on the "/about-us.html" page
|
|
60
|
+
* Example #7: Given I am on "https://un.org"
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
Given(/^(I am |we are )*on( the)* "([^"]*)?"( page)*$/, async function (pronounCase, theCase, url, pageCase) {
|
|
64
|
+
await gotoUrl(this.page, this.launchUrl + url);
|
|
65
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: 10000 });
|
|
66
|
+
await waitForPageLoad(this.page);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Navigate to the homepage.
|
|
71
|
+
*
|
|
72
|
+
* Example #1: When I go to homepage
|
|
73
|
+
* Example #2: When I go to the homepage
|
|
74
|
+
* Example #3: When I navigate to the homepage
|
|
75
|
+
* Example #4: When navigating to the homepage
|
|
76
|
+
* Example #5: When navigating to homepage
|
|
77
|
+
* Example #6: When navigating to the frontpage
|
|
78
|
+
* Example #7: When we go to the homepage
|
|
79
|
+
* Example #8: When we navigate to the homepage
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|frontpage)$/, async function (pronounCase, theCase, pageCase) {
|
|
83
|
+
const defaultTime = this.minWaitTime.page || 3000;
|
|
84
|
+
await gotoUrl(this.page, this.launchUrl);
|
|
85
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
86
|
+
await waitForPageLoad(this.page, defaultTime);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Navigate to a specific page.
|
|
91
|
+
*
|
|
92
|
+
* Example #1: When I go to "/contact-us.html"
|
|
93
|
+
* Example #2: When I go to "/user/login"
|
|
94
|
+
* Example #3: When I navigate to "/admin/dashboard"
|
|
95
|
+
* Example #4: When navigating to "/products"
|
|
96
|
+
* Example #5: When we go to "/products"
|
|
97
|
+
* Example #6: When we navigate to "/terms"
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, async function (pronounCase, url) {
|
|
101
|
+
const defaultTime = this.minWaitTime.page || 3000;
|
|
102
|
+
await gotoUrl(this.page, this.launchUrl + url);
|
|
103
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
104
|
+
await waitForPageLoad(this.page, defaultTime);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
// Browser history + reload
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Moves forward one page in browser history.
|
|
113
|
+
*
|
|
114
|
+
* Example #1: When I move forward one page
|
|
115
|
+
* Example #2: When we move forward one page
|
|
116
|
+
* Example #3: And move forward one page
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
When(/^(I |we )*move forward one page$/, async function (pronounCase) {
|
|
120
|
+
await this.page.goForward();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Moves backward one page in browser history.
|
|
125
|
+
*
|
|
126
|
+
* Example #1: When I move backward one page
|
|
127
|
+
* Example #2: When we move backward one page
|
|
128
|
+
* Example #3: And move backward one page
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
When(/^(I |we )*move backward one page$/, async function (pronounCase) {
|
|
132
|
+
await this.page.goBack();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Reloads the current page.
|
|
137
|
+
*
|
|
138
|
+
* Example #1: When I reload
|
|
139
|
+
* Example #2: And I reload the page
|
|
140
|
+
* Example #3: And we reload page
|
|
141
|
+
* Example #4: And we reload the page
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
When(/^(I |we )*reload( the)*( page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
145
|
+
await this.page.reload();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// URL / path assertions
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Assert that the current page is or is not the homepage.
|
|
154
|
+
*
|
|
155
|
+
* Example #1: Then I should be on homepage
|
|
156
|
+
* Example #2: And I should be on the homepage
|
|
157
|
+
* Example #3: Then I should be on frontpage
|
|
158
|
+
* Example #4: And should be on the homepage
|
|
159
|
+
* Example #5: Then should be on homepage
|
|
160
|
+
* Example #6: And we should be on homepage
|
|
161
|
+
* Example #7: Then should be on frontpage
|
|
162
|
+
* Example #8: And we should be on the homepage
|
|
163
|
+
* Example #9: Then I should not be on homepage
|
|
164
|
+
* Example #10: And I should not be on the homepage
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
Then(/^(I |we )*should( not)* be on( the)* (homepage|frontpage)$/, async function (pronounCase, notCase, theCase, pageCase) {
|
|
168
|
+
const currentUrl = this.page.url();
|
|
169
|
+
if (notCase) {
|
|
170
|
+
assert.ok(currentUrl !== this.launchUrl && !currentUrl.startsWith(this.launchUrl + '/'),
|
|
171
|
+
`Should NOT be on homepage but current URL is: ${currentUrl}`);
|
|
172
|
+
} else {
|
|
173
|
+
assert.ok(currentUrl.startsWith(this.launchUrl),
|
|
174
|
+
`Should be on homepage but current URL is: ${currentUrl}`);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Assert that the current path is or is not equal to the specified path.
|
|
180
|
+
*
|
|
181
|
+
* Example #1: Then I should be on "/"
|
|
182
|
+
* Example #2: And I should be on "/user/login"
|
|
183
|
+
* Example #3: And I should be on "https://un.org"
|
|
184
|
+
* Example #4: Then we should be on the "/" page
|
|
185
|
+
* Example #5: And we should be on "/user/login"
|
|
186
|
+
* Example #6: Then should be on the "/user/reset" page
|
|
187
|
+
* Example #7: Then I should not be on "/"
|
|
188
|
+
* Example #8: And I should not be on "/user/login"
|
|
189
|
+
* Example #9: And I should not be on "https://un.org"
|
|
190
|
+
* Example #10: And we should not be on the "https://un.org" page
|
|
191
|
+
*
|
|
192
|
+
*/
|
|
193
|
+
Then(/^(I |we )*should( not)* be on( the)* "([^"]*)?"( page)*$/, async function (pronounCase, notCase, theCase, url, pageCase) {
|
|
194
|
+
const currentUrl = this.page.url();
|
|
195
|
+
if (notCase) {
|
|
196
|
+
assert.ok(!currentUrl.includes(url), `URL should NOT contain "${url}" but it is: ${currentUrl}`);
|
|
197
|
+
} else {
|
|
198
|
+
assert.ok(currentUrl.includes(url), `URL should contain "${url}" but it is: ${currentUrl}`);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Assert that the current URL matches or does not match a regex pattern.
|
|
204
|
+
*
|
|
205
|
+
* Example #1: Then the url should match "/contact-us.html"
|
|
206
|
+
* Example #2: Then the url should not match "/contact-us.html"
|
|
207
|
+
* Example #3: And the url should match "^https://"
|
|
208
|
+
*
|
|
209
|
+
*/
|
|
210
|
+
Then(/^(the )*url should( not)* match "([^"]*)?"$/, async function (theCase, notCase, pattern) {
|
|
211
|
+
const currentUrl = this.page.url();
|
|
212
|
+
const regex = new RegExp(pattern);
|
|
213
|
+
if (notCase) {
|
|
214
|
+
assert.ok(!regex.test(currentUrl), `URL "${currentUrl}" should NOT match "${pattern}" but it does.`);
|
|
215
|
+
} else {
|
|
216
|
+
assert.ok(regex.test(currentUrl), `URL "${currentUrl}" should match "${pattern}" but it does not.`);
|
|
217
|
+
}
|
|
218
|
+
});
|