@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,615 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.storePaths = exports.assertPathValue = exports.assertValue = void 0;
|
|
37
|
+
exports.verifyValue = verifyValue;
|
|
38
|
+
exports.verifyPathValue = verifyPathValue;
|
|
39
|
+
exports.getLastResponseJsonPathValue = getLastResponseJsonPathValue;
|
|
40
|
+
exports.storeLastResponseJsonPathsToVariables = storeLastResponseJsonPathsToVariables;
|
|
41
|
+
exports.getPathValueFromLastResponse = getPathValueFromLastResponse;
|
|
42
|
+
exports.getLastResponseArray = getLastResponseArray;
|
|
43
|
+
exports.getPropertyFromLastResponseArray = getPropertyFromLastResponseArray;
|
|
44
|
+
exports.extractFromLastResponse = extractFromLastResponse;
|
|
45
|
+
exports.verifyStatus = verifyStatus;
|
|
46
|
+
exports.verifyHeader = verifyHeader;
|
|
47
|
+
exports.verifySchema = verifySchema;
|
|
48
|
+
exports.verifyError = verifyError;
|
|
49
|
+
/**
|
|
50
|
+
* @file apiValidationActions.ts
|
|
51
|
+
*
|
|
52
|
+
* Validation utilities for API testing across Playwright and Cucumber runners.
|
|
53
|
+
* Provides value and JSON path assertions with variable interpolation.
|
|
54
|
+
*
|
|
55
|
+
* Key Features:
|
|
56
|
+
* - Hybrid runner support with Allure-compatible steps.
|
|
57
|
+
* - Flexible path resolution for body, headers, status, and status text.
|
|
58
|
+
* - Optional partial text checks and assertion control.
|
|
59
|
+
*
|
|
60
|
+
* Authors: Renish Kozhithottathil [Lead Automation Principal, NCS]
|
|
61
|
+
* Date: 2025-07-01
|
|
62
|
+
* Version: v1.0.0
|
|
63
|
+
*
|
|
64
|
+
* Note: This file adheres to the PlayQ Enterprise Automation Standards.
|
|
65
|
+
*/
|
|
66
|
+
const allure = __importStar(require("allure-js-commons"));
|
|
67
|
+
const global_1 = require("../../../global");
|
|
68
|
+
const test_1 = require("@playwright/test");
|
|
69
|
+
// Inline runner helpers
|
|
70
|
+
function isPlaywrightRunner() { return process.env.TEST_RUNNER === 'playwright'; }
|
|
71
|
+
function isCucumberRunner() { return process.env.TEST_RUNNER === 'cucumber'; }
|
|
72
|
+
const __allureAny_api = allure;
|
|
73
|
+
if (typeof __allureAny_api.step !== 'function') {
|
|
74
|
+
__allureAny_api.step = async (_name, fn) => await fn();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Api: Verify value -actual: {param} -expected: {param} -options: {param}
|
|
78
|
+
*
|
|
79
|
+
* Verifies that a given value matches the expected value.
|
|
80
|
+
* Throws an error if the values do not match.
|
|
81
|
+
*
|
|
82
|
+
* @param actual - The actual value to verify.
|
|
83
|
+
* @param expected - The expected value to compare against.
|
|
84
|
+
* @param message - Optional. Custom error message on failure.
|
|
85
|
+
*/
|
|
86
|
+
async function verifyValue(actual, expected, options) {
|
|
87
|
+
const resolvedActual = global_1.vars.replaceVariables(String(actual));
|
|
88
|
+
const resolvedExpected = global_1.vars.replaceVariables(expected);
|
|
89
|
+
const options_json = typeof options === "string" ? global_1.vars.parseLooseJson(options) : options || {};
|
|
90
|
+
const { assert = true, partial_text = false } = options_json;
|
|
91
|
+
// Input validation
|
|
92
|
+
if (expected === undefined || expected === null) {
|
|
93
|
+
throw new Error("Expected value must be provided for verification.");
|
|
94
|
+
}
|
|
95
|
+
const stepName = `Api: Verify value -actual: ${resolvedActual} -expected: ${resolvedExpected} -options: ${JSON.stringify(options_json)}`;
|
|
96
|
+
if (isPlaywrightRunner()) {
|
|
97
|
+
await test_1.test.step(stepName, async () => {
|
|
98
|
+
await doVerifyValue();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
await doVerifyValue();
|
|
103
|
+
}
|
|
104
|
+
async function doVerifyValue() {
|
|
105
|
+
// Debug log for type and value
|
|
106
|
+
console.debug(`[verifyValue] actual (type: ${typeof actual}):`, actual);
|
|
107
|
+
if (partial_text) {
|
|
108
|
+
if (!resolvedActual.includes(resolvedExpected)) {
|
|
109
|
+
console.warn(`❌ Verification failed (partial_text): expected '${resolvedActual}' to include '${resolvedExpected}'`);
|
|
110
|
+
await global_1.comm.attachLog(`❌ Verification failed (partial_text): expected '${resolvedActual}' to include '${resolvedExpected}'`, "text/plain", "Verification Details");
|
|
111
|
+
if (assert)
|
|
112
|
+
throw new Error(`Verification failed (partial_text): expected '${resolvedActual}' to include '${resolvedExpected}'`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
console.info(`✅ Verification passed (partial_text): expected '${resolvedActual}' to include '${resolvedExpected}'`);
|
|
116
|
+
await global_1.comm.attachLog(`✅ Verification passed (partial_text): expected '${resolvedActual}' to include '${resolvedExpected}'`, "text/plain", "Verification Details");
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (resolvedActual !== resolvedExpected) {
|
|
121
|
+
console.warn(`❌ Verification failed: expected: '${resolvedExpected}', actual: '${resolvedActual}'`);
|
|
122
|
+
await global_1.comm.attachLog(`❌ Verification failed: expected: '${resolvedExpected}', actual: '${resolvedActual}'`, "text/plain", "Verification Details");
|
|
123
|
+
if (assert)
|
|
124
|
+
throw new Error(`Verification failed: expected '${resolvedExpected}', but got '${resolvedActual}'`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.info(`✅ Verification passed: expected: '${resolvedExpected}', actual: '${resolvedActual}'`);
|
|
128
|
+
await global_1.comm.attachLog(`✅ Verification passed: expected: '${resolvedExpected}', actual: '${resolvedActual}'`, "text/plain", "Verification Details");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Api: Verify api path value in last response -path: {param} -expected: {param} -options: {param}
|
|
134
|
+
*
|
|
135
|
+
* Verifies that a value at a given JSON path in the last API response matches the expected value.
|
|
136
|
+
* Throws an error if the values do not match.
|
|
137
|
+
*
|
|
138
|
+
* @param path - The JSON path to extract from the last response body/header/status.
|
|
139
|
+
* @param expected - The expected value to compare against.
|
|
140
|
+
* @param options - Optional. Supports { assert: boolean, partial_text: boolean }
|
|
141
|
+
*/
|
|
142
|
+
async function verifyPathValue(path, expected, options) {
|
|
143
|
+
const resolvedExpected = global_1.vars.replaceVariables(expected);
|
|
144
|
+
const options_json = typeof options === "string" ? global_1.vars.parseLooseJson(options) : options || {};
|
|
145
|
+
const { assert = true, partial_text = false } = options_json;
|
|
146
|
+
// Input validation
|
|
147
|
+
if (!path || typeof path !== 'string') {
|
|
148
|
+
throw new Error("Path must be a non-empty string for verification.");
|
|
149
|
+
}
|
|
150
|
+
if (expected === undefined || expected === null) {
|
|
151
|
+
throw new Error("Expected value must be provided for verification.");
|
|
152
|
+
}
|
|
153
|
+
const sources = {
|
|
154
|
+
body: global_1.vars.getValue("playq.api.last.resBody"),
|
|
155
|
+
header: global_1.vars.getValue("playq.api.last.resHeader"),
|
|
156
|
+
status: global_1.vars.getValue("playq.api.last.resStatus"),
|
|
157
|
+
statusText: global_1.vars.getValue("playq.api.last.resStatusText")
|
|
158
|
+
};
|
|
159
|
+
let actual;
|
|
160
|
+
let allureMsg = "";
|
|
161
|
+
const stepName = `Api: Verify api path value in last response -path: ${path} -expected: ${resolvedExpected} -options: ${JSON.stringify(options_json)}`;
|
|
162
|
+
if (isPlaywrightRunner()) {
|
|
163
|
+
await test_1.test.step(stepName, async () => {
|
|
164
|
+
await doVerifyPathValue();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
await doVerifyPathValue();
|
|
169
|
+
}
|
|
170
|
+
async function doVerifyPathValue() {
|
|
171
|
+
actual = getPathValue(path, sources);
|
|
172
|
+
// Debug log for extracted value
|
|
173
|
+
console.debug(`[verifyPathValue] path: ${path}, extracted value (type: ${typeof actual}):`, actual, `Expected: ${resolvedExpected}`);
|
|
174
|
+
// verifyValue(actual, resolvedExpected, options);
|
|
175
|
+
if (partial_text) {
|
|
176
|
+
if (!actual || !actual.includes(resolvedExpected)) {
|
|
177
|
+
console.warn(`❌ Verification failed (partial_text): expected '${actual}' to include '${resolvedExpected}'`);
|
|
178
|
+
await global_1.comm.attachLog(`❌ Verification failed (partial_text): expected '${actual}' to include '${resolvedExpected}'`, "text/plain", "Verification Details");
|
|
179
|
+
if (assert)
|
|
180
|
+
throw new Error(`Verification failed (partial_text): expected '${actual}' to include '${resolvedExpected}'`);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
await global_1.comm.attachLog(`✅ Verification passed (partial_text): expected '${actual}' to include '${resolvedExpected}'`, "text/plain", "Verification Details");
|
|
184
|
+
console.assert(`✅ Verification passed (partial_text): expected '${actual}' to include '${resolvedExpected}'`);
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// Handle null/undefined actual values
|
|
189
|
+
const actualString = (actual !== null && actual !== undefined) ? actual.toString() : String(actual);
|
|
190
|
+
if (actualString !== resolvedExpected) {
|
|
191
|
+
console.warn(`❌ Verification failed: expected: '${resolvedExpected}', actual: '${actual}'`);
|
|
192
|
+
await global_1.comm.attachLog(`❌ Verification failed: expected: '${resolvedExpected}', actual: '${actual}'`, "text/plain", "Verification Details");
|
|
193
|
+
if (assert)
|
|
194
|
+
throw new Error(`Verification failed: expected '${resolvedExpected}', but got '${actual}'`);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
await global_1.comm.attachLog(`✅ Verification passed: expected: '${resolvedExpected}', actual: '${actual}'`, "text/plain", "Verification Details");
|
|
198
|
+
console.assert(`✅ Verification passed: expected: '${resolvedExpected}', actual: '${actual}'`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Api: Get last response JSON path value -path: {param} -storeTo: {param}
|
|
204
|
+
*
|
|
205
|
+
* Get the value at a given JSON path from the last API response body.
|
|
206
|
+
* Example: path = "data[0].id" will return the id of the first item in data array.
|
|
207
|
+
* Supports paths like "x.data[0].id" (where "x" is treated as the root).
|
|
208
|
+
*
|
|
209
|
+
* @param path - JSON path string; supports leading "x." as body alias.
|
|
210
|
+
* @returns The extracted value or undefined if not found.
|
|
211
|
+
* @throws Error if `path` is not a non-empty string.
|
|
212
|
+
|
|
213
|
+
*/
|
|
214
|
+
async function getLastResponseJsonPathValue(path) {
|
|
215
|
+
// Input validation
|
|
216
|
+
if (!path || typeof path !== 'string') {
|
|
217
|
+
throw new Error("Path must be a non-empty string for JSON path extraction.");
|
|
218
|
+
}
|
|
219
|
+
const stepName = `Api: Get last response JSON path value -path: ${path}`;
|
|
220
|
+
if (isPlaywrightRunner()) {
|
|
221
|
+
return await test_1.test.step(stepName, async () => {
|
|
222
|
+
return await doGetLastResponseJsonPathValue();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return await doGetLastResponseJsonPathValue();
|
|
226
|
+
async function doGetLastResponseJsonPathValue() {
|
|
227
|
+
const resBody = global_1.vars.getValue("playq.api.last.resBody");
|
|
228
|
+
if (!resBody)
|
|
229
|
+
return undefined;
|
|
230
|
+
const json = JSON.parse(resBody);
|
|
231
|
+
// Remove leading "x." if present
|
|
232
|
+
const normalisedPath = path.startsWith('x.') ? path.slice(2) : path;
|
|
233
|
+
// Simple dot/bracket notation path resolver
|
|
234
|
+
const segments = normalisedPath
|
|
235
|
+
.replace(/^\[(\d+)\]/, '$1') // handle root array [0]
|
|
236
|
+
.replace(/\[(\d+)\]/g, '.$1') // handle nested arrays
|
|
237
|
+
.split('.')
|
|
238
|
+
.filter(Boolean);
|
|
239
|
+
let result = json;
|
|
240
|
+
for (const seg of segments) {
|
|
241
|
+
if (result == null)
|
|
242
|
+
return undefined;
|
|
243
|
+
result = result[seg];
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Api: Store last response JSON paths to variables -paths: {param} -vars: {param}
|
|
250
|
+
*
|
|
251
|
+
* Assign multiple values from the last API response body, header, status, or status text to variables.
|
|
252
|
+
* @param pathVarString Comma-separated JSON paths (e.g. "x.data[1].email,h.content-type,s.,t.")
|
|
253
|
+
* @param varKeyString Comma-separated variable keys (e.g. "var.email,var.contentType,var.status,var.statusText")
|
|
254
|
+
* Prefixes (case-insensitive):
|
|
255
|
+
* x. / (body). = response body (default if no prefix)
|
|
256
|
+
* h. / (header). = response header
|
|
257
|
+
* s / (status) / (statusCode) = response status code
|
|
258
|
+
* t / (statusText) = response status text
|
|
259
|
+
* Examples:
|
|
260
|
+
* "x.data[0].id" or "(body).data[0].id" → from body
|
|
261
|
+
* "h.content-type" or "(header).content-type" → from header
|
|
262
|
+
* "s" or "(status)" or "(statusCode)" → response status code
|
|
263
|
+
* "t" or "(statusText)" → response status text
|
|
264
|
+
* "data[0].id" → from body (default)
|
|
265
|
+
*
|
|
266
|
+
* @throws Error if inputs are missing or the number of paths and variable keys differ.
|
|
267
|
+
*/
|
|
268
|
+
async function storeLastResponseJsonPathsToVariables(pathVarString, varKeyString) {
|
|
269
|
+
// Input validation
|
|
270
|
+
if (!pathVarString || !varKeyString) {
|
|
271
|
+
throw new Error("Both pathVarString and varKeyString must be provided.");
|
|
272
|
+
}
|
|
273
|
+
const execute = async () => {
|
|
274
|
+
var _a, _b;
|
|
275
|
+
const resBody = global_1.vars.getValue("playq.api.last.resBody");
|
|
276
|
+
const resHeader = global_1.vars.getValue("playq.api.last.resHeader");
|
|
277
|
+
const resStatus = global_1.vars.getValue("playq.api.last.resStatus");
|
|
278
|
+
const resStatusText = global_1.vars.getValue("playq.api.last.resStatusText");
|
|
279
|
+
if (!resBody && !resHeader && !resStatus && !resStatusText)
|
|
280
|
+
return;
|
|
281
|
+
const jsonBody = resBody ? JSON.parse(resBody) : {};
|
|
282
|
+
const jsonHeader = resHeader ? JSON.parse(resHeader) : {};
|
|
283
|
+
const paths = pathVarString.split(',').map(s => s.trim());
|
|
284
|
+
const varKeys = varKeyString.split(',').map(s => s.trim());
|
|
285
|
+
if (paths.length !== varKeys.length) {
|
|
286
|
+
throw new Error("Number of paths and variable keys must match.");
|
|
287
|
+
}
|
|
288
|
+
for (let i = 0; i < paths.length; i++) {
|
|
289
|
+
let path = paths[i];
|
|
290
|
+
const varKey = varKeys[i];
|
|
291
|
+
let result;
|
|
292
|
+
const lowerPath = path.toLowerCase();
|
|
293
|
+
if (lowerPath.startsWith('h.')) {
|
|
294
|
+
// Header: h.header-name
|
|
295
|
+
const headerKey = path.slice(2).toLowerCase();
|
|
296
|
+
result = (_a = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === headerKey)) === null || _a === void 0 ? void 0 : _a[1];
|
|
297
|
+
}
|
|
298
|
+
else if (lowerPath.startsWith('(header).')) {
|
|
299
|
+
// Header: (header).header-name
|
|
300
|
+
const headerKey = path.slice(9).toLowerCase();
|
|
301
|
+
result = (_b = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === headerKey)) === null || _b === void 0 ? void 0 : _b[1];
|
|
302
|
+
}
|
|
303
|
+
else if (lowerPath.startsWith('s') || lowerPath.startsWith('s.')) {
|
|
304
|
+
// Status: s.
|
|
305
|
+
result = resStatus;
|
|
306
|
+
}
|
|
307
|
+
else if (lowerPath.startsWith('(status)') || lowerPath.startsWith('(statuscode)') || lowerPath.startsWith('(status).') || lowerPath.startsWith('(statuscode).')) {
|
|
308
|
+
// Status: (status).
|
|
309
|
+
result = resStatus;
|
|
310
|
+
}
|
|
311
|
+
else if (lowerPath.startsWith('t.')) {
|
|
312
|
+
// Status Text: t.
|
|
313
|
+
result = resStatusText;
|
|
314
|
+
}
|
|
315
|
+
else if (lowerPath.startsWith('(statustext)') || lowerPath.startsWith('(statustext).')) {
|
|
316
|
+
// Status Text: (statusText).
|
|
317
|
+
result = resStatusText;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
// Body: x., (body)., or no prefix
|
|
321
|
+
let normalisedPath = path;
|
|
322
|
+
if (lowerPath.startsWith('x.'))
|
|
323
|
+
normalisedPath = path.slice(2);
|
|
324
|
+
else if (lowerPath.startsWith('(body).'))
|
|
325
|
+
normalisedPath = path.slice(7);
|
|
326
|
+
const segments = normalisedPath
|
|
327
|
+
.replace(/^\[(\d+)\]/, '$1')
|
|
328
|
+
.replace(/\[(\d+)\]/g, '.$1')
|
|
329
|
+
.split('.')
|
|
330
|
+
.filter(Boolean);
|
|
331
|
+
result = jsonBody;
|
|
332
|
+
for (const seg of segments) {
|
|
333
|
+
if (result == null)
|
|
334
|
+
break;
|
|
335
|
+
result = result[seg];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (result !== undefined && result !== null) {
|
|
339
|
+
global_1.vars.setValue(varKey, result.toString());
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
if (isPlaywrightRunner()) {
|
|
344
|
+
await test_1.test.step(`Api: Store last response JSON paths to variables -paths: ${pathVarString} -vars: ${varKeyString}`, async () => {
|
|
345
|
+
await execute();
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
await execute();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Internal helper used only by verifyPathValue
|
|
353
|
+
function getPathValueInternal(path, sources) {
|
|
354
|
+
var _a, _b;
|
|
355
|
+
const lowerPath = path.toLowerCase();
|
|
356
|
+
const jsonBody = typeof sources.body === "string" && sources.body ? JSON.parse(sources.body) : sources.body || {};
|
|
357
|
+
const jsonHeader = typeof sources.header === "string" && sources.header ? JSON.parse(sources.header) : sources.header || {};
|
|
358
|
+
if (lowerPath.startsWith('h.')) {
|
|
359
|
+
const headerKey = path.slice(2).toLowerCase();
|
|
360
|
+
return (_a = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === headerKey)) === null || _a === void 0 ? void 0 : _a[1];
|
|
361
|
+
}
|
|
362
|
+
if (lowerPath.startsWith('(header).')) {
|
|
363
|
+
const headerKey = path.slice(9).toLowerCase();
|
|
364
|
+
return (_b = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === headerKey)) === null || _b === void 0 ? void 0 : _b[1];
|
|
365
|
+
}
|
|
366
|
+
if (lowerPath === 's' || lowerPath === 's.' || lowerPath.startsWith('s.') || lowerPath.startsWith('(status)') || lowerPath.startsWith('(statuscode)') || lowerPath.startsWith('(status).') || lowerPath.startsWith('(statuscode).')) {
|
|
367
|
+
return sources.status;
|
|
368
|
+
}
|
|
369
|
+
if (lowerPath === 't' || lowerPath === 't.' || lowerPath.startsWith('(statustext)') || lowerPath.startsWith('(statustext).')) {
|
|
370
|
+
return sources.statusText;
|
|
371
|
+
}
|
|
372
|
+
let normalisedPath = path;
|
|
373
|
+
if (lowerPath.startsWith('x.'))
|
|
374
|
+
normalisedPath = path.slice(2);
|
|
375
|
+
else if (lowerPath.startsWith('(body).'))
|
|
376
|
+
normalisedPath = path.slice(7);
|
|
377
|
+
const segments = normalisedPath
|
|
378
|
+
.replace(/^\[(\d+)\]/, '$1') // handle root array [0]
|
|
379
|
+
.replace(/\[(\d+)\]/g, '.$1') // handle nested arrays
|
|
380
|
+
.split('.')
|
|
381
|
+
.filter(Boolean);
|
|
382
|
+
let result = jsonBody;
|
|
383
|
+
for (const seg of segments) {
|
|
384
|
+
if (result == null)
|
|
385
|
+
return undefined;
|
|
386
|
+
result = result[seg];
|
|
387
|
+
}
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Generic internal function to extract a value from a JSON object, header, status, or status text
|
|
392
|
+
* using a flexible path syntax.
|
|
393
|
+
*
|
|
394
|
+
* @param path - Path string with optional prefix (e.g., "x.data[0].id", "h.content-type", "s", "t")
|
|
395
|
+
* @param sources - Object containing { body, header, status, statusText }
|
|
396
|
+
* @returns The extracted value or undefined if not found.
|
|
397
|
+
*/
|
|
398
|
+
function getPathValue(path, sources) {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
const lowerPath = path.toLowerCase();
|
|
401
|
+
// Prepare parsed objects
|
|
402
|
+
const jsonBody = typeof sources.body === "string" && sources.body
|
|
403
|
+
? JSON.parse(sources.body)
|
|
404
|
+
: sources.body || {};
|
|
405
|
+
const jsonHeader = typeof sources.header === "string" && sources.header
|
|
406
|
+
? JSON.parse(sources.header)
|
|
407
|
+
: sources.header || {};
|
|
408
|
+
if (lowerPath.startsWith('h.')) {
|
|
409
|
+
// Header: h.header-name
|
|
410
|
+
const headerKey = path.slice(2).toLowerCase();
|
|
411
|
+
return (_a = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === headerKey)) === null || _a === void 0 ? void 0 : _a[1];
|
|
412
|
+
}
|
|
413
|
+
if (lowerPath.startsWith('(header).')) {
|
|
414
|
+
// Header: (header).header-name
|
|
415
|
+
const headerKey = path.slice(9).toLowerCase();
|
|
416
|
+
return (_b = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === headerKey)) === null || _b === void 0 ? void 0 : _b[1];
|
|
417
|
+
}
|
|
418
|
+
if (lowerPath === 's' || lowerPath === 's.' ||
|
|
419
|
+
lowerPath.startsWith('s.') ||
|
|
420
|
+
lowerPath.startsWith('(status)') || lowerPath.startsWith('(statuscode)') ||
|
|
421
|
+
lowerPath.startsWith('(status).') || lowerPath.startsWith('(statuscode).')) {
|
|
422
|
+
return sources.status;
|
|
423
|
+
}
|
|
424
|
+
if (lowerPath === 't' || lowerPath === 't.' ||
|
|
425
|
+
lowerPath.startsWith('(statustext)') || lowerPath.startsWith('(statustext).')) {
|
|
426
|
+
return sources.statusText;
|
|
427
|
+
}
|
|
428
|
+
// Body: x., (body)., or no prefix
|
|
429
|
+
let normalisedPath = path;
|
|
430
|
+
if (lowerPath.startsWith('x.'))
|
|
431
|
+
normalisedPath = path.slice(2);
|
|
432
|
+
else if (lowerPath.startsWith('(body).'))
|
|
433
|
+
normalisedPath = path.slice(7);
|
|
434
|
+
const segments = normalisedPath
|
|
435
|
+
.replace(/^\[(\d+)\]/, '$1') // handle root array [0]
|
|
436
|
+
.replace(/\[(\d+)\]/g, '.$1') // handle nested arrays
|
|
437
|
+
.split('.')
|
|
438
|
+
.filter(Boolean);
|
|
439
|
+
let result = jsonBody;
|
|
440
|
+
for (const seg of segments) {
|
|
441
|
+
if (result == null)
|
|
442
|
+
return undefined;
|
|
443
|
+
result = result[seg];
|
|
444
|
+
}
|
|
445
|
+
return result;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Api: Get path value from last response -path: {param} -storeTo: {param}
|
|
449
|
+
*
|
|
450
|
+
* Get a value from the last API response using a flexible path.
|
|
451
|
+
* Supports body, header, status, and statusText via prefixes:
|
|
452
|
+
* - Body: default or `x.` or `(body).`
|
|
453
|
+
* - Header: `h.` or `(header).`
|
|
454
|
+
* - Status code: `s` or `(status)` or `(statusCode)`
|
|
455
|
+
* - Status text: `t` or `(statusText)`
|
|
456
|
+
*
|
|
457
|
+
* @param path - Path string (e.g., `title`, `x.data[0].id`, `h.content-type`, `s`, `t`)
|
|
458
|
+
* @param options - Optional JSON string or object (reserved)
|
|
459
|
+
* @returns Extracted value or undefined
|
|
460
|
+
* @throws Error if `path` is not a non-empty string
|
|
461
|
+
*/
|
|
462
|
+
async function getPathValueFromLastResponse(path, options) {
|
|
463
|
+
if (!path || typeof path !== 'string') {
|
|
464
|
+
throw new Error("Path must be a non-empty string");
|
|
465
|
+
}
|
|
466
|
+
const options_json = typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {};
|
|
467
|
+
const sources = {
|
|
468
|
+
body: global_1.vars.getValue("playq.api.last.resBody"),
|
|
469
|
+
header: global_1.vars.getValue("playq.api.last.resHeader"),
|
|
470
|
+
status: global_1.vars.getValue("playq.api.last.resStatus"),
|
|
471
|
+
statusText: global_1.vars.getValue("playq.api.last.resStatusText")
|
|
472
|
+
};
|
|
473
|
+
const stepName = `Api: Get path value from last response -path: ${path} -options: ${JSON.stringify(options_json)}`;
|
|
474
|
+
const run = async () => getPathValue(path, sources);
|
|
475
|
+
if (isPlaywrightRunner()) {
|
|
476
|
+
return await test_1.test.step(stepName, run);
|
|
477
|
+
}
|
|
478
|
+
return run();
|
|
479
|
+
}
|
|
480
|
+
// Friendly aliases
|
|
481
|
+
exports.assertValue = verifyValue;
|
|
482
|
+
exports.assertPathValue = verifyPathValue;
|
|
483
|
+
exports.storePaths = storeLastResponseJsonPathsToVariables;
|
|
484
|
+
/**
|
|
485
|
+
* Api: Extract the entire root-level array from the last API response body.
|
|
486
|
+
* @returns {any[]} The parsed array, or throws if not an array.
|
|
487
|
+
*/
|
|
488
|
+
async function getLastResponseArray() {
|
|
489
|
+
const resBody = global_1.vars.getValue("playq.api.last.resBody");
|
|
490
|
+
if (!resBody)
|
|
491
|
+
throw new Error("No last response body found.");
|
|
492
|
+
const arr = JSON.parse(resBody);
|
|
493
|
+
if (!Array.isArray(arr))
|
|
494
|
+
throw new Error("Last response body is not an array.");
|
|
495
|
+
return arr;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Api: Extract a property from each object in the root-level array from the last API response body.
|
|
499
|
+
* @param {string} property - The property name to extract from each object.
|
|
500
|
+
* @returns {any[]} Array of property values.
|
|
501
|
+
*/
|
|
502
|
+
async function getPropertyFromLastResponseArray(property) {
|
|
503
|
+
const arr = await getLastResponseArray();
|
|
504
|
+
return arr.map(obj => obj && typeof obj === 'object' ? obj[property] : undefined);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Api: Generic extractor for last response body (array, object, or primitive).
|
|
508
|
+
* If a path is provided, will attempt to extract using dot/bracket notation.
|
|
509
|
+
* If no path is provided, returns the parsed body (array/object/primitive).
|
|
510
|
+
* @param {string} [path] - Optional dot/bracket path (e.g., 'data[0].id').
|
|
511
|
+
* @returns {any} Extracted value or the parsed body.
|
|
512
|
+
*/
|
|
513
|
+
async function extractFromLastResponse(path) {
|
|
514
|
+
const resBody = global_1.vars.getValue("playq.api.last.resBody");
|
|
515
|
+
if (!resBody)
|
|
516
|
+
throw new Error("No last response body found.");
|
|
517
|
+
const json = JSON.parse(resBody);
|
|
518
|
+
if (!path)
|
|
519
|
+
return json;
|
|
520
|
+
// Simple dot/bracket notation path resolver
|
|
521
|
+
const segments = path.replace(/\[(\w+)\]/g, '.$1').split('.').filter(Boolean);
|
|
522
|
+
let result = json;
|
|
523
|
+
for (const seg of segments) {
|
|
524
|
+
if (result == null)
|
|
525
|
+
return undefined;
|
|
526
|
+
result = result[seg];
|
|
527
|
+
}
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Api: Assert last response status code.
|
|
532
|
+
* @param expectedStatus - Expected HTTP status code (string or number).
|
|
533
|
+
* @param options - Optional: { assert: boolean }
|
|
534
|
+
*/
|
|
535
|
+
async function verifyStatus(expectedStatus, options) {
|
|
536
|
+
const actual = global_1.vars.getValue("playq.api.last.resStatus");
|
|
537
|
+
const expected = String(expectedStatus);
|
|
538
|
+
const options_json = typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {};
|
|
539
|
+
const { assert = true } = options_json;
|
|
540
|
+
if (actual !== expected) {
|
|
541
|
+
await global_1.comm.attachLog(`❌ Status code mismatch: expected ${expected}, got ${actual}`, "text/plain");
|
|
542
|
+
if (assert)
|
|
543
|
+
throw new Error(`Status code mismatch: expected ${expected}, got ${actual}`);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
await global_1.comm.attachLog(`✅ Status code matched: ${expected}`, "text/plain");
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Api: Assert last response header value.
|
|
551
|
+
* @param header - Header name (case-insensitive).
|
|
552
|
+
* @param expectedValue - Expected value (string).
|
|
553
|
+
* @param options - Optional: { assert: boolean, partial_text: boolean }
|
|
554
|
+
*/
|
|
555
|
+
async function verifyHeader(header, expectedValue, options) {
|
|
556
|
+
var _a;
|
|
557
|
+
const resHeader = global_1.vars.getValue("playq.api.last.resHeader");
|
|
558
|
+
const jsonHeader = resHeader ? JSON.parse(resHeader) : {};
|
|
559
|
+
const actual = (_a = Object.entries(jsonHeader).find(([k]) => k.toLowerCase() === header.toLowerCase())) === null || _a === void 0 ? void 0 : _a[1];
|
|
560
|
+
const options_json = typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {};
|
|
561
|
+
const { assert = true, partial_text = false } = options_json;
|
|
562
|
+
if (partial_text
|
|
563
|
+
? !(typeof actual === "string" && actual.includes(expectedValue))
|
|
564
|
+
: actual !== expectedValue) {
|
|
565
|
+
await global_1.comm.attachLog(`❌ Header mismatch: ${header} expected ${expectedValue}, got ${actual}`, "text/plain");
|
|
566
|
+
if (assert)
|
|
567
|
+
throw new Error(`Header mismatch: ${header} expected ${expectedValue}, got ${actual}`);
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
await global_1.comm.attachLog(`✅ Header matched: ${header} = ${expectedValue}`, "text/plain");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Api: Assert last response body matches JSON schema.
|
|
575
|
+
* @param schema - JSON schema object.
|
|
576
|
+
* @param options - Optional: { assert: boolean }
|
|
577
|
+
*/
|
|
578
|
+
async function verifySchema(schema, options) {
|
|
579
|
+
const resBody = global_1.vars.getValue("playq.api.last.resBody");
|
|
580
|
+
const options_json = typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {};
|
|
581
|
+
const { assert = true } = options_json;
|
|
582
|
+
if (!resBody)
|
|
583
|
+
throw new Error("No last response body found.");
|
|
584
|
+
const Ajv = require('ajv');
|
|
585
|
+
const ajv = new Ajv();
|
|
586
|
+
const json = JSON.parse(resBody);
|
|
587
|
+
const valid = ajv.validate(schema, json);
|
|
588
|
+
if (!valid) {
|
|
589
|
+
await global_1.comm.attachLog(`❌ Schema validation failed: ${JSON.stringify(ajv.errors)}`, "application/json");
|
|
590
|
+
if (assert)
|
|
591
|
+
throw new Error(`Schema validation failed: ${JSON.stringify(ajv.errors)}`);
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
await global_1.comm.attachLog(`✅ Schema validation passed.`, "text/plain");
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Api: Assert last response is error/timeout (negative test).
|
|
599
|
+
* @param expectedStatus - Expected error status code (string or number).
|
|
600
|
+
* @param options - Optional: { assert: boolean }
|
|
601
|
+
*/
|
|
602
|
+
async function verifyError(expectedStatus, options) {
|
|
603
|
+
const actual = global_1.vars.getValue("playq.api.last.resStatus");
|
|
604
|
+
const expected = String(expectedStatus);
|
|
605
|
+
const options_json = typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {};
|
|
606
|
+
const { assert = true } = options_json;
|
|
607
|
+
if (actual !== expected) {
|
|
608
|
+
await global_1.comm.attachLog(`❌ Expected error status ${expected}, got ${actual}`, "text/plain");
|
|
609
|
+
if (assert)
|
|
610
|
+
throw new Error(`Expected error status ${expected}, got ${actual}`);
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
await global_1.comm.attachLog(`✅ Error status matched: ${expected}`, "text/plain");
|
|
614
|
+
}
|
|
615
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file apiActions.ts
|
|
3
|
+
*
|
|
4
|
+
* Unified API actions bridging Playwright and Cucumber.
|
|
5
|
+
* Provides request helpers and validation utilities with reporting.
|
|
6
|
+
*
|
|
7
|
+
* Key Features:
|
|
8
|
+
* - Hybrid context: Playwright Runner (page) and Cucumber World (webFixture)
|
|
9
|
+
* - Rich options for assertions, timeouts, and attachments
|
|
10
|
+
* - Robust error handling, logging, and Allure-compatible step wrappers
|
|
11
|
+
*
|
|
12
|
+
* Authors: Renish Kozhithottathil [Lead Automation Principal, NCS]
|
|
13
|
+
* Version: v1.0.0
|
|
14
|
+
*
|
|
15
|
+
* Note: This file adheres to the PlayQ Enterprise Automation Standards.
|
|
16
|
+
*/
|
|
17
|
+
export * from './api/apiRequestActions';
|
|
18
|
+
export * from './api/apiValidationActions';
|
|
@@ -0,0 +1,34 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* @file apiActions.ts
|
|
19
|
+
*
|
|
20
|
+
* Unified API actions bridging Playwright and Cucumber.
|
|
21
|
+
* Provides request helpers and validation utilities with reporting.
|
|
22
|
+
*
|
|
23
|
+
* Key Features:
|
|
24
|
+
* - Hybrid context: Playwright Runner (page) and Cucumber World (webFixture)
|
|
25
|
+
* - Rich options for assertions, timeouts, and attachments
|
|
26
|
+
* - Robust error handling, logging, and Allure-compatible step wrappers
|
|
27
|
+
*
|
|
28
|
+
* Authors: Renish Kozhithottathil [Lead Automation Principal, NCS]
|
|
29
|
+
* Version: v1.0.0
|
|
30
|
+
*
|
|
31
|
+
* Note: This file adheres to the PlayQ Enterprise Automation Standards.
|
|
32
|
+
*/
|
|
33
|
+
__exportStar(require("./api/apiRequestActions"), exports);
|
|
34
|
+
__exportStar(require("./api/apiValidationActions"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|