automation_model 1.0.441-dev → 1.0.441-stage

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/lib/network.js ADDED
@@ -0,0 +1,144 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ function _getNetworkFile(world = null, stable = null, context = null) {
4
+ let networkFile = null;
5
+ if (world && world.reportFolder) {
6
+ networkFile = path.join(world.reportFolder, "network.json");
7
+ }
8
+ else if (stable.reportFolder) {
9
+ networkFile = path.join(stable.reportFolder, "network.json");
10
+ }
11
+ else if (context && context.reportFolder) {
12
+ networkFile = path.join(context.reportFolder, "network.json");
13
+ }
14
+ else {
15
+ networkFile = "network.json";
16
+ }
17
+ return networkFile;
18
+ }
19
+ function registerDownloadEvent(page, world, context) {
20
+ if (page) {
21
+ let downloadPath = "./downloads";
22
+ if (world && world.downloadsPath) {
23
+ downloadPath = world.downloadsPath;
24
+ }
25
+ else if (context && context.downloadsPath) {
26
+ downloadPath = context.downloadsPath;
27
+ }
28
+ if (!fs.existsSync(downloadPath)) {
29
+ fs.mkdirSync(downloadPath);
30
+ }
31
+ page.on("download", async (download) => {
32
+ const suggestedFilename = download.suggestedFilename(); // Get the original file name
33
+ const filePath = `${downloadPath}/${suggestedFilename}`;
34
+ // Save the download with the original name
35
+ await download.saveAs(filePath);
36
+ console.log(`Downloaded file saved as: ${filePath}`);
37
+ });
38
+ }
39
+ }
40
+ function registerNetworkEvents(world, stable, context, page) {
41
+ const networkFile = _getNetworkFile(world, stable, context);
42
+ function saveNetworkData() {
43
+ if (context && context.networkData) {
44
+ fs.writeFileSync(networkFile, JSON.stringify(context.networkData, null, 2), "utf8");
45
+ }
46
+ }
47
+ if (!context) {
48
+ console.error("No context found to register network events");
49
+ return;
50
+ }
51
+ // Map to hold request start times and IDs
52
+ const requestTimes = new Map();
53
+ let requestIdCounter = 0;
54
+ if (page) {
55
+ if (!context.networkData) {
56
+ context.networkData = [];
57
+ const networkData = context.networkData;
58
+ // Event listener for when a request is made
59
+ page.on("request", (request) => {
60
+ const requestId = requestIdCounter++;
61
+ request.requestId = requestId; // Assign a unique ID to the request
62
+ const startTime = Date.now();
63
+ requestTimes.set(requestId, startTime);
64
+ // Initialize data for this request
65
+ networkData.push({
66
+ requestId,
67
+ requestStart: startTime,
68
+ requestUrl: request.url(),
69
+ method: request.method(),
70
+ status: "Pending",
71
+ responseTime: null,
72
+ responseReceived: null,
73
+ responseEnd: null,
74
+ size: null,
75
+ });
76
+ saveNetworkData();
77
+ });
78
+ // Event listener for when a response is received
79
+ page.on("response", async (response) => {
80
+ const request = response.request();
81
+ const requestId = request.requestId;
82
+ const receivedTime = Date.now();
83
+ // Find the corresponding data object
84
+ const data = networkData.find((item) => item.requestId === requestId);
85
+ if (data) {
86
+ data.status = response.status();
87
+ data.responseReceived = receivedTime;
88
+ saveNetworkData();
89
+ }
90
+ else {
91
+ console.error("No data found for request ID", requestId);
92
+ }
93
+ });
94
+ // Event listener for when a request is finished
95
+ page.on("requestfinished", async (request) => {
96
+ const requestId = request.requestId;
97
+ const endTime = Date.now();
98
+ const startTime = requestTimes.get(requestId);
99
+ const response = await request.response();
100
+ // Find the corresponding data object
101
+ const data = networkData.find((item) => item.requestId === requestId);
102
+ if (data) {
103
+ data.responseEnd = endTime;
104
+ data.responseTime = endTime - startTime;
105
+ // Get response size
106
+ try {
107
+ const body = await response.body();
108
+ data.size = body.length;
109
+ }
110
+ catch (e) {
111
+ data.size = 0;
112
+ }
113
+ saveNetworkData();
114
+ }
115
+ else {
116
+ console.error("No data found for request ID", requestId);
117
+ }
118
+ });
119
+ // Event listener for when a request fails
120
+ page.on("requestfailed", (request) => {
121
+ const requestId = request.requestId;
122
+ const endTime = Date.now();
123
+ const startTime = requestTimes.get(requestId);
124
+ // Find the corresponding data object
125
+ const data = networkData.find((item) => item.requestId === requestId);
126
+ if (data) {
127
+ data.responseEnd = endTime;
128
+ data.responseTime = endTime - startTime;
129
+ data.status = "Failed";
130
+ data.size = 0;
131
+ saveNetworkData();
132
+ }
133
+ else {
134
+ console.error("No data found for request ID", requestId);
135
+ }
136
+ });
137
+ }
138
+ }
139
+ else {
140
+ console.error("No page found to register network events");
141
+ }
142
+ }
143
+ export { registerNetworkEvents, registerDownloadEvent };
144
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/network.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,SAAS,eAAe,CAAC,QAAa,IAAI,EAAE,SAAc,IAAI,EAAE,UAAe,IAAI;IACjF,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,KAAK,IAAI,KAAK,CAAC,YAAY,EAAE;QAC/B,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;KAC7D;SAAM,IAAI,MAAM,CAAC,YAAY,EAAE;QAC9B,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;KAC9D;SAAM,IAAI,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE;QAC1C,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;KAC/D;SAAM;QACL,WAAW,GAAG,cAAc,CAAC;KAC9B;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AACD,SAAS,qBAAqB,CAAC,IAAS,EAAE,KAAU,EAAE,OAAY;IAChE,IAAI,IAAI,EAAE;QACR,IAAI,YAAY,GAAG,aAAa,CAAC;QACjC,IAAI,KAAK,IAAI,KAAK,CAAC,aAAa,EAAE;YAChC,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC;SACpC;aAAM,IAAI,OAAO,IAAI,OAAO,CAAC,aAAa,EAAE;YAC3C,YAAY,GAAG,OAAO,CAAC,aAA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CAAC;gBAC3B,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBAE9C,qCAAqC;gBACrC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;gBAE3E,IAAI,IAAI,EAAE;oBACR,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;oBAC3B,IAAI,CAAC,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;oBACxC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;oBACvB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;oBACd,eAAe,EAAE,CAAC;iBACnB;qBAAM;oBACL,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,SAAS,CAAC,CAAC;iBAC1D;YACH,CAAC,CAAC,CAAC;SACJ;KACF;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC3D;AACH,CAAC;AACD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,CAAC"}
@@ -1,19 +1,25 @@
1
1
  import type { Browser, Page } from "playwright";
2
2
  type Params = Record<string, string>;
3
+ export declare const apps: {};
3
4
  declare class StableBrowser {
4
5
  browser: Browser;
5
6
  page: Page;
6
7
  logger: any;
7
8
  context: any;
9
+ world?: any;
8
10
  project_path: null;
9
11
  webLogFile: null;
12
+ networkLogger: null;
10
13
  configuration: null;
11
- constructor(browser: Browser, page: Page, logger?: any, context?: any);
14
+ appName: string;
15
+ constructor(browser: Browser, page: Page, logger?: any, context?: any, world?: any);
16
+ registerEventListeners(context: any): void;
17
+ switchApp(appName: any): Promise<void>;
18
+ _copyContext(from: any, to: any): void;
12
19
  getWebLogFile(logFolder: string): string;
13
- registerConsoleLogListener(page: Page, context: any, logFile: string): void;
14
- registerRequestListener(): void;
20
+ registerConsoleLogListener(page: Page, context: any): void;
21
+ registerRequestListener(page: Page, context: any, logFile: string): void;
15
22
  goto(url: string): Promise<void>;
16
- _validateSelectors(selectors: any): void;
17
23
  _fixUsingParams(text: any, _params: Params): any;
18
24
  _fixLocatorUsingParams(locator: any, _params: Params): any;
19
25
  _isObject(value: any): any;
@@ -25,20 +31,24 @@ declare class StableBrowser {
25
31
  closeUnexpectedPopups(info: any, _params: any): Promise<{
26
32
  rerun: boolean;
27
33
  }>;
28
- _locate(selectors: any, info: any, _params?: Params, timeout?: number): Promise<any>;
34
+ _locate(selectors: any, info: any, _params?: Params, timeout: any): Promise<any>;
35
+ _findFrameScope(selectors: any, timeout: number | undefined, info: any): Promise<any>;
36
+ _getDocumentBody(selectors: any, timeout: number | undefined, info: any): Promise<any>;
29
37
  _locate_internal(selectors: any, info: any, _params?: Params, timeout?: number): Promise<any>;
30
38
  _scanLocatorsGroup(locatorsGroup: any, scope: any, _params: any, info: any, visibleOnly: any): Promise<{
31
39
  foundElements: any[];
32
40
  }>;
33
- click(selectors: any, _params?: Params, options?: {}, world?: null): Promise<{}>;
34
- setCheck(selectors: any, checked?: boolean, _params?: Params, options?: {}, world?: null): Promise<{}>;
35
- hover(selectors: any, _params?: Params, options?: {}, world?: null): Promise<{}>;
36
- selectOption(selectors: any, values: any, _params?: null, options?: {}, world?: null): Promise<{}>;
37
- type(_value: any, _params?: null, options?: {}, world?: null): Promise<{}>;
41
+ simpleClick(elementDescription: any, _params?: Params, options?: {}, world?: null): Promise<void>;
42
+ simpleClickType(elementDescription: any, value: any, _params?: Params, options?: {}, world?: null): Promise<void>;
43
+ click(selectors: any, _params?: Params, options?: {}, world?: null): Promise<any>;
44
+ setCheck(selectors: any, checked?: boolean, _params?: Params, options?: {}, world?: null): Promise<any>;
45
+ hover(selectors: any, _params?: Params, options?: {}, world?: null): Promise<any>;
46
+ selectOption(selectors: any, values: any, _params?: null, options?: {}, world?: null): Promise<any>;
47
+ type(_value: any, _params?: null, options?: {}, world?: null): Promise<any>;
38
48
  setInputValue(selectors: any, value: any, _params?: null, options?: {}, world?: null): Promise<void>;
39
49
  setDateTime(selectors: any, value: any, format?: null, enter?: boolean, _params?: null, options?: {}, world?: null): Promise<void>;
40
- clickType(selectors: any, _value: any, enter?: boolean, _params?: null, options?: {}, world?: null): Promise<{}>;
41
- fill(selectors: any, value: any, enter?: boolean, _params?: null, options?: {}, world?: null): Promise<{}>;
50
+ clickType(selectors: any, _value: any, enter?: boolean, _params?: null, options?: {}, world?: null): Promise<any>;
51
+ fill(selectors: any, value: any, enter?: boolean, _params?: null, options?: {}, world?: null): Promise<any>;
42
52
  getText(selectors: any, _params?: null, options?: {}, info?: {}, world?: null): Promise<{
43
53
  text: any;
44
54
  screenshotId: any;
@@ -65,8 +75,8 @@ declare class StableBrowser {
65
75
  value: any;
66
76
  element?: undefined;
67
77
  }>;
68
- containsPattern(selectors: any, pattern: any, text: any, _params?: null, options?: {}, world?: null): Promise<{}>;
69
- containsText(selectors: any, text: any, climb: any, _params?: null, options?: {}, world?: null): Promise<{}>;
78
+ containsPattern(selectors: any, pattern: any, text: any, _params?: null, options?: {}, world?: null): Promise<any>;
79
+ containsText(selectors: any, text: any, climb: any, _params?: null, options?: {}, world?: null): Promise<any>;
70
80
  _getDataFile(world?: null): string;
71
81
  waitForUserInput(message: any, world?: null): Promise<void>;
72
82
  setTestData(testData: any, world?: null): void;
@@ -81,7 +91,7 @@ declare class StableBrowser {
81
91
  getTestData(world?: null): {};
82
92
  _screenShot(options?: {}, world?: null, info?: null): Promise<{}>;
83
93
  takeScreenshot(screenshotPath: any): Promise<any>;
84
- verifyElementExistInPage(selectors: any, _params?: null, options?: {}, world?: null): Promise<{}>;
94
+ verifyElementExistInPage(selectors: any, _params?: null, options?: {}, world?: null): Promise<any>;
85
95
  extractAttribute(selectors: any, attribute: any, variable: any, _params?: null, options?: {}, world?: null): Promise<{}>;
86
96
  extractEmailData(emailAddress: any, options: any, world: any): Promise<{
87
97
  emailUrl: any;
@@ -95,7 +105,7 @@ declare class StableBrowser {
95
105
  verifyTableData(selectors: any, data: any, _params?: null, options?: {}, world?: null): Promise<void>;
96
106
  getTableData(selectors: any, _params?: null, options?: {}, world?: null): Promise<any>;
97
107
  analyzeTable(selectors: any, query: any, operator: any, value: any, _params?: null, options?: {}, world?: null): Promise<{}>;
98
- _replaceWithLocalData(value: any, world: any, _decrypt?: boolean, totpWait?: boolean): Promise<any>;
108
+ _replaceWithLocalData(value: any, world: any, _decrypt?: boolean, totpWait?: boolean): Promise<string>;
99
109
  _getLoadTimeout(options: any): number;
100
110
  waitForPageLoad(options?: {}, world?: null): Promise<void>;
101
111
  closePage(options?: {}, world?: null): Promise<void>;