@auxcode/auxta 1.3.125 → 1.3.126

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.
@@ -97,11 +97,45 @@ function createEmptyReport(body) {
97
97
  }
98
98
  function uploadStep(stepLog, scenarioName, screenshot, errMessage) {
99
99
  return __awaiter(this, void 0, void 0, function* () {
100
+ var _a;
100
101
  let scenarios = [];
101
102
  let token = yield auth();
102
103
  let lastStep = stepLog[stepLog.length - 1];
103
104
  const stepLogFormat = JSON.parse(JSON.stringify(stepLog));
104
105
  stepLogFormat.pop();
106
+ try {
107
+ for (let i = 0; i < stepLogFormat.length; i++) {
108
+ const st = stepLogFormat[i];
109
+ const emb = (_a = st === null || st === void 0 ? void 0 : st.result) === null || _a === void 0 ? void 0 : _a.embedding;
110
+ if (emb && typeof st.embeddings === 'undefined') {
111
+ st.embeddings = [emb];
112
+ }
113
+ }
114
+ }
115
+ catch (_b) { }
116
+ try {
117
+ const byTab = (errMessage === null || errMessage === void 0 ? void 0 : errMessage.byTab) || undefined;
118
+ if (byTab) {
119
+ for (let idx = 0; idx < stepLogFormat.length; idx++) {
120
+ const step = stepLogFormat[idx];
121
+ if (typeof (step === null || step === void 0 ? void 0 : step.name) === 'string') {
122
+ const m = step.name.match(/^(\d+)\s+Image/i);
123
+ if (m) {
124
+ const tabNum = Number(m[1]);
125
+ const tabErr = byTab[String(tabNum)] || byTab[tabNum];
126
+ if (tabErr) {
127
+ stepLogFormat[idx] = Object.assign({}, step, {
128
+ result: Object.assign({}, step.result, {
129
+ error_message: JSON.stringify(tabErr)
130
+ })
131
+ });
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ catch (_c) { }
105
139
  let output = (yield axios_1.default.post(config_1.config.auxtaURL + "create-steps", {
106
140
  json: {
107
141
  name: scenarioName,
@@ -1,8 +1,18 @@
1
1
  import { UploadModel } from "../auxta/models/upload.model";
2
2
  import puppeteer = require("puppeteer");
3
3
  export declare class Puppeteer {
4
+ private attachListenersToAllTabs;
5
+ getTabLogs(): {
6
+ [k: number]: {
7
+ console: string[];
8
+ https: string[];
9
+ debug: any[];
10
+ url?: string;
11
+ };
12
+ };
4
13
  defaultPage: puppeteer.Page;
5
14
  private browser;
15
+ private _tabLogs;
6
16
  private static setupHeader;
7
17
  startBrowser(): Promise<void>;
8
18
  close(): Promise<void>;
@@ -22,6 +22,109 @@ const config_1 = require("../auxta/configs/config");
22
22
  const start_suite_helper_1 = require("../auxta/utilities/start-suite.helper");
23
23
  const puppeteer = require("puppeteer");
24
24
  class Puppeteer {
25
+ constructor() {
26
+ this._tabLogs = {};
27
+ }
28
+ attachListenersToAllTabs(consoleMessage, httpsMessage, debugMessage) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ let tabSeq = 0;
31
+ const serializeArgs = (msg) => __awaiter(this, void 0, void 0, function* () {
32
+ const out = [];
33
+ try {
34
+ const args = msg.args && typeof msg.args === 'function' ? msg.args() : [];
35
+ for (const a of args) {
36
+ try {
37
+ out.push(yield a.jsonValue());
38
+ }
39
+ catch (_a) {
40
+ try {
41
+ out.push(String(a));
42
+ }
43
+ catch (_b) {
44
+ out.push('[unserializable]');
45
+ }
46
+ }
47
+ }
48
+ }
49
+ catch (_c) { }
50
+ return out;
51
+ });
52
+ const attach = (page, fixedIndex) => __awaiter(this, void 0, void 0, function* () {
53
+ const id = typeof fixedIndex === 'number' ? fixedIndex : (++tabSeq);
54
+ const suffix = ` [tab ${id}]`;
55
+ if (!this._tabLogs[id])
56
+ this._tabLogs[id] = { console: [], https: [], debug: [] };
57
+ page
58
+ .on('console', (message) => __awaiter(this, void 0, void 0, function* () {
59
+ try {
60
+ const entry = {
61
+ ts: Date.now(),
62
+ level: message.type && typeof message.type === 'function' ? message.type() : 'log',
63
+ text: (message.text && typeof message.text === 'function') ? message.text() : String(message)
64
+ };
65
+ try {
66
+ const loc = (message.location && typeof message.location === 'function') ? message.location() : undefined;
67
+ if (loc)
68
+ entry.location = loc;
69
+ }
70
+ catch (_a) { }
71
+ try {
72
+ entry.args = yield serializeArgs(message);
73
+ }
74
+ catch (_b) { }
75
+ this._tabLogs[id].debug.push(entry);
76
+ if (debugMessage)
77
+ debugMessage.push(entry);
78
+ const short = `${String(entry.level).substr(0, 3).toUpperCase()} ${entry.text}${suffix}`;
79
+ consoleMessage.push(short);
80
+ this._tabLogs[id].console.push(`${String(entry.level).substr(0, 3).toUpperCase()} ${entry.text}`);
81
+ }
82
+ catch (_c) {
83
+ }
84
+ }))
85
+ .on('pageerror', ({ message }) => {
86
+ consoleMessage.push(`${message}${suffix}`);
87
+ this._tabLogs[id].console.push(`${message}`);
88
+ })
89
+ .on('response', (response) => {
90
+ try {
91
+ const line = `${response.status()} ${response.url()}${suffix}`;
92
+ httpsMessage.push(line);
93
+ this._tabLogs[id].https.push(`${response.status()} ${response.url()}`);
94
+ this._tabLogs[id].url = response.url();
95
+ }
96
+ catch (_a) { }
97
+ })
98
+ .on('requestfailed', (request) => {
99
+ try {
100
+ const failure = request.failure && request.failure();
101
+ const err = failure ? failure.errorText : '';
102
+ const line = `${err !== null && err !== void 0 ? err : ''} ${request.url()}${suffix}`;
103
+ httpsMessage.push(line);
104
+ this._tabLogs[id].https.push(`${err !== null && err !== void 0 ? err : ''} ${request.url()}`);
105
+ this._tabLogs[id].url = request.url();
106
+ }
107
+ catch (_a) { }
108
+ });
109
+ });
110
+ const pages = yield this.browser.pages();
111
+ tabSeq = pages.length - 1;
112
+ yield Promise.all(pages.map((p, idx) => attach(p, idx)));
113
+ this.browser.on('targetcreated', (target) => __awaiter(this, void 0, void 0, function* () {
114
+ try {
115
+ if (typeof target.page === 'function') {
116
+ const page = yield target.page();
117
+ if (page)
118
+ yield attach(page);
119
+ }
120
+ }
121
+ catch (_a) { }
122
+ }));
123
+ });
124
+ }
125
+ getTabLogs() {
126
+ return this._tabLogs;
127
+ }
25
128
  static setupHeader(event, uploadModel) {
26
129
  let close = true;
27
130
  if (process.env.ENVIRONMENT !== 'LOCAL' && event) {
@@ -79,13 +182,10 @@ class Puppeteer {
79
182
  }
80
183
  });
81
184
  }
82
- initiateBrowser(consoleMessage, httpsMessage) {
185
+ initiateBrowser(consoleMessage, httpsMessage, debugStack) {
83
186
  return __awaiter(this, void 0, void 0, function* () {
84
187
  yield this.startBrowser();
85
- this.defaultPage.on('console', (message) => consoleMessage.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
86
- .on('pageerror', ({ message }) => consoleMessage.push(message))
87
- .on('response', (response) => httpsMessage.push(`${response.status()} ${response.url()}`))
88
- .on('requestfailed', (request) => { var _a; return httpsMessage.push(`${request.failure() !== null ? (_a = request.failure()) === null || _a === void 0 ? void 0 : _a.errorText : ""} ${request.url()}`); });
188
+ yield this.attachListenersToAllTabs(consoleMessage, httpsMessage, debugStack);
89
189
  });
90
190
  }
91
191
  logFail(consoleMessage) {
@@ -97,7 +197,9 @@ class Puppeteer {
97
197
  }
98
198
  run(event_1, callback_1) {
99
199
  return __awaiter(this, arguments, void 0, function* (event, callback, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel) {
200
+ var _a, _b, _c, _d;
100
201
  let close;
202
+ let debugStack = [];
101
203
  try {
102
204
  if (uploadModel === undefined) {
103
205
  uploadModel = AuxTA_1.default.getUploadModel();
@@ -113,7 +215,7 @@ class Puppeteer {
113
215
  let httpsMessage = [];
114
216
  log_service_1.default.push('When', log_service_1.default.tag, `Starting puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
115
217
  try {
116
- yield this.initiateBrowser(consoleMessage, httpsMessage);
218
+ yield this.initiateBrowser(consoleMessage, httpsMessage, debugStack);
117
219
  yield callback(event);
118
220
  log_service_1.default.push('When', log_service_1.default.tag, `Finished puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
119
221
  }
@@ -126,7 +228,7 @@ class Puppeteer {
126
228
  log_service_1.default.push('When', log_service_1.default.tag, `Retrying puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
127
229
  try {
128
230
  yield this.close();
129
- yield this.initiateBrowser(consoleMessage, httpsMessage);
231
+ yield this.initiateBrowser(consoleMessage, httpsMessage, debugStack);
130
232
  yield callback(event);
131
233
  log_service_1.default.push('When', log_service_1.default.tag, `Finished puppeteer process from the 2nd try`, status_of_step_1.StatusOfStep.PASSED);
132
234
  }
@@ -150,11 +252,24 @@ class Puppeteer {
150
252
  let url = this.defaultPage.url();
151
253
  if (close)
152
254
  yield this.close();
255
+ let activeTabIndex = undefined;
256
+ try {
257
+ const _pagesForFinish = yield this.defaultPage.browser().pages();
258
+ if (_pagesForFinish && _pagesForFinish.length)
259
+ activeTabIndex = _pagesForFinish.length - 1;
260
+ }
261
+ catch (_e) { }
262
+ const tabLogs = this.getTabLogs();
263
+ const chosen = (activeTabIndex !== undefined && tabLogs && tabLogs[activeTabIndex]) ? tabLogs[activeTabIndex] : undefined;
264
+ const perTabConsole = (_a = chosen === null || chosen === void 0 ? void 0 : chosen.console) !== null && _a !== void 0 ? _a : consoleMessage;
265
+ const perTabHttps = (_b = chosen === null || chosen === void 0 ? void 0 : chosen.https) !== null && _b !== void 0 ? _b : httpsMessage;
266
+ const perTabUrl = (_c = chosen === null || chosen === void 0 ? void 0 : chosen.url) !== null && _c !== void 0 ? _c : url;
267
+ const perTabDebug = (_d = chosen === null || chosen === void 0 ? void 0 : chosen.debug) !== null && _d !== void 0 ? _d : debugStack;
153
268
  return yield (0, report_hook_1.onTestEnd)(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
154
- currentPageUrl: url,
155
- console: consoleMessage,
156
- https: httpsMessage,
157
- error: errMessage
269
+ currentPageUrl: perTabUrl,
270
+ console: perTabConsole,
271
+ https: perTabHttps,
272
+ error: errMessage, debug: perTabDebug, byTab: this.getTabLogs()
158
273
  });
159
274
  }
160
275
  catch (e) {
@@ -188,13 +303,11 @@ class Puppeteer {
188
303
  }
189
304
  }
190
305
  let consoleStack = [];
306
+ let debugStack = [];
191
307
  try {
192
308
  yield log_service_1.default.push('When', log_service_1.default.tag, `Starting puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
193
309
  yield this.startBrowser();
194
- this.defaultPage.on('console', (message) => consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
195
- .on('pageerror', ({ message }) => consoleStack.push(message))
196
- .on('response', (response) => consoleStack.push(`${response.status()} ${response.url()}`))
197
- .on('requestfailed', (request) => { var _a; return consoleStack.push(`${request.failure() !== null ? (_a = request.failure()) === null || _a === void 0 ? void 0 : _a.errorText : ""} ${request.url()}`); });
310
+ yield this.attachListenersToAllTabs(consoleStack, consoleStack, debugStack);
198
311
  yield callback(event);
199
312
  log_service_1.default.push('When', log_service_1.default.tag, `Finished puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
200
313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.125",
3
+ "version": "1.3.126",
4
4
  "description": "",
5
5
  "main": "./build/AuxTA.js",
6
6
  "types": "./build/AuxTA.d.ts",