playwright-cucumber-ts-steps 0.1.7 → 1.0.0
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.
- package/README.md +21 -11
- package/package.json +9 -2
- package/src/actions/clickSteps.ts +364 -142
- package/src/actions/cookieSteps.ts +66 -0
- package/src/actions/debugSteps.ts +17 -3
- package/src/actions/elementFindSteps.ts +822 -117
- package/src/actions/fillFormSteps.ts +234 -177
- package/src/actions/index.ts +12 -0
- package/src/actions/inputSteps.ts +318 -82
- package/src/actions/interceptionSteps.ts +295 -57
- package/src/actions/miscSteps.ts +984 -254
- package/src/actions/mouseSteps.ts +212 -55
- package/src/actions/scrollSteps.ts +114 -16
- package/src/actions/storageSteps.ts +267 -42
- package/src/assertions/buttonAndTextVisibilitySteps.ts +353 -95
- package/src/assertions/cookieSteps.ts +115 -36
- package/src/assertions/elementSteps.ts +414 -85
- package/src/assertions/formInputSteps.ts +375 -108
- package/src/assertions/index.ts +11 -0
- package/src/assertions/interceptionRequestsSteps.ts +619 -195
- package/src/assertions/locationSteps.ts +280 -64
- package/src/assertions/roleTestIdSteps.ts +244 -26
- package/src/assertions/semanticSteps.ts +257 -69
- package/src/assertions/storageSteps.ts +234 -73
- package/src/assertions/visualSteps.ts +245 -68
- package/src/custom_setups/loginHooks.ts +21 -2
- package/src/helpers/world.ts +30 -4
- package/src/index.ts +4 -25
- package/lib/actions/clickSteps.d.ts +0 -1
- package/lib/actions/clickSteps.js +0 -165
- package/lib/actions/cookieSteps.d.ts +0 -1
- package/lib/actions/cookieSteps.js +0 -28
- package/lib/actions/debugSteps.d.ts +0 -1
- package/lib/actions/debugSteps.js +0 -8
- package/lib/actions/elementFindSteps.d.ts +0 -1
- package/lib/actions/elementFindSteps.js +0 -217
- package/lib/actions/fillFormSteps.d.ts +0 -1
- package/lib/actions/fillFormSteps.js +0 -130
- package/lib/actions/inputSteps.d.ts +0 -1
- package/lib/actions/inputSteps.js +0 -97
- package/lib/actions/interceptionSteps.d.ts +0 -1
- package/lib/actions/interceptionSteps.js +0 -71
- package/lib/actions/miscSteps.d.ts +0 -1
- package/lib/actions/miscSteps.js +0 -320
- package/lib/actions/mouseSteps.d.ts +0 -1
- package/lib/actions/mouseSteps.js +0 -66
- package/lib/actions/scrollSteps.d.ts +0 -1
- package/lib/actions/scrollSteps.js +0 -23
- package/lib/actions/storageSteps.d.ts +0 -1
- package/lib/actions/storageSteps.js +0 -72
- package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -1
- package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -150
- package/lib/assertions/cookieSteps.d.ts +0 -1
- package/lib/assertions/cookieSteps.js +0 -45
- package/lib/assertions/elementSteps.d.ts +0 -1
- package/lib/assertions/elementSteps.js +0 -90
- package/lib/assertions/formInputSteps.d.ts +0 -1
- package/lib/assertions/formInputSteps.js +0 -87
- package/lib/assertions/interceptionRequestsSteps.d.ts +0 -1
- package/lib/assertions/interceptionRequestsSteps.js +0 -201
- package/lib/assertions/locationSteps.d.ts +0 -1
- package/lib/assertions/locationSteps.js +0 -87
- package/lib/assertions/roleTestIdSteps.d.ts +0 -1
- package/lib/assertions/roleTestIdSteps.js +0 -26
- package/lib/assertions/semanticSteps.d.ts +0 -1
- package/lib/assertions/semanticSteps.js +0 -67
- package/lib/assertions/storageSteps.d.ts +0 -1
- package/lib/assertions/storageSteps.js +0 -74
- package/lib/assertions/visualSteps.d.ts +0 -1
- package/lib/assertions/visualSteps.js +0 -76
- package/lib/custom_setups/loginHooks.d.ts +0 -1
- package/lib/custom_setups/loginHooks.js +0 -113
- package/lib/helpers/checkPeerDeps.d.ts +0 -1
- package/lib/helpers/checkPeerDeps.js +0 -19
- package/lib/helpers/compareSnapshots.d.ts +0 -6
- package/lib/helpers/compareSnapshots.js +0 -20
- package/lib/helpers/hooks.d.ts +0 -1
- package/lib/helpers/hooks.js +0 -210
- package/lib/helpers/utils/fakerUtils.d.ts +0 -1
- package/lib/helpers/utils/fakerUtils.js +0 -60
- package/lib/helpers/utils/index.d.ts +0 -4
- package/lib/helpers/utils/index.js +0 -20
- package/lib/helpers/utils/optionsUtils.d.ts +0 -24
- package/lib/helpers/utils/optionsUtils.js +0 -88
- package/lib/helpers/utils/resolveUtils.d.ts +0 -6
- package/lib/helpers/utils/resolveUtils.js +0 -72
- package/lib/helpers/utils/sessionUtils.d.ts +0 -3
- package/lib/helpers/utils/sessionUtils.js +0 -40
- package/lib/helpers/world.d.ts +0 -31
- package/lib/helpers/world.js +0 -104
- package/lib/iframes/frames.d.ts +0 -1
- package/lib/iframes/frames.js +0 -11
- package/lib/index.d.ts +0 -28
- package/lib/index.js +0 -48
- package/lib/register.d.ts +0 -1
- package/lib/register.js +0 -6
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// e2e/step_definitions/common/actions/cookieSteps.ts
|
|
4
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
-
(0, cucumber_1.When)("I clear all cookies", async function () {
|
|
6
|
-
await this.page.context().clearCookies();
|
|
7
|
-
this.log("Cleared all cookies");
|
|
8
|
-
});
|
|
9
|
-
(0, cucumber_1.When)("I clear cookies", async function () {
|
|
10
|
-
await this.page.context().clearCookies();
|
|
11
|
-
this.log("Cleared cookies (alias)");
|
|
12
|
-
});
|
|
13
|
-
(0, cucumber_1.When)("I clear cookie {string}", async function (name) {
|
|
14
|
-
await this.page.context().addCookies([
|
|
15
|
-
{
|
|
16
|
-
name,
|
|
17
|
-
value: "",
|
|
18
|
-
domain: new URL(this.page.url()).hostname,
|
|
19
|
-
path: "/",
|
|
20
|
-
expires: 0,
|
|
21
|
-
},
|
|
22
|
-
]);
|
|
23
|
-
this.log(`Cleared cookie: ${name}`);
|
|
24
|
-
});
|
|
25
|
-
(0, cucumber_1.When)("I log all cookies", async function () {
|
|
26
|
-
const cookies = await this.page.context().cookies();
|
|
27
|
-
console.log("Cookies:", cookies);
|
|
28
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// e2e/step_definitions/common/actions/debugSteps.ts
|
|
4
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
-
(0, cucumber_1.When)("I debug with message {string}", async function (message) {
|
|
6
|
-
await this.page.pause();
|
|
7
|
-
this.log(`Paused test for debugging: ${message}`);
|
|
8
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
4
|
-
const test_1 = require("@playwright/test");
|
|
5
|
-
// =============================
|
|
6
|
-
// WHEN I FIND ELEMENT(S)
|
|
7
|
-
// =============================
|
|
8
|
-
(0, cucumber_1.When)("I find element by selector {string}", async function (selector) {
|
|
9
|
-
this.element = this.page.locator(selector);
|
|
10
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
11
|
-
});
|
|
12
|
-
(0, cucumber_1.When)("I find link by text {string}", async function (text) {
|
|
13
|
-
this.currentLocator = this.getScope().getByRole("link", { name: text });
|
|
14
|
-
});
|
|
15
|
-
(0, cucumber_1.When)("I find heading by text {string}", async function (text) {
|
|
16
|
-
this.currentLocator = this.getScope().getByRole("heading", { name: text });
|
|
17
|
-
});
|
|
18
|
-
(0, cucumber_1.When)("I find headings by text {string}", async function (text) {
|
|
19
|
-
this.currentLocator = this.getScope().getByRole("heading", { name: text });
|
|
20
|
-
});
|
|
21
|
-
(0, cucumber_1.When)("I find elements by selector {string}", async function (selector) {
|
|
22
|
-
this.elements = this.page.locator(selector);
|
|
23
|
-
const count = await this.elements.count();
|
|
24
|
-
this.log?.(`Found ${count} elements with selector ${selector}`);
|
|
25
|
-
});
|
|
26
|
-
(0, cucumber_1.When)("I find element by text {string}", async function (text) {
|
|
27
|
-
this.element = this.page.getByText(text, { exact: true });
|
|
28
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
29
|
-
});
|
|
30
|
-
(0, cucumber_1.When)("I find element by title {string}", async function (title) {
|
|
31
|
-
this.element = this.page.getByTitle(title);
|
|
32
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
33
|
-
});
|
|
34
|
-
(0, cucumber_1.When)("I find element by testid {string}", async function (testid) {
|
|
35
|
-
this.element = this.page.getByTestId(testid);
|
|
36
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
37
|
-
});
|
|
38
|
-
(0, cucumber_1.When)("I find element by role {string}", async function (role) {
|
|
39
|
-
this.element = this.page.getByRole(role);
|
|
40
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
41
|
-
});
|
|
42
|
-
(0, cucumber_1.When)("I find element by placeholder text {string}", async function (text) {
|
|
43
|
-
this.element = this.page.getByPlaceholder(text);
|
|
44
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
45
|
-
});
|
|
46
|
-
(0, cucumber_1.When)("I find element by label text {string}", async function (label) {
|
|
47
|
-
this.element = this.page.getByLabel(label);
|
|
48
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
49
|
-
});
|
|
50
|
-
(0, cucumber_1.When)("I find elements by label text {string}", async function (label) {
|
|
51
|
-
this.currentLocator = this.getScope().getByLabel(label);
|
|
52
|
-
});
|
|
53
|
-
(0, cucumber_1.When)("I find element by alt text {string}", async function (alt) {
|
|
54
|
-
this.element = this.page.getByAltText(alt);
|
|
55
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
56
|
-
});
|
|
57
|
-
(0, cucumber_1.When)("I find element by name {string}", async function (name) {
|
|
58
|
-
this.element = this.page.getByRole("textbox", { name });
|
|
59
|
-
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
60
|
-
});
|
|
61
|
-
(0, cucumber_1.When)("I find elements by name {string}", async function (name) {
|
|
62
|
-
this.currentLocator = this.getScope().locator(`[name="${name}"]`);
|
|
63
|
-
});
|
|
64
|
-
(0, cucumber_1.When)("I find buttons by text {string}", async function (buttonText) {
|
|
65
|
-
// 🧠 Resolve alias
|
|
66
|
-
if (buttonText.startsWith("@")) {
|
|
67
|
-
const alias = buttonText.slice(1);
|
|
68
|
-
buttonText = this.data?.[alias];
|
|
69
|
-
if (!buttonText) {
|
|
70
|
-
throw new Error(`No value found for alias "@${alias}"`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// 🔍 Locate all matching buttons
|
|
74
|
-
this.elements = this.page.getByRole("button", {
|
|
75
|
-
name: buttonText,
|
|
76
|
-
exact: false,
|
|
77
|
-
});
|
|
78
|
-
this.log?.(`🔘 Stored all buttons matching text "${buttonText}"`);
|
|
79
|
-
});
|
|
80
|
-
// =============================
|
|
81
|
-
// WHEN I GET ELEMENT(S)
|
|
82
|
-
// =============================
|
|
83
|
-
(0, cucumber_1.When)("I get element by selector {string}", async function (selector) {
|
|
84
|
-
this.element = this.page.locator(selector).first();
|
|
85
|
-
});
|
|
86
|
-
(0, cucumber_1.When)("I get elements by selector {string}", async function (selector) {
|
|
87
|
-
this.elements = this.page.locator(selector);
|
|
88
|
-
});
|
|
89
|
-
(0, cucumber_1.When)("I get first element", async function () {
|
|
90
|
-
if (!this.elements)
|
|
91
|
-
throw new Error("No element collection found");
|
|
92
|
-
this.element = this.elements.first();
|
|
93
|
-
});
|
|
94
|
-
(0, cucumber_1.When)("I get last element", async function () {
|
|
95
|
-
if (!this.elements)
|
|
96
|
-
throw new Error("No element collection found");
|
|
97
|
-
this.element = this.elements.last();
|
|
98
|
-
});
|
|
99
|
-
(0, cucumber_1.When)(/^I get (\d+)(?:st|nd|rd|th) element$/, async function (index) {
|
|
100
|
-
if (!this.elements)
|
|
101
|
-
throw new Error("No elements stored to pick from");
|
|
102
|
-
const count = await this.elements.count();
|
|
103
|
-
if (index < 1 || index > count) {
|
|
104
|
-
throw new Error(`Cannot get element ${index} — only ${count} found`);
|
|
105
|
-
}
|
|
106
|
-
this.element = this.elements.nth(index - 1);
|
|
107
|
-
this.log?.(`Selected ${index} element from stored elements`);
|
|
108
|
-
});
|
|
109
|
-
(0, cucumber_1.When)("I find elements by role {string}", async function (role) {
|
|
110
|
-
const locator = this.page.getByRole(role);
|
|
111
|
-
const count = await locator.count();
|
|
112
|
-
if (count === 0) {
|
|
113
|
-
throw new Error(`No elements found with role "${role}"`);
|
|
114
|
-
}
|
|
115
|
-
this.elements = locator;
|
|
116
|
-
this.log?.(`Stored ${count} elements with role "${role}"`);
|
|
117
|
-
});
|
|
118
|
-
(0, cucumber_1.When)("I get {int}rd element", async function (index) {
|
|
119
|
-
if (!this.elements)
|
|
120
|
-
throw new Error("No element collection found");
|
|
121
|
-
this.element = this.elements.nth(index);
|
|
122
|
-
});
|
|
123
|
-
(0, cucumber_1.When)("I get focused element", async function () {
|
|
124
|
-
this.element = (await this.page.evaluateHandle(() => document.activeElement));
|
|
125
|
-
});
|
|
126
|
-
(0, cucumber_1.When)("I store element text as {string}", async function (alias) {
|
|
127
|
-
const element = this.element;
|
|
128
|
-
if (!element)
|
|
129
|
-
throw new Error("No element selected");
|
|
130
|
-
const text = await element.textContent();
|
|
131
|
-
this.data[alias] = text?.trim();
|
|
132
|
-
this.log?.(`Stored text "${text}" as "${alias}"`);
|
|
133
|
-
});
|
|
134
|
-
(0, cucumber_1.When)("I find textarea by label text {string}", async function (label) {
|
|
135
|
-
this.element = this.page.getByLabel(label);
|
|
136
|
-
this.log?.(`Stored textarea with label "${label}"`);
|
|
137
|
-
});
|
|
138
|
-
(0, cucumber_1.When)("I find textarea by placeholder text {string}", async function (placeholder) {
|
|
139
|
-
this.element = this.page.getByPlaceholder(placeholder);
|
|
140
|
-
this.log?.(`Stored textarea with placeholder "${placeholder}"`);
|
|
141
|
-
});
|
|
142
|
-
(0, cucumber_1.When)("I find textareas by label text {string}", async function (label) {
|
|
143
|
-
this.elements = this.page.locator(`label:has-text("${label}") + textarea`);
|
|
144
|
-
this.log?.(`Stored multiple textareas with label "${label}"`);
|
|
145
|
-
});
|
|
146
|
-
(0, cucumber_1.When)("I find textarea by name {string}", async function (name) {
|
|
147
|
-
this.element = this.page.locator(`textarea[name="${name}"]`);
|
|
148
|
-
this.log?.(`Stored textarea with name "${name}"`);
|
|
149
|
-
});
|
|
150
|
-
(0, cucumber_1.When)("I find textareas by ID {string}", async function (id) {
|
|
151
|
-
this.elements = this.page.locator(`textarea#${id}`);
|
|
152
|
-
this.log?.(`Stored multiple textareas with ID "${id}"`);
|
|
153
|
-
});
|
|
154
|
-
(0, cucumber_1.When)("I find input by ID {string}", async function (id) {
|
|
155
|
-
this.element = this.page.locator(`input#${id}`);
|
|
156
|
-
this.log?.(`Stored input with ID "${id}"`);
|
|
157
|
-
});
|
|
158
|
-
(0, cucumber_1.When)("I find inputs by ID {string}", async function (id) {
|
|
159
|
-
this.elements = this.page.locator(`input#${id}`);
|
|
160
|
-
this.log?.(`Stored multiple inputs with ID "${id}"`);
|
|
161
|
-
});
|
|
162
|
-
(0, cucumber_1.When)("I find textareas by placeholder text {string}", async function (placeholder) {
|
|
163
|
-
this.elements = this.page.locator(`textarea[placeholder="${placeholder}"]`);
|
|
164
|
-
this.log?.(`Stored multiple textareas with placeholder "${placeholder}"`);
|
|
165
|
-
});
|
|
166
|
-
(0, cucumber_1.When)("I find input by label text {string}", async function (label) {
|
|
167
|
-
this.element = this.page.getByLabel(label);
|
|
168
|
-
this.log?.(`Stored input with label "${label}"`);
|
|
169
|
-
});
|
|
170
|
-
(0, cucumber_1.When)("I find input by name {string}", async function (name) {
|
|
171
|
-
this.element = this.page.locator(`input[name="${name}"]`);
|
|
172
|
-
this.log?.(`Stored input with name "${name}"`);
|
|
173
|
-
});
|
|
174
|
-
(0, cucumber_1.When)("I find input by placeholder text {string}", async function (placeholder) {
|
|
175
|
-
this.element = this.page.getByPlaceholder(placeholder);
|
|
176
|
-
this.log?.(`Stored input with placeholder "${placeholder}"`);
|
|
177
|
-
});
|
|
178
|
-
(0, cucumber_1.When)("I find inputs by name {string}", async function (name) {
|
|
179
|
-
this.elements = this.page.locator(`input[name="${name}"]`);
|
|
180
|
-
this.log?.(`Stored multiple inputs with name "${name}"`);
|
|
181
|
-
});
|
|
182
|
-
(0, cucumber_1.When)("I find inputs by placeholder text {string}", async function (placeholder) {
|
|
183
|
-
this.elements = this.page.locator(`input[placeholder="${placeholder}"]`);
|
|
184
|
-
this.log?.(`Stored multiple inputs with placeholder "${placeholder}"`);
|
|
185
|
-
});
|
|
186
|
-
(0, cucumber_1.When)("I find inputs by label text {string}", async function (label) {
|
|
187
|
-
this.elements = this.page.locator(`label:has-text("${label}") + input`);
|
|
188
|
-
this.log?.(`Stored multiple inputs with label "${label}"`);
|
|
189
|
-
});
|
|
190
|
-
(0, cucumber_1.When)("I find inputs by display value {string}", async function (value) {
|
|
191
|
-
// 🧠 Handle alias
|
|
192
|
-
if (value.startsWith("@")) {
|
|
193
|
-
const alias = value.slice(1);
|
|
194
|
-
value = this.data?.[alias];
|
|
195
|
-
if (!value) {
|
|
196
|
-
throw new Error(`No value found for alias "@${alias}"`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
// 🔍 Find all matching inputs
|
|
200
|
-
this.elements = this.page.locator(`input[value="${value}"]`);
|
|
201
|
-
this.log?.(`📦 Stored multiple inputs with display value "${value}"`);
|
|
202
|
-
});
|
|
203
|
-
(0, cucumber_1.When)("I find input by display value {string}", async function (value) {
|
|
204
|
-
// 🧠 Handle alias
|
|
205
|
-
if (value.startsWith("@")) {
|
|
206
|
-
const alias = value.slice(1);
|
|
207
|
-
value = this.data?.[alias];
|
|
208
|
-
if (!value) {
|
|
209
|
-
throw new Error(`No value found for alias "@${alias}"`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// 🎯 Try to find input element with matching display value
|
|
213
|
-
const locator = this.page.locator(`input[value="${value}"]`);
|
|
214
|
-
await (0, test_1.expect)(locator).toBeVisible({ timeout: 5000 });
|
|
215
|
-
this.element = locator;
|
|
216
|
-
this.log?.(`🔍 Found input with value: "${value}"`);
|
|
217
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,130 +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
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
9
|
-
const test_1 = require("@playwright/test");
|
|
10
|
-
const resolveUtils_1 = require("../helpers/utils/resolveUtils");
|
|
11
|
-
(0, cucumber_1.When)("I fill the following {string} form data:", async function (_formName, dataTable) {
|
|
12
|
-
// const scope = this.frame ?? this.page;
|
|
13
|
-
const rows = dataTable.hashes();
|
|
14
|
-
for (const row of rows) {
|
|
15
|
-
const target = row.Target.trim();
|
|
16
|
-
const rawValue = row.Value.trim();
|
|
17
|
-
const locator = this.getLocator(target);
|
|
18
|
-
const value = (0, resolveUtils_1.resolveLoginValue)(rawValue, this);
|
|
19
|
-
// ✅ Assertions
|
|
20
|
-
if (rawValue.startsWith("assert:")) {
|
|
21
|
-
const [, type, expected] = rawValue.split(":");
|
|
22
|
-
if (type === "visible") {
|
|
23
|
-
await (0, test_1.expect)(locator).toBeVisible();
|
|
24
|
-
}
|
|
25
|
-
else if (type === "text") {
|
|
26
|
-
await (0, test_1.expect)(locator).toHaveText(expected ?? "", {
|
|
27
|
-
useInnerText: true,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
else if (type === "value") {
|
|
31
|
-
await (0, test_1.expect)(locator).toHaveValue(expected ?? "");
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw new Error(`❌ Unknown assertion: ${type}`);
|
|
35
|
-
}
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
// ✅ UI interactions
|
|
39
|
-
if (rawValue === "click") {
|
|
40
|
-
await locator.click();
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (rawValue === "check") {
|
|
44
|
-
await locator.check();
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (rawValue === "uncheck") {
|
|
48
|
-
await locator.uncheck();
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (rawValue === "select") {
|
|
52
|
-
await locator.selectOption({ index: 0 });
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
// ✅ File upload
|
|
56
|
-
if (rawValue.startsWith("upload:")) {
|
|
57
|
-
const filePath = rawValue.split("upload:")[1].trim();
|
|
58
|
-
const resolvedPath = path_1.default.resolve(filePath);
|
|
59
|
-
if (!fs_1.default.existsSync(resolvedPath))
|
|
60
|
-
throw new Error(`File not found: ${filePath}`);
|
|
61
|
-
await locator.setInputFiles(resolvedPath);
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
// ✅ Drag and drop
|
|
65
|
-
if (rawValue.startsWith("drag:")) {
|
|
66
|
-
const targetSelector = rawValue.split("drag:")[1].trim();
|
|
67
|
-
const targetLocator = this.getLocator(targetSelector);
|
|
68
|
-
await locator.dragTo(targetLocator);
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
// ✅ Local/sessionStorage
|
|
72
|
-
if (rawValue.startsWith("set:localStorage:")) {
|
|
73
|
-
const [, , key] = rawValue.split(":");
|
|
74
|
-
if (typeof key !== "string" || !key) {
|
|
75
|
-
throw new Error("Local storage key must be a non-empty string");
|
|
76
|
-
}
|
|
77
|
-
await this.page.evaluate(([k, v]) => localStorage.setItem(k, v), [key, value ?? ""]);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (rawValue.startsWith("set:sessionStorage:")) {
|
|
81
|
-
const [, , key] = rawValue.split(":");
|
|
82
|
-
if (typeof key !== "string" || key === undefined) {
|
|
83
|
-
throw new Error("Session storage key must be a string");
|
|
84
|
-
}
|
|
85
|
-
await this.page.evaluate((args) => {
|
|
86
|
-
const [k, v] = args;
|
|
87
|
-
sessionStorage.setItem(k, v);
|
|
88
|
-
}, [key, value ?? ""]);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
// ✅ Wait
|
|
92
|
-
if (rawValue.startsWith("wait:")) {
|
|
93
|
-
const [, timeMs] = rawValue.split(":");
|
|
94
|
-
const waitTime = Number(timeMs);
|
|
95
|
-
if (!isNaN(waitTime)) {
|
|
96
|
-
await this.page.waitForTimeout(waitTime);
|
|
97
|
-
}
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
// ✅ Reload
|
|
101
|
-
if (rawValue === "reload") {
|
|
102
|
-
await this.page.reload();
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
// ✅ Request handling
|
|
106
|
-
if (rawValue.startsWith("request:")) {
|
|
107
|
-
const [, method, url, file] = rawValue.replace("request:", "").split(":");
|
|
108
|
-
const payloadDir = row.PayloadDir || this.parameters?.payloadDir || "payload";
|
|
109
|
-
const filePath = path_1.default.resolve(payloadDir, file);
|
|
110
|
-
if (!fs_1.default.existsSync(filePath)) {
|
|
111
|
-
throw new Error(`Payload file not found: ${filePath}`);
|
|
112
|
-
}
|
|
113
|
-
const payload = JSON.parse(fs_1.default.readFileSync(filePath, "utf-8"));
|
|
114
|
-
const response = await this.page.request[method.toLowerCase()](url, {
|
|
115
|
-
data: payload,
|
|
116
|
-
});
|
|
117
|
-
const responseBody = await response.json();
|
|
118
|
-
this.data.lastApiResponse = responseBody;
|
|
119
|
-
this.data.lastStatusCode = response.status();
|
|
120
|
-
if (row.SaveAs) {
|
|
121
|
-
this.data[row.SaveAs] = responseBody;
|
|
122
|
-
}
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// ✅ Default: fill
|
|
126
|
-
if (value !== undefined) {
|
|
127
|
-
await locator.fill(String(value));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// e2e/step_definitions/common/actions/inputSteps.ts
|
|
4
|
-
// import fs from "fs";
|
|
5
|
-
// import path from "path";
|
|
6
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
7
|
-
const fakerUtils_1 = require("../helpers/utils/fakerUtils");
|
|
8
|
-
const optionsUtils_1 = require("../helpers/utils/optionsUtils");
|
|
9
|
-
(0, cucumber_1.When)("I check", async function (...rest) {
|
|
10
|
-
const maybeTable = rest[0];
|
|
11
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
12
|
-
await this.element?.check(options);
|
|
13
|
-
this.log?.("✅ Checked stored checkbox");
|
|
14
|
-
});
|
|
15
|
-
(0, cucumber_1.When)("I uncheck", async function (...rest) {
|
|
16
|
-
const maybeTable = rest[0];
|
|
17
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
18
|
-
await this.element?.uncheck(options);
|
|
19
|
-
this.log?.("✅ Unchecked stored checkbox");
|
|
20
|
-
});
|
|
21
|
-
(0, cucumber_1.When)("I check input", async function (...rest) {
|
|
22
|
-
const maybeTable = rest[0];
|
|
23
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
24
|
-
if (!this.element)
|
|
25
|
-
throw new Error("No input selected");
|
|
26
|
-
await this.element.check(options);
|
|
27
|
-
});
|
|
28
|
-
(0, cucumber_1.When)("I uncheck input", async function (...rest) {
|
|
29
|
-
const maybeTable = rest[0];
|
|
30
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
31
|
-
if (!this.element)
|
|
32
|
-
throw new Error("No input selected");
|
|
33
|
-
await this.element.uncheck(options);
|
|
34
|
-
});
|
|
35
|
-
// const DEFAULT_PAYLOAD_DIR = "payload";
|
|
36
|
-
const typeStep = async function (textOrAlias, ...rest) {
|
|
37
|
-
if (!this.element)
|
|
38
|
-
throw new Error("No element selected");
|
|
39
|
-
const maybeTable = rest[0];
|
|
40
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseFillOptions)(maybeTable) : {};
|
|
41
|
-
const text = textOrAlias.startsWith("@")
|
|
42
|
-
? (this.data[textOrAlias.slice(1)] ??
|
|
43
|
-
(() => {
|
|
44
|
-
throw new Error(`No value found for alias "${textOrAlias}"`);
|
|
45
|
-
})())
|
|
46
|
-
: (0, fakerUtils_1.evaluateFaker)(textOrAlias);
|
|
47
|
-
await this.element.fill("");
|
|
48
|
-
await this.element.fill(text, options);
|
|
49
|
-
this.data.lastTyped = text;
|
|
50
|
-
this.log?.(`⌨️ Typed "${text}" into selected element`);
|
|
51
|
-
};
|
|
52
|
-
(0, cucumber_1.When)("I type {string}", typeStep);
|
|
53
|
-
(0, cucumber_1.When)("I type stored {string}", typeStep);
|
|
54
|
-
(0, cucumber_1.When)("I type random {string}", typeStep);
|
|
55
|
-
(0, cucumber_1.When)("I set value {string}", async function (valueOrAlias, ...rest) {
|
|
56
|
-
if (!this.element)
|
|
57
|
-
throw new Error("No element selected");
|
|
58
|
-
const maybeTable = rest[0];
|
|
59
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseFillOptions)(maybeTable) : {};
|
|
60
|
-
const value = valueOrAlias.startsWith("@")
|
|
61
|
-
? (this.data[valueOrAlias.slice(1)] ??
|
|
62
|
-
(() => {
|
|
63
|
-
throw new Error(`No value found for alias "${valueOrAlias}"`);
|
|
64
|
-
})())
|
|
65
|
-
: (0, fakerUtils_1.evaluateFaker)(valueOrAlias);
|
|
66
|
-
await this.element.fill(value, options);
|
|
67
|
-
this.data.lastValueSet = value;
|
|
68
|
-
this.log?.(`📝 Set value to "${value}"`);
|
|
69
|
-
});
|
|
70
|
-
(0, cucumber_1.When)("I clear", async function () {
|
|
71
|
-
if (!this.element)
|
|
72
|
-
throw new Error("No element selected");
|
|
73
|
-
await this.element.fill("");
|
|
74
|
-
this.log?.("🧼 Cleared value of selected element");
|
|
75
|
-
});
|
|
76
|
-
(0, cucumber_1.When)("I submit", async function () {
|
|
77
|
-
// const maybeTable = rest[0];
|
|
78
|
-
const form = this.element ?? this.page.locator("form");
|
|
79
|
-
await form.evaluate((f) => f.submit());
|
|
80
|
-
this.log?.("📨 Submitted form");
|
|
81
|
-
});
|
|
82
|
-
(0, cucumber_1.When)("I select option {string}", async function (option, ...rest) {
|
|
83
|
-
if (!this.element)
|
|
84
|
-
throw new Error("No select element stored");
|
|
85
|
-
const maybeTable = rest[0];
|
|
86
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseSelectOptions)(maybeTable) : {};
|
|
87
|
-
await this.element.selectOption({ label: option }, options);
|
|
88
|
-
this.log?.(`🔽 Selected option "${option}"`);
|
|
89
|
-
});
|
|
90
|
-
(0, cucumber_1.When)("I select file {string}", async function (filePath, ...rest) {
|
|
91
|
-
if (!this.element)
|
|
92
|
-
throw new Error("No file input selected");
|
|
93
|
-
const maybeTable = rest[0];
|
|
94
|
-
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseSelectOptions)(maybeTable) : {};
|
|
95
|
-
await this.element.setInputFiles(filePath, options);
|
|
96
|
-
this.log?.(`📁 Set input file to "${filePath}"`);
|
|
97
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// e2e/step_definitions/common/interceptionSteps.ts
|
|
4
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
-
let lastResponse;
|
|
6
|
-
(0, cucumber_1.When)("I intercept URL {string} and stub body:", async function (url, body) {
|
|
7
|
-
let parsedBody;
|
|
8
|
-
try {
|
|
9
|
-
parsedBody = JSON.parse(body);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
13
|
-
throw new Error(`Failed to parse JSON body: ${message}`);
|
|
14
|
-
}
|
|
15
|
-
await this.page.route(url, (route) => {
|
|
16
|
-
route.fulfill({
|
|
17
|
-
status: 200,
|
|
18
|
-
contentType: "application/json",
|
|
19
|
-
body: JSON.stringify(parsedBody),
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
this.log(`Intercepted and stubbed URL "${url}" with body: ${JSON.stringify(parsedBody)}`);
|
|
23
|
-
});
|
|
24
|
-
//Making Direct API Requests (Optional, Advanced)
|
|
25
|
-
(0, cucumber_1.When)("I make request to {string}", async function (url) {
|
|
26
|
-
const response = await this.page.request.get(url);
|
|
27
|
-
const status = response.status();
|
|
28
|
-
const body = await response.text();
|
|
29
|
-
this.data.lastResponse = { status, body };
|
|
30
|
-
this.log(`Made GET request to "${url}" — Status: ${status}`);
|
|
31
|
-
});
|
|
32
|
-
(0, cucumber_1.When)("I make a POST request to {string} with JSON body:", async function (url, docString) {
|
|
33
|
-
let payload;
|
|
34
|
-
try {
|
|
35
|
-
payload = JSON.parse(docString);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
39
|
-
throw new Error(`Invalid JSON: ${message}`);
|
|
40
|
-
}
|
|
41
|
-
const response = await this.page.request.post(url, { data: payload });
|
|
42
|
-
const status = response.status();
|
|
43
|
-
const body = await response.text();
|
|
44
|
-
this.data.lastResponse = { status, body };
|
|
45
|
-
this.log(`Made POST request to "${url}" — Status: ${status}`);
|
|
46
|
-
});
|
|
47
|
-
(0, cucumber_1.When)("I intercept URL {string}", async function (url) {
|
|
48
|
-
await this.page.route(url, async (route) => {
|
|
49
|
-
await route.continue();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
(0, cucumber_1.When)("I intercept URL {string} and stub body {string}", async function (url, body) {
|
|
53
|
-
await this.page.route(url, (route) => {
|
|
54
|
-
route.fulfill({
|
|
55
|
-
status: 200,
|
|
56
|
-
contentType: "application/json",
|
|
57
|
-
body,
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
(0, cucumber_1.When)("I make a request to {string}", async function (url) {
|
|
62
|
-
const response = await this.page.request.get(url);
|
|
63
|
-
this.data.lastResponse = response;
|
|
64
|
-
});
|
|
65
|
-
(0, cucumber_1.When)('I make a "{word}" request to {string}', async function (method, url, table) {
|
|
66
|
-
const options = table ? Object.fromEntries(table.rows()) : {};
|
|
67
|
-
if (options.body)
|
|
68
|
-
options.body = JSON.stringify(JSON.parse(options.body));
|
|
69
|
-
const res = await fetch(url, { method, ...options });
|
|
70
|
-
lastResponse = res;
|
|
71
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|