@auxcode/auxta 1.3.133 → 1.3.135

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.
@@ -61,7 +61,7 @@ class LogSteps {
61
61
  };
62
62
  }
63
63
  push(keyword, tag, name, status, screenshot = new Uint8Array(), imageCompareKey = '') {
64
- console.log(`System log -- status: ${status} -- tag: ${tag} -- : ${name} `);
64
+ console.log(`${new Date().toISOString()} System log -- status: ${status} -- tag: ${tag} -- : ${name} `);
65
65
  this.statusCounter[status]++;
66
66
  const currentStep = new Date().getTime();
67
67
  if (screenshot.byteLength != 0) {
@@ -264,7 +264,7 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
264
264
  }
265
265
  catch (e) {
266
266
  this.log('Then', `I wait for the password step of the microsoft login`, AuxTA_1.StepStatus.FAILED);
267
- throw new Error(`I wait for the password step of the microsoft login`);
267
+ throw new Error(`I wait for the password step of the microsoft login (${yield (0, extend_default_page_1.describePageFailure)(loginPage, e)})`);
268
268
  }
269
269
  yield this.failOnMicrosoftLoginError(loginPage, login_error);
270
270
  const accountTypeTile = yield loginPage.$(account_type_tile);
@@ -286,7 +286,7 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
286
286
  }
287
287
  catch (e) {
288
288
  this.log('Then', `I type password into the ${password_input}`, AuxTA_1.StepStatus.FAILED);
289
- throw new Error(`I type password into the ${password_input}`);
289
+ throw new Error(`I type password into the ${password_input} (${yield (0, extend_default_page_1.describePageFailure)(loginPage, e)})`);
290
290
  }
291
291
  yield loginPage.keyboard.press('Enter');
292
292
  if (staySignIn) {
@@ -306,7 +306,7 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
306
306
  }
307
307
  catch (e) {
308
308
  this.log('Then', `I wait for the Stay signed in prompt of the microsoft login`, AuxTA_1.StepStatus.FAILED);
309
- throw new Error(`I wait for the Stay signed in prompt of the microsoft login`);
309
+ throw new Error(`I wait for the Stay signed in prompt of the microsoft login (${yield (0, extend_default_page_1.describePageFailure)(loginPage, e)})`);
310
310
  }
311
311
  if (outcome === 'error') {
312
312
  yield this.failOnMicrosoftLoginError(loginPage, login_error);
@@ -1,3 +1,4 @@
1
+ export declare function describePageFailure(page: any, error: any): Promise<string>;
1
2
  export declare class ExtendDefaultPage {
2
3
  defaultTimeout: number;
3
4
  extend_page_functions(page: any, time?: number): Promise<any>;
@@ -13,9 +13,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ExtendDefaultPage = void 0;
16
+ exports.describePageFailure = describePageFailure;
16
17
  const log_service_1 = __importDefault(require("../../auxta/services/log.service"));
17
18
  const status_of_step_1 = require("../../auxta/enums/status-of.step");
18
19
  const config_1 = require("../../auxta/configs/config");
20
+ function describePageFailure(page, error) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ var _a, _b, _c;
23
+ const reason = String((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error).split('\n')[0];
24
+ let url = '';
25
+ let text = '';
26
+ try {
27
+ url = page.url();
28
+ text = yield page.evaluate(() => { var _a, _b; return ((_b = (_a = document.body) === null || _a === void 0 ? void 0 : _a.innerText) !== null && _b !== void 0 ? _b : '').replace(/\s+/g, ' ').trim().slice(0, 300); });
29
+ }
30
+ catch (e) {
31
+ text = `(page text unavailable: ${String((_b = e === null || e === void 0 ? void 0 : e.message) !== null && _b !== void 0 ? _b : e).split('\n')[0]})`;
32
+ }
33
+ const failedRequests = ((_c = page.__auxtaFailedRequests) !== null && _c !== void 0 ? _c : []).slice(-10).join(', ') || 'none';
34
+ const details = `reason: ${reason} | url: ${url} | page text: ${text} | failed requests: ${failedRequests}`;
35
+ console.log(`${new Date().toISOString()} Failure details -- ${details}`);
36
+ return details;
37
+ });
38
+ }
19
39
  class ExtendDefaultPage {
20
40
  constructor() {
21
41
  this.defaultTimeout = config_1.config.timeout;
@@ -23,6 +43,16 @@ class ExtendDefaultPage {
23
43
  extend_page_functions(page_1) {
24
44
  return __awaiter(this, arguments, void 0, function* (page, time = this.defaultTimeout) {
25
45
  this.defaultTimeout = config_1.config.timeout;
46
+ if (!page.__auxtaFailedRequests) {
47
+ page.__auxtaFailedRequests = [];
48
+ page.on('requestfailed', (request) => {
49
+ var _a, _b;
50
+ const entry = `${new Date().toISOString()} ${(_b = (_a = request.failure()) === null || _a === void 0 ? void 0 : _a.errorText) !== null && _b !== void 0 ? _b : 'unknown error'} ${request.url()}`;
51
+ page.__auxtaFailedRequests.push(entry);
52
+ if (page.__auxtaFailedRequests.length > 50)
53
+ page.__auxtaFailedRequests.shift();
54
+ });
55
+ }
26
56
  const { goto: original_goto, click: original_click, type: original_type, waitForNetworkIdle: original_waitForNetworkIdle } = page;
27
57
  page.goto = function goto(url, options) {
28
58
  log_service_1.default.push('Then', log_service_1.default.tag, `I go to the '${url}' page`, status_of_step_1.StatusOfStep.PASSED);
@@ -44,7 +74,7 @@ class ExtendDefaultPage {
44
74
  catch (e) {
45
75
  const msg = `I click on the '${selector}'`;
46
76
  log_service_1.default.push('Then', log_service_1.default.tag, msg, status_of_step_1.StatusOfStep.FAILED);
47
- throw new Error(msg);
77
+ throw new Error(`${msg} (${yield describePageFailure(page, e)})`);
48
78
  }
49
79
  });
50
80
  };
@@ -59,7 +89,7 @@ class ExtendDefaultPage {
59
89
  }
60
90
  catch (e) {
61
91
  log_service_1.default.push('Then', log_service_1.default.tag, message, status_of_step_1.StatusOfStep.FAILED);
62
- throw new Error(message);
92
+ throw new Error(`${message} (${yield describePageFailure(page, e)})`);
63
93
  }
64
94
  return result;
65
95
  });
@@ -80,7 +110,7 @@ class ExtendDefaultPage {
80
110
  catch (e) {
81
111
  const msg = `I type '${value}' into the '${field}' field`;
82
112
  log_service_1.default.push('Then', log_service_1.default.tag, msg, status_of_step_1.StatusOfStep.FAILED);
83
- throw new Error(msg);
113
+ throw new Error(`${msg} (${yield describePageFailure(page, e)})`);
84
114
  }
85
115
  });
86
116
  };
@@ -15,6 +15,7 @@ export declare class Puppeteer {
15
15
  private _tabLogs;
16
16
  private static setupHeader;
17
17
  startBrowser(): Promise<void>;
18
+ private reloadIfBlank;
18
19
  close(): Promise<void>;
19
20
  private initiateBrowser;
20
21
  private logFail;
@@ -171,6 +171,24 @@ class Puppeteer {
171
171
  yield AuxTA_1.default.extend_page_functions(this.defaultPage);
172
172
  yield this.defaultPage.goto(config_1.config.baseURL, { waitUntil: 'networkidle0' });
173
173
  yield this.defaultPage.waitForNetworkIdle();
174
+ yield this.reloadIfBlank(this.defaultPage);
175
+ });
176
+ }
177
+ reloadIfBlank(page_1) {
178
+ return __awaiter(this, arguments, void 0, function* (page, retries = 2, renderTimeout = 10000) {
179
+ var _a;
180
+ for (let attempt = 1; attempt <= retries; attempt++) {
181
+ const rendered = yield page.waitForFunction(() => !!document.body && (document.body.innerText.trim().length > 0 || !!document.querySelector('button, input, a[href]')), { timeout: renderTimeout, polling: 500 }).then(() => true, () => false);
182
+ if (rendered)
183
+ return;
184
+ const failedRequests = ((_a = page.__auxtaFailedRequests) !== null && _a !== void 0 ? _a : []).slice(-10).join(', ') || 'none';
185
+ const message = `The page ${page.url()} stayed blank after loading, reloading it (attempt ${attempt} of ${retries}, failed requests: ${failedRequests})`;
186
+ console.log(`${new Date().toISOString()} ${message}`);
187
+ log_service_1.default.push('When', log_service_1.default.tag, message, status_of_step_1.StatusOfStep.LOG);
188
+ page.__auxtaFailedRequests = [];
189
+ yield page.reload({ waitUntil: 'networkidle0' });
190
+ yield page.waitForNetworkIdle();
191
+ }
174
192
  });
175
193
  }
176
194
  close() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.133",
3
+ "version": "1.3.135",
4
4
  "description": "",
5
5
  "main": "./build/AuxTA.js",
6
6
  "types": "./build/AuxTA.d.ts",
@@ -9,8 +9,8 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "tsc": "tsc -p tsconfig.json",
12
- "prepublish": "tsc",
13
- "test": "npm run prepublish & node ./build/AuxTA.js"
12
+ "prepublishOnly": "tsc -p tsconfig.json --incremental false",
13
+ "test": "npm run tsc && node ./build/AuxTA.js"
14
14
  },
15
15
  "author": "auxcode",
16
16
  "license": "ISC",