webship-js 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +7 -31
- package/.drone.yml +68 -0
- package/.harness/webship-js-pipeline.yml +101 -0
- package/.semaphore/semaphore.yml +58 -0
- package/.teamcity/pom.xml +52 -0
- package/.teamcity/settings.kts +92 -0
- package/.travis.yml +24 -3
- package/AGENTS.md +53 -17
- package/CLAUDE.md +327 -105
- package/Jenkinsfile +54 -0
- package/azure-pipelines.yml +82 -0
- package/bamboo-specs/bamboo.yml +131 -0
- package/bin/init-webship.js +0 -13
- package/bin/postinstall.js +0 -0
- package/buildspec.yml +56 -0
- package/cloudbuild.yaml +49 -0
- package/codefresh.yml +77 -0
- package/cucumber.js +39 -14
- package/docs/00-quick-start.md +0 -0
- package/docs/01-getting-started.md +0 -0
- package/docs/02-bbr-smart-waits.md +0 -0
- package/docs/03-selector-registry.md +0 -0
- package/docs/04-step-reference.md +74 -3
- package/docs/05-web-first-assertions.md +0 -0
- package/docs/06-network-and-dialogs.md +0 -0
- package/docs/07-auth-state.md +0 -0
- package/docs/08-clock-mocking.md +0 -0
- package/docs/09-api-testing.md +0 -0
- package/docs/10-accessibility.md +0 -0
- package/docs/11-debugging.md +0 -0
- package/docs/12-ai-agent-guide.md +0 -0
- package/docs/13-faq.md +0 -0
- package/docs/14-recipes-cookbook.md +0 -0
- package/docs/15-tag-conventions.md +0 -0
- package/docs/16-ci-cd.md +879 -0
- package/docs/README.md +116 -0
- package/docs/advanced-screenshots/then-i-save-fullscreen-screenshot.md +0 -0
- package/docs/advanced-screenshots/then-i-save-width-x-height-screenshot.md +0 -0
- package/docs/advanced-screenshots/when-i-save-screenshot-name-filename.md +0 -0
- package/docs/advanced-screenshots.md +0 -0
- package/docs/advanced-selectors.md +0 -0
- package/docs/api-step-definitions.md +0 -0
- package/docs/global-settings.md +45 -22
- package/docs/install-webship-js/ddev-webship-js.md +0 -0
- package/docs/install-webship-js.md +0 -1
- package/docs/overview.md +0 -1
- package/docs/step-definitions/given-i-am-anonymous-user.md +0 -0
- package/docs/step-definitions/given-i-am-homepage.md +0 -0
- package/docs/step-definitions/given-i-am-specific-page.md +0 -0
- package/docs/step-definitions/then-i-should-be.md +0 -0
- package/docs/step-definitions/then-i-should-see.md +0 -0
- package/docs/step-definitions/then-item-checkbox.md +0 -0
- package/docs/step-definitions/then-item-link-should-contain-url.md +0 -0
- package/docs/step-definitions/then-item-should-contain.md +0 -0
- package/docs/step-definitions/then-radio-button-value-should-be-selected.md +0 -0
- package/docs/step-definitions/then-response-status-code-should-be-number.md +0 -0
- package/docs/step-definitions/then-value-radio-button-selected.md +0 -0
- package/docs/step-definitions/when-i-attach-file-file-name-element.md +0 -0
- package/docs/step-definitions/when-i-check-checkbox.md +0 -0
- package/docs/step-definitions/when-i-click-link.md +0 -0
- package/docs/step-definitions/when-i-click-operation-text-row.md +0 -0
- package/docs/step-definitions/when-i-fill.md +0 -0
- package/docs/step-definitions/when-i-go-homepage.md +0 -0
- package/docs/step-definitions/when-i-go-specific-page.md +0 -0
- package/docs/step-definitions/when-i-move-backward-one-page.md +0 -0
- package/docs/step-definitions/when-i-move-forward-one-page.md +0 -0
- package/docs/step-definitions/when-i-press-button.md +0 -0
- package/docs/step-definitions/when-i-reload-page.md +0 -0
- package/docs/step-definitions/when-i-scroll.md +0 -0
- package/docs/step-definitions/when-i-select-option-select-list.md +0 -0
- package/docs/step-definitions/when-i-select-radio-button-value.md +0 -0
- package/docs/step-definitions/when-i-uncheck-checkbox.md +0 -0
- package/docs/step-definitions/when-i-wait-ajax-finish.md +0 -0
- package/docs/step-definitions/when-i-wait.md +0 -0
- package/docs/step-definitions.md +0 -0
- package/examples/a11y.html +0 -0
- package/examples/account.html +0 -0
- package/examples/ajax-wait-examples.html +0 -0
- package/examples/cookies.html +0 -0
- package/examples/date.html +0 -0
- package/examples/dynamic-examples.html +0 -0
- package/examples/element.html +0 -0
- package/examples/field.html +0 -0
- package/examples/keyboard.html +0 -0
- package/examples/links.html +0 -0
- package/examples/modal.html +0 -0
- package/examples/path.html +0 -0
- package/examples/table.html +0 -0
- package/examples/test--modal-dialogs.html +0 -0
- package/examples/test--when--i-additionally-select.html +0 -0
- package/examples/test--when--i-select-radio-button.html +0 -0
- package/examples/video-demo.html +43 -0
- package/package.json +1 -1
- package/playwright.config.ts +0 -0
- package/tests/assets/test-document.pdf +0 -0
- package/tests/features/a11y.feature +0 -0
- package/tests/features/ajax-wait-examples.feature +0 -0
- package/tests/features/cookie.feature +0 -0
- package/tests/features/date.feature +0 -0
- package/tests/features/dynamic-content-examples.feature +0 -0
- package/tests/features/element.feature +0 -0
- package/tests/features/field.feature +0 -0
- package/tests/features/keyboard.feature +0 -0
- package/tests/features/link.feature +0 -0
- package/tests/features/modal-advanced-example.feature +0 -0
- package/tests/features/modal-basic-example.feature +0 -0
- package/tests/features/modal-error-handling-example.feature +0 -0
- package/tests/features/modal.feature +0 -0
- package/tests/features/path.feature +0 -0
- package/tests/features/response.feature +0 -0
- package/tests/features/responsive.feature +0 -0
- package/tests/features/table.feature +0 -0
- package/tests/features/test--given--i-am-an-anonymous-user.feature +0 -0
- package/tests/features/test--then--i-save-screenshot.feature +0 -0
- package/tests/features/test--then--i-see-locator.feature +0 -0
- package/tests/features/test--then--i-should-see-n-elements.feature +0 -0
- package/tests/features/test--then--print-current-url-and-response.feature +0 -0
- package/tests/features/test--when--i-additionally-select.feature +0 -0
- package/tests/features/test--when--i-follow.feature +0 -0
- package/tests/features/test--when--i-select-radio-button.feature +0 -0
- package/tests/features/video.feature +18 -0
- package/tests/features/wait.feature +0 -0
- package/tests/features/yaml.feature +0 -0
- package/tests/reports/README.md +0 -0
- package/tests/selectors/_canonical-keys.json +0 -0
- package/tests/selectors/back-end-selectors.json +0 -0
- package/tests/selectors/cms-contentful-admin.json +0 -0
- package/tests/selectors/cms-craft-admin.json +0 -0
- package/tests/selectors/cms-drupal-cms-gin.json +0 -0
- package/tests/selectors/cms-drupal-core-claro.json +0 -0
- package/tests/selectors/cms-generic-admin.json +0 -0
- package/tests/selectors/cms-ghost-admin.json +0 -0
- package/tests/selectors/cms-joomla-admin.json +0 -0
- package/tests/selectors/cms-magento2-admin.json +0 -0
- package/tests/selectors/cms-prestashop-admin.json +0 -0
- package/tests/selectors/cms-shopify-admin.json +0 -0
- package/tests/selectors/cms-strapi-admin.json +0 -0
- package/tests/selectors/cms-typo3-admin.json +0 -0
- package/tests/selectors/cms-woocommerce-front.json +0 -0
- package/tests/selectors/cms-wordpress-admin.json +0 -0
- package/tests/selectors/framework-ant-design.json +0 -0
- package/tests/selectors/framework-bootstrap.json +0 -0
- package/tests/selectors/framework-bulma.json +0 -0
- package/tests/selectors/framework-chakra.json +0 -0
- package/tests/selectors/framework-foundation.json +0 -0
- package/tests/selectors/framework-material-ui.json +0 -0
- package/tests/selectors/framework-shadcn.json +0 -0
- package/tests/selectors/framework-tailwind.json +0 -0
- package/tests/selectors/framework-vuetify.json +0 -0
- package/tests/selectors/front-end-selectors.json +0 -0
- package/tests/selectors/homepage-selectors.json +0 -0
- package/tests/step-definitions/a11y.steps.js +3 -1
- package/tests/step-definitions/action.steps.js +2 -2
- package/tests/step-definitions/api.steps.js +17 -16
- package/tests/step-definitions/assertion.steps.js +2 -2
- package/tests/step-definitions/auth.steps.js +3 -1
- package/tests/step-definitions/clock.steps.js +38 -38
- package/tests/step-definitions/cookie.steps.js +0 -0
- package/tests/step-definitions/debug.steps.js +13 -5
- package/tests/step-definitions/dialog.steps.js +0 -0
- package/tests/step-definitions/element.steps.js +47 -5
- package/tests/step-definitions/field.steps.js +0 -0
- package/tests/step-definitions/file-download.steps.js +38 -20
- package/tests/step-definitions/form.steps.js +6 -6
- package/tests/step-definitions/iframe.steps.js +65 -15
- package/tests/step-definitions/input.steps.js +47 -8
- package/tests/step-definitions/javascript.steps.js +195 -34
- package/tests/step-definitions/keyboard.steps.js +38 -4
- package/tests/step-definitions/link.steps.js +0 -0
- package/tests/step-definitions/metatag.steps.js +0 -0
- package/tests/step-definitions/modal.steps.js +39 -14
- package/tests/step-definitions/navigation.steps.js +0 -0
- package/tests/step-definitions/network.steps.js +61 -19
- package/tests/step-definitions/path.steps.js +0 -0
- package/tests/step-definitions/response.steps.js +0 -0
- package/tests/step-definitions/responsive.steps.js +3 -1
- package/tests/step-definitions/rest.steps.js +0 -0
- package/tests/step-definitions/screenshot.steps.js +0 -0
- package/tests/step-definitions/scroll.steps.js +0 -0
- package/tests/step-definitions/selectors.steps.js +19 -17
- package/tests/step-definitions/storage.steps.js +0 -0
- package/tests/step-definitions/table.steps.js +0 -0
- package/tests/step-definitions/video.steps.js +178 -0
- package/tests/step-definitions/wait.steps.js +0 -0
- package/tests/step-definitions/web-first.steps.js +3 -1
- package/tests/step-definitions/webship.js +234 -15
- package/tests/step-definitions/xml.steps.js +4 -2
- package/tests/step-definitions/yaml.steps.js +13 -11
- package/tsconfig.json +0 -0
- package/videos/README.md +32 -0
- package/.travis-ci.yml +0 -16
- package/docs/diffy-step-definitions/then-compare-diffy-env1-env2.md +0 -30
- package/docs/diffy-step-definitions/then-create-diffy-comparison-name-value.md +0 -21
- package/docs/diffy-step-definitions/then-create-diffy-comparison.md +0 -25
- package/docs/diffy-step-definitions/then-create-diffy-screenshot-environment-name.md +0 -35
- package/docs/diffy-step-definitions/then-i-take-screenshot.md +0 -21
- package/docs/diffy-step-definitions/then-i-take-screenshots-all-breakpoints.md +0 -27
- package/docs/diffy-step-definitions/then-send-screenshots-diffy-name-value.md +0 -27
- package/docs/diffy-step-definitions/then-upload-folder-url-diffy-snapshotname.md +0 -28
- package/docs/diffy-step-definitions/then-wait-diffy-comparison-complete.md +0 -21
- package/docs/diffy-step-definitions/when-i-resize-window-number.md +0 -29
- package/docs/diffy-step-definitions.md +0 -21
- package/docs/index.md +0 -104
- package/examples/diffy/baseline.html +0 -54
- package/examples/diffy/changed.html +0 -63
- package/examples/diffy/index.html +0 -52
- package/tests/features/diffy/test--diffy-01-example-demo.feature +0 -22
- package/tests/features/diffy/test--diffy-02-all-steps.feature +0 -52
- package/tests/features/diffy/test--diffy-03-real-api.feature +0 -21
- package/tests/step-definitions-diffy/README.md +0 -329
- package/tests/step-definitions-diffy/mock-diffy-api/server.js +0 -84
- package/tests/step-definitions-diffy/webship-diffy-mock.js +0 -31
- package/tests/step-definitions-diffy/webship-diffy.js +0 -459
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { Given, When, Then, Before } = require('@cucumber/cucumber');
|
|
2
2
|
const axios = require('axios');
|
|
3
3
|
const assert = require('assert');
|
|
4
|
+
const { friendly } = require('./webship');
|
|
4
5
|
|
|
5
6
|
// Global variables to store API response and request data
|
|
6
7
|
let apiResponse = null;
|
|
@@ -163,7 +164,7 @@ Given(/^(?:I set the request body to|we set the request body to|the request body
|
|
|
163
164
|
const processedData = replacePlaceHolder(jsonData);
|
|
164
165
|
apiRequestData = JSON.parse(processedData);
|
|
165
166
|
} catch (error) {
|
|
166
|
-
throw
|
|
167
|
+
throw friendly(`Invalid JSON in request body: ${error.message}`);
|
|
167
168
|
}
|
|
168
169
|
});
|
|
169
170
|
|
|
@@ -232,7 +233,7 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method
|
|
|
232
233
|
}
|
|
233
234
|
});
|
|
234
235
|
} catch (error) {
|
|
235
|
-
throw
|
|
236
|
+
throw friendly(`${method} request failed: ${error.message}`);
|
|
236
237
|
}
|
|
237
238
|
});
|
|
238
239
|
|
|
@@ -278,7 +279,7 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async fun
|
|
|
278
279
|
}
|
|
279
280
|
});
|
|
280
281
|
} catch (error) {
|
|
281
|
-
throw
|
|
282
|
+
throw friendly(`${method} request with values failed: ${error.message}`);
|
|
282
283
|
}
|
|
283
284
|
});
|
|
284
285
|
|
|
@@ -351,7 +352,7 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async funct
|
|
|
351
352
|
}
|
|
352
353
|
});
|
|
353
354
|
} catch (error) {
|
|
354
|
-
throw
|
|
355
|
+
throw friendly(`${method} request with body failed: ${error.message}`);
|
|
355
356
|
}
|
|
356
357
|
});
|
|
357
358
|
|
|
@@ -416,7 +417,7 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async
|
|
|
416
417
|
}
|
|
417
418
|
});
|
|
418
419
|
} catch (error) {
|
|
419
|
-
throw
|
|
420
|
+
throw friendly(`${method} request with form data failed: ${error.message}`);
|
|
420
421
|
}
|
|
421
422
|
});
|
|
422
423
|
|
|
@@ -436,7 +437,7 @@ When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async
|
|
|
436
437
|
*/
|
|
437
438
|
Then(/^(?:the )?API response code should be (\d+)$/, function (expectedCode) {
|
|
438
439
|
if (!apiResponse) {
|
|
439
|
-
throw
|
|
440
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
440
441
|
}
|
|
441
442
|
|
|
442
443
|
const expected = parseInt(expectedCode);
|
|
@@ -459,7 +460,7 @@ Then(/^(?:the )?API response code should be (\d+)$/, function (expectedCode) {
|
|
|
459
460
|
*/
|
|
460
461
|
Then(/^(?:the )?API response should contain "([^"]*)"$/, function (expectedText) {
|
|
461
462
|
if (!apiResponse) {
|
|
462
|
-
throw
|
|
463
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
463
464
|
}
|
|
464
465
|
|
|
465
466
|
const responseBody = typeof apiResponse.data === 'string' ?
|
|
@@ -484,7 +485,7 @@ Then(/^(?:the )?API response should contain "([^"]*)"$/, function (expectedText)
|
|
|
484
485
|
*/
|
|
485
486
|
Then(/^(?:the )?API response should not contain "([^"]*)"$/, function (unexpectedText) {
|
|
486
487
|
if (!apiResponse) {
|
|
487
|
-
throw
|
|
488
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
488
489
|
}
|
|
489
490
|
|
|
490
491
|
const responseBody = typeof apiResponse.data === 'string' ?
|
|
@@ -531,7 +532,7 @@ Then(/^(?:the )?API response should not contain "([^"]*)"$/, function (unexpecte
|
|
|
531
532
|
*/
|
|
532
533
|
Then(/^(?:the )?API response should contain json:$/, function (docString) {
|
|
533
534
|
if (!apiResponse) {
|
|
534
|
-
throw
|
|
535
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
535
536
|
}
|
|
536
537
|
|
|
537
538
|
let expectedJson;
|
|
@@ -540,14 +541,14 @@ Then(/^(?:the )?API response should contain json:$/, function (docString) {
|
|
|
540
541
|
try {
|
|
541
542
|
expectedJson = JSON.parse(replacePlaceHolder(docString.trim()));
|
|
542
543
|
} catch (error) {
|
|
543
|
-
throw
|
|
544
|
+
throw friendly(`Cannot convert expected JSON: ${docString}`);
|
|
544
545
|
}
|
|
545
546
|
|
|
546
547
|
try {
|
|
547
548
|
actualJson = typeof apiResponse.data === 'string' ?
|
|
548
549
|
JSON.parse(apiResponse.data) : apiResponse.data;
|
|
549
550
|
} catch (error) {
|
|
550
|
-
throw
|
|
551
|
+
throw friendly(`Cannot convert actual response to JSON: ${apiResponse.data}`);
|
|
551
552
|
}
|
|
552
553
|
|
|
553
554
|
// Check that expected properties exist in actual response and match values
|
|
@@ -573,7 +574,7 @@ Then(/^(?:the )?API response should contain json:$/, function (docString) {
|
|
|
573
574
|
*/
|
|
574
575
|
Then(/^(?:the JSON response should have|the API response should have|the JSON property) "([^"]*)" (?:equal to|should be) (.+)$/, function (propertyPath, expectedValue) {
|
|
575
576
|
if (!apiResponse) {
|
|
576
|
-
throw
|
|
577
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
577
578
|
}
|
|
578
579
|
|
|
579
580
|
// Replace placeholders in expected value first
|
|
@@ -612,7 +613,7 @@ Then(/^(?:the JSON response should have|the API response should have|the JSON pr
|
|
|
612
613
|
*/
|
|
613
614
|
Then(/^(?:the JSON response should have property|the API response should contain property) "([^"]*)"$/, function (propertyPath) {
|
|
614
615
|
if (!apiResponse) {
|
|
615
|
-
throw
|
|
616
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
616
617
|
}
|
|
617
618
|
|
|
618
619
|
const actualValue = getNestedProperty(apiResponse.data, propertyPath);
|
|
@@ -635,7 +636,7 @@ Then(/^(?:the JSON response should have property|the API response should contain
|
|
|
635
636
|
*/
|
|
636
637
|
Then(/^(?:the JSON response should not have property|the API response should not contain property) "([^"]*)"$/, function (propertyPath) {
|
|
637
638
|
if (!apiResponse) {
|
|
638
|
-
throw
|
|
639
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
639
640
|
}
|
|
640
641
|
|
|
641
642
|
const actualValue = getNestedProperty(apiResponse.data, propertyPath);
|
|
@@ -659,7 +660,7 @@ Then(/^(?:the JSON response should not have property|the API response should not
|
|
|
659
660
|
*/
|
|
660
661
|
Then(/^(?:the response should be valid JSON|the API response should be valid JSON)$/, function () {
|
|
661
662
|
if (!apiResponse) {
|
|
662
|
-
throw
|
|
663
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
663
664
|
}
|
|
664
665
|
|
|
665
666
|
assert(typeof apiResponse.data === 'object' && apiResponse.data !== null,
|
|
@@ -680,7 +681,7 @@ Then(/^(?:the response should be valid JSON|the API response should be valid JSO
|
|
|
680
681
|
*/
|
|
681
682
|
Then(/^(?:the response header|the header) "([^"]*)" should (?:be|contain) "([^"]*)"$/, function (headerName, expectedValue) {
|
|
682
683
|
if (!apiResponse) {
|
|
683
|
-
throw
|
|
684
|
+
throw friendly('No API response available. Make sure to send a request first.');
|
|
684
685
|
}
|
|
685
686
|
|
|
686
687
|
const actualValue = apiResponse.headers[headerName.toLowerCase()];
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const { Then } = require('@cucumber/cucumber');
|
|
12
12
|
const assert = require('assert');
|
|
13
13
|
const axios = require('axios');
|
|
14
|
-
const { buildSelector, getLocatorText } = require('./webship');
|
|
14
|
+
const { buildSelector, getLocatorText, friendly } = require('./webship');
|
|
15
15
|
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
17
|
// Plain page-text
|
|
@@ -257,7 +257,7 @@ Then(/^(I |we )*should see (\d+) "([^"]*)" elements?$/, async function (pronounC
|
|
|
257
257
|
const expected = parseInt(num, 10);
|
|
258
258
|
const actual = await this.page.locator(selector).count();
|
|
259
259
|
if (actual !== expected) {
|
|
260
|
-
throw
|
|
260
|
+
throw friendly(`Expected ${expected} "${selector}" element(s), got ${actual}.`);
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { friendly } = require('./webship');
|
|
4
|
+
|
|
3
5
|
// Authentication-state helpers built on Playwright's `storageState` API.
|
|
4
6
|
//
|
|
5
7
|
// Save the cookies + localStorage of an authenticated context to a JSON file
|
|
@@ -73,7 +75,7 @@ When(/^(I |we )*save the auth state to "([^"]*)"$/, async function (pronoun, tar
|
|
|
73
75
|
Given(/^(I |we )*restore the auth state from "([^"]*)"$/, async function (pronoun, source) {
|
|
74
76
|
const file = resolveStoragePath(source);
|
|
75
77
|
if (!fs.existsSync(file)) {
|
|
76
|
-
throw
|
|
78
|
+
throw friendly(`Auth state file not found: ${file}`);
|
|
77
79
|
}
|
|
78
80
|
const playwrightConfig = require(path.join(process.cwd(), 'playwright.config'));
|
|
79
81
|
const newContext = await this.playwrightBrowser.newContext({
|
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { friendly } = require('./webship');
|
|
4
|
+
|
|
3
5
|
// Clock / time-mocking steps backed by Playwright's `page.clock` API.
|
|
4
|
-
//
|
|
5
|
-
// Useful for testing relative-time UIs ("5 minutes ago"), debounced inputs,
|
|
6
|
-
// throttled re-renders, scheduled UI changes (toast auto-dismiss, session
|
|
7
|
-
// timeout), and any flow gated on `Date.now()` or `setTimeout`.
|
|
8
|
-
//
|
|
9
|
-
// Once the fake clock is installed, page-level `Date.now()` and `new Date()`
|
|
10
|
-
// return the fake time, and pending timers stay paused until explicitly
|
|
11
|
-
// advanced.
|
|
12
6
|
|
|
13
7
|
const { Given, When } = require('@cucumber/cucumber');
|
|
14
8
|
|
|
9
|
+
const ISO_HINT = 'install the fake clock first via "Given the system time is \\"YYYY-MM-DDTHH:MM:SSZ\\"".';
|
|
10
|
+
|
|
15
11
|
/**
|
|
16
12
|
* Install a fake clock anchored at an ISO 8601 instant.
|
|
17
13
|
*
|
|
18
|
-
* After this step, `Date.now()` inside the page returns the fake time and
|
|
19
|
-
* `setTimeout` / `setInterval` callbacks queue but do not fire until you
|
|
20
|
-
* advance the clock.
|
|
21
|
-
*
|
|
22
14
|
* Example #1: Given the system time is "2026-05-08T10:00:00Z"
|
|
23
15
|
* Example #2: Given the system time is "2026-01-01T00:00:00Z"
|
|
24
|
-
* And I am on "/feed"
|
|
25
16
|
* Example #3: Given the system time is "2026-12-31T23:59:55Z"
|
|
26
|
-
* And I am on "/countdown"
|
|
27
17
|
* Example #4: Given the system time is "2026-05-08T10:00:00Z"
|
|
28
|
-
* And I am on "/feed"
|
|
29
|
-
* And "<.timestamp>" should have text "just now"
|
|
30
18
|
* Example #5: Given the system time is "2026-07-04T12:00:00-04:00"
|
|
31
|
-
* And I am on "/holiday-banner"
|
|
32
19
|
*
|
|
33
20
|
*/
|
|
34
21
|
Given(/^the system time is "([^"]*)"$/, async function (iso) {
|
|
35
|
-
|
|
22
|
+
const d = new Date(iso);
|
|
23
|
+
if (isNaN(d.getTime())) {
|
|
24
|
+
throw friendly({
|
|
25
|
+
action: `set the system time to "${iso}"`,
|
|
26
|
+
hint: 'use an ISO 8601 date like "2026-05-08T10:00:00Z".',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
try { await this.page.clock.install({ time: d }); }
|
|
30
|
+
catch (e) { throw friendly({ action: `install a fake clock at "${iso}"`, cause: e, hint: 'open a page first via "Given I am on \\"/path\\"".' }); }
|
|
36
31
|
});
|
|
37
32
|
|
|
38
33
|
/**
|
|
39
|
-
* Advance the fake clock forward by N milliseconds
|
|
40
|
-
* `setTimeout` / `setInterval` callback scheduled within that interval.
|
|
34
|
+
* Advance the fake clock forward by N milliseconds.
|
|
41
35
|
*
|
|
42
36
|
* Example #1: When I advance the clock by 500 ms
|
|
43
37
|
* Example #2: When I advance the clock by 1500 ms
|
|
@@ -47,7 +41,8 @@ Given(/^the system time is "([^"]*)"$/, async function (iso) {
|
|
|
47
41
|
*
|
|
48
42
|
*/
|
|
49
43
|
When(/^(I |we )*advance the clock by (\d+) ?ms$/, async function (pronoun, ms) {
|
|
50
|
-
await this.page.clock.runFor(parseInt(ms, 10));
|
|
44
|
+
try { await this.page.clock.runFor(parseInt(ms, 10)); }
|
|
45
|
+
catch (e) { throw friendly({ action: `advance the clock by ${ms} ms`, cause: e, hint: ISO_HINT }); }
|
|
51
46
|
});
|
|
52
47
|
|
|
53
48
|
/**
|
|
@@ -61,7 +56,8 @@ When(/^(I |we )*advance the clock by (\d+) ?ms$/, async function (pronoun, ms) {
|
|
|
61
56
|
*
|
|
62
57
|
*/
|
|
63
58
|
When(/^(I |we )*advance the clock by (\d+) seconds?$/, async function (pronoun, seconds) {
|
|
64
|
-
await this.page.clock.runFor(parseInt(seconds, 10) * 1000);
|
|
59
|
+
try { await this.page.clock.runFor(parseInt(seconds, 10) * 1000); }
|
|
60
|
+
catch (e) { throw friendly({ action: `advance the clock by ${seconds} second(s)`, cause: e, hint: ISO_HINT }); }
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
/**
|
|
@@ -75,46 +71,42 @@ When(/^(I |we )*advance the clock by (\d+) seconds?$/, async function (pronoun,
|
|
|
75
71
|
*
|
|
76
72
|
*/
|
|
77
73
|
When(/^(I |we )*advance the clock by (\d+) minutes?$/, async function (pronoun, minutes) {
|
|
78
|
-
await this.page.clock.runFor(parseInt(minutes, 10) * 60 * 1000);
|
|
74
|
+
try { await this.page.clock.runFor(parseInt(minutes, 10) * 60 * 1000); }
|
|
75
|
+
catch (e) { throw friendly({ action: `advance the clock by ${minutes} minute(s)`, cause: e, hint: ISO_HINT }); }
|
|
79
76
|
});
|
|
80
77
|
|
|
81
78
|
/**
|
|
82
|
-
* Pause the fake clock
|
|
83
|
-
* explicitly advanced. Useful between actions when you do not want a long
|
|
84
|
-
* tick to fire mid-step.
|
|
79
|
+
* Pause the fake clock.
|
|
85
80
|
*
|
|
86
81
|
* Example #1: When I pause the clock
|
|
87
|
-
* Example #2:
|
|
88
|
-
* When I pause the clock
|
|
82
|
+
* Example #2: When I pause the clock
|
|
89
83
|
* Example #3: When we pause the clock
|
|
90
84
|
* Example #4: And I pause the clock
|
|
91
85
|
* Example #5: When I pause the clock
|
|
92
|
-
* Then "<.timer>" should have text "00:00"
|
|
93
86
|
*
|
|
94
87
|
*/
|
|
95
88
|
When(/^(I |we )*pause the clock$/, async function () {
|
|
96
|
-
await this.page.clock.pauseAt(await this.page.evaluate(() => Date.now()));
|
|
89
|
+
try { await this.page.clock.pauseAt(await this.page.evaluate(() => Date.now())); }
|
|
90
|
+
catch (e) { throw friendly({ action: 'pause the clock', cause: e, hint: ISO_HINT }); }
|
|
97
91
|
});
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
|
-
* Resume the fake clock
|
|
94
|
+
* Resume the fake clock.
|
|
101
95
|
*
|
|
102
96
|
* Example #1: When I resume the clock
|
|
103
|
-
* Example #2: When I
|
|
104
|
-
* And I resume the clock
|
|
97
|
+
* Example #2: When I resume the clock
|
|
105
98
|
* Example #3: When we resume the clock
|
|
106
99
|
* Example #4: And I resume the clock
|
|
107
100
|
* Example #5: When I resume the clock
|
|
108
|
-
* And I advance the clock by 5 seconds
|
|
109
101
|
*
|
|
110
102
|
*/
|
|
111
103
|
When(/^(I |we )*resume the clock$/, async function () {
|
|
112
|
-
await this.page.clock.resume();
|
|
104
|
+
try { await this.page.clock.resume(); }
|
|
105
|
+
catch (e) { throw friendly({ action: 'resume the clock', cause: e, hint: 'pause the clock first via "When I pause the clock".' }); }
|
|
113
106
|
});
|
|
114
107
|
|
|
115
108
|
/**
|
|
116
|
-
* Set the fake clock to a specific time
|
|
117
|
-
* `advance` if you want pending timers in the gap to fire.
|
|
109
|
+
* Set the fake clock to a specific time.
|
|
118
110
|
*
|
|
119
111
|
* Example #1: When I set the system time to "2026-05-08T12:30:00Z"
|
|
120
112
|
* Example #2: When I set the system time to "2026-12-31T23:59:55Z"
|
|
@@ -124,5 +116,13 @@ When(/^(I |we )*resume the clock$/, async function () {
|
|
|
124
116
|
*
|
|
125
117
|
*/
|
|
126
118
|
When(/^(I |we )*set the system time to "([^"]*)"$/, async function (pronoun, iso) {
|
|
127
|
-
|
|
119
|
+
const d = new Date(iso);
|
|
120
|
+
if (isNaN(d.getTime())) {
|
|
121
|
+
throw friendly({
|
|
122
|
+
action: `set the system time to "${iso}"`,
|
|
123
|
+
hint: 'use an ISO 8601 date like "2026-05-08T12:30:00Z".',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
try { await this.page.clock.setSystemTime(d); }
|
|
127
|
+
catch (e) { throw friendly({ action: `set the system time to "${iso}"`, cause: e, hint: ISO_HINT }); }
|
|
128
128
|
});
|
|
File without changes
|
|
@@ -13,8 +13,12 @@ const { Then } = require('@cucumber/cucumber');
|
|
|
13
13
|
* Example #3: And print current URL
|
|
14
14
|
*/
|
|
15
15
|
Then(/^print current URL$/, function () {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
try {
|
|
17
|
+
console.log('\n--- Current URL ---');
|
|
18
|
+
console.log(` ${this.page.url()}`);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.log(`\n--- Current URL unavailable: ${e.message} ---`);
|
|
21
|
+
}
|
|
18
22
|
});
|
|
19
23
|
|
|
20
24
|
/**
|
|
@@ -25,7 +29,11 @@ Then(/^print current URL$/, function () {
|
|
|
25
29
|
* Example #3: And print last response
|
|
26
30
|
*/
|
|
27
31
|
Then(/^print last response$/, async function () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
try {
|
|
33
|
+
const html = await this.page.content();
|
|
34
|
+
console.log('\n--- Last Response (HTML) ---');
|
|
35
|
+
console.log(html);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.log(`\n--- Last response unavailable: ${e.message} ---`);
|
|
38
|
+
}
|
|
31
39
|
});
|
|
File without changes
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { friendly } = require('./webship');
|
|
4
|
+
|
|
3
5
|
// Element interactions and visual / positional assertions using Playwright.
|
|
4
6
|
|
|
5
7
|
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
@@ -153,7 +155,15 @@ Then('the element {string} should be centered in the viewport', async function (
|
|
|
153
155
|
*
|
|
154
156
|
*/
|
|
155
157
|
When(/^(I |we )*click on the element "([^"]*)"$/, async function (pronoun, sel) {
|
|
156
|
-
|
|
158
|
+
try {
|
|
159
|
+
await this.page.locator(sel).first().click();
|
|
160
|
+
} catch (e) {
|
|
161
|
+
throw friendly({
|
|
162
|
+
action: `click on the element "${sel}"`,
|
|
163
|
+
cause: e,
|
|
164
|
+
hint: `check that the element exists on the page, is visible, and is clickable.`,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
157
167
|
});
|
|
158
168
|
|
|
159
169
|
/**
|
|
@@ -170,7 +180,15 @@ When(/^(I |we )*click on the element "([^"]*)"$/, async function (pronoun, sel)
|
|
|
170
180
|
*
|
|
171
181
|
*/
|
|
172
182
|
When(/^(I |we )*trigger the JS event "([^"]*)" on the element "([^"]*)"$/, async function (pronoun, event, sel) {
|
|
173
|
-
|
|
183
|
+
try {
|
|
184
|
+
await this.page.locator(sel).first().dispatchEvent(event);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
throw friendly({
|
|
187
|
+
action: `trigger the "${event}" event on "${sel}"`,
|
|
188
|
+
cause: e,
|
|
189
|
+
hint: `use a standard event name like click, change, input, focus, or blur.`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
174
192
|
});
|
|
175
193
|
|
|
176
194
|
/**
|
|
@@ -184,7 +202,15 @@ When(/^(I |we )*trigger the JS event "([^"]*)" on the element "([^"]*)"$/, async
|
|
|
184
202
|
*
|
|
185
203
|
*/
|
|
186
204
|
When(/^(I |we )*scroll to the element "([^"]*)"$/, async function (pronoun, sel) {
|
|
187
|
-
|
|
205
|
+
try {
|
|
206
|
+
await this.page.locator(sel).first().scrollIntoViewIfNeeded();
|
|
207
|
+
} catch (e) {
|
|
208
|
+
throw friendly({
|
|
209
|
+
action: `scroll to "${sel}"`,
|
|
210
|
+
cause: e,
|
|
211
|
+
hint: `check the element exists on the page and was not removed before scrolling.`,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
188
214
|
});
|
|
189
215
|
|
|
190
216
|
/**
|
|
@@ -198,7 +224,15 @@ When(/^(I |we )*scroll to the element "([^"]*)"$/, async function (pronoun, sel)
|
|
|
198
224
|
*
|
|
199
225
|
*/
|
|
200
226
|
When(/^(I |we )*hover over the element "([^"]*)"$/, async function (pronoun, sel) {
|
|
201
|
-
|
|
227
|
+
try {
|
|
228
|
+
await this.page.locator(sel).first().hover();
|
|
229
|
+
} catch (e) {
|
|
230
|
+
throw friendly({
|
|
231
|
+
action: `hover over "${sel}"`,
|
|
232
|
+
cause: e,
|
|
233
|
+
hint: `check the element exists, is visible, and is not covered by another element.`,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
202
236
|
});
|
|
203
237
|
|
|
204
238
|
/**
|
|
@@ -212,7 +246,15 @@ When(/^(I |we )*hover over the element "([^"]*)"$/, async function (pronoun, sel
|
|
|
212
246
|
*
|
|
213
247
|
*/
|
|
214
248
|
When(/^(I |we )*focus on the element "([^"]*)"$/, async function (pronoun, sel) {
|
|
215
|
-
|
|
249
|
+
try {
|
|
250
|
+
await this.page.locator(sel).first().focus();
|
|
251
|
+
} catch (e) {
|
|
252
|
+
throw friendly({
|
|
253
|
+
action: `focus on "${sel}"`,
|
|
254
|
+
cause: e,
|
|
255
|
+
hint: `the element must be focusable — an input, button, link, or have a tabindex.`,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
216
258
|
});
|
|
217
259
|
|
|
218
260
|
/**
|
|
File without changes
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { friendly } = require('./webship');
|
|
4
|
+
|
|
3
5
|
// Validate file downloads triggered via URL or link click.
|
|
4
6
|
|
|
5
7
|
const { When, Then } = require('@cucumber/cucumber');
|
|
@@ -30,15 +32,23 @@ function tmpDownloadDir() {
|
|
|
30
32
|
*/
|
|
31
33
|
When(/^(I |we )*download the file from the URL "([^"]*)"$/, async function (pronoun, url) {
|
|
32
34
|
const target = url.startsWith('http') ? url : (this.launchUrl || '') + url;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
try {
|
|
36
|
+
const resp = await this.page.request.get(target);
|
|
37
|
+
assert.strictEqual(resp.status(), 200, `Download failed with status ${resp.status()}.`);
|
|
38
|
+
const buffer = await resp.body();
|
|
39
|
+
const cd = resp.headers()['content-disposition'] || '';
|
|
40
|
+
const m = /filename="?([^"]+)"?/.exec(cd);
|
|
41
|
+
const filename = m ? m[1] : path.basename(new URL(target).pathname) || 'download';
|
|
42
|
+
const filePath = path.join(tmpDownloadDir(), filename);
|
|
43
|
+
fs.writeFileSync(filePath, buffer);
|
|
44
|
+
this._lastDownload = { path: filePath, filename, content: buffer };
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw friendly({
|
|
47
|
+
action: `download "${target}"`,
|
|
48
|
+
cause: e,
|
|
49
|
+
hint: `check the URL is reachable and returns a successful response.`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
42
52
|
});
|
|
43
53
|
|
|
44
54
|
/**
|
|
@@ -52,17 +62,25 @@ When(/^(I |we )*download the file from the URL "([^"]*)"$/, async function (pron
|
|
|
52
62
|
*
|
|
53
63
|
*/
|
|
54
64
|
When(/^(I |we )*download the file from the link "([^"]*)"$/, async function (pronoun, linkText) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.page.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
try {
|
|
66
|
+
const [download] = await Promise.all([
|
|
67
|
+
this.page.waitForEvent('download'),
|
|
68
|
+
this.page.getByRole('link', { name: linkText }).first().click().catch(() =>
|
|
69
|
+
this.page.locator(`a:has-text("${linkText}")`).first().click()
|
|
70
|
+
),
|
|
71
|
+
]);
|
|
72
|
+
const filename = download.suggestedFilename();
|
|
73
|
+
const filePath = path.join(tmpDownloadDir(), filename);
|
|
74
|
+
await download.saveAs(filePath);
|
|
75
|
+
const content = fs.readFileSync(filePath);
|
|
76
|
+
this._lastDownload = { path: filePath, filename, content };
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throw friendly({
|
|
79
|
+
action: `download from link "${linkText}"`,
|
|
80
|
+
cause: e,
|
|
81
|
+
hint: `the link must offer a downloadable file (not open in a new tab). If the link only navigates, use "When I download the file from the URL ..." instead.`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
66
84
|
});
|
|
67
85
|
|
|
68
86
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// check / uncheck, radio buttons.
|
|
6
6
|
|
|
7
7
|
const { When } = require('@cucumber/cucumber');
|
|
8
|
-
const { buildSelector, fillField } = require('./webship');
|
|
8
|
+
const { buildSelector, fillField, friendly } = require('./webship');
|
|
9
9
|
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// Fill — by label, attribute, table, reverse syntax
|
|
@@ -177,7 +177,7 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, async function (pronounCase
|
|
|
177
177
|
try {
|
|
178
178
|
await loc.selectOption(option);
|
|
179
179
|
} catch (e) {
|
|
180
|
-
throw
|
|
180
|
+
throw friendly(
|
|
181
181
|
`Could not select "${option}" from "${selectList}".\n` +
|
|
182
182
|
` ${(e.message || '').split('\n')[0]}\n` +
|
|
183
183
|
` Hints:\n` +
|
|
@@ -231,7 +231,7 @@ When(/^(I |we )*additionally select "([^"]*)" from "([^"]*)"$/, async function (
|
|
|
231
231
|
}, option);
|
|
232
232
|
|
|
233
233
|
if (nextValueForLabel === null) {
|
|
234
|
-
throw
|
|
234
|
+
throw friendly(`Option "${option}" not found in select "${select}".`);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
const combined = Array.from(new Set([...currentValues, nextValueForLabel]));
|
|
@@ -264,7 +264,7 @@ When(/^(I |we )*check "([^"]*)?"$/, async function (pronounCase, item) {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
} catch (e) {
|
|
267
|
-
throw
|
|
267
|
+
throw friendly(
|
|
268
268
|
`Could not check "${item}".\n` +
|
|
269
269
|
` ${(e.message || '').split('\n')[0]}\n` +
|
|
270
270
|
` Hints: confirm the label / id / class matches; ensure the input is visible and not disabled.`
|
|
@@ -294,7 +294,7 @@ When(/^(I |we )*uncheck "([^"]*)?"$/, async function (pronounCase, item) {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
} catch (e) {
|
|
297
|
-
throw
|
|
297
|
+
throw friendly(
|
|
298
298
|
`Could not uncheck "${item}".\n` +
|
|
299
299
|
` ${(e.message || '').split('\n')[0]}\n` +
|
|
300
300
|
` Hints: confirm the label / id / class matches; ensure the input is visible and not disabled.`
|
|
@@ -324,7 +324,7 @@ When(/^(I |we )*select radio button "([^"]*)?"$/, async function (pronounCase, i
|
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
} catch (e) {
|
|
327
|
-
throw
|
|
327
|
+
throw friendly(
|
|
328
328
|
`Could not select radio button "${item}".\n` +
|
|
329
329
|
` ${(e.message || '').split('\n')[0]}\n` +
|
|
330
330
|
` Hints: try matching by [value=...], by label text, or by #id / .class.`
|