@auxcode/auxta 1.3.118 → 1.3.120
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/build/auxta/helpers/console-debug.helper.d.ts +14 -0
- package/build/auxta/helpers/console-debug.helper.js +58 -0
- package/build/auxta/hooks/report.hook.js +22 -1
- package/build/auxta/utilities/screenshot.helper.js +1 -1
- package/build/macros/helpers/code.helper.js +1 -1
- package/build/puppeteer/puppeteer.d.ts +1 -0
- package/build/puppeteer/puppeteer.js +49 -3
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import puppeteer = require("puppeteer");
|
|
2
|
+
export type UserConsoleEntry = {
|
|
3
|
+
level: puppeteer.ConsoleMessageType;
|
|
4
|
+
text: string;
|
|
5
|
+
args: string[];
|
|
6
|
+
location?: {
|
|
7
|
+
url?: string;
|
|
8
|
+
lineNumber?: number;
|
|
9
|
+
columnNumber?: number;
|
|
10
|
+
};
|
|
11
|
+
pageUrl: string;
|
|
12
|
+
ts: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function attachUserConsoleCapture(page: puppeteer.Page, push: (e: UserConsoleEntry) => void): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.attachUserConsoleCapture = attachUserConsoleCapture;
|
|
13
|
+
function safeStringify(v) {
|
|
14
|
+
if (typeof v === "string")
|
|
15
|
+
return v;
|
|
16
|
+
try {
|
|
17
|
+
return JSON.stringify(v);
|
|
18
|
+
}
|
|
19
|
+
catch (_a) {
|
|
20
|
+
return String(v);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function attachUserConsoleCapture(page, push) {
|
|
24
|
+
page.on("console", (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const level = msg.type();
|
|
26
|
+
if (!["debug", "log", "info", "warning", "error"].includes(level))
|
|
27
|
+
return;
|
|
28
|
+
const loc = typeof msg.location === "function" ? msg.location() : undefined;
|
|
29
|
+
const args = [];
|
|
30
|
+
try {
|
|
31
|
+
const handles = msg.args();
|
|
32
|
+
for (let i = 0; i < Math.min(handles.length, 5); i++) {
|
|
33
|
+
try {
|
|
34
|
+
const val = yield handles[i].jsonValue();
|
|
35
|
+
args.push(safeStringify(val));
|
|
36
|
+
}
|
|
37
|
+
catch (_a) {
|
|
38
|
+
try {
|
|
39
|
+
const s = yield handles[i].evaluate((x) => Object.prototype.toString.call(x));
|
|
40
|
+
args.push(String(s));
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
args.push(String(handles[i]));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (_c) { }
|
|
49
|
+
push({
|
|
50
|
+
level: level,
|
|
51
|
+
text: msg.text(),
|
|
52
|
+
args,
|
|
53
|
+
location: loc,
|
|
54
|
+
pageUrl: page.url(),
|
|
55
|
+
ts: Date.now(),
|
|
56
|
+
});
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -21,12 +32,22 @@ const start_suite_helper_1 = require("../utilities/start-suite.helper");
|
|
|
21
32
|
const status_of_step_1 = require("../enums/status-of.step");
|
|
22
33
|
function onTestEnd(body, featureName, scenarioName, statusCode, screenshotBuffer, errMessage) {
|
|
23
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a, _b;
|
|
24
36
|
let isFinal = false;
|
|
25
37
|
if (process.env.ENVIRONMENT == "LIVE") {
|
|
26
38
|
console.log('--- Uploading scenario and feature for AUXTA report ---');
|
|
27
39
|
const stepsArr = log_service_1.default.returnScenarioReport();
|
|
28
40
|
try {
|
|
29
|
-
const
|
|
41
|
+
const _c = errMessage || {}, { debugCandidate = [] } = _c, restErrors = __rest(_c, ["debugCandidate"]);
|
|
42
|
+
let errorPayload = restErrors;
|
|
43
|
+
const failed = statusCode !== 200;
|
|
44
|
+
const hasScreenshot = !!(screenshotBuffer &&
|
|
45
|
+
((typeof Buffer !== 'undefined' && ((_b = (_a = Buffer).isBuffer) === null || _b === void 0 ? void 0 : _b.call(_a, screenshotBuffer)) && screenshotBuffer.length > 0) ||
|
|
46
|
+
(typeof screenshotBuffer.byteLength === 'number' && screenshotBuffer.byteLength > 0)));
|
|
47
|
+
if (failed && hasScreenshot && Array.isArray(debugCandidate) && debugCandidate.length) {
|
|
48
|
+
errorPayload = Object.assign(Object.assign({}, restErrors), { debug: debugCandidate });
|
|
49
|
+
}
|
|
50
|
+
const stepRes = yield (0, report_service_1.uploadStep)(stepsArr, scenarioName, screenshotBuffer, errorPayload);
|
|
30
51
|
const scenarioRes = yield (0, report_service_1.uploadScenario)(stepRes, featureName, (0, path_1.basename)(__filename), (statusCode != 200));
|
|
31
52
|
const scenario = {
|
|
32
53
|
scenarioId: scenarioRes.scenarioRef,
|
|
@@ -31,7 +31,7 @@ function captureScreenshot() {
|
|
|
31
31
|
while (count <= RETRY_NUMBERS) {
|
|
32
32
|
try {
|
|
33
33
|
const lastPage = pages[pages.length - 1] || puppeteer_1.default.defaultPage;
|
|
34
|
-
log_service_1.default.push('When', log_service_1.default.tag, `Just before retry ${count}`, status_of_step_1.default.PASSED);
|
|
34
|
+
log_service_1.default.push('When', log_service_1.default.tag, `Just before retry ${count}. Pages: ${pages.length}. Is last page closed?: ${lastPage.isClosed()}`, status_of_step_1.default.PASSED);
|
|
35
35
|
const screenshotBuffer = yield lastPage.screenshot({
|
|
36
36
|
captureBeyondViewport: false,
|
|
37
37
|
encoding: 'binary'
|
|
@@ -172,7 +172,7 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
|
|
|
172
172
|
const url = page.url();
|
|
173
173
|
let message = `I am on the ${selector} page`;
|
|
174
174
|
if (!url.includes(selector)) {
|
|
175
|
-
log_service_1.default.push('And', log_service_1.default.tag, message
|
|
175
|
+
log_service_1.default.push('And', log_service_1.default.tag, `${message}. URL: ${url}`, status_of_step_1.StatusOfStep.FAILED);
|
|
176
176
|
throw new Error(message);
|
|
177
177
|
}
|
|
178
178
|
log_service_1.default.push('And', log_service_1.default.tag, message, status_of_step_1.StatusOfStep.PASSED);
|
|
@@ -21,7 +21,11 @@ const status_of_step_1 = require("../auxta/enums/status-of.step");
|
|
|
21
21
|
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
|
+
const console_debug_helper_1 = require("../auxta/helpers/console-debug.helper");
|
|
24
25
|
class Puppeteer {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.userConsoleMessages = [];
|
|
28
|
+
}
|
|
25
29
|
static setupHeader(event, uploadModel) {
|
|
26
30
|
let close = true;
|
|
27
31
|
if (process.env.ENVIRONMENT !== 'LOCAL' && event) {
|
|
@@ -57,7 +61,6 @@ class Puppeteer {
|
|
|
57
61
|
executablePath: puppeteer.default.executablePath(),
|
|
58
62
|
args,
|
|
59
63
|
env,
|
|
60
|
-
protocolTimeout: 360000,
|
|
61
64
|
ignoreDefaultArgs: ["--enable-automation"],
|
|
62
65
|
defaultViewport: process.env.ENVIRONMENT === 'LOCAL' ? null : {
|
|
63
66
|
width: config_1.config.screenWidth,
|
|
@@ -83,10 +86,50 @@ class Puppeteer {
|
|
|
83
86
|
initiateBrowser(consoleMessage, httpsMessage) {
|
|
84
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
88
|
yield this.startBrowser();
|
|
86
|
-
this.
|
|
89
|
+
this.browser.on('targetcreated', (target) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
try {
|
|
91
|
+
if (target.type() !== 'page')
|
|
92
|
+
return;
|
|
93
|
+
const page = yield target.page();
|
|
94
|
+
if (!page)
|
|
95
|
+
return;
|
|
96
|
+
(0, console_debug_helper_1.attachUserConsoleCapture)(page, (entry) => {
|
|
97
|
+
this.userConsoleMessages.push(entry);
|
|
98
|
+
if (this.userConsoleMessages.length > 300)
|
|
99
|
+
this.userConsoleMessages.shift();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (_a) { }
|
|
103
|
+
}));
|
|
104
|
+
this.defaultPage.on('console', (msg) => {
|
|
105
|
+
var _a;
|
|
106
|
+
const t = typeof msg.type === 'function' ? msg.type() : (msg.type || '');
|
|
107
|
+
if (t !== 'error')
|
|
108
|
+
return;
|
|
109
|
+
let loc = '';
|
|
110
|
+
try {
|
|
111
|
+
const l = typeof msg.location === 'function' ? msg.location() : undefined;
|
|
112
|
+
if (l) {
|
|
113
|
+
const at = `${l.url || ''}` +
|
|
114
|
+
`${l.lineNumber != null ? ':' + l.lineNumber : ''}` +
|
|
115
|
+
`${l.columnNumber != null ? ':' + l.columnNumber : ''}`;
|
|
116
|
+
loc = at ? ` @ ${at}` : '';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (_b) { }
|
|
120
|
+
const text = typeof msg.text === 'function' ? msg.text() : String((_a = msg.text) !== null && _a !== void 0 ? _a : '');
|
|
121
|
+
if (text === 'pages' || /^\d+$/.test(text))
|
|
122
|
+
return;
|
|
123
|
+
consoleMessage.push(`${String(t).toUpperCase()} ${text}${loc}`);
|
|
124
|
+
})
|
|
87
125
|
.on('pageerror', ({ message }) => consoleMessage.push(message))
|
|
88
126
|
.on('response', (response) => httpsMessage.push(`${response.status()} ${response.url()}`))
|
|
89
127
|
.on('requestfailed', (request) => { var _a; return httpsMessage.push(`${request.failure() !== null ? (_a = request.failure()) === null || _a === void 0 ? void 0 : _a.errorText : ""} ${request.url()}`); });
|
|
128
|
+
(0, console_debug_helper_1.attachUserConsoleCapture)(this.defaultPage, (entry) => {
|
|
129
|
+
this.userConsoleMessages.push(entry);
|
|
130
|
+
if (this.userConsoleMessages.length > 300)
|
|
131
|
+
this.userConsoleMessages.shift();
|
|
132
|
+
});
|
|
90
133
|
});
|
|
91
134
|
}
|
|
92
135
|
logFail(consoleMessage) {
|
|
@@ -151,17 +194,20 @@ class Puppeteer {
|
|
|
151
194
|
let url = this.defaultPage.url();
|
|
152
195
|
if (close)
|
|
153
196
|
yield this.close();
|
|
197
|
+
const debugCandidate = this.userConsoleMessages.slice(-150);
|
|
154
198
|
return yield (0, report_hook_1.onTestEnd)(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
|
|
155
199
|
currentPageUrl: url,
|
|
156
200
|
console: consoleMessage,
|
|
157
201
|
https: httpsMessage,
|
|
158
|
-
error: errMessage
|
|
202
|
+
error: errMessage,
|
|
203
|
+
debugCandidate
|
|
159
204
|
});
|
|
160
205
|
}
|
|
161
206
|
catch (e) {
|
|
162
207
|
console.log("Lib error:", e);
|
|
163
208
|
}
|
|
164
209
|
finally {
|
|
210
|
+
this.userConsoleMessages = [];
|
|
165
211
|
log_service_1.default.clear();
|
|
166
212
|
}
|
|
167
213
|
});
|