playwright-cucumber-ts-steps 0.0.5 → 0.0.7

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.
@@ -1,15 +1,5 @@
1
1
  // e2e/step_definitions/common/interceptionSteps.ts
2
- import { When, Then } from "@cucumber/cucumber";
3
- import { expect } from "@playwright/test";
4
- When("I intercept URL {string}", async function (url) {
5
- this.interceptedRequests = [];
6
- await this.page.route(url, (route, request) => {
7
- this.interceptedRequests.push(request);
8
- this.log(`Intercepted request to: ${request.url()}`);
9
- route.continue();
10
- });
11
- this.log(`Setup interception for URL: "${url}"`);
12
- });
2
+ import { When } from "@cucumber/cucumber";
13
3
  When("I intercept URL {string} and stub body:", async function (url, body) {
14
4
  let parsedBody;
15
5
  try {
@@ -29,7 +19,7 @@ When("I intercept URL {string} and stub body:", async function (url, body) {
29
19
  this.log(`Intercepted and stubbed URL "${url}" with body: ${JSON.stringify(parsedBody)}`);
30
20
  });
31
21
  //Making Direct API Requests (Optional, Advanced)
32
- When("I make a request to {string}", async function (url) {
22
+ When("I make request to {string}", async function (url) {
33
23
  const response = await this.page.request.get(url);
34
24
  const status = response.status();
35
25
  const body = await response.text();
@@ -51,14 +41,21 @@ When("I make a POST request to {string} with JSON body:", async function (url, d
51
41
  this.data.lastResponse = { status, body };
52
42
  this.log(`Made POST request to "${url}" — Status: ${status}`);
53
43
  });
54
- // Accessing the Last Response
55
- Then("I should see response status {int}", function (expectedStatus) {
56
- var _a;
57
- expect((_a = this.data.lastResponse) === null || _a === void 0 ? void 0 : _a.status).toBe(expectedStatus);
58
- this.log(`Verified response status is ${expectedStatus}`);
44
+ When("I intercept URL {string}", async function (url) {
45
+ await this.page.route(url, async (route) => {
46
+ await route.continue();
47
+ });
59
48
  });
60
- Then("I should see response body contains {string}", function (expectedText) {
61
- var _a;
62
- expect((_a = this.data.lastResponse) === null || _a === void 0 ? void 0 : _a.body).toContain(expectedText);
63
- this.log(`Verified response body contains "${expectedText}"`);
49
+ When("I intercept URL {string} and stub body {string}", async function (url, body) {
50
+ await this.page.route(url, (route) => {
51
+ route.fulfill({
52
+ status: 200,
53
+ contentType: "application/json",
54
+ body,
55
+ });
56
+ });
57
+ });
58
+ When("I make a request to {string}", async function (url) {
59
+ const response = await this.page.request.get(url);
60
+ this.data.lastResponse = response;
64
61
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,191 @@
1
+ import { Then } from "@cucumber/cucumber";
2
+ import { expect } from "@playwright/test";
3
+ // Accessing the Last Response
4
+ Then("I should see response status {int}", function (expectedStatus) {
5
+ var _a;
6
+ expect((_a = this.data.lastResponse) === null || _a === void 0 ? void 0 : _a.status).toBe(expectedStatus);
7
+ this.log(`Verified response status is ${expectedStatus}`);
8
+ });
9
+ Then("I should see response body contains {string}", function (expectedText) {
10
+ var _a;
11
+ expect((_a = this.data.lastResponse) === null || _a === void 0 ? void 0 : _a.body).toContain(expectedText);
12
+ this.log(`Verified response body contains "${expectedText}"`);
13
+ });
14
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ 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
+ throw new Error(`Response body is not valid JSON: ${e.message}`);
177
+ }
178
+ });
179
+ Then("I see response body is not JSON", async function () {
180
+ const res = this.data.lastResponse;
181
+ if (!res)
182
+ throw new Error("No response available");
183
+ const body = await res.text();
184
+ try {
185
+ JSON.parse(body);
186
+ throw new Error(`Expected response body to not be JSON, but it is`);
187
+ }
188
+ catch (e) {
189
+ this.log(`Verified response body is not JSON: ${e.message}`);
190
+ }
191
+ });
package/dist/index.d.ts CHANGED
@@ -1,28 +1,28 @@
1
- export * from "./actions/Interception & Requests";
1
+ export * from "./actions/clickSteps";
2
+ export * from "./actions/cookieSteps";
3
+ export * from "./actions/debugSteps";
4
+ export * from "./actions/elementFindSteps";
5
+ export * from "./actions/inputSteps";
6
+ export * from "./actions/interceptionSteps";
7
+ export * from "./actions/miscSteps";
8
+ export * from "./actions/mouseSteps";
9
+ export * from "./actions/scrollSteps";
10
+ export * from "./actions/storageSteps";
2
11
  export * from "./assertions/button_and_text_visibility";
3
12
  export * from "./assertions/cookieSteps";
4
13
  export * from "./assertions/elementSteps";
5
14
  export * from "./assertions/formInputSteps";
15
+ export * from "./assertions/InterceptionRequests";
6
16
  export * from "./assertions/locationSteps";
7
- export * from "./actions/miscSteps";
8
17
  export * from "./assertions/roleTestIdSteps";
9
18
  export * from "./assertions/semanticSteps";
10
19
  export * from "./assertions/storageSteps";
20
+ export * from "./assertions/visualSteps";
11
21
  export * from "./custom_setups/global-login";
12
- export * from "./actions/Interception & Requests";
13
- export * from "./actions/cookieSteps";
14
- export * from "./actions/clickSteps";
15
- export * from "./actions/cookieSteps";
16
- export * from "./actions/debugSteps";
17
- export * from "./actions/elementFindSteps";
18
- export * from "./actions/inputSteps";
19
- export * from "./actions/mouseSteps";
20
- export * from "./actions/scrollSteps";
21
- export * from "./actions/storageSteps";
22
22
  export * from "./custom_setups/loginHooks";
23
23
  export * from "./iframes/frames";
24
+ export * from "./helpers/compareSnapshots";
25
+ export * from "./helpers/hooks";
24
26
  export * from "./helpers/utils";
25
27
  export * from "./helpers/world";
26
- export * from "./helpers/hooks";
27
- export * from "./helpers/compareSnapshots";
28
28
  export type { CustomWorld } from "./helpers/world";
package/dist/index.js CHANGED
@@ -1,29 +1,29 @@
1
1
  //src/index.ts
2
- export * from "./actions/Interception & Requests";
2
+ export * from "./actions/clickSteps";
3
+ export * from "./actions/cookieSteps";
4
+ export * from "./actions/debugSteps";
5
+ export * from "./actions/elementFindSteps";
6
+ export * from "./actions/inputSteps";
7
+ export * from "./actions/interceptionSteps";
8
+ export * from "./actions/miscSteps";
9
+ export * from "./actions/mouseSteps";
10
+ export * from "./actions/scrollSteps";
11
+ export * from "./actions/storageSteps";
3
12
  export * from "./assertions/button_and_text_visibility";
4
13
  export * from "./assertions/cookieSteps";
5
14
  export * from "./assertions/elementSteps";
6
15
  export * from "./assertions/formInputSteps";
16
+ export * from "./assertions/InterceptionRequests";
7
17
  export * from "./assertions/locationSteps";
8
- export * from "./actions/miscSteps";
9
18
  export * from "./assertions/roleTestIdSteps";
10
19
  export * from "./assertions/semanticSteps";
11
20
  export * from "./assertions/storageSteps";
21
+ export * from "./assertions/visualSteps";
12
22
  export * from "./custom_setups/global-login";
13
- export * from "./actions/Interception & Requests";
14
- export * from "./actions/cookieSteps";
15
- export * from "./actions/clickSteps";
16
- export * from "./actions/cookieSteps";
17
- export * from "./actions/debugSteps";
18
- export * from "./actions/elementFindSteps";
19
- export * from "./actions/inputSteps";
20
- export * from "./actions/mouseSteps";
21
- export * from "./actions/scrollSteps";
22
- export * from "./actions/storageSteps";
23
23
  export * from "./custom_setups/loginHooks";
24
24
  export * from "./iframes/frames";
25
25
  // Export core utilities and helpers
26
+ export * from "./helpers/compareSnapshots";
27
+ export * from "./helpers/hooks";
26
28
  export * from "./helpers/utils";
27
29
  export * from "./helpers/world";
28
- export * from "./helpers/hooks";
29
- export * from "./helpers/compareSnapshots";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-cucumber-ts-steps",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A collection of reusable Playwright step definitions for Cucumber in TypeScript, designed to streamline end-to-end testing across web, API, and mobile applications.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",