webship-js 2.0.1 → 2.0.2

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.
Files changed (41) hide show
  1. package/bin/generate-reports.js +191 -0
  2. package/bin/init-webship.js +343 -0
  3. package/bin/postinstall.js +8 -74
  4. package/cucumber.js +59 -1
  5. package/examples/diffy/baseline.html +54 -0
  6. package/examples/diffy/changed.html +63 -0
  7. package/examples/diffy/index.html +52 -0
  8. package/examples/index.html +6 -0
  9. package/examples/test--when--i-additionally-select.html +27 -0
  10. package/package.json +10 -4
  11. package/tests/features/diffy/test--diffy-01-example-demo.feature +22 -0
  12. package/tests/features/diffy/test--diffy-02-all-steps.feature +52 -0
  13. package/tests/features/diffy/test--diffy-03-real-api.feature +21 -0
  14. package/tests/features/test--then--i-save-screenshot.feature +33 -0
  15. package/tests/features/test--then--i-see-locator.feature +320 -0
  16. package/tests/features/test--then--i-should-see-n-elements.feature +24 -0
  17. package/tests/features/test--then--print-current-url-and-response.feature +21 -0
  18. package/tests/features/test--when--i-additionally-select.feature +30 -0
  19. package/tests/features/test--when--i-follow.feature +22 -0
  20. package/tests/selectors/back-end-selectors.json +13 -0
  21. package/tests/selectors/front-end-selectors.json +16 -0
  22. package/tests/selectors/homepage-selectors.json +13 -0
  23. package/tests/step-definitions/webship-api.js +234 -41
  24. package/tests/step-definitions/webship-screenshot.js +427 -0
  25. package/tests/step-definitions/webship-selectors.js +961 -0
  26. package/tests/step-definitions/webship.js +829 -230
  27. package/tests/step-definitions-diffy/README.md +329 -0
  28. package/tests/step-definitions-diffy/mock-diffy-api/server.js +84 -0
  29. package/tests/step-definitions-diffy/webship-diffy-mock.js +31 -0
  30. package/tests/step-definitions-diffy/webship-diffy.js +472 -0
  31. package/generate-reports.js +0 -22
  32. package/required/cucumber.js +0 -37
  33. package/required/generate-reports.js +0 -22
  34. package/required/package.json +0 -18
  35. package/required/playwright.config.ts +0 -37
  36. package/required/tests/features/README.md +0 -1
  37. package/required/tests/features/check-homepage.feature +0 -8
  38. package/required/tests/reports/README.md +0 -1
  39. package/required/tests/step-definitions/README.md +0 -1
  40. package/required/tests/step-definitions/custom.js +0 -4
  41. package/required/tsconfig.json +0 -12
package/cucumber.js CHANGED
@@ -3,7 +3,8 @@ module.exports = {
3
3
  timeout: 30000,
4
4
  requireModule: ['ts-node/register'],
5
5
  require: [
6
- 'tests/step-definitions/**/*.js',
6
+ 'tests/step-definitions/**/*.js', // Default Webship-js step definitions.
7
+ 'tests/step-definitions-diffy/**/*.js', // diffy.website step definitions.
7
8
  ],
8
9
  paths: ['tests/features/**/*.feature'],
9
10
  format: [
@@ -31,6 +32,63 @@ module.exports = {
31
32
  before_step: 0,
32
33
  after_step: 0,
33
34
  },
35
+ selectors: {
36
+ // Named CSS selectors — layout components and element locators in one registry.
37
+ // Register inline: When I add "name" selector for "css" css selector
38
+ // Or in bulk: Given I define css selectors:
39
+ // | name | css selector |
40
+ css: {
41
+ // 'header': 'header.page-header',
42
+ // 'main nav': 'nav[role="navigation"]',
43
+ // 'breadcrumb': '.breadcrumb',
44
+ // 'breadcrumb first link': '.breadcrumb li:nth-child(1) a',
45
+ // 'message': '.messages',
46
+ // 'error message': '.messages.error',
47
+ // 'success message': '.messages.status',
48
+ // 'warning message': '.messages.warning',
49
+ },
50
+ // Named XPath selectors — use with: When I add "name" selector for "xpath" xpath selector
51
+ xpath: {
52
+ // 'page title': '//h1[contains(@class,"page-header")]',
53
+ },
54
+ // Load additional selectors from JSON files at scenario start.
55
+ filesPath: './tests/selectors/', // base path for selector files
56
+ files: [], // e.g. ['homepage-selectors.json'] or ['front-end-selectors.json', 'back-end-selectors.json']
57
+ // Relative-position scroll offset (px) — WEBSHIP_SELECTORS_OFFSET
58
+ offset: 60,
59
+ // Viewport breakpoints — WEBSHIP_SELECTORS_BREAKPOINTS (JSON string)
60
+ breakpoints: {
61
+ xs: { width: 375, height: 667 }, // phone portrait
62
+ sm: { width: 576, height: 800 }, // large phone / phablet
63
+ md: { width: 768, height: 1024 }, // tablet portrait
64
+ lg: { width: 992, height: 768 }, // small laptop / tablet landscape
65
+ xl: { width: 1200, height: 900, default: true }, // desktop
66
+ xxl: { width: 1400, height: 900 }, // wide desktop / HD
67
+ xxxl: { width: 1920, height: 1080 }, // Full HD / large monitor
68
+ },
69
+ },
70
+ screenshot: {
71
+ dir: './screenshots', // WEBSHIP_SCREENSHOT_DIR
72
+ purge: false, // WEBSHIP_SCREENSHOT_PURGE
73
+ onFailed: true, // WEBSHIP_SCREENSHOT_ON_FAILED
74
+ onEveryStep: false, // WEBSHIP_SCREENSHOT_ON_EVERY_STEP
75
+ alwaysFullscreen: false, // WEBSHIP_SCREENSHOT_FULLSCREEN
76
+ failedPrefix: 'failed_', // WEBSHIP_SCREENSHOT_FAILED_PREFIX
77
+ filenamePattern: '{datetime}.{feature_file}.feature_{step_line}.{ext}', // WEBSHIP_SCREENSHOT_PATTERN
78
+ filenamePatternFailed: '{failed_prefix}{datetime}.{feature_file}.feature_{step_line}.{ext}', // WEBSHIP_SCREENSHOT_PATTERN_FAIL
79
+ infoTypes: '', // WEBSHIP_SCREENSHOT_INFO_TYPES e.g. "url,feature,step,datetime"
80
+ },
81
+ diffy: {
82
+ apiKey: 'mock-key', // DIFFY_API_KEY
83
+ projectId: 1, // DIFFY_PROJECT_ID
84
+ breakpoints: '640,1200', // DIFFY_BREAKPOINTS
85
+ windowHeight: 2000, // DIFFY_WINDOW_HEIGHT
86
+ screenshotsDir: '', // DIFFY_SCREENSHOTS_DIR
87
+ baseUrl: 'http://127.0.0.1:3099/', // DIFFY_API_BASE_URL (mock server)
88
+ maxWait: 30, // DIFFY_MAX_WAIT (seconds)
89
+ env1Url: '', // DIFFY_ENV1_URL (custom env)
90
+ env2Url: '', // DIFFY_ENV2_URL (custom env)
91
+ },
34
92
  },
35
93
  },
36
94
  };
@@ -0,0 +1,54 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Diffy Example — Baseline</title>
7
+ <style>
8
+ body { font-family: system-ui, sans-serif; margin: 0; color: #222; }
9
+ header { background: #1e40af; color: #fff; padding: 24px 32px; }
10
+ header h1 { margin: 0; font-size: 28px; }
11
+ nav { background: #eef2ff; padding: 12px 32px; }
12
+ nav a { margin-right: 16px; color: #1e40af; text-decoration: none; }
13
+ main { padding: 32px; max-width: 960px; margin: 0 auto; }
14
+ .card {
15
+ background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
16
+ padding: 20px; margin-bottom: 16px;
17
+ }
18
+ .card h2 { margin-top: 0; color: #1e40af; }
19
+ .cta {
20
+ display: inline-block; background: #1e40af; color: #fff;
21
+ padding: 10px 20px; border-radius: 6px; text-decoration: none;
22
+ }
23
+ footer { background: #f3f4f6; padding: 16px 32px; color: #6b7280; font-size: 14px; }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <header>
28
+ <h1>Webship-JS — Diffy Baseline</h1>
29
+ <p>Stable layout captured as the reference snapshot.</p>
30
+ </header>
31
+ <nav>
32
+ <a href="../index.html">Home</a>
33
+ <a href="index.html">Diffy index</a>
34
+ <a href="baseline.html">Baseline</a>
35
+ <a href="changed.html">Changed</a>
36
+ </nav>
37
+ <main>
38
+ <div class="card">
39
+ <h2>Feature A</h2>
40
+ <p>Baseline copy for feature A. This block is unchanged between versions.</p>
41
+ </div>
42
+ <div class="card">
43
+ <h2>Feature B</h2>
44
+ <p>Original baseline copy. Diffy should flag differences on the changed page.</p>
45
+ <a class="cta" href="#">Call to action</a>
46
+ </div>
47
+ <div class="card">
48
+ <h2>Pricing</h2>
49
+ <p>Plan: <strong>$19/month</strong></p>
50
+ </div>
51
+ </main>
52
+ <footer>&copy; 2026 Webship-JS Diffy example — baseline</footer>
53
+ </body>
54
+ </html>
@@ -0,0 +1,63 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Diffy Example — Changed</title>
7
+ <style>
8
+ body { font-family: system-ui, sans-serif; margin: 0; color: #222; }
9
+ header { background: #b91c1c; color: #fff; padding: 24px 32px; }
10
+ header h1 { margin: 0; font-size: 32px; }
11
+ nav { background: #fee2e2; padding: 12px 32px; }
12
+ nav a { margin-right: 16px; color: #b91c1c; text-decoration: none; }
13
+ main { padding: 32px; max-width: 960px; margin: 0 auto; }
14
+ .card {
15
+ background: #fff; border: 2px solid #fca5a5; border-radius: 12px;
16
+ padding: 24px; margin-bottom: 20px;
17
+ }
18
+ .card h2 { margin-top: 0; color: #b91c1c; }
19
+ .cta {
20
+ display: inline-block; background: #b91c1c; color: #fff;
21
+ padding: 12px 28px; border-radius: 999px; text-decoration: none;
22
+ font-weight: bold;
23
+ }
24
+ .badge {
25
+ display: inline-block; background: #fbbf24; color: #7c2d12;
26
+ padding: 4px 10px; border-radius: 4px; font-size: 13px; margin-left: 8px;
27
+ }
28
+ footer { background: #fef2f2; padding: 16px 32px; color: #7f1d1d; font-size: 14px; }
29
+ </style>
30
+ </head>
31
+ <body>
32
+ <header>
33
+ <h1>Webship-JS — Diffy Changed <span style="font-size:14px;">(v2)</span></h1>
34
+ <p>Layout + palette shifted. Diffy should report regressions vs baseline.</p>
35
+ </header>
36
+ <nav>
37
+ <a href="../index.html">Home</a>
38
+ <a href="index.html">Diffy index</a>
39
+ <a href="baseline.html">Baseline</a>
40
+ <a href="changed.html">Changed</a>
41
+ </nav>
42
+ <main>
43
+ <div class="card">
44
+ <h2>Feature A</h2>
45
+ <p>Baseline copy for feature A. This block is unchanged between versions.</p>
46
+ </div>
47
+ <div class="card">
48
+ <h2>Feature B <span class="badge">NEW</span></h2>
49
+ <p><strong>Redesigned</strong> copy with a new badge and fatter card padding.</p>
50
+ <a class="cta" href="#">Buy now</a>
51
+ </div>
52
+ <div class="card">
53
+ <h2>Pricing</h2>
54
+ <p>Plan: <strong>$29/month</strong> (was $19)</p>
55
+ </div>
56
+ <div class="card">
57
+ <h2>Testimonials</h2>
58
+ <p>Entirely new section — Diffy should flag this as added content.</p>
59
+ </div>
60
+ </main>
61
+ <footer>&copy; 2026 Webship-JS Diffy example — changed build</footer>
62
+ </body>
63
+ </html>
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Diffy examples — Webship-JS</title>
7
+ <style>
8
+ body { font-family: system-ui, sans-serif; margin: 0; color: #222; }
9
+ header { background: #0f172a; color: #fff; padding: 24px 32px; }
10
+ header h1 { margin: 0; font-size: 26px; }
11
+ main { padding: 32px; max-width: 820px; margin: 0 auto; }
12
+ .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
13
+ .pair a {
14
+ display: block; padding: 20px; border-radius: 8px;
15
+ text-decoration: none; color: #fff;
16
+ }
17
+ .pair a.base { background: #1e40af; }
18
+ .pair a.changed { background: #b91c1c; }
19
+ .pair h2 { margin: 0 0 8px 0; }
20
+ .pair small { opacity: 0.85; }
21
+ p { line-height: 1.5; }
22
+ code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }
23
+ footer { background: #f3f4f6; padding: 14px 32px; color: #6b7280; font-size: 14px; }
24
+ a.back { color: #1e40af; }
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <header>
29
+ <h1>Webship-JS — Diffy visual-regression examples</h1>
30
+ </header>
31
+ <main>
32
+ <p><a class="back" href="/">&larr; Back to examples index</a></p>
33
+ <p>
34
+ Two deliberately different pages. Run
35
+ <code>npx cucumber-js --config cucumber.js -p diffy</code>
36
+ (against a mock or real Diffy API) to capture screenshots of both pages
37
+ at each breakpoint and request a comparison.
38
+ </p>
39
+ <div class="pair">
40
+ <a class="base" href="baseline.html">
41
+ <h2>Baseline</h2>
42
+ <small>Reference snapshot — blue palette, rect CTA, $19/mo</small>
43
+ </a>
44
+ <a class="changed" href="changed.html">
45
+ <h2>Changed</h2>
46
+ <small>Visible regressions — red palette, NEW badge, pill CTA, $29/mo, added Testimonials</small>
47
+ </a>
48
+ </div>
49
+ </main>
50
+ <footer>&copy; 2026 Webship-JS Diffy examples</footer>
51
+ </body>
52
+ </html>
@@ -27,5 +27,11 @@
27
27
  <li><a href="test--when-i-wait-max-of-time.html">When I Wait a Maximum of Time</a></li>
28
28
  <li><a href="test--modal-dialogs.html">Modal Dialog Interactions</a></li>
29
29
  </ul>
30
+ <h3>Diffy visual-regression examples</h3>
31
+ <ul>
32
+ <li><a href="diffy/index.html">Diffy — examples index</a></li>
33
+ <li><a href="diffy/baseline.html">Diffy — Baseline page</a></li>
34
+ <li><a href="diffy/changed.html">Diffy — Changed page (visible regressions)</a></li>
35
+ </ul>
30
36
  </body>
31
37
  </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Multi Select</title>
6
+ </head>
7
+ <body>
8
+ <h1>Multi Select</h1>
9
+
10
+ <label for="Colors">Colors:</label>
11
+ <select name="Colors" id="Colors" multiple size="5">
12
+ <option value="red">Red</option>
13
+ <option value="blue">Blue</option>
14
+ <option value="green">Green</option>
15
+ <option value="yellow">Yellow</option>
16
+ <option value="black">Black</option>
17
+ </select>
18
+
19
+ <label for="Roles">Roles:</label>
20
+ <select name="Roles" id="Roles" multiple size="4">
21
+ <option value="admin">Admin</option>
22
+ <option value="editor">Editor</option>
23
+ <option value="viewer">Viewer</option>
24
+ <option value="guest">Guest</option>
25
+ </select>
26
+ </body>
27
+ </html>
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "init-webship-js": "./bin/init-webship.js",
8
+ "generate-reports": "./bin/generate-reports.js"
9
+ },
6
10
  "directories": {
7
11
  "test": "test"
8
12
  },
@@ -11,9 +15,11 @@
11
15
  },
12
16
  "scripts": {
13
17
  "postinstall": "node ./bin/postinstall.js",
14
- "test": "cucumber-js --config cucumber.js; node generate-reports.js;",
15
- "test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js; node generate-reports.js;",
16
- "test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js; node generate-reports.js;",
18
+ "test": "cucumber-js --config cucumber.js",
19
+ "test:chromium": "BROWSER=chromium cucumber-js --config cucumber.js",
20
+ "test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js",
21
+ "test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js",
22
+ "generate-reports": "node ./bin/generate-reports.js",
17
23
  "start": "http-server examples -p 8080 -s"
18
24
  },
19
25
  "repository": {
@@ -0,0 +1,22 @@
1
+ Feature: Diffy — example pages demo
2
+ Drive the bundled /diffy/baseline.html and /diffy/changed.html example
3
+ pages through the Diffy capture + comparison flow. Safe to run against
4
+ the mock Diffy API for local development.
5
+
6
+ Config resolution (per-scenario):
7
+ 1. process.env.DIFFY_*
8
+ 2. cucumber.js worldParameters.diffy.*
9
+ 3. built-in defaults
10
+
11
+ @diffy @example
12
+ Scenario: Capture baseline and changed, send to diffy, compare
13
+ Given I am on "/diffy/baseline.html"
14
+ Then I take screenshots for all breakpoints
15
+ Then send screenshots to diffy with name "example-baseline"
16
+
17
+ Given I am on "/diffy/changed.html"
18
+ Then I take screenshots for all breakpoints
19
+ Then send screenshots to diffy with name "example-changed"
20
+
21
+ Then create diffy comparison with name "example-demo"
22
+ Then wait for diffy comparison to complete
@@ -0,0 +1,52 @@
1
+ Feature: Diffy — all step definitions smoke test
2
+ Exercise every Diffy step at least once against the example pages.
3
+ Intended for mock-Diffy runs (some steps require specific Diffy plan
4
+ features and may fail against production with a valid key).
5
+
6
+ @diffy @smoke
7
+ Scenario: Resize, take screenshot, breakpoints loop, send
8
+ Given I am on "/diffy/baseline.html"
9
+ When I resize window to "640"
10
+ Then I take screenshot
11
+ Given I am on "/diffy/changed.html"
12
+ Then I take screenshots for all breakpoints
13
+ Then send screenshots to diffy with name "smoke-set-1"
14
+
15
+ Given I am on "/diffy/baseline.html"
16
+ Then I take screenshots for all breakpoints
17
+ Then send screenshots to diffy with name "smoke-set-2"
18
+
19
+ Then create diffy comparison
20
+ Then wait for diffy comparison to complete
21
+
22
+ @diffy @smoke @named-compare
23
+ Scenario: Named comparison variant
24
+ Given I am on "/diffy/baseline.html"
25
+ Then I take screenshots for all breakpoints
26
+ Then send screenshots to diffy with name "smoke-named-a"
27
+
28
+ Given I am on "/diffy/changed.html"
29
+ Then I take screenshots for all breakpoints
30
+ Then send screenshots to diffy with name "smoke-named-b"
31
+
32
+ Then create diffy comparison with name "PR-smoke"
33
+ Then wait for diffy comparison to complete
34
+
35
+ @diffy @smoke @env-compare
36
+ Scenario: Server-side environment compare
37
+ Then compare diffy "prod" with "stage"
38
+ Then wait for diffy comparison to complete
39
+
40
+ @diffy @smoke @env-screenshot
41
+ Scenario: Trigger Diffy-side screenshot run per environment
42
+ Then create diffy screenshot from "production" environment
43
+ Then create diffy screenshot from "staging" environment
44
+ Then create diffy comparison with name "env-pair"
45
+ Then wait for diffy comparison to complete
46
+
47
+ @diffy @smoke @folder-upload
48
+ Scenario: Upload PNG folders to Diffy
49
+ Then upload folder "/tmp/diffy-test-screenshots/baseline" to diffy as "folder-baseline"
50
+ Then upload folder "/tmp/diffy-test-screenshots/feature" to diffy as "folder-feature"
51
+ Then create diffy comparison with name "folder-pair"
52
+ Then wait for diffy comparison to complete
@@ -0,0 +1,21 @@
1
+ Feature: Diffy — real API smoke
2
+ Run the minimum set against the production Diffy API. Requires valid
3
+ DIFFY_API_KEY and DIFFY_PROJECT_ID for a project whose allowed URLs
4
+ match LAUNCH_URL (e.g. http://localhost:8080 via ngrok, or a hosted
5
+ copy of /examples).
6
+
7
+ Do NOT run without a live key. Scoped behind @real-api so mock runs
8
+ skip it automatically (cucumber-js --tags "not @real-api").
9
+
10
+ @diffy @real-api
11
+ Scenario: Real API baseline + changed comparison
12
+ Given I am on "/diffy/baseline.html"
13
+ Then I take screenshots for all breakpoints
14
+ Then send screenshots to diffy with name "real-baseline"
15
+
16
+ Given I am on "/diffy/changed.html"
17
+ Then I take screenshots for all breakpoints
18
+ Then send screenshots to diffy with name "real-changed"
19
+
20
+ Then create diffy comparison with name "real-api-demo"
21
+ Then wait for diffy comparison to complete
@@ -0,0 +1,33 @@
1
+ Feature: Save screenshots to disk.
2
+ As a tester,
3
+ I want to capture screenshots at arbitrary points in my scenarios
4
+ so that I can review rendered pages and debug failures.
5
+
6
+ Background:
7
+ Given I am on homepage
8
+
9
+ Scenario: Save a screenshot at the current viewport size.
10
+ Then I save screenshot
11
+
12
+ Scenario: Save a full-page screenshot.
13
+ Then I save fullscreen screenshot
14
+
15
+ Scenario: Save a screenshot after resizing the viewport.
16
+ Then I save 1440 x 900 screenshot
17
+
18
+ Scenario: Save a full-page screenshot at a fixed viewport.
19
+ Then I save fullscreen 1200 x 800 screenshot
20
+
21
+ Scenario: Save a screenshot with an explicit filename.
22
+ Then I save screenshot with name "webship-home.png"
23
+
24
+ Scenario: Save a full-page screenshot with an explicit filename.
25
+ Then I save fullscreen screenshot with name "webship-home-full.png"
26
+
27
+ Scenario: Save a screenshot with filename tokens.
28
+ Then I save screenshot with name "{feature_file}_{step_line}_{datetime}.png"
29
+
30
+ @screenshots
31
+ Scenario: Auto-capture a screenshot after every step in a tagged scenario.
32
+ Given I am on "/about-us.html"
33
+ Then I should see "About Us"