webship-js 2.0.0 → 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 (34) hide show
  1. package/README.md +1 -7
  2. package/bin/generate-reports.js +191 -0
  3. package/bin/init-webship.js +343 -0
  4. package/bin/postinstall.js +26 -0
  5. package/cucumber.js +59 -1
  6. package/examples/account.html +32 -0
  7. package/examples/diffy/baseline.html +54 -0
  8. package/examples/diffy/changed.html +63 -0
  9. package/examples/diffy/index.html +52 -0
  10. package/examples/index.html +6 -0
  11. package/examples/test--when--i-additionally-select.html +27 -0
  12. package/package.json +11 -4
  13. package/tests/features/diffy/test--diffy-01-example-demo.feature +22 -0
  14. package/tests/features/diffy/test--diffy-02-all-steps.feature +52 -0
  15. package/tests/features/diffy/test--diffy-03-real-api.feature +21 -0
  16. package/tests/features/test--given--i-am-an-anonymous-user.feature +10 -0
  17. package/tests/features/test--then--i-save-screenshot.feature +33 -0
  18. package/tests/features/test--then--i-see-locator.feature +320 -0
  19. package/tests/features/test--then--i-should-see-n-elements.feature +24 -0
  20. package/tests/features/test--then--print-current-url-and-response.feature +21 -0
  21. package/tests/features/test--when--i-additionally-select.feature +30 -0
  22. package/tests/features/test--when--i-follow.feature +22 -0
  23. package/tests/selectors/back-end-selectors.json +13 -0
  24. package/tests/selectors/front-end-selectors.json +16 -0
  25. package/tests/selectors/homepage-selectors.json +13 -0
  26. package/tests/step-definitions/webship-api.js +234 -41
  27. package/tests/step-definitions/webship-screenshot.js +427 -0
  28. package/tests/step-definitions/webship-selectors.js +961 -0
  29. package/tests/step-definitions/webship.js +835 -226
  30. package/tests/step-definitions-diffy/README.md +329 -0
  31. package/tests/step-definitions-diffy/mock-diffy-api/server.js +84 -0
  32. package/tests/step-definitions-diffy/webship-diffy-mock.js +31 -0
  33. package/tests/step-definitions-diffy/webship-diffy.js +472 -0
  34. package/generate-reports.js +0 -22
package/README.md CHANGED
@@ -18,13 +18,7 @@ All you need to know is at [webship-js Docs](https://webship.co/docs/webship-js/
18
18
  npm install webship-js
19
19
  ```
20
20
 
21
- ## Install files required by the webship-js tool
22
-
23
- ```
24
- bash <(wget -O - https://raw.githubusercontent.com/webship/wbash/v1/webship-js/v2/template.sh)
25
- ```
26
-
27
- ## Automated Functional Acceptance Testing
21
+ ## Automated Functional Acceptance Testing
28
22
 
29
23
  ```
30
24
  npm test
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const path = require('path');
6
+ const reporter = require('cucumber-html-reporter');
7
+
8
+ const THEMES = new Set(['bootstrap', 'hierarchy', 'foundation', 'simple']);
9
+
10
+ function bool(v) {
11
+ return v !== 'false' && v !== '0' && v !== 'no';
12
+ }
13
+
14
+ function capitalize(s) {
15
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
16
+ }
17
+
18
+ function parseArgs(argv) {
19
+ const opts = {
20
+ metadata: {},
21
+ scenarioTimestamp: true,
22
+ reportSuiteAsScenarios: true,
23
+ failedSummaryReport: true,
24
+ launchReport: false,
25
+ noInlineScreenshots: false,
26
+ storeScreenshots: false,
27
+ ignoreBadJsonFile: false,
28
+ };
29
+ for (let i = 0; i < argv.length; i++) {
30
+ const a = argv[i];
31
+ const next = () => argv[++i];
32
+ switch (a) {
33
+ case '-h':
34
+ case '--help': opts.help = true; break;
35
+ case '--json': opts.jsonFile = next(); break;
36
+ case '--out':
37
+ case '--output': opts.output = next(); break;
38
+ case '--theme': opts.theme = next(); break;
39
+ case '--title': opts.brandTitle = next(); break;
40
+ case '--name': opts.name = next(); break;
41
+ case '--launch': opts.launchReport = true; break;
42
+ case '--layout': opts.columnLayout = Number(next()); break;
43
+ case '--no-scenario-timestamp': opts.scenarioTimestamp = false; break;
44
+ case '--no-suite-as-scenarios': opts.reportSuiteAsScenarios = false; break;
45
+ case '--no-failed-summary': opts.failedSummaryReport = false; break;
46
+ case '--no-inline-screenshots': opts.noInlineScreenshots = true; break;
47
+ case '--store-screenshots': opts.storeScreenshots = true; break;
48
+ case '--screenshots-dir': opts.screenshotsDirectory = next(); break;
49
+ case '--ignore-bad-json': opts.ignoreBadJsonFile = true; break;
50
+ case '--app-version': opts.metadata['App Version'] = next(); break;
51
+ case '--env': opts.metadata['Test Environment'] = next(); break;
52
+ case '--browser': opts.metadata['Browser'] = next(); break;
53
+ case '--platform': opts.metadata['Platform'] = next(); break;
54
+ case '--parallel': opts.metadata['Parallel'] = next(); break;
55
+ case '--executed': opts.metadata['Executed'] = next(); break;
56
+ case '--metadata': {
57
+ const kv = next() || '';
58
+ const eq = kv.indexOf('=');
59
+ if (eq > 0) opts.metadata[kv.slice(0, eq)] = kv.slice(eq + 1);
60
+ break;
61
+ }
62
+ default:
63
+ if (a.startsWith('--')) {
64
+ console.error(`[webship-js] Unknown option: ${a}`);
65
+ opts.help = true;
66
+ }
67
+ }
68
+ }
69
+ return opts;
70
+ }
71
+
72
+ function printHelp() {
73
+ process.stdout.write(
74
+ [
75
+ 'Usage: generate-reports [options]',
76
+ '',
77
+ 'Generate cucumber HTML report from JSON output.',
78
+ '',
79
+ 'Input / Output:',
80
+ ' --json <path> JSON input (env WEBSHIP_REPORT_JSON,',
81
+ ' default: tests/reports/cucumber_report.json)',
82
+ ' --out <path> HTML output (env WEBSHIP_REPORT_OUT,',
83
+ ' default: tests/reports/cucumber_report.html)',
84
+ '',
85
+ 'Format:',
86
+ ' --theme <name> bootstrap | hierarchy | foundation | simple',
87
+ ' (env WEBSHIP_REPORT_THEME, default: bootstrap)',
88
+ ' --title <s> Brand title (env WEBSHIP_REPORT_TITLE)',
89
+ ' --name <s> Report name',
90
+ ' --layout <1|2> Column layout (default: 1)',
91
+ ' --launch Launch report in browser after generation',
92
+ ' --no-scenario-timestamp Hide per-scenario timestamp',
93
+ ' --no-suite-as-scenarios Report suites instead of scenarios',
94
+ ' --no-failed-summary Hide failed-scenarios summary',
95
+ ' --no-inline-screenshots Link screenshots instead of embedding',
96
+ ' --store-screenshots Copy screenshots into report dir',
97
+ ' --screenshots-dir <dir> Source screenshots directory',
98
+ ' --ignore-bad-json Do not fail on malformed JSON entries',
99
+ '',
100
+ 'Metadata:',
101
+ ' --app-version <s> App Version (env WEBSHIP_REPORT_APP_VERSION)',
102
+ ' --env <s> Test Environment (env WEBSHIP_REPORT_ENV)',
103
+ ' --browser <s> Browser (env BROWSER)',
104
+ ' --platform <s> Platform (default: process.platform)',
105
+ ' --parallel <s> Parallel (default: Scenarios)',
106
+ ' --executed <s> Executed (env WEBSHIP_REPORT_EXECUTED)',
107
+ ' --metadata key=value Arbitrary key/value (repeatable)',
108
+ '',
109
+ ' -h, --help Show this help',
110
+ '',
111
+ ].join('\n')
112
+ );
113
+ }
114
+
115
+ function run(argv) {
116
+ const args = parseArgs(argv);
117
+ if (args.help) return printHelp();
118
+
119
+ const cwd = process.cwd();
120
+ const jsonFile = path.resolve(
121
+ cwd,
122
+ args.jsonFile ||
123
+ process.env.WEBSHIP_REPORT_JSON ||
124
+ 'tests/reports/cucumber_report.json'
125
+ );
126
+ const output = path.resolve(
127
+ cwd,
128
+ args.output ||
129
+ process.env.WEBSHIP_REPORT_OUT ||
130
+ 'tests/reports/cucumber_report.html'
131
+ );
132
+
133
+ const theme =
134
+ args.theme || process.env.WEBSHIP_REPORT_THEME || 'bootstrap';
135
+ if (!THEMES.has(theme)) {
136
+ console.error(
137
+ `[webship-js] Unknown theme "${theme}". Use one of: ${[...THEMES].join(', ')}`
138
+ );
139
+ process.exit(1);
140
+ }
141
+
142
+ const metadata = {
143
+ 'App Version':
144
+ args.metadata['App Version'] ||
145
+ process.env.WEBSHIP_REPORT_APP_VERSION ||
146
+ '2.0.0',
147
+ 'Test Environment':
148
+ args.metadata['Test Environment'] ||
149
+ process.env.WEBSHIP_REPORT_ENV ||
150
+ 'development',
151
+ Browser:
152
+ args.metadata['Browser'] ||
153
+ (process.env.BROWSER ? capitalize(process.env.BROWSER) : 'Chromium'),
154
+ Platform: args.metadata['Platform'] || process.platform,
155
+ Parallel: args.metadata['Parallel'] || 'Scenarios',
156
+ Executed:
157
+ args.metadata['Executed'] ||
158
+ process.env.WEBSHIP_REPORT_EXECUTED ||
159
+ 'Remote',
160
+ };
161
+ for (const [k, v] of Object.entries(args.metadata)) {
162
+ metadata[k] = v;
163
+ }
164
+
165
+ const options = {
166
+ theme,
167
+ jsonFile,
168
+ output,
169
+ reportSuiteAsScenarios: args.reportSuiteAsScenarios,
170
+ scenarioTimestamp: args.scenarioTimestamp,
171
+ launchReport: args.launchReport,
172
+ brandTitle:
173
+ args.brandTitle || process.env.WEBSHIP_REPORT_TITLE || 'Test Report',
174
+ name: args.name || process.env.WEBSHIP_REPORT_NAME,
175
+ columnLayout: args.columnLayout || 1,
176
+ noInlineScreenshots: args.noInlineScreenshots,
177
+ storeScreenshots: args.storeScreenshots,
178
+ screenshotsDirectory: args.screenshotsDirectory,
179
+ ignoreBadJsonFile: args.ignoreBadJsonFile,
180
+ failedSummaryReport: args.failedSummaryReport,
181
+ metadata,
182
+ };
183
+
184
+ reporter.generate(options);
185
+ }
186
+
187
+ if (require.main === module) {
188
+ run(process.argv.slice(2));
189
+ }
190
+
191
+ module.exports = { run };
@@ -0,0 +1,343 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { spawnSync } = require('child_process');
8
+
9
+ const packagePath = path.join(__dirname, '..');
10
+
11
+ const CUCUMBER_JS = `module.exports = {
12
+ default: {
13
+ timeout: 30000,
14
+ requireModule: ['ts-node/register'],
15
+ require: [
16
+ 'node_modules/webship-js/tests/step-definitions/**/*.js', // Webship-js core step definitions (auto HTML report on exit; disable: WEBSHIP_REPORT_DISABLE=1).
17
+ // 'node_modules/webship-js/tests/step-definitions-diffy/**/*.js', // Diffy step definitions (optional).
18
+ 'tests/step-definitions/**/*.js', // Your custom step definitions.
19
+ ],
20
+ paths: ['tests/features/**/*.feature'],
21
+ format: [
22
+ '@cucumber/pretty-formatter',
23
+ 'json:tests/reports/cucumber_report.json',
24
+ ],
25
+ formatOptions: {
26
+ colorsEnabled: true,
27
+ theme: {
28
+ 'feature keyword': ['bold', 'blue'],
29
+ 'feature name': ['blue', 'underline'],
30
+ 'feature description': ['blueBright'],
31
+ 'scenario keyword': ['bold', 'magenta'],
32
+ 'scenario name': ['magenta', 'underline'],
33
+ 'step keyword': ['bold', 'green'],
34
+ 'step text': ['greenBright', 'italic'],
35
+ },
36
+ },
37
+ worldParameters: {
38
+ launchUrl: process.env.LAUNCH_URL || 'http://localhost:8080',
39
+ minWaitTime: {
40
+ page: 3000,
41
+ before_scenario: 0,
42
+ after_scenario: 0,
43
+ before_step: 0,
44
+ after_step: 0,
45
+ },
46
+ selectors: {
47
+ css: {},
48
+ xpath: {},
49
+ filesPath: './tests/selectors/',
50
+ files: [],
51
+ offset: 60,
52
+ breakpoints: {
53
+ xs: { width: 375, height: 667 },
54
+ sm: { width: 576, height: 800 },
55
+ md: { width: 768, height: 1024 },
56
+ lg: { width: 992, height: 768 },
57
+ xl: { width: 1200, height: 900, default: true },
58
+ xxl: { width: 1400, height: 900 },
59
+ xxxl: { width: 1920, height: 1080 },
60
+ },
61
+ },
62
+ screenshot: {
63
+ dir: './screenshots',
64
+ purge: false,
65
+ onFailed: true,
66
+ onEveryStep: false,
67
+ alwaysFullscreen: false,
68
+ failedPrefix: 'failed_',
69
+ filenamePattern: '{datetime}.{feature_file}.feature_{step_line}.{ext}',
70
+ filenamePatternFailed: '{failed_prefix}{datetime}.{feature_file}.feature_{step_line}.{ext}',
71
+ infoTypes: '',
72
+ },
73
+ // Diffy visual-regression (optional). Uncomment and set apiKey / projectId to enable.
74
+ // diffy: {
75
+ // apiKey: '', // DIFFY_API_KEY
76
+ // projectId: 0, // DIFFY_PROJECT_ID
77
+ // breakpoints: '640,1200', // DIFFY_BREAKPOINTS
78
+ // windowHeight: 2000, // DIFFY_WINDOW_HEIGHT
79
+ // screenshotsDir: '', // DIFFY_SCREENSHOTS_DIR
80
+ // baseUrl: 'https://app.diffy.website/api/', // DIFFY_API_BASE_URL
81
+ // maxWait: 30, // DIFFY_MAX_WAIT (seconds)
82
+ // env1Url: '', // DIFFY_ENV1_URL
83
+ // env2Url: '', // DIFFY_ENV2_URL
84
+ // },
85
+ },
86
+ },
87
+ };
88
+ `;
89
+
90
+ const PLAYWRIGHT_CONFIG_TS = `import type { LaunchOptions, BrowserContextOptions } from 'playwright';
91
+
92
+ type BrowserName = 'chromium' | 'firefox' | 'webkit';
93
+
94
+ const browser = (process.env.BROWSER || 'chromium') as BrowserName;
95
+
96
+ const chromiumArgs: string[] = [
97
+ '--no-sandbox',
98
+ '--disable-dev-shm-usage',
99
+ '--disable-setuid-sandbox',
100
+ '--disable-web-security',
101
+ '--ignore-certificate-errors',
102
+ '--disable-extensions',
103
+ '--incognito',
104
+ '--disable-infobars',
105
+ ];
106
+
107
+ interface PlaywrightConfig {
108
+ browser: BrowserName;
109
+ launchOptions: LaunchOptions;
110
+ contextOptions: BrowserContextOptions;
111
+ }
112
+
113
+ const config: PlaywrightConfig = {
114
+ browser,
115
+ launchOptions: {
116
+ headless: true,
117
+ slowMo: 300,
118
+ args: browser === 'chromium' ? chromiumArgs : [],
119
+ },
120
+ contextOptions: {
121
+ viewport: { width: 1600, height: 1200 },
122
+ ignoreHTTPSErrors: true,
123
+ },
124
+ };
125
+
126
+ export = config;
127
+ `;
128
+
129
+ const TSCONFIG_JSON = {
130
+ compilerOptions: {
131
+ target: 'ES2020',
132
+ module: 'CommonJS',
133
+ strict: true,
134
+ esModuleInterop: true,
135
+ types: ['node'],
136
+ },
137
+ 'ts-node': {
138
+ ignore: ['node_modules/(?!webship-js/)'],
139
+ },
140
+ };
141
+
142
+ const FEATURE_SAMPLE = `Feature: Check the home page
143
+ As a nonymouse user
144
+ I want to be able to visit the home page
145
+ So that I know that the site is working
146
+
147
+ Scenario: Check homepage
148
+ Given I am on the homepage
149
+ 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."
150
+ `;
151
+
152
+ const CUSTOM_STEP_JS = `const { Given, When, Then } = require('@cucumber/cucumber');
153
+ const playwrightConfig = require(require('path').join(process.cwd(), 'playwright.config'));
154
+
155
+ // Add your custom step definitions here.
156
+ `;
157
+
158
+ const TEXT_ASSETS = {
159
+ 'cucumber.js': CUCUMBER_JS,
160
+ 'playwright.config.ts': PLAYWRIGHT_CONFIG_TS,
161
+ 'tests/features/README.md': '# Features\n',
162
+ 'tests/features/check-homepage.feature': FEATURE_SAMPLE,
163
+ 'tests/reports/README.md': '# Reports\n',
164
+ 'tests/step-definitions/README.md': '# Step Definitions\n',
165
+ 'tests/step-definitions/custom.js': CUSTOM_STEP_JS,
166
+ };
167
+
168
+ const TEST_SCRIPTS = {
169
+ test: 'cucumber-js --config cucumber.js',
170
+ 'test:chromium': 'BROWSER=chromium cucumber-js --config cucumber.js',
171
+ 'test:firefox': 'BROWSER=firefox cucumber-js --config cucumber.js',
172
+ 'test:webkit': 'BROWSER=webkit cucumber-js --config cucumber.js',
173
+ 'generate-reports': 'generate-reports',
174
+ };
175
+
176
+ const DEFAULT_PKG = {
177
+ name: 'project-name',
178
+ version: '2.0.0',
179
+ description: '',
180
+ main: 'index.js',
181
+ author: '',
182
+ license: 'MIT',
183
+ private: false,
184
+ scripts: {},
185
+ homepage: 'https://github.com/webship/webship-js',
186
+ dependencies: {},
187
+ };
188
+
189
+ function parseArgs(argv) {
190
+ const opts = { force: false, skipBrowsers: false, help: false, cwd: null };
191
+ for (let i = 0; i < argv.length; i++) {
192
+ const a = argv[i];
193
+ if (a === '--force' || a === '-f') opts.force = true;
194
+ else if (a === '--skip-browsers') opts.skipBrowsers = true;
195
+ else if (a === '--help' || a === '-h') opts.help = true;
196
+ else if (a === '--cwd') opts.cwd = argv[++i];
197
+ }
198
+ return opts;
199
+ }
200
+
201
+ function printHelp() {
202
+ process.stdout.write(
203
+ [
204
+ 'Usage: init-webship-js [options]',
205
+ '',
206
+ 'Scaffold a webship-js project: cucumber.js, playwright.config.ts,',
207
+ 'tsconfig.json, tests/ tree, and package.json scripts.',
208
+ 'Idempotent — safe to run multiple times.',
209
+ '',
210
+ 'Options:',
211
+ ' -f, --force Overwrite existing files',
212
+ ' --skip-browsers Skip `playwright install chromium`',
213
+ ' --cwd <dir> Target directory (default: $INIT_CWD or cwd)',
214
+ ' -h, --help Show this help',
215
+ '',
216
+ ].join('\n')
217
+ );
218
+ }
219
+
220
+ function writeFileIfMissing(destPath, content, { force }) {
221
+ if (!force && fs.existsSync(destPath)) return false;
222
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
223
+ fs.writeFileSync(destPath, content, 'utf8');
224
+ return true;
225
+ }
226
+
227
+ function ensureDir(dir) {
228
+ fs.mkdirSync(dir, { recursive: true });
229
+ }
230
+
231
+ function readPkgVersion() {
232
+ try {
233
+ const pkg = JSON.parse(
234
+ fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8')
235
+ );
236
+ const major = String(pkg.version).split('.')[0] || '2';
237
+ return `~${major}.0.0`;
238
+ } catch {
239
+ return '~2.0.0';
240
+ }
241
+ }
242
+
243
+ function writeTextAssets(projectPath, opts) {
244
+ const results = [];
245
+ for (const [rel, content] of Object.entries(TEXT_ASSETS)) {
246
+ const dest = path.join(projectPath, rel);
247
+ const written = writeFileIfMissing(dest, content, opts);
248
+ results.push({ file: rel, written });
249
+ }
250
+ return results;
251
+ }
252
+
253
+ function writeTsconfig(projectPath, opts) {
254
+ const dest = path.join(projectPath, 'tsconfig.json');
255
+ if (!opts.force && fs.existsSync(dest)) return false;
256
+ fs.writeFileSync(dest, JSON.stringify(TSCONFIG_JSON, null, 2) + '\n', 'utf8');
257
+ return true;
258
+ }
259
+
260
+ function ensurePackageJson(projectPath, opts) {
261
+ const pkgPath = path.join(projectPath, 'package.json');
262
+ const existed = fs.existsSync(pkgPath);
263
+
264
+ let pkg;
265
+ if (existed) {
266
+ pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
267
+ } else {
268
+ pkg = { ...DEFAULT_PKG };
269
+ }
270
+
271
+ pkg.scripts = pkg.scripts || {};
272
+ for (const [name, cmd] of Object.entries(TEST_SCRIPTS)) {
273
+ if (opts.force || !pkg.scripts[name]) {
274
+ pkg.scripts[name] = cmd;
275
+ }
276
+ }
277
+
278
+ pkg.dependencies = pkg.dependencies || {};
279
+ if (opts.force || !pkg.dependencies['webship-js']) {
280
+ pkg.dependencies['webship-js'] = readPkgVersion();
281
+ }
282
+
283
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
284
+ return { created: !existed };
285
+ }
286
+
287
+ function installBrowsers(projectPath) {
288
+ console.log('\n [webship-js] Installing Playwright browsers...\n');
289
+ const res = spawnSync(
290
+ 'npx',
291
+ ['playwright', 'install', '--with-deps', 'chromium'],
292
+ { cwd: projectPath, stdio: 'inherit', shell: true }
293
+ );
294
+ return res.status === 0;
295
+ }
296
+
297
+ function run(argv) {
298
+ const opts = parseArgs(argv);
299
+ if (opts.help) return printHelp();
300
+
301
+ const projectPath = path.resolve(
302
+ opts.cwd || process.env.INIT_CWD || process.cwd()
303
+ );
304
+
305
+ if (
306
+ projectPath === packagePath ||
307
+ projectPath.startsWith(path.join(packagePath, 'node_modules'))
308
+ ) {
309
+ console.log(' [webship-js] Skipping init inside webship-js itself.');
310
+ return;
311
+ }
312
+
313
+ console.log(`\n [webship-js] Initializing project at ${projectPath}\n`);
314
+
315
+ ensureDir(projectPath);
316
+ ensureDir(path.join(projectPath, 'tests', 'features'));
317
+ ensureDir(path.join(projectPath, 'tests', 'reports'));
318
+ ensureDir(path.join(projectPath, 'tests', 'step-definitions'));
319
+ ensureDir(path.join(projectPath, 'tests', 'selectors'));
320
+ ensureDir(path.join(projectPath, 'screenshots'));
321
+
322
+ const assetResults = writeTextAssets(projectPath, opts);
323
+ const tsconfigWritten = writeTsconfig(projectPath, opts);
324
+ const pkgResult = ensurePackageJson(projectPath, opts);
325
+
326
+ for (const r of assetResults) {
327
+ console.log(` [${r.written ? 'wrote ' : 'kept '}] ${r.file}`);
328
+ }
329
+ console.log(` [${tsconfigWritten ? 'wrote ' : 'kept '}] tsconfig.json`);
330
+ console.log(
331
+ ` [${pkgResult.created ? 'wrote ' : 'merged'}] package.json`
332
+ );
333
+
334
+ if (!opts.skipBrowsers) installBrowsers(projectPath);
335
+
336
+ console.log('\n [webship-js] Setup complete!\n');
337
+ }
338
+
339
+ if (require.main === module) {
340
+ run(process.argv.slice(2));
341
+ }
342
+
343
+ module.exports = { run };
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { run } = require('./init-webship');
8
+
9
+ const packagePath = path.join(__dirname, '..');
10
+ const projectPath = process.env.INIT_CWD || process.cwd();
11
+
12
+ // Skip when invoked from webship-js itself (development / CI).
13
+ if (
14
+ projectPath === packagePath ||
15
+ projectPath.startsWith(path.join(packagePath, 'node_modules'))
16
+ ) {
17
+ process.exit(0);
18
+ }
19
+
20
+ // Only run on a fresh project — cucumber.js absence marks an uninitialized project.
21
+ // Re-installs (npm install, npm ci) will not overwrite user customizations.
22
+ if (fs.existsSync(path.join(projectPath, 'cucumber.js'))) {
23
+ process.exit(0);
24
+ }
25
+
26
+ run(['--cwd', projectPath]);
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,32 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>My Account</title>
6
+ <style>
7
+ body { font-family: sans-serif; max-width: 600px; margin: 60px auto; padding: 0 20px; }
8
+ h1 { color: #333; }
9
+ .account-info { background: #f5f5f5; border-radius: 6px; padding: 20px; margin-top: 20px; }
10
+ a { color: #0066cc; }
11
+ </style>
12
+ <script>
13
+ function getCookie(name) {
14
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
15
+ return match ? decodeURIComponent(match[1]) : null;
16
+ }
17
+
18
+ window.addEventListener('DOMContentLoaded', function () {
19
+ if (!getCookie('session')) {
20
+ window.location.replace('/');
21
+ }
22
+ });
23
+ </script>
24
+ </head>
25
+ <body>
26
+ <h1>My Account</h1>
27
+ <div class="account-info">
28
+ <p>Welcome back! You are logged in.</p>
29
+ <p><a href="/">Back to homepage</a></p>
30
+ </div>
31
+ </body>
32
+ </html>