@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,91 @@
|
|
|
1
|
+
export const FIRST_NAMES = [
|
|
2
|
+
"Amit", "Rahul", "Rohit", "Suresh", "Ankit",
|
|
3
|
+
"Neha", "Priya", "Kiran", "Sneha", "Pooja",
|
|
4
|
+
"John", "Michael", "David", "Chris", "Daniel",
|
|
5
|
+
"Emma", "Sophia", "Olivia", "Emily", "Isabella"
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
export const LAST_NAMES = [
|
|
9
|
+
"Sharma", "Verma", "Patel", "Singh", "Mehta",
|
|
10
|
+
"Gupta", "Iyer", "Reddy", "Kapoor",
|
|
11
|
+
"Smith", "Johnson", "Brown", "Taylor", "Anderson"
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export const EMAIL_DOMAINS = [
|
|
15
|
+
"gmail.com",
|
|
16
|
+
"yahoo.com",
|
|
17
|
+
"outlook.com",
|
|
18
|
+
"hotmail.com",
|
|
19
|
+
"example.com"
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export const COUNTRY_CODES = [
|
|
23
|
+
"+1", // USA
|
|
24
|
+
"+44", // UK
|
|
25
|
+
"+91", // India
|
|
26
|
+
"+61", // Australia
|
|
27
|
+
"+81", // Japan
|
|
28
|
+
"+49" // Germany
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export const INDIA_LOCATIONS = [
|
|
32
|
+
{
|
|
33
|
+
state: "Maharashtra",
|
|
34
|
+
cities: ["Mumbai", "Pune", "Nagpur"],
|
|
35
|
+
pincodePrefix: "4"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
state: "Karnataka",
|
|
39
|
+
cities: ["Bengaluru", "Mysuru", "Mangalore"],
|
|
40
|
+
pincodePrefix: "5"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
state: "Tamil Nadu",
|
|
44
|
+
cities: ["Chennai", "Coimbatore", "Madurai"],
|
|
45
|
+
pincodePrefix: "6"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
state: "Delhi",
|
|
49
|
+
cities: ["New Delhi", "Dwarka", "Rohini"],
|
|
50
|
+
pincodePrefix: "1"
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export const USA_LOCATIONS = [
|
|
55
|
+
{
|
|
56
|
+
state: "California",
|
|
57
|
+
cities: ["Los Angeles", "San Francisco", "San Diego"]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
state: "New York",
|
|
61
|
+
cities: ["New York City", "Buffalo", "Albany"]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
state: "Texas",
|
|
65
|
+
cities: ["Houston", "Dallas", "Austin"]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
state: "Illinois",
|
|
69
|
+
cities: ["Chicago", "Springfield"]
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
export const STREET_NAMES = [
|
|
74
|
+
"MG Road",
|
|
75
|
+
"Park Street",
|
|
76
|
+
"Main Street",
|
|
77
|
+
"Church Road",
|
|
78
|
+
"Link Road",
|
|
79
|
+
"High Street",
|
|
80
|
+
"Market Road"
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
export const LOREM_WORDS = [
|
|
84
|
+
"lorem", "ipsum", "dolor", "sit", "amet",
|
|
85
|
+
"consectetur", "adipiscing", "elit", "sed", "do",
|
|
86
|
+
"eiusmod", "tempor", "incididunt", "ut", "labore",
|
|
87
|
+
"et", "dolore", "magna", "aliqua", "enim",
|
|
88
|
+
"minim", "veniam", "quis", "nostrud", "exercitation",
|
|
89
|
+
"ullamco", "laboris", "nisi", "aliquip", "ex",
|
|
90
|
+
"ea", "commodo", "consequat"
|
|
91
|
+
];
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import * as XLSX from "xlsx";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { parseStringPromise } from "xml2js";
|
|
5
|
+
import pdfParseModule = require("pdf-parse");
|
|
6
|
+
import { exec } from "child_process";
|
|
7
|
+
import { promisify } from "util";
|
|
8
|
+
import pdfParse = require("pdf-parse");
|
|
9
|
+
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
|
|
12
|
+
export class FileCommonUtils {
|
|
13
|
+
// ================== PATH RESOLVER ==================
|
|
14
|
+
private static resolvePath(fileName: string): string {
|
|
15
|
+
return path.resolve(process.cwd(), "test-data", fileName);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ================== EXCEL ==================
|
|
19
|
+
static readExcel<T = Record<string, any>>(
|
|
20
|
+
fileName: string,
|
|
21
|
+
sheetName?: string,
|
|
22
|
+
): T[] {
|
|
23
|
+
try {
|
|
24
|
+
const filePath = this.resolvePath(fileName);
|
|
25
|
+
const workbook = XLSX.readFile(filePath);
|
|
26
|
+
const targetSheet = sheetName ?? workbook.SheetNames[0];
|
|
27
|
+
if (!targetSheet) return [];
|
|
28
|
+
const worksheet = workbook.Sheets[targetSheet];
|
|
29
|
+
if (!worksheet) return [];
|
|
30
|
+
// Cast to any because defval is not in TypeScript XLSX type
|
|
31
|
+
return XLSX.utils.sheet_to_json<T>(worksheet, { defval: "" } as any);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`Failed to read Excel: ${fileName}`, error);
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static writeExcel(
|
|
39
|
+
fileName: string,
|
|
40
|
+
data: Record<string, any>[],
|
|
41
|
+
sheetName = "Sheet1",
|
|
42
|
+
): void {
|
|
43
|
+
try {
|
|
44
|
+
const filePath = this.resolvePath(fileName);
|
|
45
|
+
const workbook = XLSX.utils.book_new();
|
|
46
|
+
const worksheet = XLSX.utils.json_to_sheet(data);
|
|
47
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
48
|
+
XLSX.writeFile(workbook, filePath);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(`Failed to write Excel: ${fileName}`, error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static getExcelSheetNames(fileName: string): string[] {
|
|
55
|
+
try {
|
|
56
|
+
const workbook = XLSX.readFile(this.resolvePath(fileName));
|
|
57
|
+
return workbook.SheetNames;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(`Failed to read sheet names: ${fileName}`, error);
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ================== CSV ==================
|
|
65
|
+
static readCSV<T = Record<string, string>>(
|
|
66
|
+
fileName: string,
|
|
67
|
+
delimiter = ",",
|
|
68
|
+
): T[] {
|
|
69
|
+
try {
|
|
70
|
+
const filePath = this.resolvePath(fileName);
|
|
71
|
+
const content = fs.readFileSync(filePath, "utf-8").trim();
|
|
72
|
+
if (!content) return [];
|
|
73
|
+
const [header, ...rows] = content.split("\n");
|
|
74
|
+
if (!header) return [];
|
|
75
|
+
const headers = header.split(delimiter).map((h) => h.trim());
|
|
76
|
+
return rows.map((row) => {
|
|
77
|
+
const values = row.split(delimiter);
|
|
78
|
+
const record: Record<string, string> = {};
|
|
79
|
+
headers.forEach((h, i) => (record[h] = values[i]?.trim() ?? ""));
|
|
80
|
+
return record as T;
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(`Failed to read CSV: ${fileName}`, error);
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static writeCSV(
|
|
89
|
+
fileName: string,
|
|
90
|
+
data: Record<string, any>[],
|
|
91
|
+
delimiter = ",",
|
|
92
|
+
): void {
|
|
93
|
+
try {
|
|
94
|
+
if (!data.length) return;
|
|
95
|
+
const filePath = this.resolvePath(fileName);
|
|
96
|
+
const headers = Object.keys(data[0]).join(delimiter);
|
|
97
|
+
const rows = data
|
|
98
|
+
.map((row) => Object.values(row).join(delimiter))
|
|
99
|
+
.join("\n");
|
|
100
|
+
fs.writeFileSync(filePath, `${headers}\n${rows}`, "utf-8");
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(`Failed to write CSV: ${fileName}`, error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ================== JSON / XML ==================
|
|
107
|
+
static readJson<T>(fileName: string): T | null {
|
|
108
|
+
try {
|
|
109
|
+
const filePath = this.resolvePath(fileName);
|
|
110
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8")) as T;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(`Failed to read JSON: ${fileName}`, error);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static async readXml<T>(fileName: string): Promise<T | null> {
|
|
118
|
+
try {
|
|
119
|
+
const xml = fs.readFileSync(this.resolvePath(fileName), "utf-8");
|
|
120
|
+
return await parseStringPromise(xml, { explicitArray: false });
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error(`Failed to read XML: ${fileName}`, error);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ================== DATA HELPERS ==================
|
|
128
|
+
static getRowCount<T>(data: T[]): number {
|
|
129
|
+
return data.length;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static getColumnHeaders<T extends Record<string, any>>(data: T[]): string[] {
|
|
133
|
+
return Object.keys(data[0] ?? {});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static getCellData<T extends Record<string, any>>(
|
|
137
|
+
data: T[],
|
|
138
|
+
row: number,
|
|
139
|
+
column: keyof T,
|
|
140
|
+
): any {
|
|
141
|
+
return data[row]?.[column];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static select<T extends Record<string, any>>(
|
|
145
|
+
data: T[],
|
|
146
|
+
column: keyof T,
|
|
147
|
+
value: any,
|
|
148
|
+
): T[] {
|
|
149
|
+
return data.filter((row) => row[column] === value);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ================== FILE UTILS ==================
|
|
153
|
+
static async readTextFile(filePath: string): Promise<string> {
|
|
154
|
+
try {
|
|
155
|
+
return await fs.promises.readFile(path.resolve(filePath), "utf-8");
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error(`Failed to read text file: ${filePath}`, error);
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static async readPdfFile(filePath: string): Promise<string> {
|
|
163
|
+
try {
|
|
164
|
+
const buffer = await fs.promises.readFile(path.resolve(filePath));
|
|
165
|
+
const parsed = await pdfParse(buffer);
|
|
166
|
+
return parsed.text;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error(`Failed to read PDF: ${filePath}`, error);
|
|
169
|
+
return "";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static async editTextFile(
|
|
174
|
+
filePath: string,
|
|
175
|
+
search: string | RegExp,
|
|
176
|
+
replace = "",
|
|
177
|
+
): Promise<void> {
|
|
178
|
+
try {
|
|
179
|
+
const content = await this.readTextFile(filePath);
|
|
180
|
+
const updated = content.replace(search, replace);
|
|
181
|
+
await fs.promises.writeFile(path.resolve(filePath), updated, "utf-8");
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(`Failed to edit file: ${filePath}`, error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ================== FOLDER UTILS ==================
|
|
188
|
+
static async getFileCount(folderPath: string): Promise<number> {
|
|
189
|
+
try {
|
|
190
|
+
const entries = await fs.promises.readdir(path.resolve(folderPath), {
|
|
191
|
+
withFileTypes: true,
|
|
192
|
+
});
|
|
193
|
+
return entries.filter((e) => e.isFile()).length;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error(`Failed to count files in folder: ${folderPath}`, error);
|
|
196
|
+
return 0;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static async getAllFileNames(folderPath: string): Promise<string[]> {
|
|
201
|
+
try {
|
|
202
|
+
const entries = await fs.promises.readdir(path.resolve(folderPath), {
|
|
203
|
+
withFileTypes: true,
|
|
204
|
+
});
|
|
205
|
+
return entries.filter((e) => e.isFile()).map((e) => e.name);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error(`Failed to list files in folder: ${folderPath}`, error);
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ================== PDF LINK ==================
|
|
213
|
+
static async clickLinkInsidePdf(
|
|
214
|
+
page: any,
|
|
215
|
+
filePath: string,
|
|
216
|
+
index = 0,
|
|
217
|
+
): Promise<void> {
|
|
218
|
+
const text = await this.readPdfFile(filePath);
|
|
219
|
+
const links = text.match(/https?:\/\/[^\s]+/g) ?? [];
|
|
220
|
+
if (links[index]) await page.goto(links[index]);
|
|
221
|
+
else console.warn("No valid link found in PDF");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ================== COMMAND ==================
|
|
225
|
+
static async runCommand(
|
|
226
|
+
folderPath: string,
|
|
227
|
+
command: string,
|
|
228
|
+
): Promise<string> {
|
|
229
|
+
try {
|
|
230
|
+
const { stdout } = await execAsync(command, {
|
|
231
|
+
cwd: path.resolve(folderPath),
|
|
232
|
+
});
|
|
233
|
+
return stdout;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
console.error(`Command execution failed in folder: ${folderPath}`, error);
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|