@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,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file webNavigation.ts
|
|
3
|
+
*
|
|
4
|
+
* Navigation helpers for PlayQ web actions.
|
|
5
|
+
* Provides open/refresh/switch/close tab and path navigation utilities
|
|
6
|
+
* with runner-aware Allure step wrappers and screenshot options.
|
|
7
|
+
*
|
|
8
|
+
* Authors: PlayQ Team
|
|
9
|
+
* Version: v1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import * as allure from "allure-js-commons";
|
|
12
|
+
import { Page } from "@playwright/test";
|
|
13
|
+
import { vars } from "../../../global";
|
|
14
|
+
import { processScreenshot } from "./screenshotActions";
|
|
15
|
+
import { parseLooseJson } from '../../bundle/vars';
|
|
16
|
+
import { attachLog } from '../commActions';
|
|
17
|
+
|
|
18
|
+
function isPlaywrightRunner() { return process.env.TEST_RUNNER === 'playwright'; }
|
|
19
|
+
|
|
20
|
+
const __allureAny_nav: any = allure as any;
|
|
21
|
+
if (typeof __allureAny_nav.step !== 'function') {
|
|
22
|
+
__allureAny_nav.step = async (_name: string, fn: any) => await fn();
|
|
23
|
+
}
|
|
24
|
+
// Allure compatibility shim: if step is unavailable, just run the body
|
|
25
|
+
const __allureAny_web: any = allure as any;
|
|
26
|
+
if (typeof __allureAny_web.step !== 'function') {
|
|
27
|
+
__allureAny_web.step = async (_name: string, fn: any) => await fn();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* [ACTION] Open a browser page (Playwright/Cucumber hybrid support).
|
|
32
|
+
*
|
|
33
|
+
* Opens the given URL in a new browser page or reuses the existing page based on the runner context.
|
|
34
|
+
* Supports automatic screenshot and log attachments.
|
|
35
|
+
*
|
|
36
|
+
* @param pageOverride - Optional Playwright Page object (used in Playwright tests). Not required in Cucumber.
|
|
37
|
+
* @param url - The URL to open (e.g., "https://example.com").
|
|
38
|
+
* @param options - JSON string or object for additional behaviors:
|
|
39
|
+
* - screenshot [boolean]: Capture screenshot after navigation. Default: false.
|
|
40
|
+
* - screenshotText [string]: Description for screenshot attachment. Default: "".
|
|
41
|
+
* - screenshotFullPage [boolean]: Full page screenshot or viewport only. Default: true.
|
|
42
|
+
*
|
|
43
|
+
* @returns void
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Playwright Test
|
|
47
|
+
* test('Open Google', async ({ page }) => {
|
|
48
|
+
* await openBrowser('https://google.com', '{screenshot: true, screenshotText: "Homepage"}', page);
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Cucumber Step
|
|
53
|
+
* Given("Web: Open Browser -url: {param} -options: {param}", openBrowser);
|
|
54
|
+
*
|
|
55
|
+
* @throws Error if page is not initialized or navigation fails.
|
|
56
|
+
*/
|
|
57
|
+
export async function openBrowser(
|
|
58
|
+
page: Page,
|
|
59
|
+
url: string,
|
|
60
|
+
options?: string | Record<string, any>
|
|
61
|
+
) {
|
|
62
|
+
let resolvedUrl = vars.replaceVariables(url);
|
|
63
|
+
const options_json =
|
|
64
|
+
typeof options === "string" ? parseLooseJson(options) : options || {};
|
|
65
|
+
const {
|
|
66
|
+
screenshot = false,
|
|
67
|
+
screenshotText = "",
|
|
68
|
+
screenshotFullPage = true,
|
|
69
|
+
} = options_json ?? {};
|
|
70
|
+
|
|
71
|
+
if (isPlaywrightRunner()) {
|
|
72
|
+
await __allureAny_web.step(
|
|
73
|
+
`Web: Open browser -url: ${resolvedUrl} -options: ${JSON.stringify(
|
|
74
|
+
options_json
|
|
75
|
+
)}`,
|
|
76
|
+
async () => {
|
|
77
|
+
await doOpenBrowser();
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
await doOpenBrowser();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function doOpenBrowser() {
|
|
85
|
+
if (!page) throw new Error("Page not initialised");
|
|
86
|
+
await page.goto(resolvedUrl, { waitUntil: "domcontentloaded" });
|
|
87
|
+
await processScreenshot(
|
|
88
|
+
page,
|
|
89
|
+
screenshot,
|
|
90
|
+
screenshotText,
|
|
91
|
+
screenshotFullPage
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Web: Refresh Page -options: {param}
|
|
98
|
+
*
|
|
99
|
+
* Reloads the current page.
|
|
100
|
+
*
|
|
101
|
+
* @param page Playwright Page instance
|
|
102
|
+
* @param options Optional JSON string or object (reserved for consistency)
|
|
103
|
+
*/
|
|
104
|
+
export async function refreshPage(page: Page, options?: string | Record<string, any>) {
|
|
105
|
+
const options_json = typeof options === "string" ? vars.parseLooseJson(options) : options || {};
|
|
106
|
+
const stepName = `Web: Refresh Page -options: ${JSON.stringify(options_json)}`;
|
|
107
|
+
if (isPlaywrightRunner()) {
|
|
108
|
+
await __allureAny_nav.step(stepName, async () => { await page.reload(); });
|
|
109
|
+
} else {
|
|
110
|
+
await page.reload();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Web: Switch Tab -index: {param} -options: {param}
|
|
116
|
+
*
|
|
117
|
+
* Brings the specified tab to the front by index.
|
|
118
|
+
*
|
|
119
|
+
* @param page Playwright Page instance
|
|
120
|
+
* @param index Zero-based tab index (default: 0)
|
|
121
|
+
* @param options Optional JSON string or object (reserved for consistency)
|
|
122
|
+
*/
|
|
123
|
+
export async function switchTab(page: Page, index: number = 0, options?: string | Record<string, any>) {
|
|
124
|
+
|
|
125
|
+
const options_json = typeof options === "string" ? vars.parseLooseJson(options) : options || {};
|
|
126
|
+
const ctx = page.context();
|
|
127
|
+
const stepName = `Web: Switch Tab -index: ${index} -options: ${JSON.stringify(options_json)}`;
|
|
128
|
+
if (isPlaywrightRunner()) {
|
|
129
|
+
await __allureAny_nav.step(stepName, async () => {
|
|
130
|
+
const target = ctx.pages()[index];
|
|
131
|
+
if (!target) throw new Error(`No tab at index ${index}`);
|
|
132
|
+
await target.bringToFront();
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
const target = ctx.pages()[index];
|
|
136
|
+
if (!target) throw new Error(`No tab at index ${index}`);
|
|
137
|
+
await target.bringToFront();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Web: Close Tab -options: {param}
|
|
143
|
+
*
|
|
144
|
+
* Closes the current tab.
|
|
145
|
+
*
|
|
146
|
+
* @param page Playwright Page instance
|
|
147
|
+
* @param options Optional JSON string or object (reserved for consistency)
|
|
148
|
+
*/
|
|
149
|
+
export async function closeTab(page: Page, options?: string | Record<string, any>) {
|
|
150
|
+
|
|
151
|
+
const options_json = typeof options === "string" ? vars.parseLooseJson(options) : options || {};
|
|
152
|
+
const stepName = `Web: Close Tab -options: ${JSON.stringify(options_json)}`;
|
|
153
|
+
if (isPlaywrightRunner()) {
|
|
154
|
+
await __allureAny_nav.step(stepName, async () => { await page.close(); });
|
|
155
|
+
} else {
|
|
156
|
+
await page.close();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Web: Open New Tab -url: {param} -options: {param}
|
|
162
|
+
*
|
|
163
|
+
* Opens a new tab within the current browser context and optionally navigates to a URL.
|
|
164
|
+
* Returns the created Page instance so tests can interact with it without direct Playwright APIs.
|
|
165
|
+
*
|
|
166
|
+
* @param page Playwright Page instance (used to derive the context)
|
|
167
|
+
* @param url Optional URL to navigate the new tab to
|
|
168
|
+
* @param options Optional JSON string or object:
|
|
169
|
+
* - screenshot: [boolean] Capture a screenshot after opening/navigating. Default: false.
|
|
170
|
+
* - screenshotText: [string] Description for the screenshot attachment. Default: "".
|
|
171
|
+
* - screenshotFullPage: [boolean] Capture full page screenshot. Default: true.
|
|
172
|
+
*
|
|
173
|
+
* @returns The newly opened Playwright Page
|
|
174
|
+
*/
|
|
175
|
+
export async function openNewTab(
|
|
176
|
+
page: Page,
|
|
177
|
+
url?: string,
|
|
178
|
+
options?: string | Record<string, any>
|
|
179
|
+
) {
|
|
180
|
+
const options_json = typeof options === "string" ? vars.parseLooseJson(options) : options || {};
|
|
181
|
+
const { screenshot = false, screenshotText = "", screenshotFullPage = true } = options_json ?? {};
|
|
182
|
+
const stepName = `Web: Open New Tab -url: ${url ?? ''} -options: ${JSON.stringify(options_json)}`;
|
|
183
|
+
|
|
184
|
+
async function run() {
|
|
185
|
+
if (!page) throw new Error("Page not initialised");
|
|
186
|
+
const ctx = page.context();
|
|
187
|
+
const newPage = await ctx.newPage();
|
|
188
|
+
if (url && typeof url === 'string' && url.length > 0) {
|
|
189
|
+
const targetUrl = vars.replaceVariables(url);
|
|
190
|
+
await newPage.goto(targetUrl, { waitUntil: 'domcontentloaded' });
|
|
191
|
+
await newPage.waitForLoadState('networkidle');
|
|
192
|
+
}
|
|
193
|
+
await processScreenshot(newPage, screenshot, screenshotText, screenshotFullPage);
|
|
194
|
+
return newPage;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (isPlaywrightRunner()) {
|
|
198
|
+
return await __allureAny_nav.step(stepName, run);
|
|
199
|
+
} else {
|
|
200
|
+
return await run();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Web: Navigate by Path -relativePath: {param} -options: {param}
|
|
206
|
+
*
|
|
207
|
+
* Appends a relative path to the current page's URL and navigates to it.
|
|
208
|
+
*
|
|
209
|
+
* @param relativePath - The path to append (e.g., "/settings", "profile/edit")
|
|
210
|
+
* @param options - (optional) JSON string or object:
|
|
211
|
+
* - screenshot: [boolean] Capture a screenshot after navigation. Default: false.
|
|
212
|
+
* - screenshotText: [string] Text description for the screenshot. Default: "".
|
|
213
|
+
* - screenshotFullPage: [boolean] Capture full page screenshot. Default: true.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* Web: Navigate by Path -relativePath: "/profile/edit" -options: "{screenshot: true, screenshotText: 'Profile Page'}"
|
|
217
|
+
*/
|
|
218
|
+
export async function navigateByPath(
|
|
219
|
+
page: Page,
|
|
220
|
+
relativePath: string,
|
|
221
|
+
options?: string | Record<string, any>
|
|
222
|
+
) {
|
|
223
|
+
let resolvedRelativePath = vars.getValue(relativePath);
|
|
224
|
+
const options_json =
|
|
225
|
+
typeof options === "string" ? parseLooseJson(options) : options || {};
|
|
226
|
+
const {
|
|
227
|
+
screenshot = false,
|
|
228
|
+
screenshotText = "",
|
|
229
|
+
screenshotFullPage = true,
|
|
230
|
+
} = options_json ?? {};
|
|
231
|
+
if (isPlaywrightRunner()) {
|
|
232
|
+
await __allureAny_web.step(
|
|
233
|
+
`Web: Navigate by Path -relativePath: ${relativePath} -options: ${JSON.stringify(
|
|
234
|
+
options_json
|
|
235
|
+
)}`,
|
|
236
|
+
async () => {
|
|
237
|
+
await doNavigateByPath();
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
} else {
|
|
241
|
+
await doNavigateByPath();
|
|
242
|
+
}
|
|
243
|
+
async function doNavigateByPath() {
|
|
244
|
+
if (!page) throw new Error("Page not initialised");
|
|
245
|
+
const currentUrl = page.url();
|
|
246
|
+
const targetUrl = new URL(resolvedRelativePath, currentUrl).toString();
|
|
247
|
+
|
|
248
|
+
console.log(`🌐 Navigating to: ${targetUrl}`);
|
|
249
|
+
|
|
250
|
+
await page.goto(targetUrl, { waitUntil: "domcontentloaded" });
|
|
251
|
+
await page.waitForLoadState("networkidle");
|
|
252
|
+
await page.waitForLoadState("load");
|
|
253
|
+
await processScreenshot(
|
|
254
|
+
page,
|
|
255
|
+
screenshot,
|
|
256
|
+
screenshotText,
|
|
257
|
+
screenshotFullPage
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Web: Reload Page -options: {param}
|
|
264
|
+
*
|
|
265
|
+
* Reloads the current page and optionally takes a screenshot.
|
|
266
|
+
*
|
|
267
|
+
* @param page - Playwright Page instance
|
|
268
|
+
* @param options - Optional string or object:
|
|
269
|
+
* - actionTimeout: [number] Timeout in ms (default: 30000)
|
|
270
|
+
* - screenshot: [boolean] Capture screenshot after reload (default: false)
|
|
271
|
+
* - screenshotText: [string] Description for screenshot
|
|
272
|
+
* - screenshotFullPage: [boolean] Full page screenshot (default: true)
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* await reloadPage(page, { screenshot: true, screenshotText: "After reload" });
|
|
276
|
+
*/
|
|
277
|
+
export async function reloadPage(
|
|
278
|
+
page: Page,
|
|
279
|
+
options?: string | Record<string, any>
|
|
280
|
+
) {
|
|
281
|
+
const options_json =
|
|
282
|
+
typeof options === "string" ? parseLooseJson(options) : options || {};
|
|
283
|
+
const {
|
|
284
|
+
actionTimeout = Number(vars.getConfigValue("testExecution.actionTimeout")) || 30000,
|
|
285
|
+
screenshot = false,
|
|
286
|
+
screenshotText = "",
|
|
287
|
+
screenshotFullPage = true,
|
|
288
|
+
} = options_json;
|
|
289
|
+
|
|
290
|
+
if (!page) throw new Error("Page not initialized");
|
|
291
|
+
|
|
292
|
+
if (isPlaywrightRunner()) {
|
|
293
|
+
await __allureAny_web.step(
|
|
294
|
+
`Web: Reload Page -options: ${JSON.stringify(options_json)}`,
|
|
295
|
+
async () => {
|
|
296
|
+
await doReloadPage();
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
} else {
|
|
300
|
+
await doReloadPage();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function doReloadPage() {
|
|
304
|
+
await page.reload({ timeout: actionTimeout, waitUntil: "domcontentloaded" });
|
|
305
|
+
await attachLog("✅ Page reloaded.", "text/plain");
|
|
306
|
+
await processScreenshot(
|
|
307
|
+
page,
|
|
308
|
+
screenshot,
|
|
309
|
+
screenshotText || "Page reloaded",
|
|
310
|
+
screenshotFullPage
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file webActions.ts
|
|
3
|
+
*
|
|
4
|
+
* Unified web actions bridging Playwright and Cucumber.
|
|
5
|
+
* Provides navigation, interaction, validation, and reporting helpers.
|
|
6
|
+
*
|
|
7
|
+
* Key Features:
|
|
8
|
+
* - Hybrid context: Playwright Runner (page) and Cucumber World (webFixture)
|
|
9
|
+
* - Rich options for screenshots, timeouts, locators, and assertions
|
|
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
|
+
|
|
18
|
+
export * from "./web/alertActions";
|
|
19
|
+
export * from "./web/cookieActions";
|
|
20
|
+
export * from "./web/downloadActions";
|
|
21
|
+
export * from "./web/elementReaderActions";
|
|
22
|
+
export * from "./web/formActions";
|
|
23
|
+
export * from "./web/iframeActions";
|
|
24
|
+
export * from "./web/javascriptActions";
|
|
25
|
+
export * from "./web/keyboardActions";
|
|
26
|
+
export * from "./web/localStorageActions";
|
|
27
|
+
export * from "./web/mouseActions";
|
|
28
|
+
export * from "./web/reportingActions";
|
|
29
|
+
export * from "./web/screenshotActions";
|
|
30
|
+
export * from "./web/testDataActions";
|
|
31
|
+
export * from "./web/validationActions";
|
|
32
|
+
export * from "./web/waitActions";
|
|
33
|
+
export * from "./web/webNavigation";
|