playwright-cucumber-ts-steps 1.1.8 → 1.1.10

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/dist/backend/actions/click.d.ts +132 -1
  3. package/dist/backend/actions/click.d.ts.map +1 -1
  4. package/dist/backend/actions/click.js +122 -53
  5. package/dist/backend/actions/find.d.ts +243 -1
  6. package/dist/backend/actions/find.d.ts.map +1 -1
  7. package/dist/backend/actions/find.js +196 -72
  8. package/dist/backend/actions/form.d.ts +37 -1
  9. package/dist/backend/actions/form.d.ts.map +1 -1
  10. package/dist/backend/actions/form.js +55 -3
  11. package/dist/backend/actions/formTable.d.ts +25 -1
  12. package/dist/backend/actions/formTable.d.ts.map +1 -1
  13. package/dist/backend/actions/formTable.js +27 -5
  14. package/dist/backend/actions/frames.d.ts +53 -1
  15. package/dist/backend/actions/frames.d.ts.map +1 -1
  16. package/dist/backend/actions/frames.js +48 -11
  17. package/dist/backend/actions/inputs.d.ts +139 -1
  18. package/dist/backend/actions/inputs.d.ts.map +1 -1
  19. package/dist/backend/actions/inputs.js +113 -43
  20. package/dist/backend/actions/interactions.d.ts +61 -1
  21. package/dist/backend/actions/interactions.d.ts.map +1 -1
  22. package/dist/backend/actions/interactions.js +65 -10
  23. package/dist/backend/actions/keyboard.d.ts +70 -1
  24. package/dist/backend/actions/keyboard.d.ts.map +1 -1
  25. package/dist/backend/actions/keyboard.js +59 -23
  26. package/dist/backend/actions/misc.d.ts +134 -1
  27. package/dist/backend/actions/misc.d.ts.map +1 -1
  28. package/dist/backend/actions/misc.js +106 -42
  29. package/dist/backend/actions/mobile.d.ts +74 -1
  30. package/dist/backend/actions/mobile.d.ts.map +1 -1
  31. package/dist/backend/actions/mobile.js +74 -13
  32. package/dist/backend/actions/mouse.d.ts +79 -1
  33. package/dist/backend/actions/mouse.d.ts.map +1 -1
  34. package/dist/backend/actions/mouse.js +66 -21
  35. package/dist/backend/actions/navigation.d.ts +48 -1
  36. package/dist/backend/actions/navigation.d.ts.map +1 -1
  37. package/dist/backend/actions/navigation.js +42 -15
  38. package/dist/backend/actions/waits.d.ts +55 -1
  39. package/dist/backend/actions/waits.d.ts.map +1 -1
  40. package/dist/backend/actions/waits.js +49 -17
  41. package/dist/backend/api/assertions.d.ts +32 -1
  42. package/dist/backend/api/assertions.d.ts.map +1 -1
  43. package/dist/backend/api/assertions.js +37 -9
  44. package/dist/backend/api/mock.d.ts +34 -1
  45. package/dist/backend/api/mock.d.ts.map +1 -1
  46. package/dist/backend/api/mock.js +37 -10
  47. package/dist/backend/api/network.d.ts +60 -1
  48. package/dist/backend/api/network.d.ts.map +1 -1
  49. package/dist/backend/api/network.js +53 -21
  50. package/dist/backend/api/requests.d.ts +43 -1
  51. package/dist/backend/api/requests.d.ts.map +1 -1
  52. package/dist/backend/api/requests.js +49 -17
  53. package/dist/backend/assertions/pageState.d.ts +40 -1
  54. package/dist/backend/assertions/pageState.d.ts.map +1 -1
  55. package/dist/backend/assertions/pageState.js +33 -12
  56. package/dist/backend/assertions/text.d.ts +46 -1
  57. package/dist/backend/assertions/text.d.ts.map +1 -1
  58. package/dist/backend/assertions/text.js +51 -8
  59. package/dist/backend/assertions/visibility.d.ts +102 -1
  60. package/dist/backend/assertions/visibility.d.ts.map +1 -1
  61. package/dist/backend/assertions/visibility.js +86 -36
  62. package/dist/backend/auth/index.js +2 -2
  63. package/dist/backend/db/steps.d.ts +35 -1
  64. package/dist/backend/db/steps.d.ts.map +1 -1
  65. package/dist/backend/db/steps.js +48 -15
  66. package/dist/backend/elements/alerts.d.ts +35 -1
  67. package/dist/backend/elements/alerts.d.ts.map +1 -1
  68. package/dist/backend/elements/alerts.js +39 -6
  69. package/dist/backend/elements/forms.d.ts +44 -1
  70. package/dist/backend/elements/forms.d.ts.map +1 -1
  71. package/dist/backend/elements/forms.js +50 -11
  72. package/dist/backend/elements/frames.d.ts +36 -1
  73. package/dist/backend/elements/frames.d.ts.map +1 -1
  74. package/dist/backend/elements/frames.js +43 -13
  75. package/dist/core/runner.d.ts.map +1 -1
  76. package/dist/core/runner.js +3 -4
  77. package/package.json +51 -12
@@ -1,22 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WaitForUrlContain = exports.WaitForElementHidden = exports.WaitForElementVisible = exports.WaitForLoadState = exports.WaitForNetworkIdle = void 0;
3
4
  const registry_1 = require("../../core/registry");
4
5
  const state_1 = require("../utils/state");
6
+ // =============================
7
+ // WAIT STRATEGIES
8
+ // =============================
5
9
  /**
6
- * Waits for the network to be idle (no active connections for 500ms).
7
- * Useful after clicking a button that triggers complex API calls.
8
- * Pattern: When I wait for network idle
10
+ * Waits for the network to reach an "idle" state.
11
+ * In Playwright terms, this means there are no new network connections for at least 500ms.
12
+ *
13
+ * ```gherkin
14
+ * When I wait for network idle
15
+ * ```
16
+ *
17
+ * @remarks
18
+ * **Warning:** This can be flaky on pages that have constant background polling (e.g., real-time chats, analytics).
19
+ * If the test times out here, consider using `I wait for element to be visible` instead.
9
20
  */
10
- (0, registry_1.Step)("I wait for network idle", async (page) => {
21
+ exports.WaitForNetworkIdle = (0, registry_1.Step)("I wait for network idle", async (page) => {
11
22
  await page.waitForLoadState("networkidle");
12
23
  console.log("⏳ Network is idle");
13
24
  });
14
25
  /**
15
- * Waits for the page to reach a specific load state.
16
- * Options: "load", "domcontentloaded", "networkidle".
17
- * Pattern: When I wait for load state "domcontentloaded"
26
+ * Waits for the page to reach a specific load lifecycle event.
27
+ *
28
+ * ```gherkin
29
+ * When I wait for load state "domcontentloaded"
30
+ * ```
31
+ *
32
+ * @param state - The state to wait for. Options:
33
+ * - `"load"`: Window load event fired.
34
+ * - `"domcontentloaded"`: DOM is ready (scripts might still be loading).
35
+ * - `"networkidle"`: No network connections for 500ms.
18
36
  */
19
- (0, registry_1.Step)("I wait for load state {string}", async (page, state) => {
37
+ exports.WaitForLoadState = (0, registry_1.Step)("I wait for load state {string}", async (page, state) => {
20
38
  if (!["load", "domcontentloaded", "networkidle"].includes(state)) {
21
39
  throw new Error(`❌ Invalid load state: "${state}". Use load, domcontentloaded, or networkidle.`);
22
40
  }
@@ -24,28 +42,42 @@ const state_1 = require("../utils/state");
24
42
  console.log(`⏳ Reached load state: "${state}"`);
25
43
  });
26
44
  /**
27
- * Explicitly waits for the stored element to be visible.
28
- * Pattern: When I wait for element to be visible
45
+ * Explicitly waits for the currently stored (active) element to become visible.
46
+ * Useful for ensuring animations complete or modals appear before proceeding.
47
+ *
48
+ * ```gherkin
49
+ * When I wait for element to be visible
50
+ * ```
29
51
  */
30
- (0, registry_1.Step)("I wait for element to be visible", async (page) => {
52
+ exports.WaitForElementVisible = (0, registry_1.Step)("I wait for element to be visible", async (page) => {
31
53
  const element = (0, state_1.getActiveElement)(page);
32
54
  await element.waitFor({ state: "visible" });
33
55
  console.log("⏳ Element is now visible");
34
56
  });
35
57
  /**
36
- * Explicitly waits for the stored element to be hidden/detached.
37
- * Pattern: When I wait for element to be hidden
58
+ * Explicitly waits for the currently stored (active) element to become hidden or detached from the DOM.
59
+ * Useful for verifying that loading spinners have disappeared.
60
+ *
61
+ * ```gherkin
62
+ * When I wait for element to be hidden
63
+ * ```
38
64
  */
39
- (0, registry_1.Step)("I wait for element to be hidden", async (page) => {
65
+ exports.WaitForElementHidden = (0, registry_1.Step)("I wait for element to be hidden", async (page) => {
40
66
  const element = (0, state_1.getActiveElement)(page);
41
67
  await element.waitFor({ state: "hidden" });
42
68
  console.log("⏳ Element is now hidden");
43
69
  });
44
70
  /**
45
- * Waits for a specific URL pattern.
46
- * Pattern: When I wait for URL to contain "dashboard"
71
+ * Waits until the page URL contains the specified substring (Regex match).
72
+ * Useful for verifying redirects (e.g., after login).
73
+ *
74
+ * ```gherkin
75
+ * When I wait for URL to contain "dashboard"
76
+ * ```
77
+ *
78
+ * @param urlPart - The substring to look for in the current URL.
47
79
  */
48
- (0, registry_1.Step)("I wait for URL to contain {string}", async (page, urlPart) => {
80
+ exports.WaitForUrlContain = (0, registry_1.Step)("I wait for URL to contain {string}", async (page, urlPart) => {
49
81
  await page.waitForURL(new RegExp(urlPart));
50
82
  console.log(`⏳ URL now contains: "${urlPart}"`);
51
83
  });
@@ -1,2 +1,33 @@
1
- export {};
1
+ /**
2
+ * Asserts that the HTTP status code of the last API response matches the expected integer.
3
+ *
4
+ * ```gherkin
5
+ * Then I expect the response status to be 200
6
+ * ```
7
+ *
8
+ * @param statusCode - The expected HTTP status code (e.g., 200, 404, 500).
9
+ */
10
+ export declare const ExpectResponseStatus: void;
11
+ /**
12
+ * Asserts that the body text of the last API response contains a specific substring.
13
+ *
14
+ * ```gherkin
15
+ * Then I expect the response body to contain "success"
16
+ * ```
17
+ *
18
+ * @param text - The text substring to look for in the response body.
19
+ */
20
+ export declare const ExpectResponseBodyContain: void;
21
+ /**
22
+ * Asserts that a specific property in the JSON response matches a string value.
23
+ * Supports dot notation for nested properties.
24
+ *
25
+ * ```gherkin
26
+ * Then I expect the response property "user.id" to be "12345"
27
+ * ```
28
+ *
29
+ * @param jsonPath - The dot-notation path to the JSON property (e.g., "data.user.name").
30
+ * @param value - The expected string value of the property.
31
+ */
32
+ export declare const ExpectResponseProperty: void;
2
33
  //# sourceMappingURL=assertions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../../../src/backend/api/assertions.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../../../src/backend/api/assertions.ts"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,MAMhC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,MAOrC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,MAWlC,CAAC"}
@@ -1,26 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpectResponseProperty = exports.ExpectResponseBodyContain = exports.ExpectResponseStatus = void 0;
3
4
  const test_1 = require("@playwright/test");
4
5
  const registry_1 = require("../../core/registry");
5
6
  const state_1 = require("./state");
6
- // Check Status Code
7
- (0, registry_1.Step)("I expect the response status to be {int}", async (page, statusCode) => {
7
+ // =============================
8
+ // API ASSERTIONS
9
+ // =============================
10
+ /**
11
+ * Asserts that the HTTP status code of the last API response matches the expected integer.
12
+ *
13
+ * ```gherkin
14
+ * Then I expect the response status to be 200
15
+ * ```
16
+ *
17
+ * @param statusCode - The expected HTTP status code (e.g., 200, 404, 500).
18
+ */
19
+ exports.ExpectResponseStatus = (0, registry_1.Step)("I expect the response status to be {int}", async (page, statusCode) => {
8
20
  const response = state_1.apiState.getResponse();
9
21
  (0, test_1.expect)(response.status()).toBe(statusCode);
10
22
  });
11
- // Check entire Body Text
12
- (0, registry_1.Step)("I expect the response body to contain {string}", async (page, text) => {
23
+ /**
24
+ * Asserts that the body text of the last API response contains a specific substring.
25
+ *
26
+ * ```gherkin
27
+ * Then I expect the response body to contain "success"
28
+ * ```
29
+ *
30
+ * @param text - The text substring to look for in the response body.
31
+ */
32
+ exports.ExpectResponseBodyContain = (0, registry_1.Step)("I expect the response body to contain {string}", async (page, text) => {
13
33
  const response = state_1.apiState.getResponse();
14
34
  const body = await response.text();
15
35
  (0, test_1.expect)(body).toContain(text);
16
36
  });
17
- // Check JSON Property
18
- (0, registry_1.Step)("I expect the response property {string} to be {string}", async (page, jsonPath, value) => {
37
+ /**
38
+ * Asserts that a specific property in the JSON response matches a string value.
39
+ * Supports dot notation for nested properties.
40
+ *
41
+ * ```gherkin
42
+ * Then I expect the response property "user.id" to be "12345"
43
+ * ```
44
+ *
45
+ * @param jsonPath - The dot-notation path to the JSON property (e.g., "data.user.name").
46
+ * @param value - The expected string value of the property.
47
+ */
48
+ exports.ExpectResponseProperty = (0, registry_1.Step)("I expect the response property {string} to be {string}", async (page, jsonPath, value) => {
19
49
  const response = state_1.apiState.getResponse();
20
50
  const json = await response.json();
21
51
  // FIX: Added ': string' to the 'i' parameter
22
- const actualValue = jsonPath
23
- .split(".")
24
- .reduce((o, i) => o[i], json);
52
+ const actualValue = jsonPath.split(".").reduce((o, i) => o[i], json);
25
53
  (0, test_1.expect)(String(actualValue)).toBe(value);
26
54
  });
@@ -1,2 +1,35 @@
1
- export {};
1
+ /**
2
+ * @module NetworkMocking
3
+ */
4
+ /**
5
+ * Mocks a specific API endpoint with a hardcoded inline JSON response body.
6
+ * * @example
7
+ * ```gherkin
8
+ * Given I mock the API endpoint "/api/users" with body '{"id": 1, "name": "Fake"}'
9
+ * ```
10
+ * * @param urlPattern - The URL or glob pattern to intercept.
11
+ * @param jsonBody - The raw JSON string to return as the response.
12
+ */
13
+ export declare const MockApiWithInlineJson: void;
14
+ /**
15
+ * Mocks an API endpoint using the contents of a local JSON file.
16
+ * * @example
17
+ * ```gherkin
18
+ * Given I mock the API endpoint "/api/users" with response from "mocks/users.json"
19
+ * ```
20
+ * * @param urlPattern - The URL pattern to intercept.
21
+ * @param filePath - Path to the JSON file relative to the project root.
22
+ */
23
+ export declare const MockApiWithFile: void;
24
+ /**
25
+ * Mocks an API endpoint to return a specific HTTP status code only.
26
+ * Useful for simulating server errors like 500 or 404.
27
+ * * @example
28
+ * ```gherkin
29
+ * Given I mock the API endpoint "/api/broken" with status 500
30
+ * ```
31
+ * * @param urlPattern - The URL pattern to intercept.
32
+ * @param statusCode - The HTTP status code to return.
33
+ */
34
+ export declare const MockApiStatus: void;
2
35
  //# sourceMappingURL=mock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/backend/api/mock.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/backend/api/mock.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,MAajC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,MAoB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,MAQzB,CAAC"}
@@ -33,12 +33,23 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- const registry_1 = require("../../core/registry");
36
+ exports.MockApiStatus = exports.MockApiWithFile = exports.MockApiWithInlineJson = void 0;
37
37
  const fs = __importStar(require("fs"));
38
38
  const path = __importStar(require("path"));
39
- // 1. Mock with Inline JSON
40
- // Usage: Given I mock the API endpoint "/api/users" with body '{"id": 1, "name": "Fake"}'
41
- (0, registry_1.Step)("I mock the API endpoint {string} with body {string}", async (page, urlPattern, jsonBody) => {
39
+ const registry_1 = require("../../core/registry");
40
+ /**
41
+ * @module NetworkMocking
42
+ */
43
+ /**
44
+ * Mocks a specific API endpoint with a hardcoded inline JSON response body.
45
+ * * @example
46
+ * ```gherkin
47
+ * Given I mock the API endpoint "/api/users" with body '{"id": 1, "name": "Fake"}'
48
+ * ```
49
+ * * @param urlPattern - The URL or glob pattern to intercept.
50
+ * @param jsonBody - The raw JSON string to return as the response.
51
+ */
52
+ exports.MockApiWithInlineJson = (0, registry_1.Step)("I mock the API endpoint {string} with body {string}", async (page, urlPattern, jsonBody) => {
42
53
  await page.route(urlPattern, async (route) => {
43
54
  const json = JSON.parse(jsonBody);
44
55
  await route.fulfill({
@@ -49,9 +60,16 @@ const path = __importStar(require("path"));
49
60
  });
50
61
  console.log(`🎭 Mocked ${urlPattern} with inline JSON`);
51
62
  });
52
- // 2. Mock with File
53
- // Usage: Given I mock the API endpoint "/api/users" with response from "mocks/users.json"
54
- (0, registry_1.Step)("I mock the API endpoint {string} with response from {string}", async (page, urlPattern, filePath) => {
63
+ /**
64
+ * Mocks an API endpoint using the contents of a local JSON file.
65
+ * * @example
66
+ * ```gherkin
67
+ * Given I mock the API endpoint "/api/users" with response from "mocks/users.json"
68
+ * ```
69
+ * * @param urlPattern - The URL pattern to intercept.
70
+ * @param filePath - Path to the JSON file relative to the project root.
71
+ */
72
+ exports.MockApiWithFile = (0, registry_1.Step)("I mock the API endpoint {string} with response from {string}", async (page, urlPattern, filePath) => {
55
73
  const fullPath = path.resolve(process.cwd(), filePath);
56
74
  if (!fs.existsSync(fullPath)) {
57
75
  throw new Error(`❌ Mock file not found at: ${fullPath}`);
@@ -66,10 +84,19 @@ const path = __importStar(require("path"));
66
84
  });
67
85
  console.log(`🎭 Mocked ${urlPattern} with file: ${filePath}`);
68
86
  });
69
- // 3. Mock Status Code Only (Simulate Errors)
70
- // Usage: Given I mock the API endpoint "/api/broken" with status 500
71
- (0, registry_1.Step)("I mock the API endpoint {string} with status {int}", async (page, urlPattern, statusCode) => {
87
+ /**
88
+ * Mocks an API endpoint to return a specific HTTP status code only.
89
+ * Useful for simulating server errors like 500 or 404.
90
+ * * @example
91
+ * ```gherkin
92
+ * Given I mock the API endpoint "/api/broken" with status 500
93
+ * ```
94
+ * * @param urlPattern - The URL pattern to intercept.
95
+ * @param statusCode - The HTTP status code to return.
96
+ */
97
+ exports.MockApiStatus = (0, registry_1.Step)("I mock the API endpoint {string} with status {int}", async (page, urlPattern, statusCode) => {
72
98
  await page.route(urlPattern, async (route) => {
73
99
  await route.fulfill({ status: statusCode });
74
100
  });
101
+ console.log(`🎭 Mocked ${urlPattern} with status ${statusCode}`);
75
102
  });
@@ -1,2 +1,61 @@
1
- export {};
1
+ /**
2
+ * Intercepts a network URL and returns a stubbed JSON response.
3
+ * Supports Gherkin DocStrings for the body content.
4
+ * * @example
5
+ * ```gherkin
6
+ * When I intercept URL "/api/user" and stub body:
7
+ * """
8
+ * { "id": 101, "status": "active" }
9
+ * """
10
+ * ```
11
+ */
12
+ export declare const InterceptStubJson: void;
13
+ /**
14
+ * Intercepts a URL and stubs it with a raw string (non-JSON).
15
+ * * @example
16
+ * ```gherkin
17
+ * When I intercept URL "/health" and stub body "OK"
18
+ * ```
19
+ */
20
+ export declare const InterceptStubRaw: void;
21
+ /**
22
+ * Intercepts a URL but allows it to continue (Network Spying).
23
+ * Useful for monitoring traffic without changing the response.
24
+ * * @example
25
+ * ```gherkin
26
+ * When I intercept URL "/api/*"
27
+ * ```
28
+ */
29
+ export declare const InterceptSpy: void;
30
+ /**
31
+ * Makes a GET request and stores the response in the test state.
32
+ * Stores values in `lastResponse` and `lastStatusCode`.
33
+ * * @example
34
+ * ```gherkin
35
+ * When I make request to "[https://api.example.com/v1/users](https://api.example.com/v1/users)"
36
+ * ```
37
+ */
38
+ export declare const ApiGetRequest: void;
39
+ /**
40
+ * Makes a POST request with a JSON body provided via DocString.
41
+ * * @example
42
+ * ```gherkin
43
+ * When I make a POST request to "/api/login" with JSON body:
44
+ * """
45
+ * { "username": "admin", "password": "password123" }
46
+ * """
47
+ * ```
48
+ */
49
+ export declare const ApiPostRequest: void;
50
+ /**
51
+ * Makes a generic HTTP request using the browser's `fetch` API.
52
+ * Supports a data table for headers and an optional body.
53
+ * * @example
54
+ * ```gherkin
55
+ * When I make a "PUT" request to "/api/settings"
56
+ * | Authorization | Bearer my-token |
57
+ * | body | {"theme": "dark"} |
58
+ * ```
59
+ */
60
+ export declare const BrowserFetchRequest: void;
2
61
  //# sourceMappingURL=network.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../src/backend/api/network.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../src/backend/api/network.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,MAe7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,MAY5B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,MAKvB,CAAC;AAMH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,MAexB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,MAoB1B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,MA+C/B,CAAC"}
@@ -1,26 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserFetchRequest = exports.ApiPostRequest = exports.ApiGetRequest = exports.InterceptSpy = exports.InterceptStubRaw = exports.InterceptStubJson = void 0;
3
4
  const registry_1 = require("../../core/registry");
4
5
  const state_1 = require("../utils/state");
5
- // Helper: Safely parse JSON even if it comes with DocString quotes or is undefined
6
+ /**
7
+ * Helper: Safely parse JSON even if it comes with DocString quotes or is undefined.
8
+ * Used internally by API steps to process Gherkin DocStrings.
9
+ */
6
10
  function safeJsonParse(input, context) {
7
11
  if (!input) {
8
12
  throw new Error(`❌ Missing JSON input for ${context}. Did you forget the DocString?`);
9
13
  }
10
14
  let text = typeof input === "string" ? input : JSON.stringify(input);
11
- // Clean up DocString artifacts if the runner passes them
12
- // 1. Remove surrounding triple quotes """ if present
15
+ // Clean up DocString artifacts
13
16
  text = text.replace(/^"""/g, "").replace(/"""$/g, "");
14
- // 2. Trim whitespace/newlines
15
17
  text = text.trim();
16
- // Debug Log: Show exactly what we are trying to parse
17
- // console.log(`🔍 [Debug] Parsing JSON for ${context}:`, text);
18
18
  try {
19
19
  return JSON.parse(text);
20
20
  }
21
21
  catch (e) {
22
- // If simple parse fails, it might be due to unquoted keys or single quotes
23
- // You could add a 'loose JSON' parser here if needed, but for now, strict JSON is best.
24
22
  throw new Error(`❌ Invalid JSON for ${context}.\nReceived: ${text.slice(0, 50)}...\nError: ${e.message}`);
25
23
  }
26
24
  }
@@ -28,10 +26,17 @@ function safeJsonParse(input, context) {
28
26
  // 1. INTERCEPTION / MOCKING
29
27
  // =============================
30
28
  /**
31
- * Intercepts a URL and returns a JSON response (Mocking).
32
- * Uses Regex to support optional trailing colon.
29
+ * Intercepts a network URL and returns a stubbed JSON response.
30
+ * Supports Gherkin DocStrings for the body content.
31
+ * * @example
32
+ * ```gherkin
33
+ * When I intercept URL "/api/user" and stub body:
34
+ * """
35
+ * { "id": 101, "status": "active" }
36
+ * """
37
+ * ```
33
38
  */
34
- (0, registry_1.Step)(/^I intercept URL "([^"]+)" and stub body:?$/, async (page, url, body) => {
39
+ exports.InterceptStubJson = (0, registry_1.Step)(/^I intercept URL "([^"]+)" and stub body:?$/, async (page, url, body) => {
35
40
  const parsedBody = safeJsonParse(body, `stubbing "${url}"`);
36
41
  await page.route(url, (route) => {
37
42
  route.fulfill({
@@ -44,8 +49,12 @@ function safeJsonParse(input, context) {
44
49
  });
45
50
  /**
46
51
  * Intercepts a URL and stubs it with a raw string (non-JSON).
52
+ * * @example
53
+ * ```gherkin
54
+ * When I intercept URL "/health" and stub body "OK"
55
+ * ```
47
56
  */
48
- (0, registry_1.Step)("I intercept URL {string} and stub body {string}", async (page, url, body) => {
57
+ exports.InterceptStubRaw = (0, registry_1.Step)("I intercept URL {string} and stub body {string}", async (page, url, body) => {
49
58
  await page.route(url, (route) => {
50
59
  route.fulfill({
51
60
  status: 200,
@@ -56,9 +65,14 @@ function safeJsonParse(input, context) {
56
65
  console.log(`📡 Stubbed "${url}" with raw text: "${body}"`);
57
66
  });
58
67
  /**
59
- * Intercepts a URL but allows it to continue (Spying).
68
+ * Intercepts a URL but allows it to continue (Network Spying).
69
+ * Useful for monitoring traffic without changing the response.
70
+ * * @example
71
+ * ```gherkin
72
+ * When I intercept URL "/api/*"
73
+ * ```
60
74
  */
61
- (0, registry_1.Step)("I intercept URL {string}", async (page, url) => {
75
+ exports.InterceptSpy = (0, registry_1.Step)("I intercept URL {string}", async (page, url) => {
62
76
  await page.route(url, async (route) => {
63
77
  await route.continue();
64
78
  });
@@ -68,9 +82,14 @@ function safeJsonParse(input, context) {
68
82
  // 2. MAKING API REQUESTS
69
83
  // =============================
70
84
  /**
71
- * Makes a GET request and stores the response.
85
+ * Makes a GET request and stores the response in the test state.
86
+ * Stores values in `lastResponse` and `lastStatusCode`.
87
+ * * @example
88
+ * ```gherkin
89
+ * When I make request to "[https://api.example.com/v1/users](https://api.example.com/v1/users)"
90
+ * ```
72
91
  */
73
- (0, registry_1.Step)("I make request to {string}", async (page, url) => {
92
+ exports.ApiGetRequest = (0, registry_1.Step)("I make request to {string}", async (page, url) => {
74
93
  console.log(`⚡ GET request to: ${url}`);
75
94
  const response = await page.request.get(url);
76
95
  const status = response.status();
@@ -85,10 +104,16 @@ function safeJsonParse(input, context) {
85
104
  console.log(`✅ Status: ${status}`);
86
105
  });
87
106
  /**
88
- * Makes a POST request with a JSON body.
89
- * Uses Regex to support optional trailing colon.
107
+ * Makes a POST request with a JSON body provided via DocString.
108
+ * * @example
109
+ * ```gherkin
110
+ * When I make a POST request to "/api/login" with JSON body:
111
+ * """
112
+ * { "username": "admin", "password": "password123" }
113
+ * """
114
+ * ```
90
115
  */
91
- (0, registry_1.Step)(/^I make a POST request to "([^"]+)" with JSON body:?$/, async (page, url, docString) => {
116
+ exports.ApiPostRequest = (0, registry_1.Step)(/^I make a POST request to "([^"]+)" with JSON body:?$/, async (page, url, docString) => {
92
117
  const payload = safeJsonParse(docString, `POST to "${url}"`);
93
118
  console.log(`⚡ POST request to: ${url}`);
94
119
  const response = await page.request.post(url, { data: payload });
@@ -104,9 +129,16 @@ function safeJsonParse(input, context) {
104
129
  console.log(`✅ Status: ${status}`);
105
130
  });
106
131
  /**
107
- * Makes a generic browser-context HTTP request (fetch).
132
+ * Makes a generic HTTP request using the browser's `fetch` API.
133
+ * Supports a data table for headers and an optional body.
134
+ * * @example
135
+ * ```gherkin
136
+ * When I make a "PUT" request to "/api/settings"
137
+ * | Authorization | Bearer my-token |
138
+ * | body | {"theme": "dark"} |
139
+ * ```
108
140
  */
109
- (0, registry_1.Step)('I make a "{word}" request to {string}', async (page, method, url, table) => {
141
+ exports.BrowserFetchRequest = (0, registry_1.Step)('I make a "{word}" request to {string}', async (page, method, url, table) => {
110
142
  const options = { method: method.toUpperCase() };
111
143
  const rows = table && typeof table.rows === "function" ? table.rows() : table || [];
112
144
  if (Array.isArray(rows)) {
@@ -1,2 +1,44 @@
1
- export {};
1
+ /**
2
+ * @module ApiActions
3
+ */
4
+ /**
5
+ * Performs a standard HTTP GET request and stores the response in the global API state.
6
+ * * @example
7
+ * ```gherkin
8
+ * When I make a GET request to "[https://api.example.com/users](https://api.example.com/users)"
9
+ * ```
10
+ * * @param url - The full URL or endpoint path.
11
+ */
12
+ export declare const MakeGetRequest: void;
13
+ /**
14
+ * Performs a standard HTTP DELETE request and stores the response in the global API state.
15
+ * * @example
16
+ * ```gherkin
17
+ * When I make a DELETE request to "/api/users/1"
18
+ * ```
19
+ * * @param url - The endpoint path to delete.
20
+ */
21
+ export declare const MakeDeleteRequest: void;
22
+ /**
23
+ * Performs an HTTP POST request using a Gherkin Data Table as the JSON payload.
24
+ * * @example
25
+ * ```gherkin
26
+ * When I make a POST request to "/api/users" with data
27
+ * | name | John |
28
+ * | job | Dev |
29
+ * ```
30
+ * * @param url - The target endpoint.
31
+ * @param tableData - The Gherkin Data Table (automatically converted to a JSON object).
32
+ */
33
+ export declare const MakePostRequestWithTable: void;
34
+ /**
35
+ * Performs an HTTP POST request using the contents of a local JSON file as the payload.
36
+ * * @example
37
+ * ```gherkin
38
+ * When I make a POST request to "/api/users" with payload from "data/user.json"
39
+ * ```
40
+ * * @param url - The target endpoint.
41
+ * @param filePath - Path to the JSON file relative to the project root.
42
+ */
43
+ export declare const MakePostRequestWithFile: void;
2
44
  //# sourceMappingURL=requests.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/backend/api/requests.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/backend/api/requests.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,MAIzB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,MAI5B,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,MAmBpC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,MAoBnC,CAAC"}