@playq/core 0.2.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/bin/playq.js +175 -0
- package/cucumber.js +10 -0
- package/dist/exec/featureFileCache.d.ts +21 -0
- package/dist/exec/featureFileCache.js +124 -0
- package/dist/exec/featureFilePreProcess.d.ts +12 -0
- package/dist/exec/featureFilePreProcess.js +208 -0
- package/dist/exec/preLoader.d.ts +1 -0
- package/dist/exec/preLoader.js +72 -0
- package/dist/exec/preProcessEntry.d.ts +1 -0
- package/dist/exec/preProcessEntry.js +83 -0
- package/dist/exec/preProcess_old_todelete.d.ts +1 -0
- package/dist/exec/preProcess_old_todelete.js +258 -0
- package/dist/exec/runner.d.ts +1 -0
- package/dist/exec/runner.js +221 -0
- package/dist/exec/runner_orchestrator.d.ts +1 -0
- package/dist/exec/runner_orchestrator.js +85 -0
- package/dist/exec/sgGenerator.d.ts +11 -0
- package/dist/exec/sgGenerator.js +310 -0
- package/dist/global.d.ts +15 -0
- package/dist/global.js +185 -0
- package/dist/helper/actions/api/apiRequestActions.d.ts +117 -0
- package/dist/helper/actions/api/apiRequestActions.js +374 -0
- package/dist/helper/actions/api/apiValidationActions.d.ts +119 -0
- package/dist/helper/actions/api/apiValidationActions.js +615 -0
- package/dist/helper/actions/apiActions.d.ts +18 -0
- package/dist/helper/actions/apiActions.js +34 -0
- package/dist/helper/actions/apiStepDefs.d.ts +1 -0
- package/dist/helper/actions/apiStepDefs.js +64 -0
- package/dist/helper/actions/comm/commonActions.d.ts +58 -0
- package/dist/helper/actions/comm/commonActions.js +198 -0
- package/dist/helper/actions/comm/utilityActions.d.ts +131 -0
- package/dist/helper/actions/comm/utilityActions.js +351 -0
- package/dist/helper/actions/commActions.d.ts +18 -0
- package/dist/helper/actions/commActions.js +34 -0
- package/dist/helper/actions/commStepDefs.d.ts +1 -0
- package/dist/helper/actions/commStepDefs.js +57 -0
- package/dist/helper/actions/stepGroupStepDefs.d.ts +1 -0
- package/dist/helper/actions/stepGroupStepDefs.js +15 -0
- package/dist/helper/actions/web/alertActions.d.ts +61 -0
- package/dist/helper/actions/web/alertActions.js +224 -0
- package/dist/helper/actions/web/cookieActions.d.ts +45 -0
- package/dist/helper/actions/web/cookieActions.js +186 -0
- package/dist/helper/actions/web/downloadActions.d.ts +40 -0
- package/dist/helper/actions/web/downloadActions.js +153 -0
- package/dist/helper/actions/web/elementReaderActions.d.ts +95 -0
- package/dist/helper/actions/web/elementReaderActions.js +326 -0
- package/dist/helper/actions/web/formActions.d.ts +122 -0
- package/dist/helper/actions/web/formActions.js +423 -0
- package/dist/helper/actions/web/iframeActions.d.ts +23 -0
- package/dist/helper/actions/web/iframeActions.js +108 -0
- package/dist/helper/actions/web/javascriptActions.d.ts +14 -0
- package/dist/helper/actions/web/javascriptActions.js +77 -0
- package/dist/helper/actions/web/keyboardActions.d.ts +35 -0
- package/dist/helper/actions/web/keyboardActions.js +118 -0
- package/dist/helper/actions/web/localStorageActions.d.ts +51 -0
- package/dist/helper/actions/web/localStorageActions.js +163 -0
- package/dist/helper/actions/web/mouseActions.d.ts +240 -0
- package/dist/helper/actions/web/mouseActions.js +609 -0
- package/dist/helper/actions/web/reportingActions.d.ts +34 -0
- package/dist/helper/actions/web/reportingActions.js +58 -0
- package/dist/helper/actions/web/screenshotActions.d.ts +34 -0
- package/dist/helper/actions/web/screenshotActions.js +151 -0
- package/dist/helper/actions/web/testDataActions.d.ts +21 -0
- package/dist/helper/actions/web/testDataActions.js +211 -0
- package/dist/helper/actions/web/validationActions.d.ts +547 -0
- package/dist/helper/actions/web/validationActions.js +1754 -0
- package/dist/helper/actions/web/waitActions.d.ts +191 -0
- package/dist/helper/actions/web/waitActions.js +589 -0
- package/dist/helper/actions/web/webNavigation.d.ts +104 -0
- package/dist/helper/actions/web/webNavigation.js +288 -0
- package/dist/helper/actions/webActions.d.ts +32 -0
- package/dist/helper/actions/webActions.js +48 -0
- package/dist/helper/actions/webStepDefs.d.ts +1 -0
- package/dist/helper/actions/webStepDefs.js +455 -0
- package/dist/helper/browsers/browserManager.d.ts +1 -0
- package/dist/helper/browsers/browserManager.js +56 -0
- package/dist/helper/bundle/defaultEntries.d.ts +6 -0
- package/dist/helper/bundle/defaultEntries.js +200 -0
- package/dist/helper/bundle/env.d.ts +1 -0
- package/dist/helper/bundle/env.js +157 -0
- package/dist/helper/bundle/vars.d.ts +9 -0
- package/dist/helper/bundle/vars.js +375 -0
- package/dist/helper/faker/customFaker.d.ts +55 -0
- package/dist/helper/faker/customFaker.js +45 -0
- package/dist/helper/faker/modules/data/postcodes_valid_sg.json +17 -0
- package/dist/helper/faker/modules/dateTime.d.ts +18 -0
- package/dist/helper/faker/modules/dateTime.js +106 -0
- package/dist/helper/faker/modules/mobile.d.ts +4 -0
- package/dist/helper/faker/modules/mobile.js +59 -0
- package/dist/helper/faker/modules/nric.d.ts +32 -0
- package/dist/helper/faker/modules/nric.js +84 -0
- package/dist/helper/faker/modules/passport.d.ts +3 -0
- package/dist/helper/faker/modules/passport.js +36 -0
- package/dist/helper/faker/modules/person.d.ts +14 -0
- package/dist/helper/faker/modules/person.js +73 -0
- package/dist/helper/faker/modules/postcode.d.ts +6 -0
- package/dist/helper/faker/modules/postcode.js +47 -0
- package/dist/helper/fixtures/locAggregate.d.ts +7 -0
- package/dist/helper/fixtures/locAggregate.js +94 -0
- package/dist/helper/fixtures/logFixture.d.ts +8 -0
- package/dist/helper/fixtures/logFixture.js +56 -0
- package/dist/helper/fixtures/webFixture.d.ts +19 -0
- package/dist/helper/fixtures/webFixture.js +186 -0
- package/dist/helper/fixtures/webLocFixture.d.ts +2 -0
- package/dist/helper/fixtures/webLocFixture.js +144 -0
- package/dist/helper/report/allureStepLogger.d.ts +0 -0
- package/dist/helper/report/allureStepLogger.js +25 -0
- package/dist/helper/report/customiseReport.d.ts +1 -0
- package/dist/helper/report/customiseReport.js +55 -0
- package/dist/helper/report/init.d.ts +1 -0
- package/dist/helper/report/init.js +14 -0
- package/dist/helper/report/report.d.ts +1 -0
- package/dist/helper/report/report.js +102 -0
- package/dist/helper/util/dataLoader.d.ts +10 -0
- package/dist/helper/util/dataLoader.js +73 -0
- package/dist/helper/util/logger.d.ts +4 -0
- package/dist/helper/util/logger.js +61 -0
- package/dist/helper/util/session/sessionUtil.d.ts +26 -0
- package/dist/helper/util/session/sessionUtil.js +729 -0
- package/dist/helper/util/stepHelpers.d.ts +2 -0
- package/dist/helper/util/stepHelpers.js +16 -0
- package/dist/helper/util/test-data/dataLoader.d.ts +7 -0
- package/dist/helper/util/test-data/dataLoader.js +145 -0
- package/dist/helper/util/test-data/dataTest.d.ts +10 -0
- package/dist/helper/util/test-data/dataTest.js +216 -0
- package/dist/helper/util/totp/totpHelper.d.ts +38 -0
- package/dist/helper/util/totp/totpHelper.js +117 -0
- package/dist/helper/util/utilities/cryptoUtil.d.ts +2 -0
- package/dist/helper/util/utilities/cryptoUtil.js +53 -0
- package/dist/helper/util/utilities/schemaGeneratorUtil.d.ts +2 -0
- package/dist/helper/util/utilities/schemaGeneratorUtil.js +129 -0
- package/dist/helper/util/utils.d.ts +2 -0
- package/dist/helper/util/utils.js +22 -0
- package/dist/helper/wrapper/PlaywrightWrappers.d.ts +8 -0
- package/dist/helper/wrapper/PlaywrightWrappers.js +26 -0
- package/dist/helper/wrapper/assert.d.ts +9 -0
- package/dist/helper/wrapper/assert.js +23 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +57 -0
- package/dist/scripts/get-versions.d.ts +1 -0
- package/dist/scripts/get-versions.js +98 -0
- package/dist/scripts/posttest.d.ts +1 -0
- package/dist/scripts/posttest.js +29 -0
- package/dist/scripts/pretest.d.ts +1 -0
- package/dist/scripts/pretest.js +57 -0
- package/dist/scripts/util.d.ts +1 -0
- package/dist/scripts/util.js +376 -0
- package/package.json +68 -0
- package/src/exec/featureFileCache.ts +80 -0
- package/src/exec/featureFilePreProcess.ts +239 -0
- package/src/exec/preLoader.ts +72 -0
- package/src/exec/preProcessEntry.ts +59 -0
- package/src/exec/preProcess_old_todelete.ts +289 -0
- package/src/exec/runner.ts +241 -0
- package/src/exec/runnerCuke.js +90 -0
- package/src/exec/runner_orchestrator.ts +91 -0
- package/src/exec/sgGenerator.ts +373 -0
- package/src/global.ts +130 -0
- package/src/helper/actions/api/apiRequestActions.ts +362 -0
- package/src/helper/actions/api/apiValidationActions.ts +594 -0
- package/src/helper/actions/apiActions.ts +18 -0
- package/src/helper/actions/apiStepDefs.ts +80 -0
- package/src/helper/actions/comm/commonActions.ts +165 -0
- package/src/helper/actions/comm/utilityActions.ts +344 -0
- package/src/helper/actions/commActions.ts +18 -0
- package/src/helper/actions/commStepDefs.ts +72 -0
- package/src/helper/actions/stepGroupStepDefs.ts +17 -0
- package/src/helper/actions/web/alertActions.ts +179 -0
- package/src/helper/actions/web/cookieActions.ts +124 -0
- package/src/helper/actions/web/downloadActions.ts +129 -0
- package/src/helper/actions/web/elementReaderActions.ts +323 -0
- package/src/helper/actions/web/formActions.ts +469 -0
- package/src/helper/actions/web/iframeActions.ts +67 -0
- package/src/helper/actions/web/javascriptActions.ts +38 -0
- package/src/helper/actions/web/keyboardActions.ts +101 -0
- package/src/helper/actions/web/localStorageActions.ts +109 -0
- package/src/helper/actions/web/mouseActions.ts +864 -0
- package/src/helper/actions/web/reportingActions.ts +53 -0
- package/src/helper/actions/web/screenshotActions.ts +124 -0
- package/src/helper/actions/web/testDataActions.ts +162 -0
- package/src/helper/actions/web/validationActions.ts +2287 -0
- package/src/helper/actions/web/waitActions.ts +757 -0
- package/src/helper/actions/web/webNavigation.ts +313 -0
- package/src/helper/actions/webActions.ts +33 -0
- package/src/helper/actions/webStepDefs.ts +505 -0
- package/src/helper/browsers/browserManager.ts +23 -0
- package/src/helper/bundle/defaultEntries.ts +208 -0
- package/src/helper/bundle/env.ts +119 -0
- package/src/helper/bundle/vars.ts +368 -0
- package/src/helper/faker/customFaker.ts +107 -0
- package/src/helper/faker/modules/data/postcodes_valid_sg.json +17 -0
- package/src/helper/faker/modules/dateTime.ts +121 -0
- package/src/helper/faker/modules/mobile.ts +58 -0
- package/src/helper/faker/modules/nric.ts +109 -0
- package/src/helper/faker/modules/passport.ts +34 -0
- package/src/helper/faker/modules/person.ts +93 -0
- package/src/helper/faker/modules/postcode.ts +57 -0
- package/src/helper/fixtures/locAggregate.ts +61 -0
- package/src/helper/fixtures/logFixture.ts +57 -0
- package/src/helper/fixtures/webFixture.ts +206 -0
- package/src/helper/fixtures/webLocFixture.ts +143 -0
- package/src/helper/report/allureStepLogger.ts +26 -0
- package/src/helper/report/customiseReport.ts +61 -0
- package/src/helper/report/init.ts +18 -0
- package/src/helper/report/report.ts +72 -0
- package/src/helper/util/dataLoader.ts +42 -0
- package/src/helper/util/logger.ts +32 -0
- package/src/helper/util/session/sessionUtil.ts +839 -0
- package/src/helper/util/stepHelpers.ts +14 -0
- package/src/helper/util/test-data/dataLoader.ts +108 -0
- package/src/helper/util/test-data/dataTest.ts +191 -0
- package/src/helper/util/test-data/registerUser.json +7 -0
- package/src/helper/util/totp/totpHelper.ts +102 -0
- package/src/helper/util/utilities/cryptoUtil.ts +53 -0
- package/src/helper/util/utilities/schemaGeneratorUtil.ts +143 -0
- package/src/helper/util/utils.ts +28 -0
- package/src/helper/wrapper/PlaywrightWrappers.ts +28 -0
- package/src/helper/wrapper/assert.ts +25 -0
- package/src/index.ts +17 -0
- package/src/scripts/get-versions.ts +68 -0
- package/src/scripts/posttest.ts +32 -0
- package/src/scripts/pretest.ts +48 -0
- package/src/scripts/util.ts +406 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.callApi = callApi;
|
|
40
|
+
exports.get = get;
|
|
41
|
+
exports.post = post;
|
|
42
|
+
exports.request = request;
|
|
43
|
+
exports.put = put;
|
|
44
|
+
exports.patch = patch;
|
|
45
|
+
exports.del = del;
|
|
46
|
+
exports.sendRequest = sendRequest;
|
|
47
|
+
/**
|
|
48
|
+
* @file apiRequestActions.ts
|
|
49
|
+
*
|
|
50
|
+
* Provides a unified API for API actions in Playwright and Cucumber frameworks.
|
|
51
|
+
* Supports dynamic config-driven requests, variable interpolation, and assertions.
|
|
52
|
+
*
|
|
53
|
+
* Key Features:
|
|
54
|
+
* - Hybrid context support: Playwright runner and Cucumber world.
|
|
55
|
+
* - Rich options for redirects, timeouts, auth, and type conversions.
|
|
56
|
+
* - Robust error handling and logging aligned with PlayQ standards.
|
|
57
|
+
*
|
|
58
|
+
* Authors: Renish Kozhithottathil [Lead Automation Principal, NCS]
|
|
59
|
+
* Date: 2025-07-01
|
|
60
|
+
* Version: v1.0.0
|
|
61
|
+
*
|
|
62
|
+
* Note: This file adheres to the PlayQ Enterprise Automation Standards.
|
|
63
|
+
*/
|
|
64
|
+
const axios_1 = __importDefault(require("axios"));
|
|
65
|
+
const allure = __importStar(require("allure-js-commons"));
|
|
66
|
+
const path_1 = __importDefault(require("path"));
|
|
67
|
+
const fs_1 = __importDefault(require("fs"));
|
|
68
|
+
const global_1 = require("../../../global");
|
|
69
|
+
const test_1 = require("@playwright/test");
|
|
70
|
+
// Inline runner helpers
|
|
71
|
+
function isPlaywrightRunner() { return process.env.TEST_RUNNER === 'playwright'; }
|
|
72
|
+
function isCucumberRunner() { return process.env.TEST_RUNNER === 'cucumber'; }
|
|
73
|
+
const __allureAny_api = allure;
|
|
74
|
+
if (typeof __allureAny_api.step !== 'function') {
|
|
75
|
+
__allureAny_api.step = async (_name, fn) => await fn();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Api: Call api -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
79
|
+
*
|
|
80
|
+
* Calls a predefined API action using configuration from a resource file, supporting dynamic variable replacement,
|
|
81
|
+
* custom headers, body, parameters, authentication, and assertion of expected status codes.
|
|
82
|
+
*
|
|
83
|
+
* This function is designed for hybrid Playwright/Cucumber test frameworks, enabling enterprise-grade API testing
|
|
84
|
+
* with robust error handling and flexible options.
|
|
85
|
+
*
|
|
86
|
+
* @param action - The API action name (corresponds to a file in `resources/api/{action}.api.ts`).
|
|
87
|
+
* @param config - The configuration key within the API module (e.g., "success", "errorCase").
|
|
88
|
+
* @param baseUrl - The base URL for the API endpoint.
|
|
89
|
+
* @param options - Optional. Additional options as a JSON string or object. Supports:
|
|
90
|
+
* - `maxUrlRedirects`: Maximum number of redirects (default: from config or 5).
|
|
91
|
+
* - `maxTimeout`: Request timeout in milliseconds (default: from config or 10000).
|
|
92
|
+
* - `auth`: Axios authentication object.
|
|
93
|
+
* - Any other Axios request config options.
|
|
94
|
+
*
|
|
95
|
+
* @throws Error if the API config is not found or if the response status does not match `expectedStatus` in config.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Example API config file: resources/api/user.api.ts
|
|
99
|
+
* export const api = {
|
|
100
|
+
* getUser: {
|
|
101
|
+
* path: "/users/{userId}",
|
|
102
|
+
* method: "GET",
|
|
103
|
+
* headers: { "Authorization": "Bearer ${token}" },
|
|
104
|
+
* expectedStatus: "200"
|
|
105
|
+
* }
|
|
106
|
+
* };
|
|
107
|
+
*
|
|
108
|
+
* // Usage in test:
|
|
109
|
+
* await callApi(
|
|
110
|
+
* "user",
|
|
111
|
+
* "getUser",
|
|
112
|
+
* "https://api.example.com",
|
|
113
|
+
* { userId: "123", token: "abc123" }
|
|
114
|
+
* );
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // With options as a JSON string:
|
|
118
|
+
* await callApi(
|
|
119
|
+
* "user",
|
|
120
|
+
* "getUser",
|
|
121
|
+
* "https://api.example.com",
|
|
122
|
+
* '{"userId":"123","token":"abc123","maxTimeout":5000}'
|
|
123
|
+
* );
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // With custom authentication:
|
|
127
|
+
* await callApi(
|
|
128
|
+
* "user",
|
|
129
|
+
* "getUser",
|
|
130
|
+
* "https://api.example.com",
|
|
131
|
+
* { auth: { username: "admin", password: "secret" } }
|
|
132
|
+
* );
|
|
133
|
+
*/
|
|
134
|
+
async function callApi(action, config, baseUrl, options) {
|
|
135
|
+
const options_json = typeof options === "string" ? global_1.vars.parseLooseJson(options) : options || {};
|
|
136
|
+
const { maxUrlRedirects = Number(global_1.vars.getConfigValue("apiTest.maxUrlRedirects")) || 5, // Axios defalt is 5
|
|
137
|
+
maxTimeout = Number(global_1.vars.getConfigValue("apiTest.timeout")) || 10000, auth, toNumber = undefined, toBoolean = undefined, } = options_json !== null && options_json !== void 0 ? options_json : {};
|
|
138
|
+
// Input validation
|
|
139
|
+
if (!action || typeof action !== 'string') {
|
|
140
|
+
throw new Error("Action must be a non-empty string.");
|
|
141
|
+
}
|
|
142
|
+
if (!config || typeof config !== 'string') {
|
|
143
|
+
throw new Error("Config must be a non-empty string.");
|
|
144
|
+
}
|
|
145
|
+
if (!baseUrl || typeof baseUrl !== 'string') {
|
|
146
|
+
throw new Error("Base URL must be a non-empty string.");
|
|
147
|
+
}
|
|
148
|
+
const stepName = `Api: Call api -action: ${action} -config: ${config} -baseUrl: ${baseUrl} -options: ${JSON.stringify(options_json)}`;
|
|
149
|
+
if (isPlaywrightRunner()) {
|
|
150
|
+
await test_1.test.step(stepName, async () => {
|
|
151
|
+
await doCallApi();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
await doCallApi();
|
|
156
|
+
}
|
|
157
|
+
async function doCallApi() {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
// Dynamic import of the module
|
|
160
|
+
global_1.vars.setValue("internal.api.last.resStatus", "");
|
|
161
|
+
global_1.vars.setValue("internal.api.last.resStatusText", "");
|
|
162
|
+
global_1.vars.setValue("internal.api.last.resHeader", "");
|
|
163
|
+
global_1.vars.setValue("internal.api.last.resBody", "");
|
|
164
|
+
const projectRoot = process.env.PLAYQ_PROJECT_ROOT || process.cwd();
|
|
165
|
+
const candidateTs = path_1.default.resolve(projectRoot, 'resources', 'api', `${action}.api.ts`);
|
|
166
|
+
const candidateJs = path_1.default.resolve(projectRoot, 'resources', 'api', `${action}.api.js`);
|
|
167
|
+
let actionPath;
|
|
168
|
+
if (fs_1.default.existsSync(candidateTs)) {
|
|
169
|
+
actionPath = candidateTs;
|
|
170
|
+
}
|
|
171
|
+
else if (fs_1.default.existsSync(candidateJs)) {
|
|
172
|
+
actionPath = candidateJs;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
throw new Error(`API config file not found for action '${action}'. Looked for: ${candidateTs} and ${candidateJs}`);
|
|
176
|
+
}
|
|
177
|
+
// const actionPath = require.resolve(`../../../resources/api/${action}.api.ts`);
|
|
178
|
+
const apiModule = await require(actionPath);
|
|
179
|
+
const apiConfig = apiModule.api[config];
|
|
180
|
+
if (!apiConfig) {
|
|
181
|
+
throw new Error(`Config '${config}' not found in ${actionPath}`);
|
|
182
|
+
}
|
|
183
|
+
const reqUrl = global_1.vars.replaceVariables(`${baseUrl}${(_a = apiConfig.path) !== null && _a !== void 0 ? _a : ""}`);
|
|
184
|
+
const reqMethod = global_1.vars.replaceVariables((_b = apiConfig.method) !== null && _b !== void 0 ? _b : "");
|
|
185
|
+
if (!reqMethod || typeof reqMethod !== 'string') {
|
|
186
|
+
throw new Error(`API config '${config}' must specify a valid 'method'.`);
|
|
187
|
+
}
|
|
188
|
+
const reqHeaders = apiConfig.headers
|
|
189
|
+
? JSON.parse(global_1.vars.replaceVariables(JSON.stringify(apiConfig.headers)))
|
|
190
|
+
: {};
|
|
191
|
+
const reqBody = apiConfig.body
|
|
192
|
+
? JSON.parse(global_1.vars.replaceVariables(JSON.stringify(apiConfig.body)))
|
|
193
|
+
: undefined;
|
|
194
|
+
const reqParams = apiConfig.params
|
|
195
|
+
? JSON.parse(global_1.vars.replaceVariables(JSON.stringify(apiConfig.params)))
|
|
196
|
+
: undefined;
|
|
197
|
+
if (reqBody && toNumber)
|
|
198
|
+
convertJsonNodes(reqBody, "toNumber", toNumber);
|
|
199
|
+
if (reqBody && toBoolean)
|
|
200
|
+
convertJsonNodes(reqBody, "toBoolean", toBoolean);
|
|
201
|
+
// Attach request details for traceability
|
|
202
|
+
try {
|
|
203
|
+
const reqInfo = {
|
|
204
|
+
method: reqMethod,
|
|
205
|
+
url: reqUrl,
|
|
206
|
+
headers: reqHeaders,
|
|
207
|
+
params: reqParams,
|
|
208
|
+
body: reqBody
|
|
209
|
+
};
|
|
210
|
+
await global_1.comm.attachLog(`API Request: ${JSON.stringify(reqInfo)}`, "application/json", "API Request");
|
|
211
|
+
}
|
|
212
|
+
catch { }
|
|
213
|
+
let response;
|
|
214
|
+
if (reqMethod.toUpperCase().trim() == 'GET') {
|
|
215
|
+
response = await (0, axios_1.default)({
|
|
216
|
+
method: reqMethod,
|
|
217
|
+
url: reqUrl,
|
|
218
|
+
headers: reqHeaders,
|
|
219
|
+
params: reqParams,
|
|
220
|
+
maxRedirects: maxUrlRedirects,
|
|
221
|
+
timeout: maxTimeout,
|
|
222
|
+
validateStatus: () => true,
|
|
223
|
+
auth
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
response = await (0, axios_1.default)({
|
|
228
|
+
method: reqMethod,
|
|
229
|
+
url: reqUrl,
|
|
230
|
+
headers: reqHeaders,
|
|
231
|
+
data: reqBody,
|
|
232
|
+
maxRedirects: maxUrlRedirects,
|
|
233
|
+
timeout: maxTimeout,
|
|
234
|
+
validateStatus: () => true,
|
|
235
|
+
auth
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const resStatus = (await response).status.toString();
|
|
239
|
+
const resStatusText = (await response).statusText;
|
|
240
|
+
const resHeader = JSON.stringify((await response).headers);
|
|
241
|
+
const resBody = JSON.stringify((await response).data);
|
|
242
|
+
global_1.vars.setValue("playq.api.last.resStatus", resStatus);
|
|
243
|
+
global_1.vars.setValue("playq.api.last.resStatusText", resStatusText);
|
|
244
|
+
global_1.vars.setValue("playq.api.last.resHeader", resHeader);
|
|
245
|
+
global_1.vars.setValue("playq.api.last.resBody", resBody);
|
|
246
|
+
// This console is to show the api response.
|
|
247
|
+
console.log("API Response:", {
|
|
248
|
+
status: resStatus,
|
|
249
|
+
statusText: resStatusText,
|
|
250
|
+
headers: resHeader,
|
|
251
|
+
body: resBody
|
|
252
|
+
});
|
|
253
|
+
// Attach response details
|
|
254
|
+
try {
|
|
255
|
+
await global_1.comm.attachLog(`API Response: ${JSON.stringify({ status: resStatus, statusText: resStatusText })}`, "text/plain", "API Response");
|
|
256
|
+
// Attach compact body header snapshots to avoid huge logs
|
|
257
|
+
await global_1.comm.attachLog(resHeader, "application/json", "API Response Headers");
|
|
258
|
+
await global_1.comm.attachLog(resBody, "application/json", "API Response Body");
|
|
259
|
+
}
|
|
260
|
+
catch { }
|
|
261
|
+
if (apiConfig.expectedStatus) {
|
|
262
|
+
if (apiConfig.expectedStatus != resStatus) {
|
|
263
|
+
await global_1.comm.attachLog(`❌ Status mismatch for '${config}' Expected: '${apiConfig.expectedStatus}' Actual: '${resStatus}'`, "text/plain", "API Verification");
|
|
264
|
+
throw new Error(`Api Response for '${config}' Expected: '${apiConfig.expectedStatus}' Actual: '${resStatus}'`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
await global_1.comm.attachLog(`✅ Status matched for '${config}': '${resStatus}'`, "text/plain", "API Verification");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Converts specific JSON node values within an object based on provided keys.
|
|
274
|
+
* Supports nested keys using dot notation, e.g., "payment.arreasFlag".
|
|
275
|
+
*
|
|
276
|
+
* @param obj - The JSON object to mutate (in-place). If undefined, no-op.
|
|
277
|
+
* @param type - Conversion type: "toNumber" or "toBoolean".
|
|
278
|
+
* @param keys - Comma-separated list of keys to convert.
|
|
279
|
+
*/
|
|
280
|
+
function convertJsonNodes(obj, type, keys) {
|
|
281
|
+
if (!obj || !keys || typeof keys !== 'string')
|
|
282
|
+
return;
|
|
283
|
+
const keyList = keys.split(',').map(k => k.trim());
|
|
284
|
+
for (const key of keyList) {
|
|
285
|
+
// Support nested keys like "payment.arreasFlag"
|
|
286
|
+
const path = key.split('.');
|
|
287
|
+
let ref = obj;
|
|
288
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
289
|
+
if (ref[path[i]] === undefined)
|
|
290
|
+
break;
|
|
291
|
+
ref = ref[path[i]];
|
|
292
|
+
}
|
|
293
|
+
const lastKey = path[path.length - 1];
|
|
294
|
+
if (ref && ref[lastKey] !== undefined) {
|
|
295
|
+
if (type === "toNumber")
|
|
296
|
+
ref[lastKey] = Number(ref[lastKey]);
|
|
297
|
+
if (type === "toBoolean")
|
|
298
|
+
ref[lastKey] = ref[lastKey] === "true" || ref[lastKey] === true;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Api: Get -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
304
|
+
*
|
|
305
|
+
* Sends a GET-style request using an API config. Alias of `callApi`.
|
|
306
|
+
*
|
|
307
|
+
* @param action - API action name.
|
|
308
|
+
* @param config - Config key within the action module.
|
|
309
|
+
* @param baseUrl - Base URL for the request.
|
|
310
|
+
* @param options - Additional options forwarded to `callApi`.
|
|
311
|
+
*/
|
|
312
|
+
async function get(action, config, baseUrl, options) {
|
|
313
|
+
return callApi(action, config, baseUrl, options);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Api: Post -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
317
|
+
*
|
|
318
|
+
* Sends a POST-style request using an API config. Alias of `callApi`.
|
|
319
|
+
*
|
|
320
|
+
* @param action - API action name.
|
|
321
|
+
* @param config - Config key within the action module.
|
|
322
|
+
* @param baseUrl - Base URL for the request.
|
|
323
|
+
* @param options - Additional options forwarded to `callApi`.
|
|
324
|
+
*/
|
|
325
|
+
async function post(action, config, baseUrl, options) {
|
|
326
|
+
return callApi(action, config, baseUrl, options);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Api: Request -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
330
|
+
*
|
|
331
|
+
* Sends a request (generic wrapper). Alias of `callApi`.
|
|
332
|
+
*
|
|
333
|
+
* @param action - API action name.
|
|
334
|
+
* @param config - Config key within the action module.
|
|
335
|
+
* @param baseUrl - Base URL for the request.
|
|
336
|
+
* @param options - Additional options forwarded to `callApi`.
|
|
337
|
+
*/
|
|
338
|
+
async function request(action, config, baseUrl, options) {
|
|
339
|
+
return callApi(action, config, baseUrl, options);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Api: Put -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
343
|
+
* Sends a PUT-style request using an API config. Alias of callApi.
|
|
344
|
+
*/
|
|
345
|
+
async function put(action, config, baseUrl, options) {
|
|
346
|
+
return callApi(action, config, baseUrl, { ...(typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {}), method: 'PUT' });
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Api: Patch -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
350
|
+
* Sends a PATCH-style request using an API config. Alias of callApi.
|
|
351
|
+
*/
|
|
352
|
+
async function patch(action, config, baseUrl, options) {
|
|
353
|
+
return callApi(action, config, baseUrl, { ...(typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {}), method: 'PATCH' });
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Api: Delete -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
357
|
+
* Sends a DELETE-style request using an API config. Alias of callApi.
|
|
358
|
+
*/
|
|
359
|
+
async function del(action, config, baseUrl, options) {
|
|
360
|
+
return callApi(action, config, baseUrl, { ...(typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {}), method: 'DELETE' });
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Api: Send request -method: {param} -action: {param} -config: {param} -baseUrl: {param} -options: {param}
|
|
364
|
+
*
|
|
365
|
+
* Sends an HTTP request using the specified method and API config.
|
|
366
|
+
* @param method - HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
|
|
367
|
+
* @param action - API action name.
|
|
368
|
+
* @param config - Config key within the action module.
|
|
369
|
+
* @param baseUrl - Base URL for the request.
|
|
370
|
+
* @param options - Additional options forwarded to callApi.
|
|
371
|
+
*/
|
|
372
|
+
async function sendRequest(method, action, config, baseUrl, options) {
|
|
373
|
+
return callApi(action, config, baseUrl, { ...(typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {}), method });
|
|
374
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Api: Verify value -actual: {param} -expected: {param} -options: {param}
|
|
3
|
+
*
|
|
4
|
+
* Verifies that a given value matches the expected value.
|
|
5
|
+
* Throws an error if the values do not match.
|
|
6
|
+
*
|
|
7
|
+
* @param actual - The actual value to verify.
|
|
8
|
+
* @param expected - The expected value to compare against.
|
|
9
|
+
* @param message - Optional. Custom error message on failure.
|
|
10
|
+
*/
|
|
11
|
+
export declare function verifyValue(actual: any, expected: string, options?: string | Record<string, any>): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Api: Verify api path value in last response -path: {param} -expected: {param} -options: {param}
|
|
14
|
+
*
|
|
15
|
+
* Verifies that a value at a given JSON path in the last API response matches the expected value.
|
|
16
|
+
* Throws an error if the values do not match.
|
|
17
|
+
*
|
|
18
|
+
* @param path - The JSON path to extract from the last response body/header/status.
|
|
19
|
+
* @param expected - The expected value to compare against.
|
|
20
|
+
* @param options - Optional. Supports { assert: boolean, partial_text: boolean }
|
|
21
|
+
*/
|
|
22
|
+
export declare function verifyPathValue(path: string, expected: string, options?: string | Record<string, any>): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Api: Get last response JSON path value -path: {param} -storeTo: {param}
|
|
25
|
+
*
|
|
26
|
+
* Get the value at a given JSON path from the last API response body.
|
|
27
|
+
* Example: path = "data[0].id" will return the id of the first item in data array.
|
|
28
|
+
* Supports paths like "x.data[0].id" (where "x" is treated as the root).
|
|
29
|
+
*
|
|
30
|
+
* @param path - JSON path string; supports leading "x." as body alias.
|
|
31
|
+
* @returns The extracted value or undefined if not found.
|
|
32
|
+
* @throws Error if `path` is not a non-empty string.
|
|
33
|
+
|
|
34
|
+
*/
|
|
35
|
+
export declare function getLastResponseJsonPathValue(path: string): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* Api: Store last response JSON paths to variables -paths: {param} -vars: {param}
|
|
38
|
+
*
|
|
39
|
+
* Assign multiple values from the last API response body, header, status, or status text to variables.
|
|
40
|
+
* @param pathVarString Comma-separated JSON paths (e.g. "x.data[1].email,h.content-type,s.,t.")
|
|
41
|
+
* @param varKeyString Comma-separated variable keys (e.g. "var.email,var.contentType,var.status,var.statusText")
|
|
42
|
+
* Prefixes (case-insensitive):
|
|
43
|
+
* x. / (body). = response body (default if no prefix)
|
|
44
|
+
* h. / (header). = response header
|
|
45
|
+
* s / (status) / (statusCode) = response status code
|
|
46
|
+
* t / (statusText) = response status text
|
|
47
|
+
* Examples:
|
|
48
|
+
* "x.data[0].id" or "(body).data[0].id" → from body
|
|
49
|
+
* "h.content-type" or "(header).content-type" → from header
|
|
50
|
+
* "s" or "(status)" or "(statusCode)" → response status code
|
|
51
|
+
* "t" or "(statusText)" → response status text
|
|
52
|
+
* "data[0].id" → from body (default)
|
|
53
|
+
*
|
|
54
|
+
* @throws Error if inputs are missing or the number of paths and variable keys differ.
|
|
55
|
+
*/
|
|
56
|
+
export declare function storeLastResponseJsonPathsToVariables(pathVarString: string, varKeyString: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Api: Get path value from last response -path: {param} -storeTo: {param}
|
|
59
|
+
*
|
|
60
|
+
* Get a value from the last API response using a flexible path.
|
|
61
|
+
* Supports body, header, status, and statusText via prefixes:
|
|
62
|
+
* - Body: default or `x.` or `(body).`
|
|
63
|
+
* - Header: `h.` or `(header).`
|
|
64
|
+
* - Status code: `s` or `(status)` or `(statusCode)`
|
|
65
|
+
* - Status text: `t` or `(statusText)`
|
|
66
|
+
*
|
|
67
|
+
* @param path - Path string (e.g., `title`, `x.data[0].id`, `h.content-type`, `s`, `t`)
|
|
68
|
+
* @param options - Optional JSON string or object (reserved)
|
|
69
|
+
* @returns Extracted value or undefined
|
|
70
|
+
* @throws Error if `path` is not a non-empty string
|
|
71
|
+
*/
|
|
72
|
+
export declare function getPathValueFromLastResponse(path: string, options?: string | Record<string, any>): Promise<any>;
|
|
73
|
+
export declare const assertValue: typeof verifyValue;
|
|
74
|
+
export declare const assertPathValue: typeof verifyPathValue;
|
|
75
|
+
export declare const storePaths: typeof storeLastResponseJsonPathsToVariables;
|
|
76
|
+
/**
|
|
77
|
+
* Api: Extract the entire root-level array from the last API response body.
|
|
78
|
+
* @returns {any[]} The parsed array, or throws if not an array.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getLastResponseArray(): Promise<any[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Api: Extract a property from each object in the root-level array from the last API response body.
|
|
83
|
+
* @param {string} property - The property name to extract from each object.
|
|
84
|
+
* @returns {any[]} Array of property values.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getPropertyFromLastResponseArray(property: string): Promise<any[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Api: Generic extractor for last response body (array, object, or primitive).
|
|
89
|
+
* If a path is provided, will attempt to extract using dot/bracket notation.
|
|
90
|
+
* If no path is provided, returns the parsed body (array/object/primitive).
|
|
91
|
+
* @param {string} [path] - Optional dot/bracket path (e.g., 'data[0].id').
|
|
92
|
+
* @returns {any} Extracted value or the parsed body.
|
|
93
|
+
*/
|
|
94
|
+
export declare function extractFromLastResponse(path?: string): Promise<any>;
|
|
95
|
+
/**
|
|
96
|
+
* Api: Assert last response status code.
|
|
97
|
+
* @param expectedStatus - Expected HTTP status code (string or number).
|
|
98
|
+
* @param options - Optional: { assert: boolean }
|
|
99
|
+
*/
|
|
100
|
+
export declare function verifyStatus(expectedStatus: string | number, options?: string | Record<string, any>): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Api: Assert last response header value.
|
|
103
|
+
* @param header - Header name (case-insensitive).
|
|
104
|
+
* @param expectedValue - Expected value (string).
|
|
105
|
+
* @param options - Optional: { assert: boolean, partial_text: boolean }
|
|
106
|
+
*/
|
|
107
|
+
export declare function verifyHeader(header: string, expectedValue: string, options?: string | Record<string, any>): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Api: Assert last response body matches JSON schema.
|
|
110
|
+
* @param schema - JSON schema object.
|
|
111
|
+
* @param options - Optional: { assert: boolean }
|
|
112
|
+
*/
|
|
113
|
+
export declare function verifySchema(schema: object, options?: string | Record<string, any>): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Api: Assert last response is error/timeout (negative test).
|
|
116
|
+
* @param expectedStatus - Expected error status code (string or number).
|
|
117
|
+
* @param options - Optional: { assert: boolean }
|
|
118
|
+
*/
|
|
119
|
+
export declare function verifyError(expectedStatus: string | number, options?: string | Record<string, any>): Promise<void>;
|