@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,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file elementReaderActions.ts
|
|
3
|
+
*
|
|
4
|
+
* Element reader helpers for PlayQ web actions.
|
|
5
|
+
* Provides text/value/attribute/class/html readers and a utility to store
|
|
6
|
+
* element text into a PlayQ variable, with runner-aware step wrappers.
|
|
7
|
+
*
|
|
8
|
+
* Authors: PlayQ Team
|
|
9
|
+
* Version: v1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import * as allure from "allure-js-commons";
|
|
12
|
+
import type { Page, Locator } from "playwright";
|
|
13
|
+
import { vars, webLocResolver } from "../../../global";
|
|
14
|
+
import { processScreenshot } from "./screenshotActions";
|
|
15
|
+
import { attachLog } from '../comm/commonActions';
|
|
16
|
+
const config: any = {};
|
|
17
|
+
function isPlaywrightRunner() { return process.env.TEST_RUNNER === 'playwright'; }
|
|
18
|
+
const __allureAny_reader: any = allure as any;
|
|
19
|
+
if (typeof __allureAny_reader.step !== 'function') { __allureAny_reader.step = async (_n: string, f: any) => await f(); }
|
|
20
|
+
// Allure compatibility shim: if step is unavailable, just run the body
|
|
21
|
+
const __allureAny_web: any = allure as any;
|
|
22
|
+
if (typeof __allureAny_web.step !== 'function') {
|
|
23
|
+
__allureAny_web.step = async (_name: string, fn: any) => await fn();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Web: Get Text -field: {param} -options: {param}
|
|
27
|
+
*
|
|
28
|
+
* Returns the inner text of the resolved element.
|
|
29
|
+
*
|
|
30
|
+
* @param page - Playwright Page instance
|
|
31
|
+
* @param field - Label/selector or Locator of the element
|
|
32
|
+
* @param options - Optional JSON string or object ({ pattern, actionTimeout })
|
|
33
|
+
* @returns The element's inner text
|
|
34
|
+
* @throws Error if page is not initialized or element resolution fails
|
|
35
|
+
*/
|
|
36
|
+
export async function getText(page: Page, field: string | Locator, options?: string | Record<string, any>) {
|
|
37
|
+
const options_json = typeof options === 'string' ? vars.parseLooseJson(options) : options || {};
|
|
38
|
+
const stepName = `Web: Get Text -field: ${typeof field === 'string' ? field : '<locator>'}`;
|
|
39
|
+
const run = async () => {
|
|
40
|
+
if (!page) throw new Error("Page not initialized");
|
|
41
|
+
const locator = typeof field === 'string'
|
|
42
|
+
? await webLocResolver(options_json?.fieldType || '', field, page, options_json?.pattern, typeof options_json?.actionTimeout === 'number' ? options_json.actionTimeout : undefined, options_json?.smartAiRefresh || '')
|
|
43
|
+
: field;
|
|
44
|
+
return locator.innerText();
|
|
45
|
+
};
|
|
46
|
+
if (isPlaywrightRunner()) { return __allureAny_reader.step(stepName, run); }
|
|
47
|
+
return run();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Web: Get Value -field: {param} -options: {param}
|
|
52
|
+
*
|
|
53
|
+
* Returns the input value of the resolved element.
|
|
54
|
+
*
|
|
55
|
+
* @param page - Playwright Page instance
|
|
56
|
+
* @param field - Label/selector or Locator of the element
|
|
57
|
+
* @param options - Optional JSON string or object ({ pattern, actionTimeout })
|
|
58
|
+
* @returns The input's current value
|
|
59
|
+
* @throws Error if page is not initialized or element resolution fails
|
|
60
|
+
*/
|
|
61
|
+
export async function getValue(page: Page, field: string | Locator, options?: string | Record<string, any>) {
|
|
62
|
+
const options_json = typeof options === 'string' ? vars.parseLooseJson(options) : options || {};
|
|
63
|
+
const stepName = `Web: Get Value -field: ${typeof field === 'string' ? field : '<locator>'}`;
|
|
64
|
+
const run = async () => {
|
|
65
|
+
if (!page) throw new Error("Page not initialized");
|
|
66
|
+
const locator = typeof field === 'string'
|
|
67
|
+
? await webLocResolver(options_json?.fieldType || '', field, page, options_json?.pattern, typeof options_json?.actionTimeout === 'number' ? options_json.actionTimeout : undefined, options_json?.smartAiRefresh || '')
|
|
68
|
+
: field;
|
|
69
|
+
return locator.inputValue();
|
|
70
|
+
};
|
|
71
|
+
if (isPlaywrightRunner()) { return __allureAny_reader.step(stepName, run); }
|
|
72
|
+
return run();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Web: Get Attribute -field: {param} -name: {param} -options: {param}
|
|
77
|
+
*
|
|
78
|
+
* Returns the value of an attribute from the resolved element.
|
|
79
|
+
*
|
|
80
|
+
* @param page - Playwright Page instance
|
|
81
|
+
* @param field - Label/selector or Locator of the element
|
|
82
|
+
* @param name - Attribute name
|
|
83
|
+
* @param options - Optional JSON string or object ({ pattern, actionTimeout })
|
|
84
|
+
* @returns The attribute value or null
|
|
85
|
+
* @throws Error if page is not initialized or element resolution fails
|
|
86
|
+
*/
|
|
87
|
+
export async function getAttribute(page: Page, field: string | Locator, name: string, options?: string | Record<string, any>) {
|
|
88
|
+
const options_json = typeof options === 'string' ? vars.parseLooseJson(options) : options || {};
|
|
89
|
+
const stepName = `Web: Get Attribute -field: ${typeof field === 'string' ? field : '<locator>'} -name: ${name}`;
|
|
90
|
+
const run = async () => {
|
|
91
|
+
if (!page) throw new Error("Page not initialized");
|
|
92
|
+
const locator = typeof field === 'string'
|
|
93
|
+
? await webLocResolver(options_json?.fieldType || '', field, page, options_json?.pattern, typeof options_json?.actionTimeout === 'number' ? options_json.actionTimeout : undefined, options_json?.smartAiRefresh || '')
|
|
94
|
+
: field;
|
|
95
|
+
return locator.getAttribute(name);
|
|
96
|
+
};
|
|
97
|
+
if (isPlaywrightRunner()) { return __allureAny_reader.step(stepName, run); }
|
|
98
|
+
return run();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Web: Has Class -field: {param} -className: {param} -options: {param}
|
|
103
|
+
*
|
|
104
|
+
* Checks whether the element has the specified CSS class.
|
|
105
|
+
*
|
|
106
|
+
* @param page - Playwright Page instance
|
|
107
|
+
* @param field - Label/selector or Locator of the element
|
|
108
|
+
* @param className - Class name to check
|
|
109
|
+
* @param options - Optional JSON string or object ({ pattern, actionTimeout })
|
|
110
|
+
* @returns True when class present; false otherwise
|
|
111
|
+
* @throws Error if page is not initialized or element resolution fails
|
|
112
|
+
*/
|
|
113
|
+
export async function hasClass(page: Page, field: string | Locator, className: string, options?: string | Record<string, any>) {
|
|
114
|
+
const options_json = typeof options === 'string' ? vars.parseLooseJson(options) : options || {};
|
|
115
|
+
const stepName = `Web: Has Class -field: ${typeof field === 'string' ? field : '<locator>'} -className: ${className}`;
|
|
116
|
+
const run = async () => {
|
|
117
|
+
if (!page) throw new Error("Page not initialized");
|
|
118
|
+
const locator = typeof field === 'string'
|
|
119
|
+
? await webLocResolver(options_json?.fieldType || '', field, page, options_json?.pattern, typeof options_json?.actionTimeout === 'number' ? options_json.actionTimeout : undefined, options_json?.smartAiRefresh || '')
|
|
120
|
+
: field;
|
|
121
|
+
const cls = await locator.getAttribute('class');
|
|
122
|
+
return (cls || '').split(/\s+/).includes(className);
|
|
123
|
+
};
|
|
124
|
+
if (isPlaywrightRunner()) { return __allureAny_reader.step(stepName, run); }
|
|
125
|
+
return run();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Web: Get HTML -field: {param} -options: {param}
|
|
130
|
+
*
|
|
131
|
+
* Returns the inner HTML of the resolved element.
|
|
132
|
+
*
|
|
133
|
+
* @param page - Playwright Page instance
|
|
134
|
+
* @param field - Label/selector or Locator of the element
|
|
135
|
+
* @param options - Optional JSON string or object ({ pattern, actionTimeout })
|
|
136
|
+
* @returns The element's inner HTML
|
|
137
|
+
* @throws Error if page is not initialized or element resolution fails
|
|
138
|
+
*/
|
|
139
|
+
export async function getHtml(page: Page, field: string | Locator, options?: string | Record<string, any>) {
|
|
140
|
+
const options_json = typeof options === 'string' ? vars.parseLooseJson(options) : options || {};
|
|
141
|
+
const stepName = `Web: Get HTML -field: ${typeof field === 'string' ? field : '<locator>'}`;
|
|
142
|
+
const run = async () => {
|
|
143
|
+
if (!page) throw new Error("Page not initialized");
|
|
144
|
+
const locator = typeof field === 'string'
|
|
145
|
+
? await webLocResolver(options_json?.fieldType || '', field, page, options_json?.pattern, typeof options_json?.actionTimeout === 'number' ? options_json.actionTimeout : undefined, options_json?.smartAiRefresh || '')
|
|
146
|
+
: field;
|
|
147
|
+
return locator.innerHTML();
|
|
148
|
+
};
|
|
149
|
+
if (isPlaywrightRunner()) { return __allureAny_reader.step(stepName, run); }
|
|
150
|
+
return run();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Web: Store element text in Variable -field: {param} into variable: {param} -options: {param}
|
|
155
|
+
* Stores the text content of a web element into a variable for later use.
|
|
156
|
+
* @param page - Playwright Page instance.
|
|
157
|
+
* @param field - The label, text, id, name, or selector of the web element.
|
|
158
|
+
* @param variableName - The name of the variable to store the text content.
|
|
159
|
+
* @param options - Optional JSON string or object:
|
|
160
|
+
* - actionTimeout: [number] Optional timeout in milliseconds. Default: Configured timeout.
|
|
161
|
+
* - pattern: [string] Optional pattern to refine element search.
|
|
162
|
+
* - attribute: [string] If provided, reads specific attribute instead of text/value.
|
|
163
|
+
* - trim: [boolean] Whether to trim whitespace. Default: true.
|
|
164
|
+
* - normalizeWhitespace: [boolean] Whether to normalize whitespace. Default: true.
|
|
165
|
+
* - screenshot: [boolean] Capture screenshot after storing text. Default: false.
|
|
166
|
+
* - screenshotText: [string] Description for the screenshot.
|
|
167
|
+
*/
|
|
168
|
+
export async function storeElementTextInVariable(
|
|
169
|
+
page: Page,
|
|
170
|
+
field: string | Locator,
|
|
171
|
+
variableName: string,
|
|
172
|
+
options?: string | Record<string, any>
|
|
173
|
+
) {
|
|
174
|
+
const options_json =
|
|
175
|
+
typeof options === "string" ? vars.parseLooseJson(options) : options || {};
|
|
176
|
+
// Default fieldType to "input" if not provided or falsy
|
|
177
|
+
const {
|
|
178
|
+
actionTimeout = config?.testExecution?.actionTimeout || Number(
|
|
179
|
+
vars.getConfigValue("testExecution.actionTimeout")
|
|
180
|
+
) || 30000,
|
|
181
|
+
pattern,
|
|
182
|
+
fieldType = "input",
|
|
183
|
+
attribute = "",
|
|
184
|
+
trim = true,
|
|
185
|
+
normalizeWhitespace = true,
|
|
186
|
+
screenshot = false,
|
|
187
|
+
screenshotText = "",
|
|
188
|
+
screenshotFullPage = true,
|
|
189
|
+
} = options_json;
|
|
190
|
+
|
|
191
|
+
if (isPlaywrightRunner()) {
|
|
192
|
+
await __allureAny_web.step(
|
|
193
|
+
`Web: Store element text in Variable -field: ${field} into variable: ${variableName} -options: ${JSON.stringify(
|
|
194
|
+
options_json
|
|
195
|
+
)}`,
|
|
196
|
+
async () => {
|
|
197
|
+
await doStoreElementTextInVariable();
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
} else {
|
|
201
|
+
await doStoreElementTextInVariable();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function doStoreElementTextInVariable() {
|
|
205
|
+
if (!page) throw new Error("Page not initialized");
|
|
206
|
+
|
|
207
|
+
const target =
|
|
208
|
+
typeof field === "string"
|
|
209
|
+
? await webLocResolver(fieldType, field, page, pattern, actionTimeout)
|
|
210
|
+
: field;
|
|
211
|
+
|
|
212
|
+
await target.waitFor({ state: "visible", timeout: actionTimeout });
|
|
213
|
+
|
|
214
|
+
const tag = await target.evaluate((el) => el.tagName.toLowerCase());
|
|
215
|
+
let raw: string | null;
|
|
216
|
+
|
|
217
|
+
if (attribute) {
|
|
218
|
+
raw = await target.getAttribute(attribute);
|
|
219
|
+
} else if (tag === "input" || tag === "textarea" || tag === "select") {
|
|
220
|
+
raw = await target.inputValue();
|
|
221
|
+
} else {
|
|
222
|
+
raw = await target.innerText();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let value = (raw ?? "").toString();
|
|
226
|
+
if (trim) value = value.trim();
|
|
227
|
+
if (normalizeWhitespace) value = value.replace(/\s+/g, " ");
|
|
228
|
+
|
|
229
|
+
if (typeof (vars as any).setValue === "function") {
|
|
230
|
+
vars.setValue(variableName, value);
|
|
231
|
+
} else if (typeof (vars as any).set === "function") {
|
|
232
|
+
(vars as any).set(variableName, value);
|
|
233
|
+
} else {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`No supported setter found on vars to store "${variableName}"`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
await attachLog(
|
|
240
|
+
`✅ Stored element text into "${variableName}": "${value}"`,
|
|
241
|
+
"text/plain"
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
await processScreenshot(
|
|
245
|
+
page,
|
|
246
|
+
screenshot,
|
|
247
|
+
screenshotText || `Stored text for: ${variableName}`,
|
|
248
|
+
screenshotFullPage
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Web: Get All Texts -selector/field: {param} -options: {param}
|
|
255
|
+
*
|
|
256
|
+
* Returns an array of inner texts of all elements matching the selector or field.
|
|
257
|
+
*
|
|
258
|
+
* @param page - Playwright Page instance
|
|
259
|
+
* @param field - CSS selector, label, or Locator
|
|
260
|
+
* @param options - Optional JSON string or object:
|
|
261
|
+
* - pattern: [string] Pattern for pattern engine
|
|
262
|
+
* - fieldType: [string] Pattern engine field type (default: 'field')
|
|
263
|
+
* - itemSelector: [string] Sub-selector to locate text inside each element
|
|
264
|
+
* - attribute: [string] Attribute to extract instead of innerText (e.g., 'textContent', 'value')
|
|
265
|
+
* - actionTimeout: [number] Timeout in ms
|
|
266
|
+
* @returns Array of strings representing the text of each element
|
|
267
|
+
*/
|
|
268
|
+
export async function getAllTexts(
|
|
269
|
+
page: Page,
|
|
270
|
+
field: string | Locator,
|
|
271
|
+
options?: string | Record<string, any>
|
|
272
|
+
): Promise<string[]> {
|
|
273
|
+
const options_json = typeof options === "string" ? vars.parseLooseJson(options) : options || {};
|
|
274
|
+
const {
|
|
275
|
+
pattern = '',
|
|
276
|
+
fieldType = 'field',
|
|
277
|
+
itemSelector = '',
|
|
278
|
+
attribute = 'innerText',
|
|
279
|
+
actionTimeout = config?.testExecution?.actionTimeout || Number(vars.getConfigValue("testExecution.actionTimeout")) || 30000
|
|
280
|
+
} = options_json;
|
|
281
|
+
|
|
282
|
+
const stepName = `Web: Get All Texts -field: ${typeof field === 'string' ? field : '<locator>'} -options: ${JSON.stringify(options_json)}`;
|
|
283
|
+
|
|
284
|
+
const run = async () => {
|
|
285
|
+
if (!page) throw new Error("Page not initialized");
|
|
286
|
+
|
|
287
|
+
// Resolve locator
|
|
288
|
+
const locator = typeof field === 'string'
|
|
289
|
+
? await webLocResolver(fieldType, field, page, pattern, actionTimeout)
|
|
290
|
+
: field;
|
|
291
|
+
|
|
292
|
+
const count = await locator.count();
|
|
293
|
+
if (count === 0) {
|
|
294
|
+
await attachLog(`❌ No elements found for field/selector "${field}"`, "text/plain");
|
|
295
|
+
return [];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const texts: string[] = [];
|
|
299
|
+
for (let i = 0; i < count; i++) {
|
|
300
|
+
let el = locator.nth(i);
|
|
301
|
+
if (itemSelector) el = el.locator(itemSelector);
|
|
302
|
+
|
|
303
|
+
let value: string;
|
|
304
|
+
if (attribute === 'innerText') {
|
|
305
|
+
value = (await el.innerText()).trim();
|
|
306
|
+
} else if (attribute === 'textContent') {
|
|
307
|
+
value = (await el.textContent() || '').trim();
|
|
308
|
+
} else {
|
|
309
|
+
value = (await el.getAttribute(attribute) || '').trim();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
texts.push(value.replace(/\s+/g, ' '));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
await attachLog(`✅ Retrieved texts for "${field}": ${texts.join(', ')}`, "text/plain");
|
|
316
|
+
return texts;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
if (isPlaywrightRunner()) {
|
|
320
|
+
return __allureAny_reader.step(stepName, run);
|
|
321
|
+
}
|
|
322
|
+
return run();
|
|
323
|
+
}
|