playwright-cucumber-ts-steps 0.1.3 → 0.1.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.
Files changed (74) hide show
  1. package/README.md +174 -39
  2. package/{dist → lib}/actions/clickSteps.js +10 -3
  3. package/{dist → lib}/actions/debugSteps.js +2 -5
  4. package/{dist → lib}/actions/elementFindSteps.js +15 -18
  5. package/lib/actions/fillFormSteps.js +130 -0
  6. package/{dist → lib}/actions/inputSteps.js +9 -76
  7. package/{dist → lib}/actions/interceptionSteps.js +8 -0
  8. package/{dist → lib}/actions/miscSteps.js +60 -12
  9. package/{dist → lib}/actions/storageSteps.js +26 -4
  10. package/{dist → lib}/assertions/buttonAndTextVisibilitySteps.js +3 -23
  11. package/{dist → lib}/assertions/elementSteps.js +7 -1
  12. package/{dist → lib}/assertions/locationSteps.js +16 -0
  13. package/{dist → lib}/assertions/semanticSteps.js +16 -3
  14. package/{dist → lib}/assertions/visualSteps.js +9 -5
  15. package/lib/custom_setups/loginHooks.js +113 -0
  16. package/lib/helpers/hooks.js +210 -0
  17. package/{dist → lib}/helpers/utils/index.d.ts +1 -0
  18. package/{dist → lib}/helpers/utils/index.js +1 -0
  19. package/{dist → lib}/helpers/utils/optionsUtils.d.ts +5 -0
  20. package/{dist → lib}/helpers/utils/optionsUtils.js +12 -3
  21. package/{dist → lib}/helpers/utils/resolveUtils.d.ts +2 -0
  22. package/{dist → lib}/helpers/utils/resolveUtils.js +13 -3
  23. package/lib/helpers/utils/sessionUtils.d.ts +3 -0
  24. package/lib/helpers/utils/sessionUtils.js +40 -0
  25. package/{dist → lib}/helpers/world.d.ts +13 -0
  26. package/{dist → lib}/helpers/world.js +17 -10
  27. package/lib/iframes/frames.d.ts +1 -0
  28. package/{dist → lib}/index.d.ts +1 -1
  29. package/{dist → lib}/index.js +1 -1
  30. package/{dist → lib}/register.js +1 -5
  31. package/package.json +40 -6
  32. package/dist/custom_setups/globalLogin.d.ts +0 -2
  33. package/dist/custom_setups/globalLogin.js +0 -25
  34. package/dist/custom_setups/loginHooks.js +0 -141
  35. package/dist/helpers/hooks.js +0 -184
  36. package/{dist → lib}/actions/clickSteps.d.ts +0 -0
  37. package/{dist → lib}/actions/cookieSteps.d.ts +0 -0
  38. package/{dist → lib}/actions/cookieSteps.js +0 -0
  39. package/{dist → lib}/actions/debugSteps.d.ts +0 -0
  40. package/{dist → lib}/actions/elementFindSteps.d.ts +0 -0
  41. package/{dist/actions/inputSteps.d.ts → lib/actions/fillFormSteps.d.ts} +0 -0
  42. package/{dist/actions/interceptionSteps.d.ts → lib/actions/inputSteps.d.ts} +0 -0
  43. package/{dist/actions/miscSteps.d.ts → lib/actions/interceptionSteps.d.ts} +0 -0
  44. package/{dist/actions/mouseSteps.d.ts → lib/actions/miscSteps.d.ts} +0 -0
  45. package/{dist/actions/scrollSteps.d.ts → lib/actions/mouseSteps.d.ts} +0 -0
  46. package/{dist → lib}/actions/mouseSteps.js +0 -0
  47. package/{dist/actions/storageSteps.d.ts → lib/actions/scrollSteps.d.ts} +0 -0
  48. package/{dist → lib}/actions/scrollSteps.js +0 -0
  49. package/{dist/assertions → lib/actions}/storageSteps.d.ts +0 -0
  50. package/{dist → lib}/assertions/buttonAndTextVisibilitySteps.d.ts +0 -0
  51. package/{dist → lib}/assertions/cookieSteps.d.ts +0 -0
  52. package/{dist → lib}/assertions/cookieSteps.js +0 -0
  53. package/{dist → lib}/assertions/elementSteps.d.ts +0 -0
  54. package/{dist → lib}/assertions/formInputSteps.d.ts +0 -0
  55. package/{dist → lib}/assertions/formInputSteps.js +0 -0
  56. package/{dist → lib}/assertions/interceptionRequestsSteps.d.ts +0 -0
  57. package/{dist → lib}/assertions/interceptionRequestsSteps.js +0 -0
  58. package/{dist → lib}/assertions/locationSteps.d.ts +0 -0
  59. package/{dist → lib}/assertions/roleTestIdSteps.d.ts +0 -0
  60. package/{dist → lib}/assertions/roleTestIdSteps.js +0 -0
  61. package/{dist → lib}/assertions/semanticSteps.d.ts +0 -0
  62. package/{dist/assertions/visualSteps.d.ts → lib/assertions/storageSteps.d.ts} +0 -0
  63. package/{dist → lib}/assertions/storageSteps.js +1 -1
  64. /package/{dist/custom_setups/loginHooks.d.ts → lib/assertions/visualSteps.d.ts} +0 -0
  65. /package/{dist/helpers/hooks.d.ts → lib/custom_setups/loginHooks.d.ts} +0 -0
  66. /package/{dist → lib}/helpers/checkPeerDeps.d.ts +0 -0
  67. /package/{dist → lib}/helpers/checkPeerDeps.js +0 -0
  68. /package/{dist → lib}/helpers/compareSnapshots.d.ts +0 -0
  69. /package/{dist → lib}/helpers/compareSnapshots.js +0 -0
  70. /package/{dist/iframes/frames.d.ts → lib/helpers/hooks.d.ts} +0 -0
  71. /package/{dist → lib}/helpers/utils/fakerUtils.d.ts +0 -0
  72. /package/{dist → lib}/helpers/utils/fakerUtils.js +0 -0
  73. /package/{dist → lib}/iframes/frames.js +0 -0
  74. /package/{dist → lib}/register.d.ts +0 -0
@@ -1,184 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- // support/hooks.ts
40
- const cucumber_1 = require("@cucumber/cucumber");
41
- const playwright_1 = require("playwright");
42
- const dotenv = __importStar(require("dotenv"));
43
- const fs_1 = __importDefault(require("fs"));
44
- const path_1 = __importDefault(require("path"));
45
- const compareSnapshots_1 = require("./compareSnapshots");
46
- dotenv.config();
47
- const SESSION_FILE = path_1.default.resolve("e2e/support/helper/auth", "session.json");
48
- const SCREENSHOT_DIR = path_1.default.resolve("e2e/screenshots");
49
- const VIDEO_DIR = path_1.default.resolve("e2e/videos");
50
- const SNAPSHOT_BASELINE_DIR = path_1.default.resolve("e2e/snapshots/baseline");
51
- const SNAPSHOT_DIFF_DIR = path_1.default.resolve("e2e/snapshots/diff");
52
- let sharedBrowser;
53
- (0, cucumber_1.BeforeAll)(async () => {
54
- const dirsToClean = [
55
- VIDEO_DIR,
56
- SCREENSHOT_DIR,
57
- SNAPSHOT_DIFF_DIR, // leave baseline snapshots intact
58
- ];
59
- for (const dir of dirsToClean) {
60
- try {
61
- if (fs_1.default.existsSync(dir)) {
62
- fs_1.default.rmSync(dir, { recursive: true, force: true });
63
- console.log(`🧹 Cleaned directory: ${dir}`);
64
- }
65
- }
66
- catch (err) {
67
- console.warn(`⚠️ Failed to clean directory ${dir}:`, err);
68
- }
69
- }
70
- sharedBrowser = await playwright_1.chromium.launch({
71
- headless: process.env.HEADLESS !== "false",
72
- });
73
- console.log("🚀 Launched shared browser for all scenarios");
74
- });
75
- (0, cucumber_1.AfterAll)(async () => {
76
- await sharedBrowser?.close();
77
- console.log("🧹 Closed shared browser after all scenarios");
78
- });
79
- (0, cucumber_1.Before)(async function (scenario) {
80
- // 🛡️ Ensure browser is still usable
81
- if (!sharedBrowser || !sharedBrowser.isConnected()) {
82
- console.warn("⚠️ Shared browser was disconnected. Restarting...");
83
- sharedBrowser = await playwright_1.chromium.launch({
84
- headless: process.env.HEADLESS !== "false",
85
- });
86
- }
87
- const isMobile = scenario.pickle.tags.some((t) => t.name === "@mobile");
88
- const isVisualTest = scenario.pickle.tags.some((t) => t.name === "@visual");
89
- if (isVisualTest)
90
- process.env.VISUAL_TEST = "true";
91
- const contextOptions = {
92
- recordVideo: { dir: VIDEO_DIR },
93
- ...(isMobile ? playwright_1.devices["iPhone 13 Pro"] : {}),
94
- };
95
- if (fs_1.default.existsSync(SESSION_FILE)) {
96
- contextOptions.storageState = SESSION_FILE;
97
- this.log?.("✅ Reusing session from saved file.");
98
- }
99
- const context = await sharedBrowser.newContext(contextOptions);
100
- const page = await context.newPage();
101
- this.browser = sharedBrowser;
102
- this.context = context;
103
- this.page = page;
104
- if (isMobile)
105
- this.log?.("📱 Mobile emulation enabled (iPhone 13 Pro)");
106
- });
107
- (0, cucumber_1.After)(async function (scenario) {
108
- const failed = scenario.result?.status === "FAILED";
109
- const name = scenario.pickle.name.replace(/[^a-z0-9]+/gi, "_").toLowerCase();
110
- // 📸 Screenshot on failure
111
- if (failed && this.page) {
112
- const screenshotPath = path_1.default.join(SCREENSHOT_DIR, `failed-${name}.png`);
113
- try {
114
- fs_1.default.mkdirSync(SCREENSHOT_DIR, { recursive: true });
115
- await this.page.screenshot({ path: screenshotPath, fullPage: true });
116
- console.log(`🖼️ Screenshot saved: ${screenshotPath}`);
117
- }
118
- catch (err) {
119
- console.warn("❌ Failed to save screenshot:", err);
120
- }
121
- }
122
- // 🎥 Handle video recording
123
- let rawPath;
124
- try {
125
- rawPath = await this.page?.video()?.path();
126
- }
127
- catch (err) {
128
- console.warn(`⚠️ Unable to access video path: ${err.message}`);
129
- }
130
- if (rawPath) {
131
- try {
132
- const finalPath = path_1.default.join(VIDEO_DIR, `failed-${name}.webm`);
133
- fs_1.default.mkdirSync(VIDEO_DIR, { recursive: true });
134
- if (failed) {
135
- fs_1.default.renameSync(rawPath, finalPath);
136
- console.log(`🎥 Video saved: ${finalPath}`);
137
- }
138
- else {
139
- fs_1.default.unlinkSync(rawPath);
140
- console.log(`🧹 Deleted video for passed test: ${rawPath}`);
141
- }
142
- }
143
- catch (err) {
144
- console.warn(`❌ Error handling video file: ${err.message}`);
145
- }
146
- }
147
- // 🧪 Visual regression testing
148
- if (this.page && process.env.VISUAL_TEST === "true") {
149
- fs_1.default.mkdirSync(SNAPSHOT_BASELINE_DIR, { recursive: true });
150
- fs_1.default.mkdirSync(SNAPSHOT_DIFF_DIR, { recursive: true });
151
- const baselinePath = path_1.default.join(SNAPSHOT_BASELINE_DIR, `${name}.png`);
152
- const actualPath = path_1.default.join(SNAPSHOT_DIFF_DIR, `${name}.actual.png`);
153
- const diffPath = path_1.default.join(SNAPSHOT_DIFF_DIR, `${name}.diff.png`);
154
- await this.page.screenshot({ path: actualPath, fullPage: true });
155
- if (!fs_1.default.existsSync(baselinePath)) {
156
- fs_1.default.copyFileSync(actualPath, baselinePath);
157
- console.log(`📸 Created baseline image: ${baselinePath}`);
158
- }
159
- else {
160
- try {
161
- const diffPixels = (0, compareSnapshots_1.compareSnapshots)({
162
- actualPath,
163
- baselinePath,
164
- diffPath,
165
- threshold: 0.1,
166
- });
167
- console.log(diffPixels > 0
168
- ? `⚠️ Visual diff found (${diffPixels} pixels): ${diffPath}`
169
- : "✅ No visual changes detected");
170
- }
171
- catch (err) {
172
- console.warn("❌ Error comparing snapshots:", err);
173
- }
174
- }
175
- }
176
- try {
177
- if (this.context && this.page) {
178
- await this.cleanup(scenario);
179
- }
180
- }
181
- catch (err) {
182
- console.warn("❌ Error during cleanup:", err);
183
- }
184
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cucumber_1 = require("@cucumber/cucumber");
7
6
  const fs_1 = __importDefault(require("fs"));
8
7
  const path_1 = __importDefault(require("path"));
8
+ const cucumber_1 = require("@cucumber/cucumber");
9
9
  //
10
10
  // 🗃 LOCAL STORAGE
11
11
  //
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes