@anddone/coretestautomation 1.0.8 → 1.0.9
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/dist/api/headers.d.ts +30 -0
- package/dist/api/headers.d.ts.map +1 -1
- package/dist/api/headers.js +30 -0
- package/dist/api/headers.js.map +1 -1
- package/dist/utils/apiUtils.d.ts +42 -13
- package/dist/utils/apiUtils.d.ts.map +1 -1
- package/dist/utils/apiUtils.js +42 -13
- package/dist/utils/apiUtils.js.map +1 -1
- package/dist/utils/fileCommonUtils.d.ts +115 -8
- package/dist/utils/fileCommonUtils.d.ts.map +1 -1
- package/dist/utils/fileCommonUtils.js +124 -25
- package/dist/utils/fileCommonUtils.js.map +1 -1
- package/package.json +4 -1
- package/src/api/headers.ts +31 -0
- package/src/utils/apiUtils.ts +43 -17
- package/src/utils/fileCommonUtils.ts +133 -34
package/dist/api/headers.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { Header } from "./base.api";
|
|
2
2
|
export declare class Headers {
|
|
3
3
|
static headers: Record<string, string>;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs and returns HTTP headers based on the provided options.
|
|
6
|
+
* Only the headers present in the options object will be added.
|
|
7
|
+
* If an authorization token is provided, it is automatically
|
|
8
|
+
* prefixed with "Bearer ".
|
|
9
|
+
* @param options - Optional header configuration object.
|
|
10
|
+
* Supported properties:
|
|
11
|
+
* - origin: Sets the "Origin" header
|
|
12
|
+
* - contentType: Sets the "Content-Type" header
|
|
13
|
+
* - authorization: Bearer token value (without "Bearer " prefix)
|
|
14
|
+
* - xVersion: Sets the "x-version" header
|
|
15
|
+
* - apiKey: Sets the "x-api-key" header
|
|
16
|
+
* - appKey: Sets the "x-app-key" header
|
|
17
|
+
*
|
|
18
|
+
* @returns An object containing the constructed HTTP headers.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* getHeaders({
|
|
22
|
+
* contentType: "application/json",
|
|
23
|
+
* authorization: "abc123",
|
|
24
|
+
* apiKey: "my-api-key"
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Returns:
|
|
28
|
+
* // {
|
|
29
|
+
* // "Content-Type": "application/json",
|
|
30
|
+
* // "Authorization": "Bearer abc123",
|
|
31
|
+
* // "x-api-key": "my-api-key"
|
|
32
|
+
* // }
|
|
33
|
+
*/
|
|
4
34
|
static getHeaders(options?: Header): Record<string, string>;
|
|
5
35
|
}
|
|
6
36
|
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,qBAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,qBAAa,OAAO;IAElB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,GAAE,MAAW;CAWvC"}
|
package/dist/api/headers.js
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Headers = void 0;
|
|
4
4
|
class Headers {
|
|
5
|
+
/**
|
|
6
|
+
* Constructs and returns HTTP headers based on the provided options.
|
|
7
|
+
* Only the headers present in the options object will be added.
|
|
8
|
+
* If an authorization token is provided, it is automatically
|
|
9
|
+
* prefixed with "Bearer ".
|
|
10
|
+
* @param options - Optional header configuration object.
|
|
11
|
+
* Supported properties:
|
|
12
|
+
* - origin: Sets the "Origin" header
|
|
13
|
+
* - contentType: Sets the "Content-Type" header
|
|
14
|
+
* - authorization: Bearer token value (without "Bearer " prefix)
|
|
15
|
+
* - xVersion: Sets the "x-version" header
|
|
16
|
+
* - apiKey: Sets the "x-api-key" header
|
|
17
|
+
* - appKey: Sets the "x-app-key" header
|
|
18
|
+
*
|
|
19
|
+
* @returns An object containing the constructed HTTP headers.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* getHeaders({
|
|
23
|
+
* contentType: "application/json",
|
|
24
|
+
* authorization: "abc123",
|
|
25
|
+
* apiKey: "my-api-key"
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Returns:
|
|
29
|
+
* // {
|
|
30
|
+
* // "Content-Type": "application/json",
|
|
31
|
+
* // "Authorization": "Bearer abc123",
|
|
32
|
+
* // "x-api-key": "my-api-key"
|
|
33
|
+
* // }
|
|
34
|
+
*/
|
|
5
35
|
static getHeaders(options = {}) {
|
|
6
36
|
this.headers = {};
|
|
7
37
|
if (options.origin)
|
package/dist/api/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;IAIlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,UAAU,CAAC,UAAkB,EAAE;QACpC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC5D,IAAI,OAAO,CAAC,WAAW;YAAE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;QAC5E,IAAI,OAAO,CAAC,aAAa;YACvB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC;QACpE,IAAI,OAAO,CAAC,QAAQ;YAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;QACnE,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/D,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA7CD,0BA6CC"}
|
package/dist/utils/apiUtils.d.ts
CHANGED
|
@@ -42,19 +42,19 @@ export declare class ApiUtils {
|
|
|
42
42
|
*/
|
|
43
43
|
static getRequest(): APIRequestContext;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
* Sets the API method and API path based on the provided API data JSON object
|
|
46
|
+
* and API name key.
|
|
47
|
+
*
|
|
48
|
+
* This method is generic and works with any API data file that follows the
|
|
49
|
+
* ApiFile structure (Record<string, { method: string; path: string }>).
|
|
50
|
+
*
|
|
51
|
+
* @template T - Type of the API data object passed to the method
|
|
52
|
+
* @param apiName - Key name of the API entry inside the provided API data object
|
|
53
|
+
* @param api - API data JSON object containing method and path definitions
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ApiUtils.setApiData("login", apiData);
|
|
57
|
+
*/
|
|
58
58
|
static setApiData<T extends ApiFile>(apiName: keyof T, api: T): void;
|
|
59
59
|
/**
|
|
60
60
|
* This method is to get api method.
|
|
@@ -66,6 +66,35 @@ export declare class ApiUtils {
|
|
|
66
66
|
* @returns string
|
|
67
67
|
*/
|
|
68
68
|
static getApiPath(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Builds a complete API path by replacing path parameter placeholders
|
|
71
|
+
* in the given API path with actual values.
|
|
72
|
+
*
|
|
73
|
+
* Placeholders in the apiPath should be defined using curly braces,
|
|
74
|
+
* e.g. `/users/{userId}/orders/{orderId}`.
|
|
75
|
+
*
|
|
76
|
+
* Each placeholder will be replaced with the corresponding value from
|
|
77
|
+
* the pathParams object. Values are URL-encoded using encodeURIComponent
|
|
78
|
+
* to ensure safe transmission.
|
|
79
|
+
*
|
|
80
|
+
* @param apiPath - The API endpoint path containing optional placeholders (e.g., "/users/{id}")
|
|
81
|
+
* @param pathParams - An optional key-value map where:
|
|
82
|
+
* - key represents the placeholder name (without braces)
|
|
83
|
+
* - value represents the replacement value
|
|
84
|
+
*
|
|
85
|
+
* @returns The final API path with all placeholders replaced by their encoded values.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* buildPath("/users/{id}", { id: "123" });
|
|
89
|
+
* // Returns: "/users/123"
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* buildPath("/orders/{orderId}/items/{itemId}", {
|
|
93
|
+
* orderId: "ORD-001",
|
|
94
|
+
* itemId: "ITM-10"
|
|
95
|
+
* });
|
|
96
|
+
* // Returns: "/orders/ORD-001/items/ITM-10"
|
|
97
|
+
*/
|
|
69
98
|
private static buildPath;
|
|
70
99
|
/**
|
|
71
100
|
* This method to log request details in console if apiLogs flag is true.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/apiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAElE,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,OAAO,GAAG,MAAM,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sets the API method and API path based on the provided API data JSON object
|
|
52
|
+
* and API name key.
|
|
53
|
+
*
|
|
54
|
+
* This method is generic and works with any API data file that follows the
|
|
55
|
+
* ApiFile structure (Record<string, { method: string; path: string }>).
|
|
56
|
+
*
|
|
57
|
+
* @template T - Type of the API data object passed to the method
|
|
58
|
+
* @param apiName - Key name of the API entry inside the provided API data object
|
|
59
|
+
* @param api - API data JSON object containing method and path definitions
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ApiUtils.setApiData("login", apiData);
|
|
63
|
+
*/
|
|
64
64
|
static setApiData(apiName, api) {
|
|
65
65
|
this.apiMethod = api[apiName].method;
|
|
66
66
|
this.apiPath = api[apiName].path;
|
|
@@ -79,6 +79,35 @@ class ApiUtils {
|
|
|
79
79
|
static getApiPath() {
|
|
80
80
|
return this.apiPath;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Builds a complete API path by replacing path parameter placeholders
|
|
84
|
+
* in the given API path with actual values.
|
|
85
|
+
*
|
|
86
|
+
* Placeholders in the apiPath should be defined using curly braces,
|
|
87
|
+
* e.g. `/users/{userId}/orders/{orderId}`.
|
|
88
|
+
*
|
|
89
|
+
* Each placeholder will be replaced with the corresponding value from
|
|
90
|
+
* the pathParams object. Values are URL-encoded using encodeURIComponent
|
|
91
|
+
* to ensure safe transmission.
|
|
92
|
+
*
|
|
93
|
+
* @param apiPath - The API endpoint path containing optional placeholders (e.g., "/users/{id}")
|
|
94
|
+
* @param pathParams - An optional key-value map where:
|
|
95
|
+
* - key represents the placeholder name (without braces)
|
|
96
|
+
* - value represents the replacement value
|
|
97
|
+
*
|
|
98
|
+
* @returns The final API path with all placeholders replaced by their encoded values.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* buildPath("/users/{id}", { id: "123" });
|
|
102
|
+
* // Returns: "/users/123"
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* buildPath("/orders/{orderId}/items/{itemId}", {
|
|
106
|
+
* orderId: "ORD-001",
|
|
107
|
+
* itemId: "ITM-10"
|
|
108
|
+
* });
|
|
109
|
+
* // Returns: "/orders/ORD-001/items/ITM-10"
|
|
110
|
+
*/
|
|
82
111
|
static buildPath(apiPath, pathParams) {
|
|
83
112
|
if (!pathParams)
|
|
84
113
|
return apiPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiUtils.js","sourceRoot":"","sources":["../../src/utils/apiUtils.ts"],"names":[],"mappings":";;;AAgBA,MAAa,gBAAgB;IAC3B,MAAM;QACJ,OAAO,CAAC,CAAC;IACX,CAAC;IACD,EAAE;QACA,OAAO,KAAK,CAAC;IACf,CAAC;IACD,GAAG;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAhBD,4CAgBC;AAED,MAAa,QAAQ;IAYnB;;;;OAIG;IACK,MAAM,CAAC,MAAM,CAAC,GAAY;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,OAA0B;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"apiUtils.js","sourceRoot":"","sources":["../../src/utils/apiUtils.ts"],"names":[],"mappings":";;;AAgBA,MAAa,gBAAgB;IAC3B,MAAM;QACJ,OAAO,CAAC,CAAC;IACX,CAAC;IACD,EAA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AC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC5C,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC9B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;oBAAE,OAAO,KAAK,CAAC;gBACpD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAChC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,GAAG,CAAC,MAAK,KAAK,CACxC,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACxC,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,UAAU,CAAC,CAAC;YACnC,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,yEAAyE;YACzE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;;AA1TH,4BA2TC;AA1TgB,gBAAO,GAAG,KAAK,CAAC"}
|
|
@@ -1,23 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for handling files like Excel, CSV, JSON, XML, PDF, and Text.
|
|
3
|
+
* Provides helper methods for reading, writing, and manipulating files.
|
|
4
|
+
*/
|
|
1
5
|
export declare class FileCommonUtils {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Reads data from an Excel file and returns it as an array of objects.
|
|
8
|
+
* First row is treated as column headers.
|
|
9
|
+
*
|
|
10
|
+
* @template T - Type of row object
|
|
11
|
+
* @param filePath - Path to the Excel file
|
|
12
|
+
* @param sheetName - Optional sheet name (defaults to first sheet)
|
|
13
|
+
* @returns Promise resolving to array of row objects
|
|
14
|
+
*/
|
|
15
|
+
static readExcel<T = Record<string, any>>(filePath: string, sheetName?: string): Promise<T[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Writes data into an Excel file.
|
|
18
|
+
* Creates sheet if not exists, otherwise appends rows.
|
|
19
|
+
*
|
|
20
|
+
* @param filePath - Path to Excel file
|
|
21
|
+
* @param data - Array of objects to write
|
|
22
|
+
* @param sheetName - Sheet name (default: Sheet1)
|
|
23
|
+
*/
|
|
24
|
+
static writeExcel(filePath: string, data: Record<string, any>[], sheetName?: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns all sheet names from an Excel file.
|
|
27
|
+
*
|
|
28
|
+
* @param filePath - Path to Excel file
|
|
29
|
+
* @returns Promise resolving to array of sheet names
|
|
30
|
+
*/
|
|
31
|
+
static getExcelSheetNames(filePath: string): Promise<string[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads a CSV file and returns data as array of objects.
|
|
34
|
+
*
|
|
35
|
+
* @template T
|
|
36
|
+
* @param filePath - Path to CSV file
|
|
37
|
+
* @param delimiter - Column delimiter (default: ,)
|
|
38
|
+
* @returns Array of objects
|
|
39
|
+
*/
|
|
40
|
+
static readCSV<T = Record<string, string>>(filePath: string, delimiter?: string): T[];
|
|
41
|
+
/**
|
|
42
|
+
* Writes data into a CSV file.
|
|
43
|
+
*
|
|
44
|
+
* @param filePath - Path to CSV file
|
|
45
|
+
* @param data - Array of objects
|
|
46
|
+
* @param delimiter - Column delimiter
|
|
47
|
+
*/
|
|
48
|
+
static writeCSV(filePath: string, data: Record<string, any>[], delimiter?: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Reads JSON file and converts to object.
|
|
51
|
+
*
|
|
52
|
+
* @template T
|
|
53
|
+
* @param filePath - Path to JSON file
|
|
54
|
+
* @returns Parsed object or null
|
|
55
|
+
*/
|
|
56
|
+
static readJson<T>(filePath: string): T | null;
|
|
57
|
+
/**
|
|
58
|
+
* Reads XML file and converts to object.
|
|
59
|
+
*
|
|
60
|
+
* @template T
|
|
61
|
+
* @param filePath - Path to XML file
|
|
62
|
+
* @returns Parsed XML object or null
|
|
63
|
+
*/
|
|
64
|
+
static readXml<T>(filePath: string): Promise<T | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns number of rows.
|
|
67
|
+
*/
|
|
10
68
|
static getRowCount<T>(data: T[]): number;
|
|
69
|
+
/**
|
|
70
|
+
* Returns number of columns.
|
|
71
|
+
*/
|
|
11
72
|
static getColumnCount<T extends Record<string, any>>(data: T[]): number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns column headers.
|
|
75
|
+
*/
|
|
12
76
|
static getColumnHeaders<T extends Record<string, any>>(data: T[]): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Returns value of a specific cell.
|
|
79
|
+
*/
|
|
13
80
|
static getCellData<T extends Record<string, any>>(data: T[], row: number, column: keyof T): any;
|
|
81
|
+
/**
|
|
82
|
+
* Filters rows by column value.
|
|
83
|
+
*/
|
|
14
84
|
static select<T extends Record<string, any>>(data: T[], column: keyof T, value: any): T[];
|
|
85
|
+
/**
|
|
86
|
+
* Reads text file.
|
|
87
|
+
*/
|
|
15
88
|
static readTextFile(filePath: string): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Reads PDF file and extracts text.
|
|
91
|
+
*/
|
|
16
92
|
static readPdfFile(filePath: string): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Replaces text inside a file.
|
|
95
|
+
*/
|
|
17
96
|
static editTextFile(filePath: string, search: string | RegExp, replace?: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Counts files in a folder.
|
|
99
|
+
*/
|
|
18
100
|
static getFileCount(folderPath: string): Promise<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns all file names in a folder.
|
|
103
|
+
*/
|
|
19
104
|
static getAllFileNames(folderPath: string): Promise<string[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Extracts all URLs from a PDF file and navigates to one of them in the browser.
|
|
107
|
+
*
|
|
108
|
+
* Reads the PDF file, searches for HTTP/HTTPS links using regex,
|
|
109
|
+
* and opens the selected link in the provided Playwright page.
|
|
110
|
+
*
|
|
111
|
+
* @param page - Playwright Page object used for navigation
|
|
112
|
+
* @param filePath - Path to the PDF file
|
|
113
|
+
* @param index - Index of the link to open (default: 0 = first link)
|
|
114
|
+
*
|
|
115
|
+
* @returns Promise that resolves when navigation is complete
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf");
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Open second link from PDF
|
|
122
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf", 1);
|
|
123
|
+
*/
|
|
20
124
|
static clickLinkInsidePdf(page: any, filePath: string, index?: number): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Executes shell command in a folder.
|
|
127
|
+
*/
|
|
21
128
|
static runCommand(folderPath: string, command: string): Promise<string>;
|
|
22
129
|
}
|
|
23
130
|
//# sourceMappingURL=fileCommonUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileCommonUtils.d.ts","sourceRoot":"","sources":["../../src/utils/fileCommonUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fileCommonUtils.d.ts","sourceRoot":"","sources":["../../src/utils/fileCommonUtils.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,qBAAa,eAAe;IAI1B;;;;;;;;OAQG;WACQ,SAAS,CAAC,CAAC,GAAG,MAAM,CAAC,M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IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE;IAI3E;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9C,IAAI,EAAE,CAAC,EAAE,EACT,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,GACd,GAAG;IAIN;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzC,IAAI,EAAE,CAAC,EAAE,EACT,MAAM,EAAE,MAAM,CAAC,EACf,KAAK,EAAE,GAAG,GACT,CAAC,EAAE;IAMN;;OAEG;WACU,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS3D;;MAEE;WACU,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAW3D;;OAEG;WACW,YAAY,CACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,OAAO,SAAK,GACX,OAAO,CAAC,IAAI,CAAC;IAYhB;;OAEG;WACU,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAY9D;;OAEG;WACU,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAcnE;;;;;;;;;;;;;;;;;;KAkBC;WACY,kBAAkB,CAC7B,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,KAAK,SAAI,GACR,OAAO,CAAC,IAAI,CAAC;IAShB;;OAEG;WACU,UAAU,CACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;CAWnB"}
|
|
@@ -45,15 +45,23 @@ const child_process_1 = require("child_process");
|
|
|
45
45
|
const util_1 = require("util");
|
|
46
46
|
const pdfParse = require("pdf-parse");
|
|
47
47
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
48
|
+
/**
|
|
49
|
+
* Utility class for handling files like Excel, CSV, JSON, XML, PDF, and Text.
|
|
50
|
+
* Provides helper methods for reading, writing, and manipulating files.
|
|
51
|
+
*/
|
|
48
52
|
class FileCommonUtils {
|
|
49
|
-
// ================== PATH RESOLVER ==================
|
|
50
|
-
static resolvePath(fileName) {
|
|
51
|
-
return path.resolve(process.cwd(), "test-data", fileName);
|
|
52
|
-
}
|
|
53
53
|
// ================== EXCEL ==================
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Reads data from an Excel file and returns it as an array of objects.
|
|
56
|
+
* First row is treated as column headers.
|
|
57
|
+
*
|
|
58
|
+
* @template T - Type of row object
|
|
59
|
+
* @param filePath - Path to the Excel file
|
|
60
|
+
* @param sheetName - Optional sheet name (defaults to first sheet)
|
|
61
|
+
* @returns Promise resolving to array of row objects
|
|
62
|
+
*/
|
|
63
|
+
static async readExcel(filePath, sheetName) {
|
|
55
64
|
try {
|
|
56
|
-
const filePath = this.resolvePath(fileName);
|
|
57
65
|
const workbook = new exceljs_1.default.Workbook();
|
|
58
66
|
await workbook.xlsx.readFile(filePath);
|
|
59
67
|
const worksheet = sheetName ? workbook.getWorksheet(sheetName) : workbook.worksheets[0];
|
|
@@ -81,14 +89,21 @@ class FileCommonUtils {
|
|
|
81
89
|
return data;
|
|
82
90
|
}
|
|
83
91
|
catch (error) {
|
|
84
|
-
console.error(`Failed to read Excel: ${
|
|
92
|
+
console.error(`Failed to read Excel: ${filePath}`, error);
|
|
85
93
|
return [];
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Writes data into an Excel file.
|
|
98
|
+
* Creates sheet if not exists, otherwise appends rows.
|
|
99
|
+
*
|
|
100
|
+
* @param filePath - Path to Excel file
|
|
101
|
+
* @param data - Array of objects to write
|
|
102
|
+
* @param sheetName - Sheet name (default: Sheet1)
|
|
103
|
+
*/
|
|
104
|
+
static async writeExcel(filePath, data, sheetName = 'Sheet1') {
|
|
89
105
|
var _a;
|
|
90
106
|
try {
|
|
91
|
-
const filePath = this.resolvePath(fileName);
|
|
92
107
|
const workbook = new exceljs_1.default.Workbook();
|
|
93
108
|
// Load existing Excel if it exists
|
|
94
109
|
if (fs.existsSync(filePath)) {
|
|
@@ -114,24 +129,37 @@ class FileCommonUtils {
|
|
|
114
129
|
await workbook.xlsx.writeFile(filePath);
|
|
115
130
|
}
|
|
116
131
|
catch (error) {
|
|
117
|
-
console.error(`Failed to write Excel: ${
|
|
132
|
+
console.error(`Failed to write Excel: ${filePath}`, error);
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Returns all sheet names from an Excel file.
|
|
137
|
+
*
|
|
138
|
+
* @param filePath - Path to Excel file
|
|
139
|
+
* @returns Promise resolving to array of sheet names
|
|
140
|
+
*/
|
|
141
|
+
static async getExcelSheetNames(filePath) {
|
|
121
142
|
try {
|
|
122
143
|
const workbook = new exceljs_1.default.Workbook();
|
|
123
|
-
await workbook.xlsx.readFile(
|
|
144
|
+
await workbook.xlsx.readFile(filePath);
|
|
124
145
|
return workbook.worksheets.map(ws => ws.name);
|
|
125
146
|
}
|
|
126
147
|
catch (error) {
|
|
127
|
-
console.error(`Failed to read sheet names: ${
|
|
148
|
+
console.error(`Failed to read sheet names: ${filePath}`, error);
|
|
128
149
|
return [];
|
|
129
150
|
}
|
|
130
151
|
}
|
|
131
152
|
// ================== CSV ==================
|
|
132
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Reads a CSV file and returns data as array of objects.
|
|
155
|
+
*
|
|
156
|
+
* @template T
|
|
157
|
+
* @param filePath - Path to CSV file
|
|
158
|
+
* @param delimiter - Column delimiter (default: ,)
|
|
159
|
+
* @returns Array of objects
|
|
160
|
+
*/
|
|
161
|
+
static readCSV(filePath, delimiter = ",") {
|
|
133
162
|
try {
|
|
134
|
-
const filePath = this.resolvePath(fileName);
|
|
135
163
|
const content = fs.readFileSync(filePath, "utf-8").trim();
|
|
136
164
|
if (!content)
|
|
137
165
|
return [];
|
|
@@ -147,16 +175,22 @@ class FileCommonUtils {
|
|
|
147
175
|
});
|
|
148
176
|
}
|
|
149
177
|
catch (error) {
|
|
150
|
-
console.error(`Failed to read CSV: ${
|
|
178
|
+
console.error(`Failed to read CSV: ${filePath}`, error);
|
|
151
179
|
return [];
|
|
152
180
|
}
|
|
153
181
|
}
|
|
154
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Writes data into a CSV file.
|
|
184
|
+
*
|
|
185
|
+
* @param filePath - Path to CSV file
|
|
186
|
+
* @param data - Array of objects
|
|
187
|
+
* @param delimiter - Column delimiter
|
|
188
|
+
*/
|
|
189
|
+
static writeCSV(filePath, data, delimiter = ",") {
|
|
155
190
|
var _a;
|
|
156
191
|
try {
|
|
157
192
|
if (!data.length)
|
|
158
193
|
return;
|
|
159
|
-
const filePath = this.resolvePath(fileName);
|
|
160
194
|
const headers = Object.keys((_a = data[0]) !== null && _a !== void 0 ? _a : {}).join(delimiter);
|
|
161
195
|
const rows = data
|
|
162
196
|
.map((row) => Object.values(row).join(delimiter))
|
|
@@ -164,50 +198,81 @@ class FileCommonUtils {
|
|
|
164
198
|
fs.writeFileSync(filePath, `${headers}\n${rows}`, "utf-8");
|
|
165
199
|
}
|
|
166
200
|
catch (error) {
|
|
167
|
-
console.error(`Failed to write CSV: ${
|
|
201
|
+
console.error(`Failed to write CSV: ${filePath}`, error);
|
|
168
202
|
}
|
|
169
203
|
}
|
|
170
204
|
// ================== JSON / XML ==================
|
|
171
|
-
|
|
205
|
+
/**
|
|
206
|
+
* Reads JSON file and converts to object.
|
|
207
|
+
*
|
|
208
|
+
* @template T
|
|
209
|
+
* @param filePath - Path to JSON file
|
|
210
|
+
* @returns Parsed object or null
|
|
211
|
+
*/
|
|
212
|
+
static readJson(filePath) {
|
|
172
213
|
try {
|
|
173
|
-
const filePath = this.resolvePath(fileName);
|
|
174
214
|
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
175
215
|
}
|
|
176
216
|
catch (error) {
|
|
177
|
-
console.error(`Failed to read JSON: ${
|
|
217
|
+
console.error(`Failed to read JSON: ${filePath}`, error);
|
|
178
218
|
return null;
|
|
179
219
|
}
|
|
180
220
|
}
|
|
181
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Reads XML file and converts to object.
|
|
223
|
+
*
|
|
224
|
+
* @template T
|
|
225
|
+
* @param filePath - Path to XML file
|
|
226
|
+
* @returns Parsed XML object or null
|
|
227
|
+
*/
|
|
228
|
+
static async readXml(filePath) {
|
|
182
229
|
try {
|
|
183
|
-
const xml = fs.readFileSync(
|
|
230
|
+
const xml = fs.readFileSync(filePath, "utf-8");
|
|
184
231
|
return await (0, xml2js_1.parseStringPromise)(xml, { explicitArray: false });
|
|
185
232
|
}
|
|
186
233
|
catch (error) {
|
|
187
|
-
console.error(`Failed to read XML: ${
|
|
234
|
+
console.error(`Failed to read XML: ${filePath}`, error);
|
|
188
235
|
return null;
|
|
189
236
|
}
|
|
190
237
|
}
|
|
191
238
|
// ================== DATA HELPERS ==================
|
|
239
|
+
/**
|
|
240
|
+
* Returns number of rows.
|
|
241
|
+
*/
|
|
192
242
|
static getRowCount(data) {
|
|
193
243
|
return data.length;
|
|
194
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Returns number of columns.
|
|
247
|
+
*/
|
|
195
248
|
static getColumnCount(data) {
|
|
196
249
|
var _a;
|
|
197
250
|
return Object.keys((_a = data[0]) !== null && _a !== void 0 ? _a : {}).length;
|
|
198
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Returns column headers.
|
|
254
|
+
*/
|
|
199
255
|
static getColumnHeaders(data) {
|
|
200
256
|
var _a;
|
|
201
257
|
return Object.keys((_a = data[0]) !== null && _a !== void 0 ? _a : {});
|
|
202
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Returns value of a specific cell.
|
|
261
|
+
*/
|
|
203
262
|
static getCellData(data, row, column) {
|
|
204
263
|
var _a;
|
|
205
264
|
return (_a = data[row]) === null || _a === void 0 ? void 0 : _a[column];
|
|
206
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Filters rows by column value.
|
|
268
|
+
*/
|
|
207
269
|
static select(data, column, value) {
|
|
208
270
|
return data.filter((row) => row[column] === value);
|
|
209
271
|
}
|
|
210
272
|
// ================== FILE UTILS ==================
|
|
273
|
+
/**
|
|
274
|
+
* Reads text file.
|
|
275
|
+
*/
|
|
211
276
|
static async readTextFile(filePath) {
|
|
212
277
|
try {
|
|
213
278
|
return await fs.promises.readFile(path.resolve(filePath), "utf-8");
|
|
@@ -217,6 +282,9 @@ class FileCommonUtils {
|
|
|
217
282
|
return "";
|
|
218
283
|
}
|
|
219
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Reads PDF file and extracts text.
|
|
287
|
+
*/
|
|
220
288
|
static async readPdfFile(filePath) {
|
|
221
289
|
try {
|
|
222
290
|
const buffer = await fs.promises.readFile(path.resolve(filePath));
|
|
@@ -228,6 +296,9 @@ class FileCommonUtils {
|
|
|
228
296
|
return "";
|
|
229
297
|
}
|
|
230
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Replaces text inside a file.
|
|
301
|
+
*/
|
|
231
302
|
static async editTextFile(filePath, search, replace = "") {
|
|
232
303
|
try {
|
|
233
304
|
const content = await this.readTextFile(filePath);
|
|
@@ -239,6 +310,9 @@ class FileCommonUtils {
|
|
|
239
310
|
}
|
|
240
311
|
}
|
|
241
312
|
// ================== FOLDER UTILS ==================
|
|
313
|
+
/**
|
|
314
|
+
* Counts files in a folder.
|
|
315
|
+
*/
|
|
242
316
|
static async getFileCount(folderPath) {
|
|
243
317
|
try {
|
|
244
318
|
const entries = await fs.promises.readdir(path.resolve(folderPath), {
|
|
@@ -251,6 +325,9 @@ class FileCommonUtils {
|
|
|
251
325
|
return 0;
|
|
252
326
|
}
|
|
253
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Returns all file names in a folder.
|
|
330
|
+
*/
|
|
254
331
|
static async getAllFileNames(folderPath) {
|
|
255
332
|
try {
|
|
256
333
|
const entries = await fs.promises.readdir(path.resolve(folderPath), {
|
|
@@ -264,6 +341,25 @@ class FileCommonUtils {
|
|
|
264
341
|
}
|
|
265
342
|
}
|
|
266
343
|
// ================== PDF LINK ==================
|
|
344
|
+
/**
|
|
345
|
+
* Extracts all URLs from a PDF file and navigates to one of them in the browser.
|
|
346
|
+
*
|
|
347
|
+
* Reads the PDF file, searches for HTTP/HTTPS links using regex,
|
|
348
|
+
* and opens the selected link in the provided Playwright page.
|
|
349
|
+
*
|
|
350
|
+
* @param page - Playwright Page object used for navigation
|
|
351
|
+
* @param filePath - Path to the PDF file
|
|
352
|
+
* @param index - Index of the link to open (default: 0 = first link)
|
|
353
|
+
*
|
|
354
|
+
* @returns Promise that resolves when navigation is complete
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf");
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* // Open second link from PDF
|
|
361
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf", 1);
|
|
362
|
+
*/
|
|
267
363
|
static async clickLinkInsidePdf(page, filePath, index = 0) {
|
|
268
364
|
var _a;
|
|
269
365
|
const text = await this.readPdfFile(filePath);
|
|
@@ -274,6 +370,9 @@ class FileCommonUtils {
|
|
|
274
370
|
console.warn("No valid link found in PDF");
|
|
275
371
|
}
|
|
276
372
|
// ================== COMMAND ==================
|
|
373
|
+
/**
|
|
374
|
+
* Executes shell command in a folder.
|
|
375
|
+
*/
|
|
277
376
|
static async runCommand(folderPath, command) {
|
|
278
377
|
try {
|
|
279
378
|
const { stdout } = await execAsync(command, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileCommonUtils.js","sourceRoot":"","sources":["../../src/utils/fileCommon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CAAC;QACrD,IAAI,KAAK,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;;YAC3C,OAAO,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAClD,CAAC;IAED,gDAAgD;IAEhD;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,CACrB,UAAkB,EAClB,OAAe;QAEf,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;gBAC1C,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;aAC9B,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,UAAU,EAAE,EAAE,KAAK,CAAC,CAAC;YAC1E,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AA9WD,0CA8WC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anddone/coretestautomation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"scripts": {
|
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"exceljs": "^4.4.0",
|
|
20
20
|
"pdf-parse": "^1.1.1",
|
|
21
21
|
"xml2js": "^0.6.2"
|
|
22
|
+
},
|
|
23
|
+
"overrides": {
|
|
24
|
+
"minimatch": "^10.2.1"
|
|
22
25
|
}
|
|
23
26
|
}
|
package/src/api/headers.ts
CHANGED
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
import { Header } from "./base.api";
|
|
2
2
|
|
|
3
3
|
export class Headers {
|
|
4
|
+
|
|
4
5
|
static headers: Record<string, string>;
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Constructs and returns HTTP headers based on the provided options.
|
|
9
|
+
* Only the headers present in the options object will be added.
|
|
10
|
+
* If an authorization token is provided, it is automatically
|
|
11
|
+
* prefixed with "Bearer ".
|
|
12
|
+
* @param options - Optional header configuration object.
|
|
13
|
+
* Supported properties:
|
|
14
|
+
* - origin: Sets the "Origin" header
|
|
15
|
+
* - contentType: Sets the "Content-Type" header
|
|
16
|
+
* - authorization: Bearer token value (without "Bearer " prefix)
|
|
17
|
+
* - xVersion: Sets the "x-version" header
|
|
18
|
+
* - apiKey: Sets the "x-api-key" header
|
|
19
|
+
* - appKey: Sets the "x-app-key" header
|
|
20
|
+
*
|
|
21
|
+
* @returns An object containing the constructed HTTP headers.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* getHeaders({
|
|
25
|
+
* contentType: "application/json",
|
|
26
|
+
* authorization: "abc123",
|
|
27
|
+
* apiKey: "my-api-key"
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Returns:
|
|
31
|
+
* // {
|
|
32
|
+
* // "Content-Type": "application/json",
|
|
33
|
+
* // "Authorization": "Bearer abc123",
|
|
34
|
+
* // "x-api-key": "my-api-key"
|
|
35
|
+
* // }
|
|
36
|
+
*/
|
|
6
37
|
static getHeaders(options: Header = {}) {
|
|
7
38
|
this.headers = {};
|
|
8
39
|
if (options.origin) this.headers["Origin"] = options.origin;
|
package/src/utils/apiUtils.ts
CHANGED
|
@@ -74,23 +74,20 @@ export class ApiUtils {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
static setApiData<T extends ApiFile>(
|
|
91
|
-
apiName: keyof T,
|
|
92
|
-
api: T
|
|
93
|
-
) {
|
|
77
|
+
* Sets the API method and API path based on the provided API data JSON object
|
|
78
|
+
* and API name key.
|
|
79
|
+
*
|
|
80
|
+
* This method is generic and works with any API data file that follows the
|
|
81
|
+
* ApiFile structure (Record<string, { method: string; path: string }>).
|
|
82
|
+
*
|
|
83
|
+
* @template T - Type of the API data object passed to the method
|
|
84
|
+
* @param apiName - Key name of the API entry inside the provided API data object
|
|
85
|
+
* @param api - API data JSON object containing method and path definitions
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ApiUtils.setApiData("login", apiData);
|
|
89
|
+
*/
|
|
90
|
+
static setApiData<T extends ApiFile>(apiName: keyof T, api: T) {
|
|
94
91
|
this.apiMethod = api[apiName].method;
|
|
95
92
|
this.apiPath = api[apiName].path;
|
|
96
93
|
}
|
|
@@ -111,6 +108,35 @@ export class ApiUtils {
|
|
|
111
108
|
return this.apiPath;
|
|
112
109
|
}
|
|
113
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Builds a complete API path by replacing path parameter placeholders
|
|
113
|
+
* in the given API path with actual values.
|
|
114
|
+
*
|
|
115
|
+
* Placeholders in the apiPath should be defined using curly braces,
|
|
116
|
+
* e.g. `/users/{userId}/orders/{orderId}`.
|
|
117
|
+
*
|
|
118
|
+
* Each placeholder will be replaced with the corresponding value from
|
|
119
|
+
* the pathParams object. Values are URL-encoded using encodeURIComponent
|
|
120
|
+
* to ensure safe transmission.
|
|
121
|
+
*
|
|
122
|
+
* @param apiPath - The API endpoint path containing optional placeholders (e.g., "/users/{id}")
|
|
123
|
+
* @param pathParams - An optional key-value map where:
|
|
124
|
+
* - key represents the placeholder name (without braces)
|
|
125
|
+
* - value represents the replacement value
|
|
126
|
+
*
|
|
127
|
+
* @returns The final API path with all placeholders replaced by their encoded values.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* buildPath("/users/{id}", { id: "123" });
|
|
131
|
+
* // Returns: "/users/123"
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* buildPath("/orders/{orderId}/items/{itemId}", {
|
|
135
|
+
* orderId: "ORD-001",
|
|
136
|
+
* itemId: "ITM-10"
|
|
137
|
+
* });
|
|
138
|
+
* // Returns: "/orders/ORD-001/items/ITM-10"
|
|
139
|
+
*/
|
|
114
140
|
private static buildPath(
|
|
115
141
|
apiPath: string,
|
|
116
142
|
pathParams?: Record<string, string>,
|
|
@@ -6,20 +6,28 @@ import { exec } from "child_process";
|
|
|
6
6
|
import { promisify } from "util";
|
|
7
7
|
|
|
8
8
|
const pdfParse = require("pdf-parse");
|
|
9
|
-
|
|
10
9
|
const execAsync = promisify(exec);
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Utility class for handling files like Excel, CSV, JSON, XML, PDF, and Text.
|
|
13
|
+
* Provides helper methods for reading, writing, and manipulating files.
|
|
14
|
+
*/
|
|
12
15
|
export class FileCommonUtils {
|
|
13
|
-
// ================== PATH RESOLVER ==================
|
|
14
|
-
private static resolvePath(fileName: string): string {
|
|
15
|
-
return path.resolve(process.cwd(), "test-data", fileName);
|
|
16
|
-
}
|
|
17
16
|
|
|
18
17
|
// ================== EXCEL ==================
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reads data from an Excel file and returns it as an array of objects.
|
|
21
|
+
* First row is treated as column headers.
|
|
22
|
+
*
|
|
23
|
+
* @template T - Type of row object
|
|
24
|
+
* @param filePath - Path to the Excel file
|
|
25
|
+
* @param sheetName - Optional sheet name (defaults to first sheet)
|
|
26
|
+
* @returns Promise resolving to array of row objects
|
|
27
|
+
*/
|
|
28
|
+
static async readExcel<T = Record<string, any>>(filePath: string,sheetName?: string,): Promise<T[]>
|
|
20
29
|
{
|
|
21
30
|
try {
|
|
22
|
-
const filePath = this.resolvePath(fileName);
|
|
23
31
|
const workbook = new ExcelJS.Workbook();
|
|
24
32
|
await workbook.xlsx.readFile(filePath);
|
|
25
33
|
|
|
@@ -47,16 +55,22 @@ static async readExcel<T = Record<string, any>>(fileName: string,sheetName?: str
|
|
|
47
55
|
|
|
48
56
|
return data;
|
|
49
57
|
} catch (error) {
|
|
50
|
-
console.error(`Failed to read Excel: ${
|
|
58
|
+
console.error(`Failed to read Excel: ${filePath}`, error);
|
|
51
59
|
return [];
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Writes data into an Excel file.
|
|
65
|
+
* Creates sheet if not exists, otherwise appends rows.
|
|
66
|
+
*
|
|
67
|
+
* @param filePath - Path to Excel file
|
|
68
|
+
* @param data - Array of objects to write
|
|
69
|
+
* @param sheetName - Sheet name (default: Sheet1)
|
|
70
|
+
*/
|
|
71
|
+
static async writeExcel(filePath: string, data: Record<string, any>[], sheetName = 'Sheet1'): Promise<void>
|
|
57
72
|
{
|
|
58
73
|
try {
|
|
59
|
-
const filePath = this.resolvePath(fileName);
|
|
60
74
|
const workbook = new ExcelJS.Workbook();
|
|
61
75
|
|
|
62
76
|
// Load existing Excel if it exists
|
|
@@ -85,28 +99,40 @@ static async writeExcel(fileName: string, data: Record<string, any>[], sheetName
|
|
|
85
99
|
// Save workbook (preserves all sheets)
|
|
86
100
|
await workbook.xlsx.writeFile(filePath);
|
|
87
101
|
} catch (error) {
|
|
88
|
-
console.error(`Failed to write Excel: ${
|
|
102
|
+
console.error(`Failed to write Excel: ${filePath}`, error);
|
|
89
103
|
}
|
|
90
104
|
}
|
|
91
105
|
|
|
92
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Returns all sheet names from an Excel file.
|
|
108
|
+
*
|
|
109
|
+
* @param filePath - Path to Excel file
|
|
110
|
+
* @returns Promise resolving to array of sheet names
|
|
111
|
+
*/
|
|
112
|
+
static async getExcelSheetNames(filePath: string): Promise<string[]> {
|
|
93
113
|
try {
|
|
94
114
|
const workbook = new ExcelJS.Workbook();
|
|
95
|
-
await workbook.xlsx.readFile(
|
|
115
|
+
await workbook.xlsx.readFile(filePath);
|
|
96
116
|
return workbook.worksheets.map(ws => ws.name);
|
|
97
117
|
} catch (error) {
|
|
98
|
-
console.error(`Failed to read sheet names: ${
|
|
118
|
+
console.error(`Failed to read sheet names: ${filePath}`, error);
|
|
99
119
|
return [];
|
|
100
120
|
}
|
|
101
121
|
}
|
|
102
122
|
|
|
103
123
|
// ================== CSV ==================
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Reads a CSV file and returns data as array of objects.
|
|
127
|
+
*
|
|
128
|
+
* @template T
|
|
129
|
+
* @param filePath - Path to CSV file
|
|
130
|
+
* @param delimiter - Column delimiter (default: ,)
|
|
131
|
+
* @returns Array of objects
|
|
132
|
+
*/
|
|
133
|
+
static readCSV<T = Record<string, string>>(filePath: string, delimiter = ",",): T[]
|
|
134
|
+
{
|
|
108
135
|
try {
|
|
109
|
-
const filePath = this.resolvePath(fileName);
|
|
110
136
|
const content = fs.readFileSync(filePath, "utf-8").trim();
|
|
111
137
|
if (!content) return [];
|
|
112
138
|
const [header, ...rows] = content.split("\n");
|
|
@@ -119,63 +145,92 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
119
145
|
return record as T;
|
|
120
146
|
});
|
|
121
147
|
} catch (error) {
|
|
122
|
-
console.error(`Failed to read CSV: ${
|
|
148
|
+
console.error(`Failed to read CSV: ${filePath}`, error);
|
|
123
149
|
return [];
|
|
124
150
|
}
|
|
125
151
|
}
|
|
126
152
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Writes data into a CSV file.
|
|
155
|
+
*
|
|
156
|
+
* @param filePath - Path to CSV file
|
|
157
|
+
* @param data - Array of objects
|
|
158
|
+
* @param delimiter - Column delimiter
|
|
159
|
+
*/
|
|
160
|
+
static writeCSV(filePath: string,data: Record<string, any>[], delimiter = ",",): void
|
|
161
|
+
{
|
|
132
162
|
try {
|
|
133
163
|
if (!data.length) return;
|
|
134
|
-
const filePath = this.resolvePath(fileName);
|
|
135
164
|
const headers = Object.keys(data[0] ?? {}).join(delimiter);
|
|
136
165
|
const rows = data
|
|
137
166
|
.map((row) => Object.values(row).join(delimiter))
|
|
138
167
|
.join("\n");
|
|
139
168
|
fs.writeFileSync(filePath, `${headers}\n${rows}`, "utf-8");
|
|
140
169
|
} catch (error) {
|
|
141
|
-
console.error(`Failed to write CSV: ${
|
|
170
|
+
console.error(`Failed to write CSV: ${filePath}`, error);
|
|
142
171
|
}
|
|
143
172
|
}
|
|
144
173
|
|
|
145
174
|
// ================== JSON / XML ==================
|
|
146
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Reads JSON file and converts to object.
|
|
177
|
+
*
|
|
178
|
+
* @template T
|
|
179
|
+
* @param filePath - Path to JSON file
|
|
180
|
+
* @returns Parsed object or null
|
|
181
|
+
*/
|
|
182
|
+
static readJson<T>(filePath: string): T | null {
|
|
147
183
|
try {
|
|
148
|
-
const filePath = this.resolvePath(fileName);
|
|
149
184
|
return JSON.parse(fs.readFileSync(filePath, "utf-8")) as T;
|
|
150
185
|
} catch (error) {
|
|
151
|
-
console.error(`Failed to read JSON: ${
|
|
186
|
+
console.error(`Failed to read JSON: ${filePath}`, error);
|
|
152
187
|
return null;
|
|
153
188
|
}
|
|
154
189
|
}
|
|
155
190
|
|
|
156
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Reads XML file and converts to object.
|
|
193
|
+
*
|
|
194
|
+
* @template T
|
|
195
|
+
* @param filePath - Path to XML file
|
|
196
|
+
* @returns Parsed XML object or null
|
|
197
|
+
*/
|
|
198
|
+
static async readXml<T>(filePath: string): Promise<T | null> {
|
|
157
199
|
try {
|
|
158
|
-
const xml = fs.readFileSync(
|
|
200
|
+
const xml = fs.readFileSync(filePath, "utf-8");
|
|
159
201
|
return await parseStringPromise(xml, { explicitArray: false });
|
|
160
202
|
} catch (error) {
|
|
161
|
-
console.error(`Failed to read XML: ${
|
|
203
|
+
console.error(`Failed to read XML: ${filePath}`, error);
|
|
162
204
|
return null;
|
|
163
205
|
}
|
|
164
206
|
}
|
|
165
207
|
|
|
166
208
|
// ================== DATA HELPERS ==================
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Returns number of rows.
|
|
212
|
+
*/
|
|
167
213
|
static getRowCount<T>(data: T[]): number {
|
|
168
214
|
return data.length;
|
|
169
215
|
}
|
|
170
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Returns number of columns.
|
|
219
|
+
*/
|
|
171
220
|
static getColumnCount<T extends Record<string, any>>(data: T[]): number {
|
|
172
221
|
return Object.keys(data[0] ?? {}).length;
|
|
173
222
|
}
|
|
174
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Returns column headers.
|
|
226
|
+
*/
|
|
175
227
|
static getColumnHeaders<T extends Record<string, any>>(data: T[]): string[] {
|
|
176
228
|
return Object.keys(data[0] ?? {});
|
|
177
229
|
}
|
|
178
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Returns value of a specific cell.
|
|
233
|
+
*/
|
|
179
234
|
static getCellData<T extends Record<string, any>>(
|
|
180
235
|
data: T[],
|
|
181
236
|
row: number,
|
|
@@ -184,6 +239,9 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
184
239
|
return data[row]?.[column];
|
|
185
240
|
}
|
|
186
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Filters rows by column value.
|
|
244
|
+
*/
|
|
187
245
|
static select<T extends Record<string, any>>(
|
|
188
246
|
data: T[],
|
|
189
247
|
column: keyof T,
|
|
@@ -193,6 +251,10 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
193
251
|
}
|
|
194
252
|
|
|
195
253
|
// ================== FILE UTILS ==================
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Reads text file.
|
|
257
|
+
*/
|
|
196
258
|
static async readTextFile(filePath: string): Promise<string> {
|
|
197
259
|
try {
|
|
198
260
|
return await fs.promises.readFile(path.resolve(filePath), "utf-8");
|
|
@@ -202,6 +264,9 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
202
264
|
}
|
|
203
265
|
}
|
|
204
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Reads PDF file and extracts text.
|
|
269
|
+
*/
|
|
205
270
|
static async readPdfFile(filePath: string): Promise<string> {
|
|
206
271
|
try {
|
|
207
272
|
const buffer = await fs.promises.readFile(path.resolve(filePath));
|
|
@@ -213,6 +278,9 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
213
278
|
}
|
|
214
279
|
}
|
|
215
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Replaces text inside a file.
|
|
283
|
+
*/
|
|
216
284
|
static async editTextFile(
|
|
217
285
|
filePath: string,
|
|
218
286
|
search: string | RegExp,
|
|
@@ -228,6 +296,10 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
228
296
|
}
|
|
229
297
|
|
|
230
298
|
// ================== FOLDER UTILS ==================
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Counts files in a folder.
|
|
302
|
+
*/
|
|
231
303
|
static async getFileCount(folderPath: string): Promise<number> {
|
|
232
304
|
try {
|
|
233
305
|
const entries = await fs.promises.readdir(path.resolve(folderPath), {
|
|
@@ -240,6 +312,9 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
240
312
|
}
|
|
241
313
|
}
|
|
242
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Returns all file names in a folder.
|
|
317
|
+
*/
|
|
243
318
|
static async getAllFileNames(folderPath: string): Promise<string[]> {
|
|
244
319
|
try {
|
|
245
320
|
const entries = await fs.promises.readdir(path.resolve(folderPath), {
|
|
@@ -253,6 +328,26 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
253
328
|
}
|
|
254
329
|
|
|
255
330
|
// ================== PDF LINK ==================
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Extracts all URLs from a PDF file and navigates to one of them in the browser.
|
|
334
|
+
*
|
|
335
|
+
* Reads the PDF file, searches for HTTP/HTTPS links using regex,
|
|
336
|
+
* and opens the selected link in the provided Playwright page.
|
|
337
|
+
*
|
|
338
|
+
* @param page - Playwright Page object used for navigation
|
|
339
|
+
* @param filePath - Path to the PDF file
|
|
340
|
+
* @param index - Index of the link to open (default: 0 = first link)
|
|
341
|
+
*
|
|
342
|
+
* @returns Promise that resolves when navigation is complete
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf");
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* // Open second link from PDF
|
|
349
|
+
* await FileCommonUtils.clickLinkInsidePdf(page, "test-data/sample.pdf", 1);
|
|
350
|
+
*/
|
|
256
351
|
static async clickLinkInsidePdf(
|
|
257
352
|
page: any,
|
|
258
353
|
filePath: string,
|
|
@@ -265,6 +360,10 @@ static async getExcelSheetNames(fileName: string): Promise<string[]> {
|
|
|
265
360
|
}
|
|
266
361
|
|
|
267
362
|
// ================== COMMAND ==================
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Executes shell command in a folder.
|
|
366
|
+
*/
|
|
268
367
|
static async runCommand(
|
|
269
368
|
folderPath: string,
|
|
270
369
|
command: string,
|