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
@@ -0,0 +1,472 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Webship-JS — Diffy visual-regression step definitions
5
+ //
6
+ // Talks directly to Diffy REST API (https://app.diffy.website/api/).
7
+ //
8
+ // Configuration: resolved per-scenario with this priority:
9
+ // 1. process.env.DIFFY_* (CI / shell — highest)
10
+ // 2. cucumber.js worldParameters.diffy.* (project-level defaults)
11
+ // 3. built-in defaults
12
+ //
13
+ // Supported env vars / worldParameters keys:
14
+ // DIFFY_API_KEY apiKey — https://app.diffy.website/#/keys
15
+ // DIFFY_PROJECT_ID projectId — Diffy project id
16
+ // DIFFY_BREAKPOINTS breakpoints — comma list, e.g. "640,1200"
17
+ // DIFFY_WINDOW_HEIGHT windowHeight — default 2000
18
+ // DIFFY_SCREENSHOTS_DIR screenshotsDir — on-disk copy of screenshots
19
+ // DIFFY_API_BASE_URL baseUrl — default app.diffy.website
20
+ // DIFFY_MAX_WAIT maxWait — diff polling timeout (s), default 1200
21
+ // DIFFY_ENV1_URL env1Url — custom URL for "compare diffy"
22
+ // DIFFY_ENV2_URL env2Url — custom URL for "compare diffy"
23
+ // ---------------------------------------------------------------------------
24
+
25
+ const { Given, When, Then, Before } = require('@cucumber/cucumber');
26
+ const axios = require('axios');
27
+ const fs = require('fs');
28
+ const path = require('path');
29
+
30
+ const WINDOW_PADDING = 8;
31
+
32
+ function pick(envVal, paramVal, fallback) {
33
+ if (envVal !== undefined && envVal !== '') return envVal;
34
+ if (paramVal !== undefined && paramVal !== '' && paramVal !== null) return paramVal;
35
+ return fallback;
36
+ }
37
+
38
+ function resolveConfig(parameters) {
39
+ const p = (parameters && parameters.diffy) || {};
40
+ const breakpointsRaw = pick(process.env.DIFFY_BREAKPOINTS, p.breakpoints, '1200');
41
+ return {
42
+ apiKey: pick(process.env.DIFFY_API_KEY, p.apiKey, ''),
43
+ projectId: parseInt(pick(process.env.DIFFY_PROJECT_ID, p.projectId, '0'), 10),
44
+ breakpoints: String(breakpointsRaw)
45
+ .split(',')
46
+ .map(s => parseInt(String(s).trim(), 10))
47
+ .filter(n => !Number.isNaN(n)),
48
+ windowHeight: parseInt(pick(process.env.DIFFY_WINDOW_HEIGHT, p.windowHeight, '2000'), 10),
49
+ screenshotsDir: pick(process.env.DIFFY_SCREENSHOTS_DIR, p.screenshotsDir, ''),
50
+ baseUrl: pick(process.env.DIFFY_API_BASE_URL, p.baseUrl, 'https://app.diffy.website/api/'),
51
+ maxWait: parseInt(pick(process.env.DIFFY_MAX_WAIT, p.maxWait, '1200'), 10),
52
+ env1Url: pick(process.env.DIFFY_ENV1_URL, p.env1Url, ''),
53
+ env2Url: pick(process.env.DIFFY_ENV2_URL, p.env2Url, ''),
54
+ };
55
+ }
56
+
57
+ let diffyToken = null;
58
+
59
+ async function refreshToken(cfg) {
60
+ if (!cfg.apiKey) {
61
+ throw new Error('Diffy API key missing. Set DIFFY_API_KEY env or worldParameters.diffy.apiKey.');
62
+ }
63
+ const res = await axios.post(
64
+ cfg.baseUrl + 'auth/key',
65
+ { key: cfg.apiKey },
66
+ { headers: { Accept: 'application/json', 'Content-Type': 'application/json' } }
67
+ );
68
+ if (!res.data || !res.data.token) {
69
+ throw new Error('Diffy auth/key did not return a token.');
70
+ }
71
+ diffyToken = res.data.token;
72
+ return diffyToken;
73
+ }
74
+
75
+ async function diffyRequest(cfg, method, uri, opts = {}) {
76
+ if (!diffyToken) await refreshToken(cfg);
77
+ const headers = Object.assign(
78
+ { Authorization: 'Bearer ' + diffyToken },
79
+ opts.headers || {}
80
+ );
81
+ const reqCfg = { method, url: cfg.baseUrl + uri, headers };
82
+ if (opts.json !== undefined) {
83
+ reqCfg.data = opts.json;
84
+ headers['Content-Type'] = 'application/json';
85
+ headers['Accept'] = 'application/json';
86
+ }
87
+ if (opts.form !== undefined) {
88
+ reqCfg.data = opts.form;
89
+ headers['Accept'] = 'application/json';
90
+ }
91
+ let res;
92
+ try {
93
+ res = await axios.request(reqCfg);
94
+ } catch (e) {
95
+ const body = e.response && e.response.data;
96
+ const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
97
+ const err = new Error(`Diffy API ${method} ${uri} failed: ${e.response?.status} ${bodyStr || e.message}`);
98
+ err.cause = e;
99
+ throw err;
100
+ }
101
+ return res.data;
102
+ }
103
+
104
+ function ensureProjectId(cfg) {
105
+ if (!cfg.projectId) {
106
+ throw new Error('Diffy projectId missing. Set DIFFY_PROJECT_ID env or worldParameters.diffy.projectId.');
107
+ }
108
+ }
109
+
110
+ function currentPath(page, launchUrl) {
111
+ try {
112
+ const current = page.url();
113
+ if (launchUrl && current.startsWith(launchUrl)) {
114
+ return current.slice(launchUrl.length) || '/';
115
+ }
116
+ const u = new URL(current);
117
+ return u.pathname + u.search;
118
+ } catch {
119
+ return '/';
120
+ }
121
+ }
122
+
123
+ async function takeOneScreenshot(world) {
124
+ const cfg = world.diffyConfig;
125
+ const page = world.page;
126
+ const viewport = page.viewportSize() || { width: cfg.breakpoints[0] || 1200 };
127
+ const breakpoint = viewport.width - WINDOW_PADDING;
128
+ const buffer = await page.screenshot({ fullPage: true });
129
+ const url = currentPath(page, world.launchUrl);
130
+
131
+ if (cfg.screenshotsDir) {
132
+ if (!fs.existsSync(cfg.screenshotsDir)) {
133
+ fs.mkdirSync(cfg.screenshotsDir, { recursive: true });
134
+ }
135
+ const safe = encodeURIComponent(url);
136
+ const filename = `${Date.now()}__${safe}__${breakpoint}.png`;
137
+ fs.writeFileSync(path.join(cfg.screenshotsDir, filename), buffer);
138
+ }
139
+
140
+ world.diffyScreenshots = world.diffyScreenshots || [];
141
+ world.diffyScreenshots.push({ buffer, url, breakpoint });
142
+ }
143
+
144
+ Before(async function () {
145
+ this.diffyConfig = resolveConfig(this.parameters);
146
+ this.diffyScreenshots = [];
147
+ this.diffyCreatedScreenshotIds = this.diffyCreatedScreenshotIds || [];
148
+ this.diffyCreatedDiffIds = this.diffyCreatedDiffIds || [];
149
+ });
150
+
151
+ /**
152
+ * Resize browser viewport to a breakpoint width (plus Diffy window padding).
153
+ *
154
+ * Example #1: When I resize window to "1200"
155
+ * Example #2: When we resize window to "640"
156
+ * Example #3: When I resize window to "320"
157
+ * Example #4: When we resize window to "768"
158
+ * Example #5: When I resize window to "1024"
159
+ * Example #6: When we resize window to "1440"
160
+ * Example #7: When I resize window to "1920"
161
+ * Example #8: When we resize window to "375"
162
+ *
163
+ */
164
+ When(/^(?:I |we )?resize window to "([^"]*)"$/, async function (breakpoint) {
165
+ const cfg = this.diffyConfig;
166
+ const width = parseInt(breakpoint, 10) + WINDOW_PADDING;
167
+ await this.page.setViewportSize({ width, height: cfg.windowHeight });
168
+ });
169
+
170
+ /**
171
+ * Capture a full-page screenshot at current viewport.
172
+ * Held in-memory (and optionally written to DIFFY_SCREENSHOTS_DIR) until
173
+ * "send screenshots to diffy with name" uploads the batch.
174
+ *
175
+ * Example #1: Then I take screenshot
176
+ * Example #2: Then we take screenshot
177
+ * Example #3: And I take screenshot
178
+ * Example #4: And we take screenshot
179
+ * Example #5: But I take screenshot
180
+ * Example #6: Then take screenshot
181
+ * Example #7: And take screenshot
182
+ * Example #8: When I take screenshot
183
+ * Example #9: When we take screenshot
184
+ * Example #10: Given I take screenshot
185
+ *
186
+ */
187
+ Then(/^(?:I |we )?take screenshot$/, async function () {
188
+ await takeOneScreenshot(this);
189
+ });
190
+
191
+ /**
192
+ * Resize to each configured breakpoint and capture a screenshot per breakpoint.
193
+ * Breakpoints come from DIFFY_BREAKPOINTS env or worldParameters.diffy.breakpoints.
194
+ *
195
+ * Example #1: Then I take screenshots for all breakpoints
196
+ * Example #2: Then we take screenshots for all breakpoints
197
+ * Example #3: And I take screenshots for all breakpoints
198
+ * Example #4: And we take screenshots for all breakpoints
199
+ * Example #5: Then take screenshots for all breakpoints
200
+ * Example #6: And take screenshots for all breakpoints
201
+ * Example #7: When I take screenshots for all breakpoints
202
+ * Example #8: When we take screenshots for all breakpoints
203
+ * Example #9: But I take screenshots for all breakpoints
204
+ * Example #10: Given I take screenshots for all breakpoints
205
+ *
206
+ */
207
+ Then(/^(?:I |we )?take screenshots for all breakpoints$/, async function () {
208
+ const cfg = this.diffyConfig;
209
+ if (!cfg.breakpoints.length) {
210
+ throw new Error('Diffy breakpoints empty. Set DIFFY_BREAKPOINTS or worldParameters.diffy.breakpoints.');
211
+ }
212
+ for (const bp of cfg.breakpoints) {
213
+ await this.page.setViewportSize({
214
+ width: bp + WINDOW_PADDING,
215
+ height: cfg.windowHeight,
216
+ });
217
+ await takeOneScreenshot(this);
218
+ }
219
+ });
220
+
221
+ /**
222
+ * Upload all captured screenshots to Diffy as a named custom snapshot.
223
+ * Clears in-memory buffer + on-disk screenshotsDir on success.
224
+ *
225
+ * Example #1: Then send screenshots to diffy with name "baseline"
226
+ * Example #2: Then send screenshots to diffy with name "changed"
227
+ * Example #3: Then send screenshots to diffy with name "homepage-release-2.0"
228
+ * Example #4: Then send screenshots to diffy with name "after-deploy"
229
+ * Example #5: Then send screenshots to diffy with name "smoke-run"
230
+ * Example #6: Then send screenshots to diffy with name "webship.co-prod"
231
+ *
232
+ */
233
+ Then(/^(I |we )*send screenshots to diffy with name "([^"]*)"$/, async function (pronounCase, snapshotName) {
234
+ const cfg = this.diffyConfig;
235
+ ensureProjectId(cfg);
236
+ const shots = this.diffyScreenshots || [];
237
+ if (!shots.length) {
238
+ throw new Error('No screenshots captured. Call "I take screenshot(s)" first.');
239
+ }
240
+
241
+ const form = new FormData();
242
+ form.append('snapshotName', snapshotName);
243
+ shots.forEach((s, i) => {
244
+ form.append(`files[${i}]`, new Blob([s.buffer], { type: 'image/png' }), `screenshot-${i}.png`);
245
+ form.append(`urls[${i}]`, s.url);
246
+ form.append(`breakpoints[${i}]`, String(s.breakpoint));
247
+ });
248
+
249
+ const data = await diffyRequest(
250
+ cfg,
251
+ 'POST',
252
+ `projects/${cfg.projectId}/create-custom-snapshot`,
253
+ { form }
254
+ );
255
+
256
+ const screenshotId = typeof data === 'object' ? (data.id || data.snapshotId || data) : data;
257
+ this.diffyCreatedScreenshotIds.push(screenshotId);
258
+
259
+ if (cfg.screenshotsDir && fs.existsSync(cfg.screenshotsDir)) {
260
+ for (const f of fs.readdirSync(cfg.screenshotsDir)) {
261
+ if (f.endsWith('.png')) fs.unlinkSync(path.join(cfg.screenshotsDir, f));
262
+ }
263
+ }
264
+ this.diffyScreenshots = [];
265
+ });
266
+
267
+ /**
268
+ * Create a Diffy comparison (Diff) from the last two uploaded snapshots.
269
+ *
270
+ * Example #1: Then create diffy comparison
271
+ * Example #2: And create diffy comparison
272
+ * Example #3: Then I create diffy comparison
273
+ * Example #4: Then we create diffy comparison
274
+ * Example #5: And I create diffy comparison
275
+ * Example #6: And we create diffy comparison
276
+ * Example #7: But I create diffy comparison
277
+ * Example #8: When I create diffy comparison
278
+ * Example #9: When we create diffy comparison
279
+ * Example #10: Given create diffy comparison
280
+ *
281
+ */
282
+ Then(/^(I |we )*create diffy comparison$/, async function (pronounCase) {
283
+ const cfg = this.diffyConfig;
284
+ ensureProjectId(cfg);
285
+ const ids = this.diffyCreatedScreenshotIds || [];
286
+ if (ids.length < 2) {
287
+ throw new Error('Need at least two uploaded snapshots before creating a Diff.');
288
+ }
289
+ const data = await diffyRequest(cfg, 'POST', `projects/${cfg.projectId}/diffs`, {
290
+ json: { snapshot1: ids[0], snapshot2: ids[1], name: '' },
291
+ });
292
+ const diffId = typeof data === 'object' ? (data.id || data.diffId || data) : data;
293
+ this.diffyCreatedDiffIds.push(diffId);
294
+ });
295
+
296
+ /**
297
+ * Create a named Diffy comparison from the last two uploaded snapshots.
298
+ *
299
+ * Example #1: Then create diffy comparison with name "release-2.0"
300
+ * Example #2: Then create diffy comparison with name "nightly"
301
+ * Example #3: Then create diffy comparison with name "smoke-run-42"
302
+ * Example #4: Then create diffy comparison with name "webship.co-regression"
303
+ * Example #5: Then create diffy comparison with name "before-vs-after"
304
+ * Example #6: Then create diffy comparison with name "homepage-baseline-vs-changed"
305
+ *
306
+ */
307
+ Then(/^(I |we )*create diffy comparison with name "([^"]*)"$/, async function (pronounCase, name) {
308
+ const cfg = this.diffyConfig;
309
+ ensureProjectId(cfg);
310
+ const ids = this.diffyCreatedScreenshotIds || [];
311
+ if (ids.length < 2) {
312
+ throw new Error('Need at least two uploaded snapshots before creating a Diff.');
313
+ }
314
+ const data = await diffyRequest(cfg, 'POST', `projects/${cfg.projectId}/diffs`, {
315
+ json: { snapshot1: ids[0], snapshot2: ids[1], name },
316
+ });
317
+ const diffId = typeof data === 'object' ? (data.id || data.diffId || data) : data;
318
+ this.diffyCreatedDiffIds.push(diffId);
319
+ });
320
+
321
+ /**
322
+ * Ask Diffy to capture a snapshot remotely from a named environment on the project.
323
+ * Accepts short (prod/stage/dev) or long (production/staging/development) forms, plus "custom".
324
+ *
325
+ * Example #1: Then create diffy screenshot from "production" environment
326
+ * Example #2: Then create diffy screenshot from "prod" environment
327
+ * Example #3: Then create diffy screenshot from "staging" environment
328
+ * Example #4: Then create diffy screenshot from "stage" environment
329
+ * Example #5: Then create diffy screenshot from "development" environment
330
+ * Example #6: Then create diffy screenshot from "dev" environment
331
+ * Example #7: Then create diffy screenshot from "custom" environment
332
+ *
333
+ */
334
+ Then(/^(I |we )*create diffy screenshot from "([^"]*)" environment$/, async function (pronounCase, environment) {
335
+ const cfg = this.diffyConfig;
336
+ ensureProjectId(cfg);
337
+ const map = { prod: 'production', stage: 'staging', dev: 'development' };
338
+ const env = map[environment] || environment;
339
+ const allowed = ['production', 'staging', 'development', 'custom'];
340
+ if (!allowed.includes(env)) {
341
+ throw new Error(`Invalid Diffy environment "${environment}". Expected one of ${allowed.join(', ')}.`);
342
+ }
343
+ const data = await diffyRequest(
344
+ cfg,
345
+ 'POST',
346
+ `projects/${cfg.projectId}/screenshots`,
347
+ { json: { environment: env } }
348
+ );
349
+ const screenshotId = typeof data === 'object' ? (data.id || data.snapshotId || data) : data;
350
+ this.diffyCreatedScreenshotIds.push(screenshotId);
351
+ });
352
+
353
+ /**
354
+ * Kick off a Diffy comparison between two project environments.
355
+ * Uses DIFFY_ENV1_URL / DIFFY_ENV2_URL when either side is "custom".
356
+ *
357
+ * Example #1: Then compare diffy "prod" with "stage"
358
+ * Example #2: Then compare diffy "production" with "staging"
359
+ * Example #3: Then compare diffy "prod" with "dev"
360
+ * Example #4: Then compare diffy "stage" with "dev"
361
+ * Example #5: Then compare diffy "prod" with "baseline"
362
+ * Example #6: Then compare diffy "baseline" with "custom"
363
+ * Example #7: Then compare diffy "custom" with "custom"
364
+ * Example #8: Then compare diffy "production" with "development"
365
+ *
366
+ */
367
+ Then(/^(I |we )*compare diffy "([^"]*)" with "([^"]*)"$/, async function (pronounCase, env1, env2) {
368
+ const cfg = this.diffyConfig;
369
+ ensureProjectId(cfg);
370
+ const toShort = { production: 'prod', staging: 'stage', development: 'dev' };
371
+ const e1 = toShort[env1] || env1;
372
+ const e2 = toShort[env2] || env2;
373
+ const allowed = ['prod', 'stage', 'dev', 'baseline', 'custom'];
374
+ if (!allowed.includes(e1) || !allowed.includes(e2)) {
375
+ throw new Error(`Invalid env. Allowed: ${allowed.join(', ')}.`);
376
+ }
377
+ const args = { env1: e1, env2: e2 };
378
+ if (e1 === 'custom') args.env1Url = cfg.env1Url;
379
+ if (e2 === 'custom') args.env2Url = cfg.env2Url;
380
+ const data = await diffyRequest(cfg, 'POST', `projects/${cfg.projectId}/compare`, { json: args });
381
+ const diffId = typeof data === 'object' ? (data.id || data.diffId || data) : data;
382
+ this.diffyCreatedDiffIds.push(diffId);
383
+ });
384
+
385
+ /**
386
+ * Upload every PNG/WebP under a local folder as a named Diffy custom snapshot.
387
+ * Breakpoint is read from the PNG width; URL slug is derived from file name.
388
+ *
389
+ * Example #1: Then upload folder "./screenshots/baseline" to diffy as "baseline"
390
+ * Example #2: Then upload folder "./screenshots/changed" to diffy as "changed"
391
+ * Example #3: Then upload folder "./reports/screenshots" to diffy as "nightly"
392
+ * Example #4: Then upload folder "/tmp/webship-shots" to diffy as "webship.co-snapshot"
393
+ * Example #5: Then upload folder "./out/homepage" to diffy as "homepage-release-2.0"
394
+ * Example #6: Then upload folder "./diffy/before" to diffy as "before-deploy"
395
+ *
396
+ */
397
+ Then(/^(I |we )*upload folder "([^"]*)" to diffy as "([^"]*)"$/, async function (pronounCase, folderPath, snapshotName) {
398
+ const cfg = this.diffyConfig;
399
+ ensureProjectId(cfg);
400
+ if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
401
+ throw new Error(`Folder not found: ${folderPath}`);
402
+ }
403
+ const files = [];
404
+ (function walk(dir) {
405
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
406
+ const full = path.join(dir, entry.name);
407
+ if (entry.isDirectory()) walk(full);
408
+ else if (/\.(png|webp)$/i.test(entry.name)) files.push(full);
409
+ }
410
+ })(folderPath);
411
+ if (!files.length) throw new Error(`No PNG/WebP images in ${folderPath}.`);
412
+ files.sort();
413
+
414
+ const form = new FormData();
415
+ form.append('snapshotName', snapshotName);
416
+ form.append('functionalTest', '1');
417
+ files.forEach((filepath, i) => {
418
+ const buffer = fs.readFileSync(filepath);
419
+ const rel = path.relative(folderPath, filepath).replace(/[\\/]/g, '-');
420
+ const slug = '/' + path.parse(rel).name.toLowerCase().replace(/[^a-z0-9]+/g, '-');
421
+ const width = detectPngWidth(buffer);
422
+ if (!width) throw new Error(`Cannot read width: ${filepath}`);
423
+ form.append(`files[${i}]`, new Blob([buffer], { type: 'image/png' }), path.basename(filepath));
424
+ form.append(`urls[${i}]`, slug);
425
+ form.append(`breakpoints[${i}]`, String(width));
426
+ });
427
+
428
+ const data = await diffyRequest(
429
+ cfg,
430
+ 'POST',
431
+ `projects/${cfg.projectId}/create-custom-snapshot`,
432
+ { form }
433
+ );
434
+ const screenshotId = typeof data === 'object' ? (data.id || data.snapshotId || data) : data;
435
+ this.diffyCreatedScreenshotIds.push(screenshotId);
436
+ });
437
+
438
+ function detectPngWidth(buffer) {
439
+ if (buffer.length < 24 || buffer[0] !== 0x89 || buffer[1] !== 0x50) return 0;
440
+ return buffer.readUInt32BE(16);
441
+ }
442
+
443
+ /**
444
+ * Poll the last created Diffy comparison until it reaches a terminal state.
445
+ * Timeout is DIFFY_MAX_WAIT seconds (default 1200).
446
+ *
447
+ * Example #1: Then wait for diffy comparison to complete
448
+ * Example #2: And wait for diffy comparison to complete
449
+ * Example #3: Then I wait for diffy comparison to complete
450
+ * Example #4: Then we wait for diffy comparison to complete
451
+ * Example #5: And I wait for diffy comparison to complete
452
+ * Example #6: And we wait for diffy comparison to complete
453
+ * Example #7: But I wait for diffy comparison to complete
454
+ * Example #8: When I wait for diffy comparison to complete
455
+ * Example #9: When we wait for diffy comparison to complete
456
+ * Example #10: Given wait for diffy comparison to complete
457
+ *
458
+ */
459
+ Then(/^(I |we )*wait for diffy comparison to complete$/, { timeout: 60 * 60 * 1000 }, async function (pronounCase) {
460
+ const cfg = this.diffyConfig;
461
+ const ids = this.diffyCreatedDiffIds || [];
462
+ if (!ids.length) throw new Error('No Diffy comparison created yet.');
463
+ const diffId = ids[ids.length - 1];
464
+ const step = 10;
465
+ const completed = new Set([2, 3, 4, 7]);
466
+ for (let i = 0; i < cfg.maxWait; i += step) {
467
+ const data = await diffyRequest(cfg, 'GET', `diffs/${diffId}`);
468
+ if (data && completed.has(Number(data.state))) return;
469
+ await new Promise(r => setTimeout(r, step * 1000));
470
+ }
471
+ throw new Error(`Diffy comparison ${diffId} did not complete in ${cfg.maxWait}s.`);
472
+ });
@@ -1,22 +0,0 @@
1
- var reporter = require('cucumber-html-reporter');
2
-
3
- var options = {
4
- theme: 'bootstrap',
5
- jsonFile: 'tests/reports/cucumber_report.json',
6
- output: 'tests/reports/cucumber_report.html',
7
- reportSuiteAsScenarios: true,
8
- scenarioTimestamp: true,
9
- launchReport: false,
10
- brandTitle: "Test Report",
11
- metadata: {
12
- "App Version": "7.1.0",
13
- "Test Environment": "development",
14
- "Browser": "Google Chrome",
15
- "Platform": "Linux",
16
- "Parallel": "Scenarios",
17
- "Executed": "Remote"
18
- },
19
- failedSummaryReport: true,
20
- };
21
-
22
- reporter.generate(options);
@@ -1,37 +0,0 @@
1
- module.exports = {
2
- default: {
3
- timeout: 30000,
4
- requireModule: ['ts-node/register'],
5
- require: [
6
- 'node_modules/webship-js/tests/step-definitions/**/*.js',
7
- 'tests/step-definitions/**/*.js',
8
- ],
9
- paths: ['tests/features/**/*.feature'],
10
- format: [
11
- '@cucumber/pretty-formatter',
12
- 'json:tests/reports/cucumber_report.json',
13
- ],
14
- formatOptions: {
15
- colorsEnabled: true,
16
- theme: {
17
- 'feature keyword': ['bold', 'blue'],
18
- 'feature name': ['blue', 'underline'],
19
- 'feature description': ['blueBright'],
20
- 'scenario keyword': ['bold', 'magenta'],
21
- 'scenario name': ['magenta', 'underline'],
22
- 'step keyword': ['bold', 'green'],
23
- 'step text': ['greenBright', 'italic'],
24
- },
25
- },
26
- worldParameters: {
27
- launchUrl: process.env.LAUNCH_URL || 'http://localhost:8080',
28
- minWaitTime: {
29
- page: 3000,
30
- before_scenario: 0,
31
- after_scenario: 0,
32
- before_step: 0,
33
- after_step: 0,
34
- },
35
- },
36
- },
37
- };
@@ -1,22 +0,0 @@
1
- var reporter = require('cucumber-html-reporter');
2
-
3
- var options = {
4
- theme: 'bootstrap',
5
- jsonFile: 'tests/reports/cucumber_report.json',
6
- output: 'tests/reports/cucumber_report.html',
7
- reportSuiteAsScenarios: true,
8
- scenarioTimestamp: true,
9
- launchReport: false,
10
- brandTitle: "Test Report",
11
- metadata: {
12
- "App Version": "7.1.0",
13
- "Test Environment": "development",
14
- "Browser": "Google Chrome",
15
- "Platform": "Linux",
16
- "Parallel": "Scenarios",
17
- "Executed": "Remote"
18
- },
19
- failedSummaryReport: true,
20
- };
21
-
22
- reporter.generate(options);
@@ -1,18 +0,0 @@
1
- {
2
- "name": "project-name",
3
- "version": "2.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "author": "",
7
- "license": "MIT",
8
- "private": false,
9
- "scripts": {
10
- "test": "cucumber-js --config cucumber.js; node generate-reports.js;",
11
- "test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js; node generate-reports.js;",
12
- "test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js; node generate-reports.js;"
13
- },
14
- "homepage": "https://github.com/webship/webship-js",
15
- "dependencies": {
16
- "webship-js": "~2.0.0"
17
- }
18
- }
@@ -1,37 +0,0 @@
1
- import type { LaunchOptions, BrowserContextOptions } from 'playwright';
2
-
3
- type BrowserName = 'chromium' | 'firefox' | 'webkit';
4
-
5
- const browser = (process.env.BROWSER || 'chromium') as BrowserName;
6
-
7
- const chromiumArgs: string[] = [
8
- '--no-sandbox',
9
- '--disable-dev-shm-usage',
10
- '--disable-setuid-sandbox',
11
- '--disable-web-security',
12
- '--ignore-certificate-errors',
13
- '--disable-extensions',
14
- '--incognito',
15
- '--disable-infobars',
16
- ];
17
-
18
- interface PlaywrightConfig {
19
- browser: BrowserName;
20
- launchOptions: LaunchOptions;
21
- contextOptions: BrowserContextOptions;
22
- }
23
-
24
- const config: PlaywrightConfig = {
25
- browser,
26
- launchOptions: {
27
- headless: true,
28
- slowMo: 300,
29
- args: browser === 'chromium' ? chromiumArgs : [],
30
- },
31
- contextOptions: {
32
- viewport: { width: 1600, height: 1200 },
33
- ignoreHTTPSErrors: true,
34
- },
35
- };
36
-
37
- export = config;
@@ -1 +0,0 @@
1
- # Features
@@ -1,8 +0,0 @@
1
- Feature: Check the home page
2
- As a nonymouse user
3
- I want to be able to visit the home page
4
- So that I know that the site is working
5
-
6
- Scenario: Check homepage
7
- Given I am on the homepage
8
- Then I should see "Love to help in speeding up the work of having Automated Functional Acceptance Testing for products to ship websites in a swift way."
@@ -1 +0,0 @@
1
- # Reports
@@ -1 +0,0 @@
1
- # Step Definitions
@@ -1,4 +0,0 @@
1
- const { Given, When, Then } = require('@cucumber/cucumber');
2
- const playwrightConfig = require(require('path').join(process.cwd(), 'playwright.config'));
3
-
4
- // Add your custom step definitions here.
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "CommonJS",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "types": ["node"]
8
- },
9
- "ts-node": {
10
- "ignore": ["node_modules/(?!webship-js/)"]
11
- }
12
- }