playwright-cucumber-ts-steps 0.1.0 โ 0.1.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.
- package/dist/actions/clickSteps.js +35 -33
- package/dist/actions/cookieSteps.js +7 -5
- package/dist/actions/debugSteps.js +5 -3
- package/dist/actions/elementFindSteps.js +50 -48
- package/dist/actions/inputSteps.js +40 -35
- package/dist/actions/interceptionSteps.js +9 -7
- package/dist/actions/miscSteps.js +41 -36
- package/dist/actions/mouseSteps.js +10 -8
- package/dist/actions/scrollSteps.js +7 -5
- package/dist/actions/storageSteps.js +10 -8
- package/dist/assertions/buttonAndTextVisibilitySteps.js +25 -23
- package/dist/assertions/cookieSteps.js +7 -5
- package/dist/assertions/elementSteps.js +24 -22
- package/dist/assertions/formInputSteps.js +28 -26
- package/dist/assertions/interceptionRequestsSteps.js +27 -25
- package/dist/assertions/locationSteps.js +17 -15
- package/dist/assertions/roleTestIdSteps.js +12 -10
- package/dist/assertions/semanticSteps.js +9 -7
- package/dist/assertions/storageSteps.js +23 -18
- package/dist/assertions/visualSteps.js +41 -36
- package/dist/custom_setups/globalLogin.js +10 -5
- package/dist/custom_setups/loginHooks.js +30 -25
- package/dist/helpers/checkPeerDeps.d.ts +1 -0
- package/dist/helpers/checkPeerDeps.js +19 -0
- package/dist/helpers/compareSnapshots.js +15 -9
- package/dist/helpers/hooks.js +73 -35
- package/dist/helpers/utils/fakerUtils.js +32 -26
- package/dist/helpers/utils/index.js +19 -3
- package/dist/helpers/utils/optionsUtils.js +18 -8
- package/dist/helpers/utils/resolveUtils.js +19 -11
- package/dist/helpers/world.js +45 -8
- package/dist/iframes/frames.js +4 -2
- package/dist/index.js +43 -27
- package/dist/register.js +9 -1
- package/package.json +24 -8
|
@@ -1,41 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
// e2e/step_definitions/common/actions/clickSteps.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
When("I click", async function (...rest) {
|
|
4
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
+
const optionsUtils_1 = require("../helpers/utils/optionsUtils");
|
|
6
|
+
(0, cucumber_1.When)("I click", async function (...rest) {
|
|
5
7
|
const maybeTable = rest[0];
|
|
6
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
8
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
7
9
|
if (!this.element)
|
|
8
10
|
throw new Error("โ No stored element to click.");
|
|
9
11
|
await this.element.click(options);
|
|
10
12
|
this.log?.("๐ฑ๏ธ Clicked on stored element");
|
|
11
13
|
});
|
|
12
|
-
When("I click on button {string}", async function (label, ...rest) {
|
|
14
|
+
(0, cucumber_1.When)("I click on button {string}", async function (label, ...rest) {
|
|
13
15
|
const maybeTable = rest[0];
|
|
14
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
16
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
15
17
|
const button = await this.page.getByRole("button", { name: label });
|
|
16
18
|
await button.click(options);
|
|
17
19
|
this.element = button;
|
|
18
20
|
this.log?.(`๐ฑ๏ธ Clicked on button "${label}"`);
|
|
19
21
|
});
|
|
20
|
-
When("I click on link {string}", async function (text, ...rest) {
|
|
22
|
+
(0, cucumber_1.When)("I click on link {string}", async function (text, ...rest) {
|
|
21
23
|
const maybeTable = rest[0];
|
|
22
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
24
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
23
25
|
const link = await this.page.getByRole("link", { name: text });
|
|
24
26
|
await link.click(options);
|
|
25
27
|
this.element = link;
|
|
26
28
|
this.log?.(`โ
Clicked on link "${text}"`);
|
|
27
29
|
});
|
|
28
|
-
When("I click on label {string}", async function (labelText, ...rest) {
|
|
30
|
+
(0, cucumber_1.When)("I click on label {string}", async function (labelText, ...rest) {
|
|
29
31
|
const maybeTable = rest[0];
|
|
30
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
32
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
31
33
|
const label = await this.page.getByLabel(labelText);
|
|
32
34
|
await label.click(options);
|
|
33
35
|
this.element = label;
|
|
34
36
|
this.log?.(`๐ท๏ธ Clicked on label "${labelText}"`);
|
|
35
37
|
});
|
|
36
|
-
When("I click on text {string}", async function (rawText, ...rest) {
|
|
38
|
+
(0, cucumber_1.When)("I click on text {string}", async function (rawText, ...rest) {
|
|
37
39
|
const maybeTable = rest[0];
|
|
38
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
40
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
39
41
|
let text = rawText;
|
|
40
42
|
if (rawText.startsWith("@")) {
|
|
41
43
|
const alias = rawText.slice(1);
|
|
@@ -49,18 +51,18 @@ When("I click on text {string}", async function (rawText, ...rest) {
|
|
|
49
51
|
this.element = locator.first();
|
|
50
52
|
this.log?.(`๐ฑ๏ธ Clicked on text "${text}"`);
|
|
51
53
|
});
|
|
52
|
-
When("I click on exact text {string}", async function (exactText, ...rest) {
|
|
54
|
+
(0, cucumber_1.When)("I click on exact text {string}", async function (exactText, ...rest) {
|
|
53
55
|
const maybeTable = rest[0];
|
|
54
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
56
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
55
57
|
const locator = this.page.getByText(exactText, { exact: true });
|
|
56
58
|
await locator.waitFor({ state: "visible", timeout: 5000 });
|
|
57
59
|
await locator.click(options);
|
|
58
60
|
this.element = locator;
|
|
59
61
|
this.log?.(`๐ฑ๏ธ Clicked on exact text "${exactText}"`);
|
|
60
62
|
});
|
|
61
|
-
When("I click all", async function (...rest) {
|
|
63
|
+
(0, cucumber_1.When)("I click all", async function (...rest) {
|
|
62
64
|
const maybeTable = rest[0];
|
|
63
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
65
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
64
66
|
if (!this.elements)
|
|
65
67
|
throw new Error("โ No stored elements to click.");
|
|
66
68
|
const count = await this.elements.count();
|
|
@@ -74,49 +76,49 @@ When("I click all", async function (...rest) {
|
|
|
74
76
|
}
|
|
75
77
|
this.log?.(`โ
Clicked all ${count} elements.`);
|
|
76
78
|
});
|
|
77
|
-
When("I double click on text {string}", async function (text, ...rest) {
|
|
79
|
+
(0, cucumber_1.When)("I double click on text {string}", async function (text, ...rest) {
|
|
78
80
|
const maybeTable = rest[0];
|
|
79
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
81
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
80
82
|
const element = this.element || this.page.getByText(text);
|
|
81
83
|
await element.dblclick(options);
|
|
82
84
|
this.log?.(`๐ฑ๏ธ Double-clicked on text "${text}"`);
|
|
83
85
|
});
|
|
84
|
-
When("I double click position {int} {int}", async function (x, y, ...rest) {
|
|
86
|
+
(0, cucumber_1.When)("I double click position {int} {int}", async function (x, y, ...rest) {
|
|
85
87
|
const maybeTable = rest[0];
|
|
86
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
88
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
87
89
|
await this.page.mouse.dblclick(x, y, options);
|
|
88
90
|
this.log?.(`๐ฑ๏ธ Double-clicked at (${x}, ${y})`);
|
|
89
91
|
});
|
|
90
|
-
When("I double click", async function (...rest) {
|
|
92
|
+
(0, cucumber_1.When)("I double click", async function (...rest) {
|
|
91
93
|
const maybeTable = rest[0];
|
|
92
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
94
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
93
95
|
if (!this.element)
|
|
94
96
|
throw new Error("โ No stored element to double-click.");
|
|
95
97
|
await this.element.dblclick(options);
|
|
96
98
|
this.log?.("๐ฑ๏ธ Double-clicked on stored element");
|
|
97
99
|
});
|
|
98
|
-
When("I right click", async function (...rest) {
|
|
100
|
+
(0, cucumber_1.When)("I right click", async function (...rest) {
|
|
99
101
|
const maybeTable = rest[0];
|
|
100
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
102
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
101
103
|
if (!this.element)
|
|
102
104
|
throw new Error("โ No stored element to right-click.");
|
|
103
105
|
await this.element.click({ button: "right", ...options });
|
|
104
106
|
this.log?.("๐ฑ๏ธ Right-clicked on stored element");
|
|
105
107
|
});
|
|
106
|
-
When("I right click on text {string}", async function (text, ...rest) {
|
|
108
|
+
(0, cucumber_1.When)("I right click on text {string}", async function (text, ...rest) {
|
|
107
109
|
const maybeTable = rest[0];
|
|
108
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
110
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
109
111
|
const element = this.page.getByText(text);
|
|
110
112
|
await element.click({ button: "right", ...options });
|
|
111
113
|
this.log?.(`๐ฑ๏ธ Right-clicked on text "${text}"`);
|
|
112
114
|
});
|
|
113
|
-
When("I right click position {int} {int}", async function (x, y, ...rest) {
|
|
115
|
+
(0, cucumber_1.When)("I right click position {int} {int}", async function (x, y, ...rest) {
|
|
114
116
|
const maybeTable = rest[0];
|
|
115
|
-
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
117
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseClickOptions)(maybeTable) : {};
|
|
116
118
|
await this.page.mouse.click(x, y, { button: "right", ...options });
|
|
117
119
|
this.log?.(`๐ฑ๏ธ Right-clicked at (${x}, ${y})`);
|
|
118
120
|
});
|
|
119
|
-
When("I blur", async function () {
|
|
121
|
+
(0, cucumber_1.When)("I blur", async function () {
|
|
120
122
|
await this.page.evaluate(() => {
|
|
121
123
|
const active = document.activeElement;
|
|
122
124
|
if (active && typeof active.blur === "function") {
|
|
@@ -125,14 +127,14 @@ When("I blur", async function () {
|
|
|
125
127
|
});
|
|
126
128
|
this.log?.("๐ Blurred active element");
|
|
127
129
|
});
|
|
128
|
-
When("I focus", async function () {
|
|
130
|
+
(0, cucumber_1.When)("I focus", async function () {
|
|
129
131
|
if (!this.element)
|
|
130
132
|
throw new Error("โ No stored element to focus.");
|
|
131
133
|
await this.element.focus();
|
|
132
134
|
this.log?.("๐ฏ Focused stored element");
|
|
133
135
|
});
|
|
134
|
-
When("I click all", async function (dataTable) {
|
|
135
|
-
const options = parseClickOptions(dataTable);
|
|
136
|
+
(0, cucumber_1.When)("I click all", async function (dataTable) {
|
|
137
|
+
const options = (0, optionsUtils_1.parseClickOptions)(dataTable);
|
|
136
138
|
if (!this.elements) {
|
|
137
139
|
throw new Error("โ No elements stored. Use a 'find' step before 'I click all'.");
|
|
138
140
|
}
|
|
@@ -148,7 +150,7 @@ When("I click all", async function (dataTable) {
|
|
|
148
150
|
}
|
|
149
151
|
this.log?.(`โ
Clicked all ${count} stored elements.`);
|
|
150
152
|
});
|
|
151
|
-
When(/^I click on selector "([^"]+)"$/, async function (selector) {
|
|
153
|
+
(0, cucumber_1.When)(/^I click on selector "([^"]+)"$/, async function (selector) {
|
|
152
154
|
const scope = this.getScope();
|
|
153
155
|
const element = scope.locator(selector);
|
|
154
156
|
await element.click();
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
// e2e/step_definitions/common/actions/cookieSteps.ts
|
|
2
|
-
|
|
3
|
-
When("I clear all cookies", async function () {
|
|
4
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
+
(0, cucumber_1.When)("I clear all cookies", async function () {
|
|
4
6
|
await this.page.context().clearCookies();
|
|
5
7
|
this.log("Cleared all cookies");
|
|
6
8
|
});
|
|
7
|
-
When("I clear cookies", async function () {
|
|
9
|
+
(0, cucumber_1.When)("I clear cookies", async function () {
|
|
8
10
|
await this.page.context().clearCookies();
|
|
9
11
|
this.log("Cleared cookies (alias)");
|
|
10
12
|
});
|
|
11
|
-
When("I clear cookie {string}", async function (name) {
|
|
13
|
+
(0, cucumber_1.When)("I clear cookie {string}", async function (name) {
|
|
12
14
|
await this.page.context().addCookies([
|
|
13
15
|
{
|
|
14
16
|
name,
|
|
@@ -20,7 +22,7 @@ When("I clear cookie {string}", async function (name) {
|
|
|
20
22
|
]);
|
|
21
23
|
this.log(`Cleared cookie: ${name}`);
|
|
22
24
|
});
|
|
23
|
-
When("I log all cookies", async function () {
|
|
25
|
+
(0, cucumber_1.When)("I log all cookies", async function () {
|
|
24
26
|
const cookies = await this.page.context().cookies();
|
|
25
27
|
console.log("Cookies:", cookies);
|
|
26
28
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
// e2e/step_definitions/common/actions/debugSteps.ts
|
|
2
|
-
|
|
3
|
-
When("I debug", async function () {
|
|
4
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
+
(0, cucumber_1.When)("I debug", async function () {
|
|
4
6
|
await this.page.pause();
|
|
5
7
|
this.log("Paused test for debugging");
|
|
6
8
|
});
|
|
7
|
-
When("I log {string}", async function (msg) {
|
|
9
|
+
(0, cucumber_1.When)("I log {string}", async function (msg) {
|
|
8
10
|
this.log(msg);
|
|
9
11
|
});
|
|
@@ -1,50 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
4
|
+
const test_1 = require("@playwright/test");
|
|
3
5
|
// =============================
|
|
4
6
|
// WHEN I FIND ELEMENT(S)
|
|
5
7
|
// =============================
|
|
6
|
-
When("I find element by selector {string}", async function (selector) {
|
|
8
|
+
(0, cucumber_1.When)("I find element by selector {string}", async function (selector) {
|
|
7
9
|
this.element = this.page.locator(selector);
|
|
8
|
-
await expect(this.element).toHaveCount(1);
|
|
10
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
9
11
|
});
|
|
10
|
-
When("I find elements by selector {string}", async function (selector) {
|
|
12
|
+
(0, cucumber_1.When)("I find elements by selector {string}", async function (selector) {
|
|
11
13
|
this.elements = this.page.locator(selector);
|
|
12
14
|
const count = await this.elements.count();
|
|
13
15
|
this.log?.(`Found ${count} elements with selector ${selector}`);
|
|
14
16
|
});
|
|
15
|
-
When("I find element by text {string}", async function (text) {
|
|
17
|
+
(0, cucumber_1.When)("I find element by text {string}", async function (text) {
|
|
16
18
|
this.element = this.page.getByText(text, { exact: true });
|
|
17
|
-
await expect(this.element).toHaveCount(1);
|
|
19
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
18
20
|
});
|
|
19
|
-
When("I find element by title {string}", async function (title) {
|
|
21
|
+
(0, cucumber_1.When)("I find element by title {string}", async function (title) {
|
|
20
22
|
this.element = this.page.getByTitle(title);
|
|
21
|
-
await expect(this.element).toHaveCount(1);
|
|
23
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
22
24
|
});
|
|
23
|
-
When("I find element by testid {string}", async function (testid) {
|
|
25
|
+
(0, cucumber_1.When)("I find element by testid {string}", async function (testid) {
|
|
24
26
|
this.element = this.page.getByTestId(testid);
|
|
25
|
-
await expect(this.element).toHaveCount(1);
|
|
27
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
26
28
|
});
|
|
27
|
-
When("I find element by role {string}", async function (role) {
|
|
29
|
+
(0, cucumber_1.When)("I find element by role {string}", async function (role) {
|
|
28
30
|
this.element = this.page.getByRole(role);
|
|
29
|
-
await expect(this.element).toHaveCount(1);
|
|
31
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
30
32
|
});
|
|
31
|
-
When("I find element by placeholder text {string}", async function (text) {
|
|
33
|
+
(0, cucumber_1.When)("I find element by placeholder text {string}", async function (text) {
|
|
32
34
|
this.element = this.page.getByPlaceholder(text);
|
|
33
|
-
await expect(this.element).toHaveCount(1);
|
|
35
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
34
36
|
});
|
|
35
|
-
When("I find element by label text {string}", async function (label) {
|
|
37
|
+
(0, cucumber_1.When)("I find element by label text {string}", async function (label) {
|
|
36
38
|
this.element = this.page.getByLabel(label);
|
|
37
|
-
await expect(this.element).toHaveCount(1);
|
|
39
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
38
40
|
});
|
|
39
|
-
When("I find element by alt text {string}", async function (alt) {
|
|
41
|
+
(0, cucumber_1.When)("I find element by alt text {string}", async function (alt) {
|
|
40
42
|
this.element = this.page.getByAltText(alt);
|
|
41
|
-
await expect(this.element).toHaveCount(1);
|
|
43
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
42
44
|
});
|
|
43
|
-
When("I find element by name {string}", async function (name) {
|
|
45
|
+
(0, cucumber_1.When)("I find element by name {string}", async function (name) {
|
|
44
46
|
this.element = this.page.getByRole("textbox", { name });
|
|
45
|
-
await expect(this.element).toHaveCount(1);
|
|
47
|
+
await (0, test_1.expect)(this.element).toHaveCount(1);
|
|
46
48
|
});
|
|
47
|
-
When("I find buttons by text {string}", async function (buttonText) {
|
|
49
|
+
(0, cucumber_1.When)("I find buttons by text {string}", async function (buttonText) {
|
|
48
50
|
// ๐ง Resolve alias
|
|
49
51
|
if (buttonText.startsWith("@")) {
|
|
50
52
|
const alias = buttonText.slice(1);
|
|
@@ -63,23 +65,23 @@ When("I find buttons by text {string}", async function (buttonText) {
|
|
|
63
65
|
// =============================
|
|
64
66
|
// WHEN I GET ELEMENT(S)
|
|
65
67
|
// =============================
|
|
66
|
-
When("I get element by selector {string}", async function (selector) {
|
|
68
|
+
(0, cucumber_1.When)("I get element by selector {string}", async function (selector) {
|
|
67
69
|
this.element = this.page.locator(selector).first();
|
|
68
70
|
});
|
|
69
|
-
When("I get elements by selector {string}", async function (selector) {
|
|
71
|
+
(0, cucumber_1.When)("I get elements by selector {string}", async function (selector) {
|
|
70
72
|
this.elements = this.page.locator(selector);
|
|
71
73
|
});
|
|
72
|
-
When("I get first element", async function () {
|
|
74
|
+
(0, cucumber_1.When)("I get first element", async function () {
|
|
73
75
|
if (!this.elements)
|
|
74
76
|
throw new Error("No element collection found");
|
|
75
77
|
this.element = this.elements.first();
|
|
76
78
|
});
|
|
77
|
-
When("I get last element", async function () {
|
|
79
|
+
(0, cucumber_1.When)("I get last element", async function () {
|
|
78
80
|
if (!this.elements)
|
|
79
81
|
throw new Error("No element collection found");
|
|
80
82
|
this.element = this.elements.last();
|
|
81
83
|
});
|
|
82
|
-
When(/^I get (\d+)(?:st|nd|rd|th) element$/, async function (index) {
|
|
84
|
+
(0, cucumber_1.When)(/^I get (\d+)(?:st|nd|rd|th) element$/, async function (index) {
|
|
83
85
|
if (!this.elements)
|
|
84
86
|
throw new Error("No elements stored to pick from");
|
|
85
87
|
const count = await this.elements.count();
|
|
@@ -89,7 +91,7 @@ When(/^I get (\d+)(?:st|nd|rd|th) element$/, async function (index) {
|
|
|
89
91
|
this.element = this.elements.nth(index - 1);
|
|
90
92
|
this.log?.(`Selected ${index} element from stored elements`);
|
|
91
93
|
});
|
|
92
|
-
When("I find elements by role {string}", async function (role) {
|
|
94
|
+
(0, cucumber_1.When)("I find elements by role {string}", async function (role) {
|
|
93
95
|
const locator = this.page.getByRole(role);
|
|
94
96
|
const count = await locator.count();
|
|
95
97
|
if (count === 0) {
|
|
@@ -116,15 +118,15 @@ When("I find elements by role {string}", async function (role) {
|
|
|
116
118
|
// this.log?.(`Stored ${index}th element from collection`);
|
|
117
119
|
// }
|
|
118
120
|
// );
|
|
119
|
-
When("I get {int}rd element", async function (index) {
|
|
121
|
+
(0, cucumber_1.When)("I get {int}rd element", async function (index) {
|
|
120
122
|
if (!this.elements)
|
|
121
123
|
throw new Error("No element collection found");
|
|
122
124
|
this.element = this.elements.nth(index);
|
|
123
125
|
});
|
|
124
|
-
When("I get focused element", async function () {
|
|
126
|
+
(0, cucumber_1.When)("I get focused element", async function () {
|
|
125
127
|
this.element = (await this.page.evaluateHandle(() => document.activeElement));
|
|
126
128
|
});
|
|
127
|
-
When("I store element text as {string}", async function (alias) {
|
|
129
|
+
(0, cucumber_1.When)("I store element text as {string}", async function (alias) {
|
|
128
130
|
const element = this.element;
|
|
129
131
|
if (!element)
|
|
130
132
|
throw new Error("No element selected");
|
|
@@ -132,63 +134,63 @@ When("I store element text as {string}", async function (alias) {
|
|
|
132
134
|
this.data[alias] = text?.trim();
|
|
133
135
|
this.log?.(`Stored text "${text}" as "${alias}"`);
|
|
134
136
|
});
|
|
135
|
-
When("I find textarea by label text {string}", async function (label) {
|
|
137
|
+
(0, cucumber_1.When)("I find textarea by label text {string}", async function (label) {
|
|
136
138
|
this.element = this.page.getByLabel(label);
|
|
137
139
|
this.log?.(`Stored textarea with label "${label}"`);
|
|
138
140
|
});
|
|
139
|
-
When("I find textarea by placeholder text {string}", async function (placeholder) {
|
|
141
|
+
(0, cucumber_1.When)("I find textarea by placeholder text {string}", async function (placeholder) {
|
|
140
142
|
this.element = this.page.getByPlaceholder(placeholder);
|
|
141
143
|
this.log?.(`Stored textarea with placeholder "${placeholder}"`);
|
|
142
144
|
});
|
|
143
|
-
When("I find textareas by label text {string}", async function (label) {
|
|
145
|
+
(0, cucumber_1.When)("I find textareas by label text {string}", async function (label) {
|
|
144
146
|
this.elements = this.page.locator(`label:has-text("${label}") + textarea`);
|
|
145
147
|
this.log?.(`Stored multiple textareas with label "${label}"`);
|
|
146
148
|
});
|
|
147
|
-
When("I find textarea by name {string}", async function (name) {
|
|
149
|
+
(0, cucumber_1.When)("I find textarea by name {string}", async function (name) {
|
|
148
150
|
this.element = this.page.locator(`textarea[name="${name}"]`);
|
|
149
151
|
this.log?.(`Stored textarea with name "${name}"`);
|
|
150
152
|
});
|
|
151
|
-
When("I find textareas by ID {string}", async function (id) {
|
|
153
|
+
(0, cucumber_1.When)("I find textareas by ID {string}", async function (id) {
|
|
152
154
|
this.elements = this.page.locator(`textarea#${id}`);
|
|
153
155
|
this.log?.(`Stored multiple textareas with ID "${id}"`);
|
|
154
156
|
});
|
|
155
|
-
When("I find input by ID {string}", async function (id) {
|
|
157
|
+
(0, cucumber_1.When)("I find input by ID {string}", async function (id) {
|
|
156
158
|
this.element = this.page.locator(`input#${id}`);
|
|
157
159
|
this.log?.(`Stored input with ID "${id}"`);
|
|
158
160
|
});
|
|
159
|
-
When("I find inputs by ID {string}", async function (id) {
|
|
161
|
+
(0, cucumber_1.When)("I find inputs by ID {string}", async function (id) {
|
|
160
162
|
this.elements = this.page.locator(`input#${id}`);
|
|
161
163
|
this.log?.(`Stored multiple inputs with ID "${id}"`);
|
|
162
164
|
});
|
|
163
|
-
When("I find textareas by placeholder text {string}", async function (placeholder) {
|
|
165
|
+
(0, cucumber_1.When)("I find textareas by placeholder text {string}", async function (placeholder) {
|
|
164
166
|
this.elements = this.page.locator(`textarea[placeholder="${placeholder}"]`);
|
|
165
167
|
this.log?.(`Stored multiple textareas with placeholder "${placeholder}"`);
|
|
166
168
|
});
|
|
167
|
-
When("I find input by label text {string}", async function (label) {
|
|
169
|
+
(0, cucumber_1.When)("I find input by label text {string}", async function (label) {
|
|
168
170
|
this.element = this.page.getByLabel(label);
|
|
169
171
|
this.log?.(`Stored input with label "${label}"`);
|
|
170
172
|
});
|
|
171
|
-
When("I find input by name {string}", async function (name) {
|
|
173
|
+
(0, cucumber_1.When)("I find input by name {string}", async function (name) {
|
|
172
174
|
this.element = this.page.locator(`input[name="${name}"]`);
|
|
173
175
|
this.log?.(`Stored input with name "${name}"`);
|
|
174
176
|
});
|
|
175
|
-
When("I find input by placeholder text {string}", async function (placeholder) {
|
|
177
|
+
(0, cucumber_1.When)("I find input by placeholder text {string}", async function (placeholder) {
|
|
176
178
|
this.element = this.page.getByPlaceholder(placeholder);
|
|
177
179
|
this.log?.(`Stored input with placeholder "${placeholder}"`);
|
|
178
180
|
});
|
|
179
|
-
When("I find inputs by name {string}", async function (name) {
|
|
181
|
+
(0, cucumber_1.When)("I find inputs by name {string}", async function (name) {
|
|
180
182
|
this.elements = this.page.locator(`input[name="${name}"]`);
|
|
181
183
|
this.log?.(`Stored multiple inputs with name "${name}"`);
|
|
182
184
|
});
|
|
183
|
-
When("I find inputs by placeholder text {string}", async function (placeholder) {
|
|
185
|
+
(0, cucumber_1.When)("I find inputs by placeholder text {string}", async function (placeholder) {
|
|
184
186
|
this.elements = this.page.locator(`input[placeholder="${placeholder}"]`);
|
|
185
187
|
this.log?.(`Stored multiple inputs with placeholder "${placeholder}"`);
|
|
186
188
|
});
|
|
187
|
-
When("I find inputs by label text {string}", async function (label) {
|
|
189
|
+
(0, cucumber_1.When)("I find inputs by label text {string}", async function (label) {
|
|
188
190
|
this.elements = this.page.locator(`label:has-text("${label}") + input`);
|
|
189
191
|
this.log?.(`Stored multiple inputs with label "${label}"`);
|
|
190
192
|
});
|
|
191
|
-
When("I find inputs by display value {string}", async function (value) {
|
|
193
|
+
(0, cucumber_1.When)("I find inputs by display value {string}", async function (value) {
|
|
192
194
|
// ๐ง Handle alias
|
|
193
195
|
if (value.startsWith("@")) {
|
|
194
196
|
const alias = value.slice(1);
|
|
@@ -201,7 +203,7 @@ When("I find inputs by display value {string}", async function (value) {
|
|
|
201
203
|
this.elements = this.page.locator(`input[value="${value}"]`);
|
|
202
204
|
this.log?.(`๐ฆ Stored multiple inputs with display value "${value}"`);
|
|
203
205
|
});
|
|
204
|
-
When("I find input by display value {string}", async function (value) {
|
|
206
|
+
(0, cucumber_1.When)("I find input by display value {string}", async function (value) {
|
|
205
207
|
// ๐ง Handle alias
|
|
206
208
|
if (value.startsWith("@")) {
|
|
207
209
|
const alias = value.slice(1);
|
|
@@ -212,7 +214,7 @@ When("I find input by display value {string}", async function (value) {
|
|
|
212
214
|
}
|
|
213
215
|
// ๐ฏ Try to find input element with matching display value
|
|
214
216
|
const locator = this.page.locator(`input[value="${value}"]`);
|
|
215
|
-
await expect(locator).toBeVisible({ timeout: 5000 });
|
|
217
|
+
await (0, test_1.expect)(locator).toBeVisible({ timeout: 5000 });
|
|
216
218
|
this.element = locator;
|
|
217
219
|
this.log?.(`๐ Found input with value: "${value}"`);
|
|
218
220
|
});
|
|
@@ -1,40 +1,45 @@
|
|
|
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 });
|
|
1
6
|
// e2e/step_definitions/common/actions/inputSteps.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
When("I check", async function (...rest) {
|
|
7
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
8
|
+
const test_1 = require("@playwright/test");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const fakerUtils_1 = require("../helpers/utils/fakerUtils");
|
|
12
|
+
const optionsUtils_1 = require("../helpers/utils/optionsUtils");
|
|
13
|
+
(0, cucumber_1.When)("I check", async function (...rest) {
|
|
9
14
|
const maybeTable = rest[0];
|
|
10
|
-
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
15
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
11
16
|
await this.element?.check(options);
|
|
12
17
|
this.log?.("โ
Checked stored checkbox");
|
|
13
18
|
});
|
|
14
|
-
When("I uncheck", async function (...rest) {
|
|
19
|
+
(0, cucumber_1.When)("I uncheck", async function (...rest) {
|
|
15
20
|
const maybeTable = rest[0];
|
|
16
|
-
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
21
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
17
22
|
await this.element?.uncheck(options);
|
|
18
23
|
this.log?.("โ
Unchecked stored checkbox");
|
|
19
24
|
});
|
|
20
|
-
When("I check input", async function (...rest) {
|
|
25
|
+
(0, cucumber_1.When)("I check input", async function (...rest) {
|
|
21
26
|
const maybeTable = rest[0];
|
|
22
|
-
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
27
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
23
28
|
if (!this.element)
|
|
24
29
|
throw new Error("No input selected");
|
|
25
30
|
await this.element.check(options);
|
|
26
31
|
});
|
|
27
|
-
When("I uncheck input", async function (...rest) {
|
|
32
|
+
(0, cucumber_1.When)("I uncheck input", async function (...rest) {
|
|
28
33
|
const maybeTable = rest[0];
|
|
29
|
-
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
34
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
30
35
|
if (!this.element)
|
|
31
36
|
throw new Error("No input selected");
|
|
32
37
|
await this.element.uncheck(options);
|
|
33
38
|
});
|
|
34
|
-
When("I fill the following {string} form data:", async function (_formName, tableData, ...rest) {
|
|
39
|
+
(0, cucumber_1.When)("I fill the following {string} form data:", async function (_formName, tableData, ...rest) {
|
|
35
40
|
const maybeOptionsTable = rest[0];
|
|
36
41
|
const globalOptions = maybeOptionsTable?.rowsHash
|
|
37
|
-
? parseClickOptions(maybeOptionsTable)
|
|
42
|
+
? (0, optionsUtils_1.parseClickOptions)(maybeOptionsTable)
|
|
38
43
|
: {};
|
|
39
44
|
const rows = tableData.raw().slice(1); // Remove header row
|
|
40
45
|
for (const [rawTarget, rawValue] of rows) {
|
|
@@ -60,15 +65,15 @@ When("I fill the following {string} form data:", async function (_formName, tabl
|
|
|
60
65
|
throw new Error(`No value found for alias: ${rawValue}`);
|
|
61
66
|
}
|
|
62
67
|
else {
|
|
63
|
-
resolvedValue = evaluateFaker(rawValue);
|
|
68
|
+
resolvedValue = (0, fakerUtils_1.evaluateFaker)(rawValue);
|
|
64
69
|
}
|
|
65
70
|
if (resolvedValue === "Click") {
|
|
66
71
|
await element.click(globalOptions);
|
|
67
72
|
this.log?.(`๐ฑ๏ธ Clicked on "${rawTarget}"`);
|
|
68
73
|
}
|
|
69
74
|
else if (rawTarget.includes('input[type="file"]')) {
|
|
70
|
-
const filePath =
|
|
71
|
-
if (!
|
|
75
|
+
const filePath = path_1.default.resolve("test-data", resolvedValue);
|
|
76
|
+
if (!fs_1.default.existsSync(filePath))
|
|
72
77
|
throw new Error(`File not found: ${filePath}`);
|
|
73
78
|
await element.setInputFiles(filePath);
|
|
74
79
|
this.log?.(`๐ Uploaded file to "${rawTarget}": ${resolvedValue}`);
|
|
@@ -79,7 +84,7 @@ When("I fill the following {string} form data:", async function (_formName, tabl
|
|
|
79
84
|
const keys = matches.map((m) => m[1]);
|
|
80
85
|
const inputText = resolvedValue.replace(keyPattern, "").trim();
|
|
81
86
|
const fillOptions = maybeOptionsTable?.rowsHash
|
|
82
|
-
? parseFillOptions(maybeOptionsTable)
|
|
87
|
+
? (0, optionsUtils_1.parseFillOptions)(maybeOptionsTable)
|
|
83
88
|
: {};
|
|
84
89
|
if (inputText) {
|
|
85
90
|
await element.fill(inputText, fillOptions);
|
|
@@ -92,68 +97,68 @@ When("I fill the following {string} form data:", async function (_formName, tabl
|
|
|
92
97
|
this.log?.(`๐น Pressed {${key}} on "${rawTarget}"`);
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
|
-
await expect(element).toBeVisible();
|
|
100
|
+
await (0, test_1.expect)(element).toBeVisible();
|
|
96
101
|
}
|
|
97
102
|
});
|
|
98
103
|
const typeStep = async function (textOrAlias, ...rest) {
|
|
99
104
|
if (!this.element)
|
|
100
105
|
throw new Error("No element selected");
|
|
101
106
|
const maybeTable = rest[0];
|
|
102
|
-
const options = maybeTable?.rowsHash ? parseFillOptions(maybeTable) : {};
|
|
107
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseFillOptions)(maybeTable) : {};
|
|
103
108
|
const text = textOrAlias.startsWith("@")
|
|
104
109
|
? this.data[textOrAlias.slice(1)] ??
|
|
105
110
|
(() => {
|
|
106
111
|
throw new Error(`No value found for alias "${textOrAlias}"`);
|
|
107
112
|
})()
|
|
108
|
-
: evaluateFaker(textOrAlias);
|
|
113
|
+
: (0, fakerUtils_1.evaluateFaker)(textOrAlias);
|
|
109
114
|
await this.element.fill("");
|
|
110
115
|
await this.element.fill(text, options);
|
|
111
116
|
this.data.lastTyped = text;
|
|
112
117
|
this.log?.(`โจ๏ธ Typed "${text}" into selected element`);
|
|
113
118
|
};
|
|
114
|
-
When("I type {string}", typeStep);
|
|
115
|
-
When("I type stored {string}", typeStep);
|
|
116
|
-
When("I type random {string}", typeStep);
|
|
117
|
-
When("I set value {string}", async function (valueOrAlias, ...rest) {
|
|
119
|
+
(0, cucumber_1.When)("I type {string}", typeStep);
|
|
120
|
+
(0, cucumber_1.When)("I type stored {string}", typeStep);
|
|
121
|
+
(0, cucumber_1.When)("I type random {string}", typeStep);
|
|
122
|
+
(0, cucumber_1.When)("I set value {string}", async function (valueOrAlias, ...rest) {
|
|
118
123
|
if (!this.element)
|
|
119
124
|
throw new Error("No element selected");
|
|
120
125
|
const maybeTable = rest[0];
|
|
121
|
-
const options = maybeTable?.rowsHash ? parseFillOptions(maybeTable) : {};
|
|
126
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseFillOptions)(maybeTable) : {};
|
|
122
127
|
const value = valueOrAlias.startsWith("@")
|
|
123
128
|
? this.data[valueOrAlias.slice(1)] ??
|
|
124
129
|
(() => {
|
|
125
130
|
throw new Error(`No value found for alias "${valueOrAlias}"`);
|
|
126
131
|
})()
|
|
127
|
-
: evaluateFaker(valueOrAlias);
|
|
132
|
+
: (0, fakerUtils_1.evaluateFaker)(valueOrAlias);
|
|
128
133
|
await this.element.fill(value, options);
|
|
129
134
|
this.data.lastValueSet = value;
|
|
130
135
|
this.log?.(`๐ Set value to "${value}"`);
|
|
131
136
|
});
|
|
132
|
-
When("I clear", async function () {
|
|
137
|
+
(0, cucumber_1.When)("I clear", async function () {
|
|
133
138
|
if (!this.element)
|
|
134
139
|
throw new Error("No element selected");
|
|
135
140
|
await this.element.fill("");
|
|
136
141
|
this.log?.("๐งผ Cleared value of selected element");
|
|
137
142
|
});
|
|
138
|
-
When("I submit", async function (...rest) {
|
|
143
|
+
(0, cucumber_1.When)("I submit", async function (...rest) {
|
|
139
144
|
const maybeTable = rest[0];
|
|
140
145
|
const form = this.element ?? this.page.locator("form");
|
|
141
146
|
await form.evaluate((f) => f.submit());
|
|
142
147
|
this.log?.("๐จ Submitted form");
|
|
143
148
|
});
|
|
144
|
-
When("I select option {string}", async function (option, ...rest) {
|
|
149
|
+
(0, cucumber_1.When)("I select option {string}", async function (option, ...rest) {
|
|
145
150
|
if (!this.element)
|
|
146
151
|
throw new Error("No select element stored");
|
|
147
152
|
const maybeTable = rest[0];
|
|
148
|
-
const options = maybeTable?.rowsHash ? parseSelectOptions(maybeTable) : {};
|
|
153
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseSelectOptions)(maybeTable) : {};
|
|
149
154
|
await this.element.selectOption({ label: option }, options);
|
|
150
155
|
this.log?.(`๐ฝ Selected option "${option}"`);
|
|
151
156
|
});
|
|
152
|
-
When("I select file {string}", async function (filePath, ...rest) {
|
|
157
|
+
(0, cucumber_1.When)("I select file {string}", async function (filePath, ...rest) {
|
|
153
158
|
if (!this.element)
|
|
154
159
|
throw new Error("No file input selected");
|
|
155
160
|
const maybeTable = rest[0];
|
|
156
|
-
const options = maybeTable?.rowsHash ? parseSelectOptions(maybeTable) : {};
|
|
161
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseSelectOptions)(maybeTable) : {};
|
|
157
162
|
await this.element.setInputFiles(filePath, options);
|
|
158
163
|
this.log?.(`๐ Set input file to "${filePath}"`);
|
|
159
164
|
});
|