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.
Files changed (96) hide show
  1. package/README.md +21 -11
  2. package/package.json +9 -2
  3. package/src/actions/clickSteps.ts +364 -142
  4. package/src/actions/cookieSteps.ts +66 -0
  5. package/src/actions/debugSteps.ts +17 -3
  6. package/src/actions/elementFindSteps.ts +822 -117
  7. package/src/actions/fillFormSteps.ts +234 -177
  8. package/src/actions/index.ts +12 -0
  9. package/src/actions/inputSteps.ts +318 -82
  10. package/src/actions/interceptionSteps.ts +295 -57
  11. package/src/actions/miscSteps.ts +984 -254
  12. package/src/actions/mouseSteps.ts +212 -55
  13. package/src/actions/scrollSteps.ts +114 -16
  14. package/src/actions/storageSteps.ts +267 -42
  15. package/src/assertions/buttonAndTextVisibilitySteps.ts +353 -95
  16. package/src/assertions/cookieSteps.ts +115 -36
  17. package/src/assertions/elementSteps.ts +414 -85
  18. package/src/assertions/formInputSteps.ts +375 -108
  19. package/src/assertions/index.ts +11 -0
  20. package/src/assertions/interceptionRequestsSteps.ts +619 -195
  21. package/src/assertions/locationSteps.ts +280 -64
  22. package/src/assertions/roleTestIdSteps.ts +244 -26
  23. package/src/assertions/semanticSteps.ts +257 -69
  24. package/src/assertions/storageSteps.ts +234 -73
  25. package/src/assertions/visualSteps.ts +245 -68
  26. package/src/custom_setups/loginHooks.ts +21 -2
  27. package/src/helpers/world.ts +30 -4
  28. package/src/index.ts +4 -25
  29. package/lib/actions/clickSteps.d.ts +0 -1
  30. package/lib/actions/clickSteps.js +0 -165
  31. package/lib/actions/cookieSteps.d.ts +0 -1
  32. package/lib/actions/cookieSteps.js +0 -28
  33. package/lib/actions/debugSteps.d.ts +0 -1
  34. package/lib/actions/debugSteps.js +0 -8
  35. package/lib/actions/elementFindSteps.d.ts +0 -1
  36. package/lib/actions/elementFindSteps.js +0 -217
  37. package/lib/actions/fillFormSteps.d.ts +0 -1
  38. package/lib/actions/fillFormSteps.js +0 -130
  39. package/lib/actions/inputSteps.d.ts +0 -1
  40. package/lib/actions/inputSteps.js +0 -97
  41. package/lib/actions/interceptionSteps.d.ts +0 -1
  42. package/lib/actions/interceptionSteps.js +0 -71
  43. package/lib/actions/miscSteps.d.ts +0 -1
  44. package/lib/actions/miscSteps.js +0 -320
  45. package/lib/actions/mouseSteps.d.ts +0 -1
  46. package/lib/actions/mouseSteps.js +0 -66
  47. package/lib/actions/scrollSteps.d.ts +0 -1
  48. package/lib/actions/scrollSteps.js +0 -23
  49. package/lib/actions/storageSteps.d.ts +0 -1
  50. package/lib/actions/storageSteps.js +0 -72
  51. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -1
  52. package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -150
  53. package/lib/assertions/cookieSteps.d.ts +0 -1
  54. package/lib/assertions/cookieSteps.js +0 -45
  55. package/lib/assertions/elementSteps.d.ts +0 -1
  56. package/lib/assertions/elementSteps.js +0 -90
  57. package/lib/assertions/formInputSteps.d.ts +0 -1
  58. package/lib/assertions/formInputSteps.js +0 -87
  59. package/lib/assertions/interceptionRequestsSteps.d.ts +0 -1
  60. package/lib/assertions/interceptionRequestsSteps.js +0 -201
  61. package/lib/assertions/locationSteps.d.ts +0 -1
  62. package/lib/assertions/locationSteps.js +0 -87
  63. package/lib/assertions/roleTestIdSteps.d.ts +0 -1
  64. package/lib/assertions/roleTestIdSteps.js +0 -26
  65. package/lib/assertions/semanticSteps.d.ts +0 -1
  66. package/lib/assertions/semanticSteps.js +0 -67
  67. package/lib/assertions/storageSteps.d.ts +0 -1
  68. package/lib/assertions/storageSteps.js +0 -74
  69. package/lib/assertions/visualSteps.d.ts +0 -1
  70. package/lib/assertions/visualSteps.js +0 -76
  71. package/lib/custom_setups/loginHooks.d.ts +0 -1
  72. package/lib/custom_setups/loginHooks.js +0 -113
  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 -31
  90. package/lib/helpers/world.js +0 -104
  91. package/lib/iframes/frames.d.ts +0 -1
  92. package/lib/iframes/frames.js +0 -11
  93. package/lib/index.d.ts +0 -28
  94. package/lib/index.js +0 -48
  95. package/lib/register.d.ts +0 -1
  96. package/lib/register.js +0 -6
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cucumber_1 = require("@cucumber/cucumber");
4
- /**
5
- * THEN: I see cookie "myCookie"
6
- */
7
- (0, cucumber_1.Then)("I see cookie {string}", async function (cookieName) {
8
- const cookies = await this.context.cookies();
9
- const cookie = cookies.find((c) => c.name === cookieName);
10
- if (!cookie)
11
- throw new Error(`Cookie "${cookieName}" not found`);
12
- });
13
- /**
14
- * THEN: I do not see cookie "myCookie"
15
- */
16
- (0, cucumber_1.Then)("I do not see cookie {string}", async function (name) {
17
- const cookies = await this.context.cookies();
18
- const cookie = cookies.find((c) => c.name === name);
19
- if (cookie)
20
- throw new Error(`Cookie "${name}" was found but should not exist`);
21
- });
22
- /**
23
- * THEN: I see cookie "sessionId" has value "abc123"
24
- */
25
- (0, cucumber_1.Then)("I see cookie {string} has value {string}", async function (name, expectedValue) {
26
- const cookies = await this.context.cookies();
27
- const cookie = cookies.find((c) => c.name === name);
28
- if (!cookie)
29
- throw new Error(`Cookie "${name}" not found`);
30
- if (cookie.value !== expectedValue) {
31
- throw new Error(`Expected cookie "${name}" to have value "${expectedValue}", but got "${cookie.value}"`);
32
- }
33
- });
34
- /**
35
- * THEN: I see cookie "token" contains value "auth"
36
- */
37
- (0, cucumber_1.Then)("I see cookie {string} contains value {string}", async function (name, valuePart) {
38
- const cookies = await this.context.cookies();
39
- const cookie = cookies.find((c) => c.name === name);
40
- if (!cookie)
41
- throw new Error(`Cookie "${name}" not found`);
42
- if (!cookie.value.includes(valuePart)) {
43
- throw new Error(`Cookie "${name}" does not contain value "${valuePart}"`);
44
- }
45
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,90 +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
- // ✅ ELEMENT EXISTS
7
- //
8
- (0, cucumber_1.Then)(/^I see element "([^"]+)" exists$/, async function (selector) {
9
- const el = await this.page.locator(selector);
10
- await (0, test_1.expect)(el).toHaveCount(1);
11
- });
12
- (0, cucumber_1.Then)("I see element exists", async function () {
13
- if (!this.element)
14
- throw new Error("No element stored in context");
15
- const count = (await this.element.count?.()) ?? 1;
16
- if (count === 0)
17
- throw new Error("Element does not exist");
18
- });
19
- (0, cucumber_1.Then)("I see element does not exist", async function () {
20
- if (!this.element)
21
- throw new Error("No element stored in context");
22
- const count = (await this.element.count?.()) ?? 1;
23
- if (count > 0)
24
- throw new Error("Element exists but should not");
25
- });
26
- (0, cucumber_1.Then)("I see element is visible", async function () {
27
- if (!this.element)
28
- throw new Error("No element in context");
29
- const isVisible = await this.element.isVisible();
30
- if (!isVisible)
31
- throw new Error("Element is not visible");
32
- });
33
- (0, cucumber_1.Then)("I see element is not visible", async function () {
34
- if (!this.element)
35
- throw new Error("No element in context");
36
- const isVisible = await this.element.isVisible();
37
- if (isVisible)
38
- throw new Error("Element is visible but should not be");
39
- });
40
- (0, cucumber_1.Then)(/^I see element "([^"]+)" does not exist$/, async function (selector) {
41
- const el = await this.page.locator(selector);
42
- await (0, test_1.expect)(el).toHaveCount(0);
43
- });
44
- //
45
- // 👁️ ELEMENT VISIBILITY
46
- //
47
- (0, cucumber_1.Then)(/^I see element "([^"]+)" is visible$/, async function (selector) {
48
- const el = this.page.locator(selector);
49
- await (0, test_1.expect)(el).toBeVisible();
50
- });
51
- (0, cucumber_1.Then)(/^I see element "([^"]+)" is not visible$/, async function (selector) {
52
- const el = this.page.locator(selector);
53
- await (0, test_1.expect)(el).not.toBeVisible();
54
- });
55
- //
56
- // 🔎 ATTRIBUTE ASSERTIONS
57
- //
58
- (0, cucumber_1.Then)(/^I see element "([^"]+)" attribute "([^"]+)" equals "(.*)"$/, async function (selector, attribute, expected) {
59
- const el = this.page.locator(selector);
60
- await (0, test_1.expect)(el).toHaveAttribute(attribute, expected);
61
- });
62
- (0, cucumber_1.Then)('I see element attribute "{word}" equals {string}', async function (attr, expected) {
63
- if (!this.element) {
64
- throw new Error("No element is currently selected. Use a 'find' step before asserting.");
65
- }
66
- await (0, test_1.expect)(this.element).toHaveAttribute(attr, expected);
67
- });
68
- (0, cucumber_1.Then)("I see element has attribute {string}", async function (attr) {
69
- if (!this.element)
70
- throw new Error("No element in context");
71
- const value = await this.element.getAttribute(attr);
72
- if (value === null)
73
- throw new Error(`Attribute "${attr}" not found`);
74
- });
75
- (0, cucumber_1.Then)('I see element attribute "{word}" contains {string}', async function (attr, part) {
76
- if (!this.element)
77
- throw new Error("No element in context");
78
- const value = await this.element.getAttribute(attr);
79
- if (!value?.includes(part)) {
80
- throw new Error(`Attribute "${attr}" does not contain "${part}". Got: "${value}"`);
81
- }
82
- });
83
- (0, cucumber_1.Then)(/^I see element "([^"]+)" attribute "([^"]+)" contains "(.*)"$/, async function (selector, attribute, substring) {
84
- const attr = await this.page.locator(selector).getAttribute(attribute);
85
- (0, test_1.expect)(attr?.includes(substring)).toBeTruthy();
86
- });
87
- (0, cucumber_1.Then)(/^I see element "([^"]+)" has attribute "([^"]+)"$/, async function (selector, attribute) {
88
- const attr = await this.page.locator(selector).getAttribute(attribute);
89
- (0, test_1.expect)(attr).not.toBeNull();
90
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,87 +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
- // 🧾 INPUT VALUES
7
- //
8
- (0, cucumber_1.Then)(/^I see input "([^"]+)" has value "(.*)"$/, async function (selector, value) {
9
- const el = this.page.locator(selector);
10
- await (0, test_1.expect)(el).toHaveValue(value);
11
- });
12
- (0, cucumber_1.Then)("I see input value {string}", async function (expected) {
13
- if (!this.element)
14
- throw new Error("No element stored in context");
15
- const value = await this.element.inputValue();
16
- (0, test_1.expect)(value).toBe(expected);
17
- });
18
- (0, cucumber_1.Then)("I see input value contains {string}", async function (part) {
19
- if (!this.element)
20
- throw new Error("No element stored in context");
21
- const value = await this.element.inputValue();
22
- (0, test_1.expect)(value).toContain(part);
23
- });
24
- (0, cucumber_1.Then)(/^I see input "([^"]+)" value contains "(.*)"$/, async function (selector, partial) {
25
- const val = await this.page.locator(selector).inputValue();
26
- (0, test_1.expect)(val).toContain(partial);
27
- });
28
- //
29
- // 📝 TEXTAREA VALUES
30
- //
31
- (0, cucumber_1.Then)(/^I see textarea "([^"]+)" has value "(.*)"$/, async function (selector, value) {
32
- const el = this.page.locator(selector);
33
- await (0, test_1.expect)(el).toHaveValue(value);
34
- });
35
- (0, cucumber_1.Then)("I see textarea value {string}", async function (expected) {
36
- if (!this.element)
37
- throw new Error("No textarea selected");
38
- const value = await this.element.inputValue();
39
- if (value !== expected)
40
- throw new Error(`Expected "${expected}", got "${value}"`);
41
- });
42
- (0, cucumber_1.Then)("I see textarea value contains {string}", async function (part) {
43
- if (!this.element)
44
- throw new Error("No textarea selected");
45
- const value = await this.element.inputValue();
46
- if (!value.includes(part)) {
47
- throw new Error(`Textarea does not contain "${part}". Got: "${value}"`);
48
- }
49
- });
50
- (0, cucumber_1.Then)(/^I see textarea "([^"]+)" value contains "(.*)"$/, async function (selector, partial) {
51
- const val = await this.page.locator(selector).inputValue();
52
- (0, test_1.expect)(val).toContain(partial);
53
- });
54
- //
55
- // ✅ GENERIC VALUE MATCHING
56
- //
57
- (0, cucumber_1.Then)(/^I see value "(.*)" in "([^"]+)"$/, async function (value, selector) {
58
- const el = this.page.locator(selector);
59
- await (0, test_1.expect)(el).toHaveValue(value);
60
- });
61
- (0, cucumber_1.Then)(/^I do not see value "(.*)" in "([^"]+)"$/, async function (value, selector) {
62
- const actual = await this.page.locator(selector).inputValue();
63
- (0, test_1.expect)(actual).not.toBe(value);
64
- });
65
- //
66
- // ⬇️ OPTION IN SELECT
67
- //
68
- (0, cucumber_1.Then)(/^I see option "(.*)"$/, async function (optionText) {
69
- const el = this.page.locator(`option`, { hasText: optionText });
70
- await (0, test_1.expect)(el).toHaveCount(1);
71
- });
72
- (0, cucumber_1.Then)("I see option {string}", async function (optionText) {
73
- const option = this.page.locator("option", { hasText: optionText });
74
- if (!(await option.isVisible())) {
75
- throw new Error(`Option "${optionText}" not visible`);
76
- }
77
- });
78
- (0, cucumber_1.Then)("I do not see option {string}", async function (optionText) {
79
- const option = this.page.locator("option", { hasText: optionText });
80
- if ((await option.count()) > 0 && (await option.first().isVisible())) {
81
- throw new Error(`Option "${optionText}" is visible but should not be`);
82
- }
83
- });
84
- (0, cucumber_1.Then)(/^I do not see option "(.*)"$/, async function (optionText) {
85
- const el = this.page.locator(`option`, { hasText: optionText });
86
- await (0, test_1.expect)(el).toHaveCount(0);
87
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,201 +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
- // Accessing the Last Response
6
- (0, cucumber_1.Then)("I should see response status {int}", function (expectedStatus) {
7
- (0, test_1.expect)(this.data.lastResponse?.status).toBe(expectedStatus);
8
- this.log(`Verified response status is ${expectedStatus}`);
9
- });
10
- (0, cucumber_1.Then)("I should see response body contains {string}", function (expectedText) {
11
- (0, test_1.expect)(this.data.lastResponse?.body).toContain(expectedText);
12
- this.log(`Verified response body contains "${expectedText}"`);
13
- });
14
- (0, cucumber_1.Then)("I see response body {string}", async function (expected) {
15
- const res = this.data.lastResponse;
16
- const body = await res.text();
17
- if (body !== expected)
18
- throw new Error(`Expected body "${expected}", got "${body}"`);
19
- });
20
- (0, cucumber_1.Then)("I see response body contains {string}", async function (part) {
21
- const res = this.data.lastResponse;
22
- const body = await res.text();
23
- if (!body.includes(part))
24
- throw new Error(`Body does not contain "${part}"`);
25
- });
26
- (0, cucumber_1.Then)("I see response body matches JSON schema {string}", async function (schemaPath) {
27
- const res = this.data.lastResponse;
28
- const body = await res.text();
29
- const schema = require(schemaPath); // Assuming schema is a JSON file
30
- const Ajv = require("ajv");
31
- const ajv = new Ajv();
32
- const validate = ajv.compile(schema);
33
- const valid = validate(JSON.parse(body));
34
- if (!valid) {
35
- throw new Error(`Response body does not match schema: ${ajv.errorsText(validate.errors)}`);
36
- }
37
- });
38
- (0, cucumber_1.Then)("I see response header {string} equals {string}", async function (headerName, expectedValue) {
39
- const res = this.data.lastResponse;
40
- const headerValue = res.headers()[headerName.toLowerCase()];
41
- if (headerValue !== expectedValue) {
42
- throw new Error(`Expected header "${headerName}" to be "${expectedValue}", got "${headerValue}"`);
43
- }
44
- this.log(`Verified response header "${headerName}" equals "${expectedValue}"`);
45
- });
46
- (0, cucumber_1.Then)("I see response header {string} contains {string}", async function (headerName, expectedValue) {
47
- const res = this.data.lastResponse;
48
- const headerValue = res.headers()[headerName.toLowerCase()];
49
- if (!headerValue || !headerValue.includes(expectedValue)) {
50
- throw new Error(`Expected header "${headerName}" to contain "${expectedValue}", got "${headerValue}"`);
51
- }
52
- this.log(`Verified response header "${headerName}" contains "${expectedValue}"`);
53
- });
54
- (0, cucumber_1.Then)("I see response header {string} does not contain {string}", async function (headerName, unexpectedValue) {
55
- const res = this.data.lastResponse;
56
- const headerValue = res.headers()[headerName.toLowerCase()];
57
- if (headerValue && headerValue.includes(unexpectedValue)) {
58
- throw new Error(`Expected header "${headerName}" to not contain "${unexpectedValue}", but it does`);
59
- }
60
- this.log(`Verified response header "${headerName}" does not contain "${unexpectedValue}"`);
61
- });
62
- (0, cucumber_1.Then)("I see response header {string} does not equal {string}", async function (headerName, unexpectedValue) {
63
- const res = this.data.lastResponse;
64
- const headerValue = res.headers()[headerName.toLowerCase()];
65
- if (headerValue === unexpectedValue) {
66
- throw new Error(`Expected header "${headerName}" to not equal "${unexpectedValue}", but it does`);
67
- }
68
- this.log(`Verified response header "${headerName}" does not equal "${unexpectedValue}"`);
69
- });
70
- (0, cucumber_1.Then)("I see response header {string} exists", async function (headerName) {
71
- const res = this.data.lastResponse;
72
- const headerValue = res.headers()[headerName.toLowerCase()];
73
- if (!headerValue) {
74
- throw new Error(`Expected header "${headerName}" to exist, but it does not`);
75
- }
76
- this.log(`Verified response header "${headerName}" exists`);
77
- });
78
- (0, cucumber_1.Then)("I see response header {string} does not exist", async function (headerName) {
79
- const res = this.data.lastResponse;
80
- const headerValue = res.headers()[headerName.toLowerCase()];
81
- if (headerValue) {
82
- throw new Error(`Expected header "${headerName}" to not exist, but it does`);
83
- }
84
- this.log(`Verified response header "${headerName}" does not exist`);
85
- });
86
- (0, cucumber_1.Then)("I see response status {int}", async function (status) {
87
- const res = this.data.lastResponse;
88
- if (!res)
89
- throw new Error("No response available");
90
- const actual = res.status();
91
- if (actual !== status)
92
- throw new Error(`Expected status ${status}, got ${actual}`);
93
- });
94
- (0, cucumber_1.Then)("I see response status is not {int}", async function (status) {
95
- const res = this.data.lastResponse;
96
- if (!res)
97
- throw new Error("No response available");
98
- const actual = res.status();
99
- if (actual === status)
100
- throw new Error(`Expected status not to be ${status}, but it is`);
101
- });
102
- (0, cucumber_1.Then)("I see response body matches JSON schema", async function (schema) {
103
- const res = this.data.lastResponse;
104
- if (!res)
105
- throw new Error("No response available");
106
- const body = await res.text();
107
- const Ajv = require("ajv");
108
- const ajv = new Ajv();
109
- const validate = ajv.compile(schema);
110
- const valid = validate(JSON.parse(body));
111
- if (!valid) {
112
- throw new Error(`Response body does not match schema: ${ajv.errorsText(validate.errors)}`);
113
- }
114
- this.log(`Response body matches JSON schema`);
115
- });
116
- (0, cucumber_1.Then)("I see response body is empty", async function () {
117
- const res = this.data.lastResponse;
118
- if (!res)
119
- throw new Error("No response available");
120
- const body = await res.text();
121
- if (body.trim() !== "") {
122
- throw new Error(`Expected empty response body, got "${body}"`);
123
- }
124
- this.log(`Verified response body is empty`);
125
- });
126
- (0, cucumber_1.Then)("I see response body is not empty", async function () {
127
- const res = this.data.lastResponse;
128
- if (!res)
129
- throw new Error("No response available");
130
- const body = await res.text();
131
- if (body.trim() === "") {
132
- throw new Error(`Expected non-empty response body, got empty`);
133
- }
134
- this.log(`Verified response body is not empty`);
135
- });
136
- (0, cucumber_1.Then)("I see response body matches {string}", async function (expected) {
137
- const res = this.data.lastResponse;
138
- if (!res)
139
- throw new Error("No response available");
140
- const body = await res.text();
141
- if (body !== expected) {
142
- throw new Error(`Expected body "${expected}", got "${body}"`);
143
- }
144
- this.log(`Verified response body matches: ${expected}`);
145
- });
146
- (0, cucumber_1.Then)("I see response body contains {string}", async function (part) {
147
- const res = this.data.lastResponse;
148
- if (!res)
149
- throw new Error("No response available");
150
- const body = await res.text();
151
- if (!body.includes(part)) {
152
- throw new Error(`Body does not contain "${part}"`);
153
- }
154
- this.log(`Verified response body contains: ${part}`);
155
- });
156
- (0, cucumber_1.Then)("I see response body does not contain {string}", async function (part) {
157
- const res = this.data.lastResponse;
158
- if (!res)
159
- throw new Error("No response available");
160
- const body = await res.text();
161
- if (body.includes(part)) {
162
- throw new Error(`Body contains "${part}", but it should not`);
163
- }
164
- this.log(`Verified response body does not contain: ${part}`);
165
- });
166
- (0, cucumber_1.Then)("I see response body is JSON", async function () {
167
- const res = this.data.lastResponse;
168
- if (!res)
169
- throw new Error("No response available");
170
- const body = await res.text();
171
- try {
172
- JSON.parse(body);
173
- this.log(`Verified response body is valid JSON`);
174
- }
175
- catch (e) {
176
- if (e instanceof Error) {
177
- throw new Error(`Response body is not valid JSON: ${e.message}`);
178
- }
179
- else {
180
- throw new Error(`Response body is not valid JSON: ${String(e)}`);
181
- }
182
- }
183
- });
184
- (0, cucumber_1.Then)("I see response body is not JSON", async function () {
185
- const res = this.data.lastResponse;
186
- if (!res)
187
- throw new Error("No response available");
188
- const body = await res.text();
189
- try {
190
- JSON.parse(body);
191
- throw new Error(`Expected response body to not be JSON, but it is`);
192
- }
193
- catch (e) {
194
- if (e instanceof Error) {
195
- this.log(`Verified response body is not JSON: ${e.message}`);
196
- }
197
- else {
198
- this.log(`Verified response body is not JSON: ${String(e)}`);
199
- }
200
- }
201
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,87 +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
- // 🌐 URL
7
- //
8
- (0, cucumber_1.Then)("I see URL {string}", async function (expected) {
9
- const url = this.page.url();
10
- (0, test_1.expect)(url).toBe(expected);
11
- });
12
- (0, cucumber_1.Then)("I do not see URL {string}", async function (notExpected) {
13
- const url = this.page.url();
14
- if (url === notExpected)
15
- throw new Error(`Expected not to be on URL "${notExpected}"`);
16
- });
17
- (0, cucumber_1.Then)("I see URL contains {string}", async function (expected) {
18
- const url = this.page.url();
19
- (0, test_1.expect)(url).toContain(expected);
20
- });
21
- (0, cucumber_1.Then)("I do not see URL contains {string}", async function (notExpected) {
22
- const url = this.page.url();
23
- if (url.includes(notExpected)) {
24
- throw new Error(`URL should not contain "${notExpected}", but got "${url}"`);
25
- }
26
- });
27
- //
28
- // 📍 LOCATION PARTS
29
- //
30
- (0, cucumber_1.Then)("I see location {string}", async function (expected) {
31
- const location = await this.page.evaluate(() => window.location.href);
32
- if (location !== expected) {
33
- throw new Error(`Expected location to be "${expected}", but got "${location}"`);
34
- }
35
- });
36
- (0, cucumber_1.Then)("I see pathname {string}", async function (expected) {
37
- const pathname = await this.page.evaluate(() => window.location.pathname);
38
- if (pathname !== expected) {
39
- throw new Error(`Expected pathname "${expected}", but got "${pathname}"`);
40
- }
41
- });
42
- (0, cucumber_1.Then)("I see pathname contains {string}", async function (part) {
43
- const pathname = await this.page.evaluate(() => window.location.pathname);
44
- if (!pathname.includes(part)) {
45
- throw new Error(`Pathname does not contain "${part}". Got: "${pathname}"`);
46
- }
47
- });
48
- (0, cucumber_1.Then)("I see hash {string}", async function (expected) {
49
- const hash = await this.page.evaluate(() => window.location.hash);
50
- if (hash !== expected) {
51
- throw new Error(`Expected hash "${expected}", but got "${hash}"`);
52
- }
53
- });
54
- (0, cucumber_1.Then)("I see hash contains {string}", async function (part) {
55
- const hash = await this.page.evaluate(() => window.location.hash);
56
- if (!hash.includes(part)) {
57
- throw new Error(`Expected hash to contain "${part}", but got "${hash}"`);
58
- }
59
- });
60
- (0, cucumber_1.Then)("I see search {string}", async function (expected) {
61
- const search = await this.page.evaluate(() => window.location.search);
62
- if (search !== expected) {
63
- throw new Error(`Expected search to be "${expected}", but got "${search}"`);
64
- }
65
- });
66
- (0, cucumber_1.Then)("I see search contains {string}", async function (part) {
67
- const search = await this.page.evaluate(() => window.location.search);
68
- if (!search.includes(part)) {
69
- throw new Error(`Search does not contain "${part}". Got: "${search}"`);
70
- }
71
- });
72
- (0, cucumber_1.Then)("I see location", async function (table) {
73
- const location = await this.page.evaluate(() => ({
74
- href: window.location.href,
75
- origin: window.location.origin,
76
- protocol: window.location.protocol,
77
- host: window.location.host,
78
- hostname: window.location.hostname,
79
- port: window.location.port,
80
- pathname: window.location.pathname,
81
- search: window.location.search,
82
- hash: window.location.hash,
83
- }));
84
- for (const [key, expected] of table.rows()) {
85
- (0, test_1.expect)(location[key]).toBe(expected);
86
- }
87
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +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
- // 🧩 ROLE-BASED ELEMENTS
7
- //
8
- (0, cucumber_1.Then)(/^I see role "(.*)" with name "(.*)"$/, async function (role, name) {
9
- const el = this.page.getByRole(role, { name, exact: true });
10
- await (0, test_1.expect)(el).toBeVisible();
11
- });
12
- (0, cucumber_1.Then)(/^I do not see role "(.*)" with name "(.*)"$/, async function (role, name) {
13
- const el = this.page.getByRole(role, { name, exact: true });
14
- await (0, test_1.expect)(el).toHaveCount(0);
15
- });
16
- //
17
- // 🏷️ TEST ID-BASED ELEMENTS
18
- //
19
- (0, cucumber_1.Then)(/^I see testid "(.*)"$/, async function (testId) {
20
- const el = this.page.getByTestId(testId);
21
- await (0, test_1.expect)(el).toBeVisible();
22
- });
23
- (0, cucumber_1.Then)(/^I do not see testid "(.*)"$/, async function (testId) {
24
- const el = this.page.getByTestId(testId);
25
- await (0, test_1.expect)(el).toHaveCount(0);
26
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,67 +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
- const optionsUtils_1 = require("../helpers/utils/optionsUtils");
6
- //
7
- // 🧠 HEADINGS
8
- //
9
- (0, cucumber_1.Then)("I see heading {string}", async function (text) {
10
- const heading = await this.page.locator("h1, h2, h3, h4, h5, h6", { hasText: text }).first();
11
- if (!(await heading.isVisible())) {
12
- throw new Error(`Heading "${text}" not found or not visible`);
13
- }
14
- });
15
- (0, cucumber_1.Then)("I do not see heading {string}", async function (text) {
16
- const heading = this.page.locator("h1, h2, h3, h4, h5, h6", {
17
- hasText: text,
18
- });
19
- if ((await heading.count()) > 0) {
20
- const visible = await heading.first().isVisible();
21
- if (visible)
22
- throw new Error(`Heading "${text}" is visible but should not be`);
23
- }
24
- });
25
- //
26
- // 🏷️ LABELS
27
- //
28
- (0, cucumber_1.Then)("I see label {string}", async function (text) {
29
- const label = this.page.getByLabel(text);
30
- if (!(await label.isVisible())) {
31
- throw new Error(`Label "${text}" not visible`);
32
- }
33
- });
34
- (0, cucumber_1.Then)("I do not see label {string}", async function (text) {
35
- const label = this.page.getByLabel(text);
36
- if ((await label.count()) > 0 && (await label.first().isVisible())) {
37
- throw new Error(`Label "${text}" is visible but should not be`);
38
- }
39
- });
40
- //
41
- // 🔗 LINKS
42
- //
43
- (0, cucumber_1.Then)("I see link {string}", async function (text) {
44
- const link = this.page.getByRole("link", { name: text });
45
- if (!(await link.isVisible())) {
46
- throw new Error(`Link "${text}" not visible`);
47
- }
48
- });
49
- (0, cucumber_1.Then)("I do not see link {string}", async function (text) {
50
- const link = this.page.getByRole("link", { name: text });
51
- if ((await link.count()) > 0 && (await link.first().isVisible())) {
52
- throw new Error(`Link "${text}" is visible but should not be`);
53
- }
54
- });
55
- (0, cucumber_1.Then)("I count {int} element", async function (count) {
56
- const locator = this.currentLocator ?? this.page.locator("*");
57
- await (0, test_1.expect)(locator).toHaveCount(count);
58
- });
59
- //document title assertions
60
- (0, cucumber_1.Then)("I see document title {string}", async function (expected, table) {
61
- const options = (0, optionsUtils_1.parseExpectOptions)(table);
62
- await (0, test_1.expect)(this.page).toHaveTitle(expected, options);
63
- });
64
- (0, cucumber_1.Then)("I see document title contains {string}", async function (substring, table) {
65
- const options = (0, optionsUtils_1.parseExpectOptions)(table);
66
- await (0, test_1.expect)(this.page).toHaveTitle(new RegExp(substring, "i"), options);
67
- });
@@ -1 +0,0 @@
1
- export {};