@anddone/coretestautomation 1.0.1
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/.github/workflows/npm-release.yml +102 -0
- package/dist/api/base.api.d.ts +32 -0
- package/dist/api/base.api.d.ts.map +1 -0
- package/dist/api/base.api.js +7 -0
- package/dist/api/base.api.js.map +1 -0
- package/dist/api/headers.d.ts +6 -0
- package/dist/api/headers.d.ts.map +1 -0
- package/dist/api/headers.js +23 -0
- package/dist/api/headers.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/basepage.d.ts +6 -0
- package/dist/pages/basepage.d.ts.map +1 -0
- package/dist/pages/basepage.js +10 -0
- package/dist/pages/basepage.js.map +1 -0
- package/dist/testData/api.data.json +6 -0
- package/dist/utils/apiUtils.d.ts +123 -0
- package/dist/utils/apiUtils.d.ts.map +1 -0
- package/dist/utils/apiUtils.js +264 -0
- package/dist/utils/apiUtils.js.map +1 -0
- package/dist/utils/assertionUtils.d.ts +223 -0
- package/dist/utils/assertionUtils.d.ts.map +1 -0
- package/dist/utils/assertionUtils.js +400 -0
- package/dist/utils/assertionUtils.js.map +1 -0
- package/dist/utils/commonUtils.d.ts +590 -0
- package/dist/utils/commonUtils.d.ts.map +1 -0
- package/dist/utils/commonUtils.js +1292 -0
- package/dist/utils/commonUtils.js.map +1 -0
- package/dist/utils/fakerStaticData.d.ts +16 -0
- package/dist/utils/fakerStaticData.d.ts.map +1 -0
- package/dist/utils/fakerStaticData.js +88 -0
- package/dist/utils/fakerStaticData.js.map +1 -0
- package/dist/utils/fileCommonUtils.d.ts +22 -0
- package/dist/utils/fileCommonUtils.d.ts.map +1 -0
- package/dist/utils/fileCommonUtils.js +243 -0
- package/dist/utils/fileCommonUtils.js.map +1 -0
- package/dist/utils/generationUtils.d.ts +424 -0
- package/dist/utils/generationUtils.d.ts.map +1 -0
- package/dist/utils/generationUtils.js +869 -0
- package/dist/utils/generationUtils.js.map +1 -0
- package/dist/utils/pageUtils.d.ts +90 -0
- package/dist/utils/pageUtils.d.ts.map +1 -0
- package/dist/utils/pageUtils.js +214 -0
- package/dist/utils/pageUtils.js.map +1 -0
- package/dist/utils/tableUtils.d.ts +304 -0
- package/dist/utils/tableUtils.d.ts.map +1 -0
- package/dist/utils/tableUtils.js +555 -0
- package/dist/utils/tableUtils.js.map +1 -0
- package/dist/utils/validationUtils.d.ts +80 -0
- package/dist/utils/validationUtils.d.ts.map +1 -0
- package/dist/utils/validationUtils.js +172 -0
- package/dist/utils/validationUtils.js.map +1 -0
- package/package.json +23 -0
- package/playwright.config.ts +79 -0
- package/src/api/base.api.ts +39 -0
- package/src/api/headers.ts +17 -0
- package/src/index.ts +12 -0
- package/src/pages/basepage.ts +11 -0
- package/src/testData/api.data.json +6 -0
- package/src/types/pdf-parse.d.ts +6 -0
- package/src/utils/apiUtils.ts +307 -0
- package/src/utils/assertionUtils.ts +455 -0
- package/src/utils/commonUtils.ts +1544 -0
- package/src/utils/fakerStaticData.ts +91 -0
- package/src/utils/fileCommonUtils.ts +239 -0
- package/src/utils/generationUtils.ts +929 -0
- package/src/utils/pageUtils.ts +224 -0
- package/src/utils/tableUtils.ts +715 -0
- package/src/utils/validationUtils.ts +179 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { Page, BrowserContext } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
export class PageUtils {
|
|
4
|
+
/**
|
|
5
|
+
* Navigates to specified URL and waits for DOM to load
|
|
6
|
+
* @param page Playwright Page object
|
|
7
|
+
* @param url URL where page should navigate to
|
|
8
|
+
* @param timeout Maximum wait time in milliseconds (default: 15000)
|
|
9
|
+
*/
|
|
10
|
+
static async navigateTo(page: Page, url: string, timeout: number = 15000): Promise<void> {
|
|
11
|
+
try {
|
|
12
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.warn(`Navigation skipped: ${(error as Error).message}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* closes the browser window represented by the given page object
|
|
20
|
+
* @param page Playwright page object
|
|
21
|
+
* @returns true if window is closed successfully
|
|
22
|
+
*/
|
|
23
|
+
static async closeWindow(page: Page): Promise<boolean> {
|
|
24
|
+
try {
|
|
25
|
+
await page.close();
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.warn(`Window close skipped: ${(error as Error).message}`);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* closes the window whose index has been passed
|
|
36
|
+
* @param context Playwright BrowserContext containing all open pages
|
|
37
|
+
* @param index of the window which is to be closed
|
|
38
|
+
* @returns true if window is closed
|
|
39
|
+
* calling e.g. - await closeWindowByIndex(context, 1)
|
|
40
|
+
*/
|
|
41
|
+
static async closeWindowByIndex(context: BrowserContext, index: number): Promise<boolean> {
|
|
42
|
+
try {
|
|
43
|
+
const pages = context.pages();
|
|
44
|
+
|
|
45
|
+
if (index < 0 || index >= pages.length) {
|
|
46
|
+
console.warn(`Invalid window index: ${index}`);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
await pages[index].close();
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.warn(`Window close skipped: ${(error as Error).message}`);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Closes all browser windows by closing the entire browser context
|
|
61
|
+
* @param context Playwright BrowserContext containing all open pages
|
|
62
|
+
*/
|
|
63
|
+
static async closeAllWindows(context: BrowserContext): Promise<void> {
|
|
64
|
+
try {
|
|
65
|
+
return await context.close();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.warn(`Failed to close all windows: ${(error as Error).message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* switch to particular window whose index has been passed
|
|
74
|
+
* @param context Playwright BrowserContext containing all open pages
|
|
75
|
+
* @param index of the window where we should switch
|
|
76
|
+
* @returns matching Page object if found, otherwise null
|
|
77
|
+
*/
|
|
78
|
+
static async switchToWindowByIndex(context: BrowserContext, index: number): Promise<Page | null> {
|
|
79
|
+
try {
|
|
80
|
+
const pages = context.pages();
|
|
81
|
+
|
|
82
|
+
if (index < 0 || index >= pages.length) {
|
|
83
|
+
console.warn(`Invalid window index: ${index}`);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return pages[index];
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.warn(`Window switch by index failed: ${(error as Error).message}`);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Switches to particular window whose URL has been passed
|
|
97
|
+
* @param context Playwright BrowserContext containing all opened windows
|
|
98
|
+
* @param url of the window where we should switch
|
|
99
|
+
* @returns matching page object if found, otherwise null
|
|
100
|
+
*/
|
|
101
|
+
static async switchToWindowByUrl(context: BrowserContext, url: string): Promise<Page | null> {
|
|
102
|
+
try {
|
|
103
|
+
const pages = context.pages();
|
|
104
|
+
const targetPage = pages.find(page => page.url().includes(url));
|
|
105
|
+
|
|
106
|
+
if (!targetPage) {
|
|
107
|
+
console.warn(`No window found with URL containing: ${url}`);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
return targetPage;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.warn(`Window switch by URL failed: ${(error as Error).message}`);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Method to return total number of opened browser windows
|
|
120
|
+
* @param context Playwright BrowserContext containing all open pages
|
|
121
|
+
* @returns total number of opened windows
|
|
122
|
+
*/
|
|
123
|
+
static getTotalOpenedWindows(context: BrowserContext): number {
|
|
124
|
+
try {
|
|
125
|
+
return context.pages().length;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.warn(`Failed to get total opened windows: ${(error as Error).message}`);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Method to return current window URL
|
|
135
|
+
* @param page Playwright Page object
|
|
136
|
+
* @returns URL of currently active playwright page
|
|
137
|
+
*/
|
|
138
|
+
static async getCurrentWindowURL(page: Page): Promise<string | null> {
|
|
139
|
+
try {
|
|
140
|
+
const currentUrl = page.url();
|
|
141
|
+
return currentUrl;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.warn(`Unable to get current window: ${(error as Error).message}`);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Fetches and returns title of the browser window represented by the given page
|
|
151
|
+
* @param page Playwright page object
|
|
152
|
+
* @returns title of the window
|
|
153
|
+
*/
|
|
154
|
+
static async getWindowTitle(page: Page): Promise<string | null> {
|
|
155
|
+
try {
|
|
156
|
+
return await page.title();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.warn(`Unable to get Window title: ${(error as Error).message}`);
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Gets the current page URL.
|
|
166
|
+
*
|
|
167
|
+
* @param page - Playwright Page instance
|
|
168
|
+
* @returns Current page URL or empty string if unavailable
|
|
169
|
+
*/
|
|
170
|
+
static async getCurrentUrl(page: Page): Promise<string> {
|
|
171
|
+
try {
|
|
172
|
+
return page.url();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.warn(`⚠ Unable to get current URL:`, (error as Error).message);
|
|
175
|
+
return '';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Checks whether the current page URL contains the expected value.
|
|
181
|
+
*
|
|
182
|
+
* @param page - Playwright Page instance
|
|
183
|
+
* @param expected - Expected value to be contained in the URL
|
|
184
|
+
* @returns True if URL contains expected value, otherwise false
|
|
185
|
+
*/
|
|
186
|
+
static async isUrlContains(page: Page, expected: string,): Promise<boolean> {
|
|
187
|
+
try {
|
|
188
|
+
const url = page.url();
|
|
189
|
+
return url.includes(expected);
|
|
190
|
+
} catch {
|
|
191
|
+
console.warn(`⚠ URL does not contain "${expected}"}`);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Checks whether the current page URL exactly matches the expected value.
|
|
198
|
+
*
|
|
199
|
+
* @param page - Playwright Page instance
|
|
200
|
+
* @param expected - Expected URL
|
|
201
|
+
*
|
|
202
|
+
* @returns True if URL matches exactly, otherwise false
|
|
203
|
+
*/
|
|
204
|
+
static async isUrlMatch(page: Page, expected: string): Promise<boolean> {
|
|
205
|
+
try {
|
|
206
|
+
return page.url() === expected;
|
|
207
|
+
} catch {
|
|
208
|
+
console.warn(`⚠ URL does not match "${expected}"`);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Waits until the current URL contains the expected value.
|
|
215
|
+
*/
|
|
216
|
+
static async waitUntilUrlContains(page: Page, expected: string, timeout = 15000
|
|
217
|
+
): Promise<void> {
|
|
218
|
+
try {
|
|
219
|
+
await page.waitForURL(url => url.toString().includes(expected), { timeout });
|
|
220
|
+
} catch {
|
|
221
|
+
console.error(`❌ URL did not contain "${expected}" after ${timeout}ms`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|