playwright-cucumber-ts-steps 1.0.1 → 1.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 (132) hide show
  1. package/README.md +195 -256
  2. package/dist/backend/actions/index.js +4 -0
  3. package/dist/backend/actions/interactions.js +23 -0
  4. package/dist/backend/actions/navigation.js +19 -0
  5. package/dist/backend/api/assertions.js +26 -0
  6. package/dist/backend/api/index.js +4 -0
  7. package/dist/backend/api/requests.js +24 -0
  8. package/dist/backend/api/state.js +15 -0
  9. package/dist/backend/assertions/expectVisible.js +8 -0
  10. package/dist/backend/assertions/index.js +5 -0
  11. package/dist/backend/assertions/pageState.js +25 -0
  12. package/dist/backend/assertions/text.js +20 -0
  13. package/dist/backend/assertions/visibility.js +20 -0
  14. package/dist/backend/auth/index.js +71 -0
  15. package/dist/backend/elements/alerts.js +21 -0
  16. package/dist/backend/elements/forms.js +59 -0
  17. package/dist/backend/elements/frames.js +25 -0
  18. package/dist/backend/elements/index.js +5 -0
  19. package/dist/core/registry.js +20 -0
  20. package/dist/core/runner.js +136 -0
  21. package/dist/index.js +10 -0
  22. package/dist/reporting/index.js +43 -0
  23. package/package.json +19 -101
  24. package/LICENSE +0 -21
  25. package/lib/actions/clickSteps.d.ts +0 -251
  26. package/lib/actions/clickSteps.js +0 -415
  27. package/lib/actions/cookieSteps.d.ts +0 -18
  28. package/lib/actions/cookieSteps.js +0 -93
  29. package/lib/actions/debugSteps.d.ts +0 -14
  30. package/lib/actions/debugSteps.js +0 -23
  31. package/lib/actions/elementFindSteps.d.ts +0 -668
  32. package/lib/actions/elementFindSteps.js +0 -931
  33. package/lib/actions/fillFormSteps.d.ts +0 -69
  34. package/lib/actions/fillFormSteps.js +0 -237
  35. package/lib/actions/index.d.ts +0 -11
  36. package/lib/actions/index.js +0 -28
  37. package/lib/actions/inputSteps.d.ts +0 -218
  38. package/lib/actions/inputSteps.js +0 -343
  39. package/lib/actions/interceptionSteps.d.ts +0 -169
  40. package/lib/actions/interceptionSteps.js +0 -291
  41. package/lib/actions/miscSteps.d.ts +0 -645
  42. package/lib/actions/miscSteps.js +0 -1061
  43. package/lib/actions/mouseSteps.d.ts +0 -143
  44. package/lib/actions/mouseSteps.js +0 -234
  45. package/lib/actions/scrollSteps.d.ts +0 -82
  46. package/lib/actions/scrollSteps.js +0 -123
  47. package/lib/actions/storageSteps.d.ts +0 -174
  48. package/lib/actions/storageSteps.js +0 -292
  49. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -245
  50. package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -401
  51. package/lib/assertions/cookieSteps.d.ts +0 -75
  52. package/lib/assertions/cookieSteps.js +0 -113
  53. package/lib/assertions/elementSteps.d.ts +0 -264
  54. package/lib/assertions/elementSteps.js +0 -388
  55. package/lib/assertions/formInputSteps.d.ts +0 -248
  56. package/lib/assertions/formInputSteps.js +0 -350
  57. package/lib/assertions/index.d.ts +0 -10
  58. package/lib/assertions/index.js +0 -27
  59. package/lib/assertions/interceptionRequestsSteps.d.ts +0 -353
  60. package/lib/assertions/interceptionRequestsSteps.js +0 -593
  61. package/lib/assertions/locationSteps.d.ts +0 -217
  62. package/lib/assertions/locationSteps.js +0 -310
  63. package/lib/assertions/roleTestIdSteps.d.ts +0 -159
  64. package/lib/assertions/roleTestIdSteps.js +0 -221
  65. package/lib/assertions/semanticSteps.d.ts +0 -176
  66. package/lib/assertions/semanticSteps.js +0 -252
  67. package/lib/assertions/storageSteps.d.ts +0 -149
  68. package/lib/assertions/storageSteps.js +0 -210
  69. package/lib/assertions/visualSteps.d.ts +0 -74
  70. package/lib/assertions/visualSteps.js +0 -209
  71. package/lib/custom_setups/loginHooks.d.ts +0 -1
  72. package/lib/custom_setups/loginHooks.js +0 -130
  73. package/lib/helpers/checkPeerDeps.d.ts +0 -1
  74. package/lib/helpers/checkPeerDeps.js +0 -19
  75. package/lib/helpers/compareSnapshots.d.ts +0 -6
  76. package/lib/helpers/compareSnapshots.js +0 -20
  77. package/lib/helpers/hooks.d.ts +0 -1
  78. package/lib/helpers/hooks.js +0 -210
  79. package/lib/helpers/utils/fakerUtils.d.ts +0 -1
  80. package/lib/helpers/utils/fakerUtils.js +0 -60
  81. package/lib/helpers/utils/index.d.ts +0 -4
  82. package/lib/helpers/utils/index.js +0 -20
  83. package/lib/helpers/utils/optionsUtils.d.ts +0 -24
  84. package/lib/helpers/utils/optionsUtils.js +0 -88
  85. package/lib/helpers/utils/resolveUtils.d.ts +0 -6
  86. package/lib/helpers/utils/resolveUtils.js +0 -72
  87. package/lib/helpers/utils/sessionUtils.d.ts +0 -3
  88. package/lib/helpers/utils/sessionUtils.js +0 -40
  89. package/lib/helpers/world.d.ts +0 -34
  90. package/lib/helpers/world.js +0 -110
  91. package/lib/iframes/frames.d.ts +0 -1
  92. package/lib/iframes/frames.js +0 -11
  93. package/lib/index.d.ts +0 -10
  94. package/lib/index.js +0 -28
  95. package/lib/register.d.ts +0 -1
  96. package/lib/register.js +0 -6
  97. package/src/actions/clickSteps.ts +0 -429
  98. package/src/actions/cookieSteps.ts +0 -95
  99. package/src/actions/debugSteps.ts +0 -21
  100. package/src/actions/elementFindSteps.ts +0 -961
  101. package/src/actions/fillFormSteps.ts +0 -270
  102. package/src/actions/index.ts +0 -12
  103. package/src/actions/inputSteps.ts +0 -354
  104. package/src/actions/interceptionSteps.ts +0 -325
  105. package/src/actions/miscSteps.ts +0 -1144
  106. package/src/actions/mouseSteps.ts +0 -256
  107. package/src/actions/scrollSteps.ts +0 -122
  108. package/src/actions/storageSteps.ts +0 -308
  109. package/src/assertions/buttonAndTextVisibilitySteps.ts +0 -436
  110. package/src/assertions/cookieSteps.ts +0 -131
  111. package/src/assertions/elementSteps.ts +0 -432
  112. package/src/assertions/formInputSteps.ts +0 -377
  113. package/src/assertions/index.ts +0 -11
  114. package/src/assertions/interceptionRequestsSteps.ts +0 -640
  115. package/src/assertions/locationSteps.ts +0 -315
  116. package/src/assertions/roleTestIdSteps.ts +0 -254
  117. package/src/assertions/semanticSteps.ts +0 -267
  118. package/src/assertions/storageSteps.ts +0 -250
  119. package/src/assertions/visualSteps.ts +0 -275
  120. package/src/custom_setups/loginHooks.ts +0 -154
  121. package/src/helpers/checkPeerDeps.ts +0 -19
  122. package/src/helpers/compareSnapshots.ts +0 -35
  123. package/src/helpers/hooks.ts +0 -212
  124. package/src/helpers/utils/fakerUtils.ts +0 -64
  125. package/src/helpers/utils/index.ts +0 -4
  126. package/src/helpers/utils/optionsUtils.ts +0 -104
  127. package/src/helpers/utils/resolveUtils.ts +0 -74
  128. package/src/helpers/utils/sessionUtils.ts +0 -36
  129. package/src/helpers/world.ts +0 -119
  130. package/src/iframes/frames.ts +0 -15
  131. package/src/index.ts +0 -18
  132. package/src/register.ts +0 -4
@@ -1,149 +0,0 @@
1
- import type { CustomWorld } from "../helpers/world";
2
- /**
3
- * Asserts that a Local Storage item with the given key exists for the current page's origin.
4
- *
5
- * ```gherkin
6
- * Then I see local storage item {string}
7
- * ```
8
- *
9
- * @param key - The key of the Local Storage item expected to exist.
10
- *
11
- * @example
12
- * Then I see local storage item "token"
13
- *
14
- * @remarks
15
- * This step executes `localStorage.getItem(key)` in the browser's context.
16
- * It asserts that the returned value is not `null`, indicating the item exists.
17
- * @category Storage Assertion Steps
18
- */
19
- export declare function Then_I_see_local_storage_item(this: CustomWorld, key: string): Promise<void>;
20
- /**
21
- * Asserts that a Local Storage item with the given key does NOT exist for the current page's origin.
22
- *
23
- * ```gherkin
24
- * Then I do not see local storage item {string}
25
- * ```
26
- *
27
- * @param key - The key of the Local Storage item expected NOT to exist.
28
- *
29
- * @example
30
- * Then I do not see local storage item "oldFeatureFlag"
31
- *
32
- * @remarks
33
- * This step executes `localStorage.getItem(key)` in the browser's context.
34
- * It asserts that the returned value is strictly `null`, indicating the item does not exist.
35
- * @category Storage Assertion Steps
36
- */
37
- export declare function Then_I_do_not_see_local_storage_item(this: CustomWorld, key: string): Promise<void>;
38
- /**
39
- * Asserts that a Local Storage item with the given key exactly equals the expected value.
40
- *
41
- * ```gherkin
42
- * Then I see local storage item {string} equals {string}
43
- * ```
44
- *
45
- * @param key - The key of the Local Storage item.
46
- * @param expectedValue - The exact value the item is expected to have.
47
- *
48
- * @example
49
- * Then I see local storage item "token" equals "abc123"
50
- *
51
- * @remarks
52
- * This step executes `localStorage.getItem(key)` in the browser's context.
53
- * It asserts strict equality between the retrieved value and `expectedValue`.
54
- * @category Storage Assertion Steps
55
- */
56
- export declare function Then_I_see_local_storage_item_equals(this: CustomWorld, key: string, expectedValue: string): Promise<void>;
57
- /**
58
- * Asserts that a Local Storage item with the given key contains the expected substring.
59
- *
60
- * ```gherkin
61
- * Then I see local storage item {string} contains {string}
62
- * ```
63
- *
64
- * @param key - The key of the Local Storage item.
65
- * @param part - The substring expected to be contained within the item's value.
66
- *
67
- * @example
68
- * Then I see local storage item "userSession" contains "loggedIn"
69
- *
70
- * @remarks
71
- * This step executes `localStorage.getItem(key)` in the browser's context.
72
- * It asserts that the retrieved value (if not null) includes the `part` substring.
73
- * @category Storage Assertion Steps
74
- */
75
- export declare function Then_I_see_local_storage_item_contains(this: CustomWorld, key: string, part: string): Promise<void>;
76
- /**
77
- * Asserts that a Session Storage item with the given key exists for the current page's origin.
78
- *
79
- * ```gherkin
80
- * Then I see session storage item {string}
81
- * ```
82
- *
83
- * @param key - The key of the Session Storage item expected to exist.
84
- *
85
- * @example
86
- * Then I see session storage item "sessionId"
87
- *
88
- * @remarks
89
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
90
- * It asserts that the returned value is not `null`, indicating the item exists.
91
- * @category Storage Assertion Steps
92
- */
93
- export declare function Then_I_see_session_storage_item(this: CustomWorld, key: string): Promise<void>;
94
- /**
95
- * Asserts that a Session Storage item with the given key does NOT exist for the current page's origin.
96
- *
97
- * ```gherkin
98
- * Then I do not see session storage item {string}
99
- * ```
100
- *
101
- * @param key - The key of the Session Storage item expected NOT to exist.
102
- *
103
- * @example
104
- * Then I do not see session storage item "tempData"
105
- *
106
- * @remarks
107
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
108
- * It asserts that the returned value is strictly `null`, indicating the item does not exist.
109
- * @category Storage Assertion Steps
110
- */
111
- export declare function Then_I_do_not_see_session_storage_item(this: CustomWorld, key: string): Promise<void>;
112
- /**
113
- * Asserts that a Session Storage item with the given key exactly equals the expected value.
114
- *
115
- * ```gherkin
116
- * Then I see session storage item {string} equals {string}
117
- * ```
118
- *
119
- * @param key - The key of the Session Storage item.
120
- * @param expectedValue - The exact value the item is expected to have.
121
- *
122
- * @example
123
- * Then I see session storage item "sessionId" equals "xyz789"
124
- *
125
- * @remarks
126
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
127
- * It asserts strict equality between the retrieved value and `expectedValue`.
128
- * @category Storage Assertion Steps
129
- */
130
- export declare function Then_I_see_session_storage_item_equals(this: CustomWorld, key: string, expectedValue: string): Promise<void>;
131
- /**
132
- * Asserts that a Session Storage item with the given key contains the expected substring.
133
- *
134
- * ```gherkin
135
- * Then I see session storage item {string} contains {string}
136
- * ```
137
- *
138
- * @param key - The key of the Session Storage item.
139
- * @param part - The substring expected to be contained within the item's value.
140
- *
141
- * @example
142
- * Then I see session storage item "userState" contains "authenticated"
143
- *
144
- * @remarks
145
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
146
- * It asserts that the retrieved value (if not null) includes the `part` substring.
147
- * @category Storage Assertion Steps
148
- */
149
- export declare function Then_I_see_session_storage_item_contains(this: CustomWorld, key: string, part: string): Promise<void>;
@@ -1,210 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Then_I_see_local_storage_item = Then_I_see_local_storage_item;
4
- exports.Then_I_do_not_see_local_storage_item = Then_I_do_not_see_local_storage_item;
5
- exports.Then_I_see_local_storage_item_equals = Then_I_see_local_storage_item_equals;
6
- exports.Then_I_see_local_storage_item_contains = Then_I_see_local_storage_item_contains;
7
- exports.Then_I_see_session_storage_item = Then_I_see_session_storage_item;
8
- exports.Then_I_do_not_see_session_storage_item = Then_I_do_not_see_session_storage_item;
9
- exports.Then_I_see_session_storage_item_equals = Then_I_see_session_storage_item_equals;
10
- exports.Then_I_see_session_storage_item_contains = Then_I_see_session_storage_item_contains;
11
- // import fs from "fs";
12
- // import path from "path";
13
- const cucumber_1 = require("@cucumber/cucumber");
14
- const test_1 = require("@playwright/test"); // Import expect for assertions
15
- // ===================================================================================
16
- // ASSERTIONS: LOCAL STORAGE
17
- // ===================================================================================
18
- /**
19
- * Asserts that a Local Storage item with the given key exists for the current page's origin.
20
- *
21
- * ```gherkin
22
- * Then I see local storage item {string}
23
- * ```
24
- *
25
- * @param key - The key of the Local Storage item expected to exist.
26
- *
27
- * @example
28
- * Then I see local storage item "token"
29
- *
30
- * @remarks
31
- * This step executes `localStorage.getItem(key)` in the browser's context.
32
- * It asserts that the returned value is not `null`, indicating the item exists.
33
- * @category Storage Assertion Steps
34
- */
35
- async function Then_I_see_local_storage_item(key) {
36
- const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
37
- (0, test_1.expect)(value, `Local storage item "${key}" should exist but was not found.`).not.toBeNull();
38
- this.log?.(`✅ Verified local storage item "${key}" exists.`);
39
- }
40
- (0, cucumber_1.Then)("I see local storage item {string}", Then_I_see_local_storage_item);
41
- /**
42
- * Asserts that a Local Storage item with the given key does NOT exist for the current page's origin.
43
- *
44
- * ```gherkin
45
- * Then I do not see local storage item {string}
46
- * ```
47
- *
48
- * @param key - The key of the Local Storage item expected NOT to exist.
49
- *
50
- * @example
51
- * Then I do not see local storage item "oldFeatureFlag"
52
- *
53
- * @remarks
54
- * This step executes `localStorage.getItem(key)` in the browser's context.
55
- * It asserts that the returned value is strictly `null`, indicating the item does not exist.
56
- * @category Storage Assertion Steps
57
- */
58
- async function Then_I_do_not_see_local_storage_item(key) {
59
- const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
60
- (0, test_1.expect)(value, `Expected localStorage["${key}"] to be null, but it exists with value "${value}".`).toBeNull();
61
- this.log?.(`✅ Verified local storage item "${key}" does NOT exist.`);
62
- }
63
- (0, cucumber_1.Then)("I do not see local storage item {string}", Then_I_do_not_see_local_storage_item);
64
- /**
65
- * Asserts that a Local Storage item with the given key exactly equals the expected value.
66
- *
67
- * ```gherkin
68
- * Then I see local storage item {string} equals {string}
69
- * ```
70
- *
71
- * @param key - The key of the Local Storage item.
72
- * @param expectedValue - The exact value the item is expected to have.
73
- *
74
- * @example
75
- * Then I see local storage item "token" equals "abc123"
76
- *
77
- * @remarks
78
- * This step executes `localStorage.getItem(key)` in the browser's context.
79
- * It asserts strict equality between the retrieved value and `expectedValue`.
80
- * @category Storage Assertion Steps
81
- */
82
- async function Then_I_see_local_storage_item_equals(key, expectedValue) {
83
- const actualValue = await this.page.evaluate((k) => localStorage.getItem(k), key);
84
- (0, test_1.expect)(actualValue, `Expected localStorage["${key}"] to be "${expectedValue}", but got "${actualValue}".`).toBe(expectedValue);
85
- this.log?.(`✅ Verified local storage item "${key}" equals "${expectedValue}".`);
86
- }
87
- (0, cucumber_1.Then)("I see local storage item {string} equals {string}", Then_I_see_local_storage_item_equals);
88
- /**
89
- * Asserts that a Local Storage item with the given key contains the expected substring.
90
- *
91
- * ```gherkin
92
- * Then I see local storage item {string} contains {string}
93
- * ```
94
- *
95
- * @param key - The key of the Local Storage item.
96
- * @param part - The substring expected to be contained within the item's value.
97
- *
98
- * @example
99
- * Then I see local storage item "userSession" contains "loggedIn"
100
- *
101
- * @remarks
102
- * This step executes `localStorage.getItem(key)` in the browser's context.
103
- * It asserts that the retrieved value (if not null) includes the `part` substring.
104
- * @category Storage Assertion Steps
105
- */
106
- async function Then_I_see_local_storage_item_contains(key, part) {
107
- const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
108
- (0, test_1.expect)(value, `Local storage item "${key}" not found or is null. Expected to contain "${part}".`).not.toBeNull();
109
- (0, test_1.expect)(value, `localStorage["${key}"] ("${value}") does not contain "${part}".`).toContain(part);
110
- this.log?.(`✅ Verified local storage item "${key}" contains "${part}".`);
111
- }
112
- (0, cucumber_1.Then)("I see local storage item {string} contains {string}", Then_I_see_local_storage_item_contains);
113
- // ===================================================================================
114
- // ASSERTIONS: SESSION STORAGE
115
- // ===================================================================================
116
- /**
117
- * Asserts that a Session Storage item with the given key exists for the current page's origin.
118
- *
119
- * ```gherkin
120
- * Then I see session storage item {string}
121
- * ```
122
- *
123
- * @param key - The key of the Session Storage item expected to exist.
124
- *
125
- * @example
126
- * Then I see session storage item "sessionId"
127
- *
128
- * @remarks
129
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
130
- * It asserts that the returned value is not `null`, indicating the item exists.
131
- * @category Storage Assertion Steps
132
- */
133
- async function Then_I_see_session_storage_item(key) {
134
- const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
135
- (0, test_1.expect)(value, `Session storage item "${key}" should exist but was not found.`).not.toBeNull();
136
- this.log?.(`✅ Verified session storage item "${key}" exists.`);
137
- }
138
- (0, cucumber_1.Then)("I see session storage item {string}", Then_I_see_session_storage_item);
139
- /**
140
- * Asserts that a Session Storage item with the given key does NOT exist for the current page's origin.
141
- *
142
- * ```gherkin
143
- * Then I do not see session storage item {string}
144
- * ```
145
- *
146
- * @param key - The key of the Session Storage item expected NOT to exist.
147
- *
148
- * @example
149
- * Then I do not see session storage item "tempData"
150
- *
151
- * @remarks
152
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
153
- * It asserts that the returned value is strictly `null`, indicating the item does not exist.
154
- * @category Storage Assertion Steps
155
- */
156
- async function Then_I_do_not_see_session_storage_item(key) {
157
- const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
158
- (0, test_1.expect)(value, `Expected sessionStorage["${key}"] to be null, but it exists with value "${value}".`).toBeNull();
159
- this.log?.(`✅ Verified session storage item "${key}" does NOT exist.`);
160
- }
161
- (0, cucumber_1.Then)("I do not see session storage item {string}", Then_I_do_not_see_session_storage_item);
162
- /**
163
- * Asserts that a Session Storage item with the given key exactly equals the expected value.
164
- *
165
- * ```gherkin
166
- * Then I see session storage item {string} equals {string}
167
- * ```
168
- *
169
- * @param key - The key of the Session Storage item.
170
- * @param expectedValue - The exact value the item is expected to have.
171
- *
172
- * @example
173
- * Then I see session storage item "sessionId" equals "xyz789"
174
- *
175
- * @remarks
176
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
177
- * It asserts strict equality between the retrieved value and `expectedValue`.
178
- * @category Storage Assertion Steps
179
- */
180
- async function Then_I_see_session_storage_item_equals(key, expectedValue) {
181
- const actualValue = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
182
- (0, test_1.expect)(actualValue, `Expected sessionStorage["${key}"] to be "${expectedValue}", but got "${actualValue}".`).toBe(expectedValue);
183
- this.log?.(`✅ Verified session storage item "${key}" equals "${expectedValue}".`);
184
- }
185
- (0, cucumber_1.Then)("I see session storage item {string} equals {string}", Then_I_see_session_storage_item_equals);
186
- /**
187
- * Asserts that a Session Storage item with the given key contains the expected substring.
188
- *
189
- * ```gherkin
190
- * Then I see session storage item {string} contains {string}
191
- * ```
192
- *
193
- * @param key - The key of the Session Storage item.
194
- * @param part - The substring expected to be contained within the item's value.
195
- *
196
- * @example
197
- * Then I see session storage item "userState" contains "authenticated"
198
- *
199
- * @remarks
200
- * This step executes `sessionStorage.getItem(key)` in the browser's context.
201
- * It asserts that the retrieved value (if not null) includes the `part` substring.
202
- * @category Storage Assertion Steps
203
- */
204
- async function Then_I_see_session_storage_item_contains(key, part) {
205
- const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
206
- (0, test_1.expect)(value, `Session storage item "${key}" not found or is null. Expected to contain "${part}".`).not.toBeNull();
207
- (0, test_1.expect)(value, `sessionStorage["${key}"] ("${value}") does not contain "${part}".`).toContain(part);
208
- this.log?.(`✅ Verified session storage item "${key}" contains "${part}".`);
209
- }
210
- (0, cucumber_1.Then)("I see session storage item {string} contains {string}", Then_I_see_session_storage_item_contains);
@@ -1,74 +0,0 @@
1
- import type { CustomWorld } from "../helpers/world";
2
- /**
3
- * Asserts that the current page's visual appearance matches a named baseline snapshot.
4
- * If no baseline exists for the given name, a new one is created from the current page.
5
- * Differences between current and baseline snapshots are highlighted in a 'diff' image.
6
- *
7
- * ```gherkin
8
- * Then I should see the page matches the snapshot {string}
9
- * ```
10
- *
11
- * @param name - A unique name for the snapshot (e.g., "homepage", "product-details-page").
12
- *
13
- * @example
14
- * Then I should see the page matches the snapshot "homepage"
15
- *
16
- * @remarks
17
- * This is a core step for visual regression testing.
18
- * 1. Takes a screenshot of the current page and saves it to the `current` directory.
19
- * 2. If a `baseline` snapshot does not exist, the `current` snapshot is copied to `baseline`,
20
- * and the test passes (a new baseline is established).
21
- * 3. If a `baseline` exists, it compares the `current` and `baseline` snapshots pixel by pixel
22
- * using `pixelmatch`.
23
- * 4. If a mismatch is detected (more than 0 differing pixels based on `threshold`), a `diff`
24
- * image is generated, and the test fails.
25
- *
26
- * All snapshots (baseline, current, diff) are stored in `e2e/snapshots/`.
27
- * Adjust `threshold` for sensitivity (0.1 means 10% difference in pixel color is allowed).
28
- * @category Visual Regression Steps
29
- */
30
- export declare function Then_I_should_see_page_matches_snapshot(this: CustomWorld, name: string): Promise<void>;
31
- /**
32
- * Captures a visual snapshot of a specific element identified by its selector and saves it under a given alias.
33
- * This snapshot is saved to the `current` directory and can later be compared against a baseline.
34
- *
35
- * ```gherkin
36
- * Then I capture a snapshot of the element {string} as {string}
37
- * ```
38
- *
39
- * @param selector - The CSS selector of the element to capture.
40
- * @param alias - A unique alias name for this element snapshot (e.g., "logo-image", "product-card").
41
- *
42
- * @example
43
- * Then I capture a snapshot of the element ".header .logo" as "logo-snapshot"
44
- * Then I capture a snapshot of the element "#user-profile" as "user-profile-widget"
45
- *
46
- * @remarks
47
- * This step is typically followed by {@link Then_the_snapshot_should_match_baseline | "Then the snapshot {string} should match baseline"}
48
- * to perform the actual visual comparison.
49
- * @category Visual Regression Steps
50
- */
51
- export declare function Then_I_capture_element_snapshot_as_alias(this: CustomWorld, selector: string, alias: string): Promise<void>;
52
- /**
53
- * Asserts that a previously captured named snapshot (of an element) matches its baseline.
54
- * If no baseline exists, a new one is created from the current snapshot.
55
- *
56
- * ```gherkin
57
- * Then The snapshot {string} should match baseline
58
- * ```
59
- *
60
- * @param alias - The unique alias name of the snapshot (as used in "Then I capture a snapshot...").
61
- *
62
- * @example
63
- * Then I capture a snapshot of the element ".logo" as "logo-snapshot"
64
- * Then The snapshot "logo-snapshot" should match baseline
65
- *
66
- * @remarks
67
- * This step is designed to be used after a step like
68
- * {@link Then_I_capture_element_snapshot_as_alias | "Then I capture a snapshot of the element {string} as {string}"}.
69
- * It performs the same comparison logic as `Then I should see the page matches the snapshot`,
70
- * but specifically for an element snapshot.
71
- * All snapshots (baseline, current, diff) are stored in `e2e/snapshots/`.
72
- * @category Visual Regression Steps
73
- */
74
- export declare function Then_the_snapshot_should_match_baseline(this: CustomWorld, alias: string): Promise<void>;
@@ -1,209 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Then_I_should_see_page_matches_snapshot = Then_I_should_see_page_matches_snapshot;
7
- exports.Then_I_capture_element_snapshot_as_alias = Then_I_capture_element_snapshot_as_alias;
8
- exports.Then_the_snapshot_should_match_baseline = Then_the_snapshot_should_match_baseline;
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
11
- const cucumber_1 = require("@cucumber/cucumber");
12
- const test_1 = require("@playwright/test");
13
- const pixelmatch_1 = __importDefault(require("pixelmatch")); // Ensure pixelmatch is installed: npm install pixelmatch
14
- const pngjs_1 = require("pngjs"); // Ensure pngjs is installed: npm install pngjs
15
- // --- Configuration for Snapshot Directories ---
16
- // It's good practice to make these configurable (e.g., via world.config or env variables)
17
- // For now, keeping them as resolved constants as per your original code.
18
- const SNAPSHOTS_BASE_DIR = path_1.default.resolve("e2e/snapshots"); // Base directory for all snapshots
19
- const BASELINE_DIR = path_1.default.join(SNAPSHOTS_BASE_DIR, "baseline");
20
- const CURRENT_DIR = path_1.default.join(SNAPSHOTS_BASE_DIR, "current");
21
- const DIFF_DIR = path_1.default.join(SNAPSHOTS_BASE_DIR, "diff");
22
- // Helper function to generate standardized snapshot paths
23
- function getSnapshotPaths(name) {
24
- // Sanitize the name for use in filenames
25
- const safeName = name.replace(/[^a-z0-9]/gi, "_").toLowerCase();
26
- return {
27
- baseline: path_1.default.join(BASELINE_DIR, `${safeName}.png`),
28
- current: path_1.default.join(CURRENT_DIR, `${safeName}.png`),
29
- diff: path_1.default.join(DIFF_DIR, `${safeName}.diff.png`),
30
- };
31
- }
32
- // Helper to ensure all necessary directories exist
33
- function ensureSnapshotDirs() {
34
- fs_1.default.mkdirSync(BASELINE_DIR, { recursive: true });
35
- fs_1.default.mkdirSync(CURRENT_DIR, { recursive: true });
36
- fs_1.default.mkdirSync(DIFF_DIR, { recursive: true });
37
- }
38
- // ===================================================================================
39
- // VISUAL REGRESSION ASSERTIONS: PAGE SNAPSHOTS
40
- // ===================================================================================
41
- /**
42
- * Asserts that the current page's visual appearance matches a named baseline snapshot.
43
- * If no baseline exists for the given name, a new one is created from the current page.
44
- * Differences between current and baseline snapshots are highlighted in a 'diff' image.
45
- *
46
- * ```gherkin
47
- * Then I should see the page matches the snapshot {string}
48
- * ```
49
- *
50
- * @param name - A unique name for the snapshot (e.g., "homepage", "product-details-page").
51
- *
52
- * @example
53
- * Then I should see the page matches the snapshot "homepage"
54
- *
55
- * @remarks
56
- * This is a core step for visual regression testing.
57
- * 1. Takes a screenshot of the current page and saves it to the `current` directory.
58
- * 2. If a `baseline` snapshot does not exist, the `current` snapshot is copied to `baseline`,
59
- * and the test passes (a new baseline is established).
60
- * 3. If a `baseline` exists, it compares the `current` and `baseline` snapshots pixel by pixel
61
- * using `pixelmatch`.
62
- * 4. If a mismatch is detected (more than 0 differing pixels based on `threshold`), a `diff`
63
- * image is generated, and the test fails.
64
- *
65
- * All snapshots (baseline, current, diff) are stored in `e2e/snapshots/`.
66
- * Adjust `threshold` for sensitivity (0.1 means 10% difference in pixel color is allowed).
67
- * @category Visual Regression Steps
68
- */
69
- async function Then_I_should_see_page_matches_snapshot(name) {
70
- const { page } = this;
71
- const paths = getSnapshotPaths(name);
72
- ensureSnapshotDirs(); // Ensure directories exist before taking screenshot
73
- // Take current screenshot
74
- await page.screenshot({ path: paths.current, fullPage: true });
75
- this.log?.(`📸 Captured current snapshot: "${paths.current}".`);
76
- if (!fs_1.default.existsSync(paths.baseline)) {
77
- // If no baseline exists, create one from the current screenshot
78
- fs_1.default.copyFileSync(paths.current, paths.baseline);
79
- this.log?.(`✨ Created new baseline snapshot: "${paths.baseline}".`);
80
- return; // Pass the test if a new baseline was created
81
- }
82
- // Load baseline and current images for comparison
83
- const baselineImg = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(paths.baseline));
84
- const currentImg = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(paths.current));
85
- // Ensure images have the same dimensions for comparison
86
- if (baselineImg.width !== currentImg.width || baselineImg.height !== currentImg.height) {
87
- fs_1.default.writeFileSync(paths.diff, pngjs_1.PNG.sync.write(new pngjs_1.PNG({
88
- width: Math.max(baselineImg.width, currentImg.width),
89
- height: Math.max(baselineImg.height, currentImg.height),
90
- })));
91
- throw new Error(`Visual snapshot mismatch for "${name}": Dimensions differ! ` +
92
- `Baseline: ${baselineImg.width}x${baselineImg.height}, Current: ${currentImg.width}x${currentImg.height}. ` +
93
- `Diff image generated at "${paths.diff}".`);
94
- }
95
- const { width, height } = baselineImg;
96
- const diffImg = new pngjs_1.PNG({ width, height });
97
- // Compare images pixel by pixel
98
- const pixelDiff = (0, pixelmatch_1.default)(baselineImg.data, currentImg.data, diffImg.data, width, height, { threshold: 0.1 } // Adjust threshold for sensitivity (0.1 means 10% difference in pixel color is allowed)
99
- );
100
- if (pixelDiff > 0) {
101
- // If differences found, write the diff image
102
- fs_1.default.writeFileSync(paths.diff, pngjs_1.PNG.sync.write(diffImg));
103
- this.log?.(`❌ Visual mismatch detected for "${name}". ${pixelDiff} pixels differ. Diff image: "${paths.diff}".`);
104
- }
105
- // Assert that no pixels differ
106
- (0, test_1.expect)(pixelDiff, `Visual snapshot "${name}" mismatch: ${pixelDiff} pixels differ.`).toBe(0);
107
- this.log?.(`✅ Visual snapshot "${name}" matches baseline (0 pixels differ).`);
108
- }
109
- (0, cucumber_1.Then)("I should see the page matches the snapshot {string}", Then_I_should_see_page_matches_snapshot);
110
- // ===================================================================================
111
- // VISUAL REGRESSION: ELEMENT SNAPSHOT CAPTURE & MATCH
112
- // ===================================================================================
113
- /**
114
- * Captures a visual snapshot of a specific element identified by its selector and saves it under a given alias.
115
- * This snapshot is saved to the `current` directory and can later be compared against a baseline.
116
- *
117
- * ```gherkin
118
- * Then I capture a snapshot of the element {string} as {string}
119
- * ```
120
- *
121
- * @param selector - The CSS selector of the element to capture.
122
- * @param alias - A unique alias name for this element snapshot (e.g., "logo-image", "product-card").
123
- *
124
- * @example
125
- * Then I capture a snapshot of the element ".header .logo" as "logo-snapshot"
126
- * Then I capture a snapshot of the element "#user-profile" as "user-profile-widget"
127
- *
128
- * @remarks
129
- * This step is typically followed by {@link Then_the_snapshot_should_match_baseline | "Then the snapshot {string} should match baseline"}
130
- * to perform the actual visual comparison.
131
- * @category Visual Regression Steps
132
- */
133
- async function Then_I_capture_element_snapshot_as_alias(selector, alias) {
134
- const elementLocator = this.getScope().locator(selector);
135
- ensureSnapshotDirs(); // Ensure directories exist
136
- const pathCurrent = path_1.default.join(CURRENT_DIR, `${alias}.png`);
137
- await elementLocator.screenshot({ path: pathCurrent });
138
- this.log?.(`📸 Captured snapshot of element "${selector}" saved as "${alias}".`);
139
- }
140
- (0, cucumber_1.Then)("I capture a snapshot of the element {string} as {string}", Then_I_capture_element_snapshot_as_alias);
141
- /**
142
- * Asserts that a previously captured named snapshot (of an element) matches its baseline.
143
- * If no baseline exists, a new one is created from the current snapshot.
144
- *
145
- * ```gherkin
146
- * Then The snapshot {string} should match baseline
147
- * ```
148
- *
149
- * @param alias - The unique alias name of the snapshot (as used in "Then I capture a snapshot...").
150
- *
151
- * @example
152
- * Then I capture a snapshot of the element ".logo" as "logo-snapshot"
153
- * Then The snapshot "logo-snapshot" should match baseline
154
- *
155
- * @remarks
156
- * This step is designed to be used after a step like
157
- * {@link Then_I_capture_element_snapshot_as_alias | "Then I capture a snapshot of the element {string} as {string}"}.
158
- * It performs the same comparison logic as `Then I should see the page matches the snapshot`,
159
- * but specifically for an element snapshot.
160
- * All snapshots (baseline, current, diff) are stored in `e2e/snapshots/`.
161
- * @category Visual Regression Steps
162
- */
163
- async function Then_the_snapshot_should_match_baseline(alias) {
164
- const paths = getSnapshotPaths(alias); // Get paths for baseline, current, diff based on alias
165
- ensureSnapshotDirs(); // Ensure directories exist
166
- // Check if the current snapshot file actually exists.
167
- // This is crucial because `Then I capture a snapshot` must have been run first.
168
- if (!fs_1.default.existsSync(paths.current)) {
169
- throw new Error(`Current snapshot file for alias "${alias}" not found at "${paths.current}".` +
170
- `Ensure "Then I capture a snapshot of the element {string} as {string}" was run successfully before this step.`);
171
- }
172
- // Load current image
173
- const currentImg = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(paths.current));
174
- let baselineImg = null;
175
- if (fs_1.default.existsSync(paths.baseline)) {
176
- // Load baseline image if it exists
177
- baselineImg = pngjs_1.PNG.sync.read(fs_1.default.readFileSync(paths.baseline));
178
- }
179
- if (!baselineImg) {
180
- // If no baseline exists, create one from the current snapshot
181
- fs_1.default.copyFileSync(paths.current, paths.baseline);
182
- this.log?.(`✨ Created new baseline for snapshot "${alias}": "${paths.baseline}".`);
183
- return; // Pass the test if a new baseline was created
184
- }
185
- // Ensure images have the same dimensions for comparison
186
- if (baselineImg.width !== currentImg.width || baselineImg.height !== currentImg.height) {
187
- fs_1.default.writeFileSync(paths.diff, pngjs_1.PNG.sync.write(new pngjs_1.PNG({
188
- width: Math.max(baselineImg.width, currentImg.width),
189
- height: Math.max(baselineImg.height, currentImg.height),
190
- })));
191
- throw new Error(`Visual element snapshot mismatch for "${alias}": Dimensions differ! ` +
192
- `Baseline: ${baselineImg.width}x${baselineImg.height}, Current: ${currentImg.width}x${currentImg.height}. ` +
193
- `Diff image generated at "${paths.diff}".`);
194
- }
195
- const { width, height } = baselineImg;
196
- const diffImg = new pngjs_1.PNG({ width, height });
197
- // Compare images pixel by pixel
198
- const pixelDiff = (0, pixelmatch_1.default)(baselineImg.data, currentImg.data, diffImg.data, width, height, { threshold: 0.1 } // Consistent threshold
199
- );
200
- if (pixelDiff > 0) {
201
- // If differences found, write the diff image
202
- fs_1.default.writeFileSync(paths.diff, pngjs_1.PNG.sync.write(diffImg));
203
- this.log?.(`❌ Visual mismatch detected for snapshot "${alias}". ${pixelDiff} pixels differ. Diff image: "${paths.diff}".`);
204
- }
205
- // Assert that no pixels differ
206
- (0, test_1.expect)(pixelDiff, `Visual element snapshot "${alias}" mismatch: ${pixelDiff} pixels differ.`).toBe(0);
207
- this.log?.(`✅ Visual element snapshot "${alias}" matches baseline (0 pixels differ).`);
208
- }
209
- (0, cucumber_1.Then)("The snapshot {string} should match baseline", Then_the_snapshot_should_match_baseline);
@@ -1 +0,0 @@
1
- export {};