@auxcode/auxta 0.5.3 → 0.5.7
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/cjs/AuxTA.d.ts +43 -0
- package/build/cjs/AuxTA.js +122 -0
- package/build/cjs/auxta/configs/config.d.ts +51 -0
- package/build/cjs/auxta/configs/config.js +66 -0
- package/build/cjs/auxta/enums/status-of.step.d.ts +7 -0
- package/build/cjs/auxta/enums/status-of.step.js +11 -0
- package/build/cjs/auxta/helpers/response.helper.d.ts +10 -0
- package/build/cjs/auxta/helpers/response.helper.js +15 -0
- package/build/cjs/auxta/helpers/start.helper.d.ts +1 -0
- package/build/cjs/auxta/helpers/start.helper.js +17 -0
- package/build/cjs/auxta/hooks/report.hook.d.ts +4 -0
- package/build/cjs/auxta/hooks/report.hook.js +53 -0
- package/build/cjs/auxta/models/upload.model.d.ts +20 -0
- package/build/cjs/auxta/models/upload.model.js +47 -0
- package/build/cjs/auxta/services/log.service.d.ts +26 -0
- package/build/cjs/auxta/services/log.service.js +47 -0
- package/build/cjs/auxta/services/report.service.d.ts +36 -0
- package/build/cjs/auxta/services/report.service.js +141 -0
- package/build/cjs/auxta/services/runtime.service.d.ts +16 -0
- package/build/cjs/auxta/services/runtime.service.js +41 -0
- package/build/cjs/auxta/utilities/runtime.helper.d.ts +15 -0
- package/build/cjs/auxta/utilities/runtime.helper.js +19 -0
- package/build/cjs/auxta/utilities/screenshot.helper.d.ts +2 -0
- package/build/cjs/auxta/utilities/screenshot.helper.js +25 -0
- package/build/cjs/auxta/utilities/start-suite.helper.d.ts +1 -0
- package/build/cjs/auxta/utilities/start-suite.helper.js +21 -0
- package/build/cjs/macros/helpers/code.helper.d.ts +22 -0
- package/build/cjs/macros/helpers/code.helper.js +165 -0
- package/build/cjs/puppeteer/puppeteer.d.ts +13 -0
- package/build/cjs/puppeteer/puppeteer.js +143 -0
- package/build/esm/AuxTA.d.ts +43 -0
- package/{src/AuxTA.ts → build/esm/AuxTA.js} +39 -46
- package/build/esm/auxta/configs/config.d.ts +51 -0
- package/build/esm/auxta/configs/config.js +61 -0
- package/build/esm/auxta/enums/status-of.step.d.ts +7 -0
- package/build/esm/auxta/enums/status-of.step.js +8 -0
- package/build/esm/auxta/helpers/response.helper.d.ts +10 -0
- package/{src/auxta/helpers/response.helper.ts → build/esm/auxta/helpers/response.helper.js} +1 -1
- package/build/esm/auxta/helpers/start.helper.d.ts +1 -0
- package/{src/auxta/helpers/start.helper.ts → build/esm/auxta/helpers/start.helper.js} +6 -5
- package/build/esm/auxta/hooks/report.hook.d.ts +4 -0
- package/{src/auxta/hooks/report.hook.ts → build/esm/auxta/hooks/report.hook.js} +17 -24
- package/build/esm/auxta/models/upload.model.d.ts +20 -0
- package/build/esm/auxta/models/upload.model.js +43 -0
- package/build/esm/auxta/services/log.service.d.ts +26 -0
- package/build/esm/auxta/services/log.service.js +43 -0
- package/build/esm/auxta/services/report.service.d.ts +36 -0
- package/build/esm/auxta/services/report.service.js +127 -0
- package/build/esm/auxta/services/runtime.service.d.ts +16 -0
- package/{src/auxta/services/runtime.service.ts → build/esm/auxta/services/runtime.service.js} +14 -28
- package/build/esm/auxta/utilities/runtime.helper.d.ts +15 -0
- package/{src/auxta/utilities/runtime.helper.ts → build/esm/auxta/utilities/runtime.helper.js} +3 -17
- package/build/esm/auxta/utilities/screenshot.helper.d.ts +2 -0
- package/{src/auxta/utilities/screenshot.helper.ts → build/esm/auxta/utilities/screenshot.helper.js} +10 -11
- package/build/esm/auxta/utilities/start-suite.helper.d.ts +1 -0
- package/build/esm/auxta/utilities/start-suite.helper.js +14 -0
- package/build/esm/macros/helpers/code.helper.d.ts +22 -0
- package/{src/macros/helpers/code.helper.ts → build/esm/macros/helpers/code.helper.js} +50 -98
- package/build/esm/puppeteer/puppeteer.d.ts +13 -0
- package/build/esm/puppeteer/puppeteer.js +136 -0
- package/build/tsconfig-cjs.tsbuildinfo +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -4
- package/src/auxta/configs/config.ts +0 -48
- package/src/auxta/enums/status-of.step.ts +0 -7
- package/src/auxta/models/upload.model.ts +0 -62
- package/src/auxta/services/log.service.ts +0 -58
- package/src/auxta/services/report.service.ts +0 -189
- package/src/auxta/utilities/start-suite.helper.ts +0 -16
- package/src/puppeteer/puppeteer.ts +0 -145
- package/tsconfig.json +0 -65
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.postNotificationsOnFail = exports.postNotifications = exports.getLastDayResults = exports.getReport = exports.updateReport = exports.uploadFeature = exports.uploadScenario = exports.createEmptyReport = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const config_1 = require("../configs/config");
|
|
9
|
+
function headers(token) {
|
|
10
|
+
return {
|
|
11
|
+
headers: {
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
'cookie': `authToken=${token}`
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async function auth() {
|
|
18
|
+
return axios_1.default.post(config_1.config.auxtaURL + 'login', config_1.config.auxtaCredentials, {
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
.then(({ data }) => {
|
|
24
|
+
return data.token;
|
|
25
|
+
})
|
|
26
|
+
.catch(() => {
|
|
27
|
+
throw new Error("Invalid login credentials");
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function createEmptyReport(body) {
|
|
31
|
+
const token = await auth();
|
|
32
|
+
return (await axios_1.default.post(config_1.config.auxtaURL + "create-empty-report", {
|
|
33
|
+
environment: body.environment,
|
|
34
|
+
digitalProductName: body.digitalProduct,
|
|
35
|
+
start: new Date(),
|
|
36
|
+
url: body.baseUrl
|
|
37
|
+
}, headers(token))).data.reportId;
|
|
38
|
+
}
|
|
39
|
+
exports.createEmptyReport = createEmptyReport;
|
|
40
|
+
async function uploadScenario(stepLog, scenarioName, screenshot, errMessage) {
|
|
41
|
+
let scenarios = [];
|
|
42
|
+
let token = await auth();
|
|
43
|
+
let lastStep = stepLog[stepLog.length - 1];
|
|
44
|
+
const stepLogFormat = JSON.parse(JSON.stringify(stepLog));
|
|
45
|
+
stepLogFormat.pop();
|
|
46
|
+
let output = (await axios_1.default.post(config_1.config.auxtaURL + "create-scenario", {
|
|
47
|
+
json: {
|
|
48
|
+
name: scenarioName,
|
|
49
|
+
steps: [
|
|
50
|
+
...stepLogFormat,
|
|
51
|
+
(lastStep.result.status == 'failed')
|
|
52
|
+
? Object.assign(lastStep, {
|
|
53
|
+
result: {
|
|
54
|
+
...lastStep.result,
|
|
55
|
+
error_message: JSON.stringify(errMessage)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
: lastStep,
|
|
59
|
+
{
|
|
60
|
+
keyword: "After",
|
|
61
|
+
result: {
|
|
62
|
+
status: "passed",
|
|
63
|
+
duration: 2678000000
|
|
64
|
+
},
|
|
65
|
+
embeddings: (screenshot) ? [{
|
|
66
|
+
data: screenshot.toString("base64"),
|
|
67
|
+
mime_type: "image/png"
|
|
68
|
+
}] : undefined,
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
}
|
|
72
|
+
}, headers(token))).data.scenarios;
|
|
73
|
+
scenarios.push({
|
|
74
|
+
scenarioRef: output.scenarioRef,
|
|
75
|
+
name: output.name,
|
|
76
|
+
status: output.status,
|
|
77
|
+
stepsCount: output.stepsCount
|
|
78
|
+
});
|
|
79
|
+
return scenarios;
|
|
80
|
+
}
|
|
81
|
+
exports.uploadScenario = uploadScenario;
|
|
82
|
+
async function uploadFeature(scenarioId, scenarioName, uri, hasFailed) {
|
|
83
|
+
let token = await auth();
|
|
84
|
+
return (await axios_1.default.post(config_1.config.auxtaURL + "create-feature", {
|
|
85
|
+
json: {
|
|
86
|
+
name: scenarioName,
|
|
87
|
+
uri: uri
|
|
88
|
+
},
|
|
89
|
+
scenarios: scenarioId,
|
|
90
|
+
hasFailed: hasFailed
|
|
91
|
+
}, headers(token))).data;
|
|
92
|
+
}
|
|
93
|
+
exports.uploadFeature = uploadFeature;
|
|
94
|
+
async function updateReport(reportId, feature, steps, isFinal) {
|
|
95
|
+
let token = await auth();
|
|
96
|
+
await axios_1.default.post(config_1.config.auxtaURL + "update-inprogress-report", {
|
|
97
|
+
reportId: reportId,
|
|
98
|
+
isFinal: isFinal,
|
|
99
|
+
data: {
|
|
100
|
+
feature: {
|
|
101
|
+
featureRef: feature.featureId,
|
|
102
|
+
name: feature.featureName,
|
|
103
|
+
uri: feature.featureUri,
|
|
104
|
+
status: feature.status,
|
|
105
|
+
scenariosCount: feature.scenariosCount
|
|
106
|
+
},
|
|
107
|
+
...steps
|
|
108
|
+
}
|
|
109
|
+
}, headers(token));
|
|
110
|
+
}
|
|
111
|
+
exports.updateReport = updateReport;
|
|
112
|
+
async function getReport(reportId) {
|
|
113
|
+
let token = await auth();
|
|
114
|
+
return (await axios_1.default.post(config_1.config.auxtaURL + "get-report", { reportId: reportId }, headers(token))).data;
|
|
115
|
+
}
|
|
116
|
+
exports.getReport = getReport;
|
|
117
|
+
async function getLastDayResults() {
|
|
118
|
+
let token = await auth();
|
|
119
|
+
return (await axios_1.default.get(config_1.config.auxtaURL + `get-last-day-results?url=${config_1.config.baseURL}`, headers(token))).data.results;
|
|
120
|
+
}
|
|
121
|
+
exports.getLastDayResults = getLastDayResults;
|
|
122
|
+
async function postNotifications(body) {
|
|
123
|
+
let token = await auth();
|
|
124
|
+
await axios_1.default.post(`${config_1.config.auxtaURL}post-notification-after-run-background`, {
|
|
125
|
+
environmentName: body.environment,
|
|
126
|
+
digitalProductName: body.digitalProduct,
|
|
127
|
+
organizationName: body.organization,
|
|
128
|
+
reportId: body.reportId,
|
|
129
|
+
}, headers(token));
|
|
130
|
+
}
|
|
131
|
+
exports.postNotifications = postNotifications;
|
|
132
|
+
async function postNotificationsOnFail(body) {
|
|
133
|
+
let token = await auth();
|
|
134
|
+
await axios_1.default.post(`${config_1.config.auxtaURL}post-notifications-after-case-fail-background`, {
|
|
135
|
+
environmentName: body.environment,
|
|
136
|
+
digitalProductName: body.digitalProduct,
|
|
137
|
+
organizationName: body.organization,
|
|
138
|
+
reportId: body.reportId,
|
|
139
|
+
}, headers(token));
|
|
140
|
+
}
|
|
141
|
+
exports.postNotificationsOnFail = postNotificationsOnFail;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface RunTime {
|
|
2
|
+
duration: String;
|
|
3
|
+
startTime: Date;
|
|
4
|
+
endTime: Date;
|
|
5
|
+
}
|
|
6
|
+
export declare class Runtime {
|
|
7
|
+
private start;
|
|
8
|
+
private end;
|
|
9
|
+
private runtime;
|
|
10
|
+
constructor(s: Date, e: Date);
|
|
11
|
+
private calculateDuration;
|
|
12
|
+
private splitAtDecimanlMinutes;
|
|
13
|
+
private splitAtDecimanlHours;
|
|
14
|
+
private formatRuntime;
|
|
15
|
+
returnRuntime(): RunTime;
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Runtime = void 0;
|
|
4
|
+
class Runtime {
|
|
5
|
+
constructor(s, e) {
|
|
6
|
+
this.start = s;
|
|
7
|
+
this.end = e;
|
|
8
|
+
}
|
|
9
|
+
calculateDuration() {
|
|
10
|
+
let currentTime = new Date;
|
|
11
|
+
let duration = currentTime.getTime() - this.start.getTime();
|
|
12
|
+
return duration;
|
|
13
|
+
}
|
|
14
|
+
splitAtDecimanlMinutes(time) {
|
|
15
|
+
let minutes = time.toFixed(2).toString().split('.');
|
|
16
|
+
return `${minutes[0]}m ${(Number(minutes[1]) / 100 * 60).toFixed(0)}s`;
|
|
17
|
+
}
|
|
18
|
+
splitAtDecimanlHours(time) {
|
|
19
|
+
let hours = time.toFixed(2).toString().split('.');
|
|
20
|
+
let minutes = (Number(hours[1]) / 100 * 60).toFixed(2).toString().split('.');
|
|
21
|
+
return `${hours[0]}h ${minutes[0]}m ${(Number(minutes[1]) / 100 * 60).toFixed(0)}s`;
|
|
22
|
+
}
|
|
23
|
+
formatRuntime(duration) {
|
|
24
|
+
if (duration / 1000 < 60)
|
|
25
|
+
return `${(duration / 1000).toFixed(0)}s`;
|
|
26
|
+
else {
|
|
27
|
+
if (duration / 60000 < 60)
|
|
28
|
+
return this.splitAtDecimanlMinutes(duration / 60000);
|
|
29
|
+
else
|
|
30
|
+
return this.splitAtDecimanlHours(duration / 3600000);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
returnRuntime() {
|
|
34
|
+
let duration = this.formatRuntime(this.calculateDuration());
|
|
35
|
+
let startTime = this.start;
|
|
36
|
+
let endTime = this.end;
|
|
37
|
+
this.runtime = { duration, startTime, endTime };
|
|
38
|
+
return this.runtime;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Runtime = Runtime;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RunTime } from "../services/runtime.service";
|
|
2
|
+
export declare class CalculateRuntime {
|
|
3
|
+
private runtime;
|
|
4
|
+
startTimeSeconds: string;
|
|
5
|
+
startTimeMinutes: string;
|
|
6
|
+
startTimeHours: string;
|
|
7
|
+
startTimeDay: string;
|
|
8
|
+
startTimeMonth: string;
|
|
9
|
+
endTimeSeconds: string;
|
|
10
|
+
endTimeMinutes: string;
|
|
11
|
+
endTimeHours: string;
|
|
12
|
+
endTimeDay: string;
|
|
13
|
+
endTimeMonth: string;
|
|
14
|
+
constructor(r: RunTime);
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CalculateRuntime = void 0;
|
|
4
|
+
class CalculateRuntime {
|
|
5
|
+
constructor(r) {
|
|
6
|
+
this.runtime = r;
|
|
7
|
+
this.startTimeSeconds = (this.runtime.startTime.getSeconds() < 10) ? `0${this.runtime.startTime.getSeconds()}` : `${this.runtime.startTime.getSeconds()}`;
|
|
8
|
+
this.startTimeMinutes = (this.runtime.startTime.getMinutes() < 10) ? `0${this.runtime.startTime.getMinutes()}` : `${this.runtime.startTime.getMinutes()}`;
|
|
9
|
+
this.startTimeHours = (this.runtime.startTime.getHours() < 10) ? `0${this.runtime.startTime.getHours()}` : `${this.runtime.startTime.getHours()}`;
|
|
10
|
+
this.startTimeDay = (this.runtime.startTime.getDate() < 10) ? `0${this.runtime.startTime.getDate()}` : `${this.runtime.startTime.getDate()}`;
|
|
11
|
+
this.startTimeMonth = (this.runtime.startTime.getMonth() + 1 < 10) ? `0${this.runtime.startTime.getMonth() + 1}` : `${this.runtime.startTime.getMonth() + 1}`;
|
|
12
|
+
this.endTimeSeconds = (this.runtime.endTime.getSeconds() < 10) ? `0${this.runtime.endTime.getSeconds()}` : `${this.runtime.endTime.getSeconds()}`;
|
|
13
|
+
this.endTimeMinutes = (this.runtime.endTime.getMinutes() < 10) ? `0${this.runtime.endTime.getMinutes()}` : `${this.runtime.endTime.getMinutes()}`;
|
|
14
|
+
this.endTimeHours = (this.runtime.endTime.getHours() < 10) ? `0${this.runtime.endTime.getHours()}` : `${this.runtime.endTime.getHours()}`;
|
|
15
|
+
this.endTimeDay = (this.runtime.endTime.getDate() < 10) ? `0${this.runtime.endTime.getDate()}` : `${this.runtime.endTime.getDate()}`;
|
|
16
|
+
this.endTimeMonth = (this.runtime.endTime.getMonth() + 1 < 10) ? `0${this.runtime.endTime.getMonth() + 1}` : `${this.runtime.endTime.getMonth() + 1}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CalculateRuntime = CalculateRuntime;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.captureScreenshot = void 0;
|
|
7
|
+
const puppeteer_1 = __importDefault(require("../../puppeteer/puppeteer"));
|
|
8
|
+
async function captureScreenshot() {
|
|
9
|
+
try {
|
|
10
|
+
const pages = await puppeteer_1.default.defaultPage.browser().pages();
|
|
11
|
+
if (!pages.length)
|
|
12
|
+
return undefined;
|
|
13
|
+
const lastPage = pages[pages.length - 1] || puppeteer_1.default.defaultPage;
|
|
14
|
+
const screenshotBuffer = await lastPage.screenshot({
|
|
15
|
+
fullPage: true,
|
|
16
|
+
encoding: 'binary'
|
|
17
|
+
});
|
|
18
|
+
if (Buffer.isBuffer(screenshotBuffer))
|
|
19
|
+
return screenshotBuffer;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
exports.captureScreenshot = captureScreenshot;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startSuite(suites: string[], reportId?: string): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startSuite = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const config_1 = require("../configs/config");
|
|
9
|
+
async function startSuite(suites, reportId) {
|
|
10
|
+
if (suites.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
const next = suites.shift();
|
|
13
|
+
console.log('Starting next suite: ' + next);
|
|
14
|
+
try {
|
|
15
|
+
await axios_1.default.post(`${config_1.config.netlifyPath}.netlify/functions/${next}?token=${config_1.config.token}`, { nextSuites: suites, reportId: reportId });
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
await startSuite(suites, reportId);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.startSuite = startSuite;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StatusOfStep } from "../../auxta/enums/status-of.step";
|
|
2
|
+
export declare class FunctionHelper {
|
|
3
|
+
readonly defaultTimeout: number;
|
|
4
|
+
log(keyword: string, name: string, status: StatusOfStep): void;
|
|
5
|
+
suggest(name: string): void;
|
|
6
|
+
private getEscapedText;
|
|
7
|
+
clickByText(selector: string, text: string, page?: import("puppeteer-core").Page, dotOrText?: string): Promise<void>;
|
|
8
|
+
clickByTextWithClass(class_selector: string, class_name: string, selector: string, text: string, page?: import("puppeteer-core").Page, dotOrText?: string): Promise<void>;
|
|
9
|
+
waitForSelectorWithText(selector: string, text: string, page?: import("puppeteer-core").Page, dotOrText?: string): Promise<boolean>;
|
|
10
|
+
goto(url: string, page?: import("puppeteer-core").Page): Promise<void>;
|
|
11
|
+
type(field: string, value: string, page?: import("puppeteer-core").Page): Promise<void>;
|
|
12
|
+
waitForNetwork(page?: import("puppeteer-core").Page): Promise<void>;
|
|
13
|
+
timeout(timeout?: number, page?: import("puppeteer-core").Page): Promise<void>;
|
|
14
|
+
waitForSelector(option: string, selector: string, time?: number, page?: import("puppeteer-core").Page, log_message?: boolean): Promise<void>;
|
|
15
|
+
click(selector: string, logMessages?: boolean, page?: import("puppeteer-core").Page): Promise<void>;
|
|
16
|
+
urlContains(selector: string, page?: import("puppeteer-core").Page): Promise<void>;
|
|
17
|
+
pressEnter(page?: import("puppeteer-core").Page): Promise<void>;
|
|
18
|
+
clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer-core").Page): Promise<void>;
|
|
19
|
+
closeLastPage(page?: import("puppeteer-core").Page): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
declare const _default: FunctionHelper;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FunctionHelper = void 0;
|
|
7
|
+
const log_service_1 = __importDefault(require("../../auxta/services/log.service"));
|
|
8
|
+
const puppeteer_1 = __importDefault(require("../../puppeteer/puppeteer"));
|
|
9
|
+
const status_of_step_1 = require("../../auxta/enums/status-of.step");
|
|
10
|
+
const config_1 = require("../../auxta/configs/config");
|
|
11
|
+
class FunctionHelper {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.defaultTimeout = config_1.config.timeout;
|
|
14
|
+
}
|
|
15
|
+
log(keyword, name, status) {
|
|
16
|
+
log_service_1.default.push(keyword, name, status);
|
|
17
|
+
}
|
|
18
|
+
suggest(name) {
|
|
19
|
+
log_service_1.default.addSuggestion(name);
|
|
20
|
+
}
|
|
21
|
+
getEscapedText(text) {
|
|
22
|
+
const splitedQuotes = text.replace(/'/g, `', "'", '`);
|
|
23
|
+
return `concat('${splitedQuotes}', '')`;
|
|
24
|
+
}
|
|
25
|
+
async clickByText(selector, text, page = puppeteer_1.default.defaultPage, dotOrText = '.') {
|
|
26
|
+
const message = `I click on the '${text}' '${selector}'`;
|
|
27
|
+
try {
|
|
28
|
+
const [linkHandlers] = await page.$x(`//${selector}[${dotOrText} = ${this.getEscapedText(text)}]`);
|
|
29
|
+
if (linkHandlers) {
|
|
30
|
+
await linkHandlers.click();
|
|
31
|
+
log_service_1.default.push('Then', message, status_of_step_1.StatusOfStep.PASSED);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
}
|
|
37
|
+
log_service_1.default.push('Then', message, status_of_step_1.StatusOfStep.FAILED);
|
|
38
|
+
throw new Error(message);
|
|
39
|
+
}
|
|
40
|
+
async clickByTextWithClass(class_selector, class_name, selector, text, page = puppeteer_1.default.defaultPage, dotOrText = '.') {
|
|
41
|
+
const message = `I click on the '${text}' '${selector}'`;
|
|
42
|
+
try {
|
|
43
|
+
const [linkHandlers] = await page.$x(`//${class_selector}[contains(@class,${this.getEscapedText(class_name)})]//${selector}[${dotOrText} = ${this.getEscapedText(text)}]`);
|
|
44
|
+
if (linkHandlers) {
|
|
45
|
+
await linkHandlers.click();
|
|
46
|
+
log_service_1.default.push('Then', message, status_of_step_1.StatusOfStep.PASSED);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
}
|
|
52
|
+
log_service_1.default.push('Then', message, status_of_step_1.StatusOfStep.FAILED);
|
|
53
|
+
throw new Error(message);
|
|
54
|
+
}
|
|
55
|
+
async waitForSelectorWithText(selector, text, page = puppeteer_1.default.defaultPage, dotOrText = '.') {
|
|
56
|
+
const message = `I check for '${text}' on the current page`;
|
|
57
|
+
try {
|
|
58
|
+
await page.waitForSelector(selector, {
|
|
59
|
+
timeout: this.defaultTimeout
|
|
60
|
+
});
|
|
61
|
+
const linkHandlers = await page.$x(`//${selector}[${dotOrText} = ${this.getEscapedText(text)}]`);
|
|
62
|
+
if (linkHandlers.length > 0) {
|
|
63
|
+
log_service_1.default.push('And', message, status_of_step_1.StatusOfStep.PASSED);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
}
|
|
69
|
+
log_service_1.default.push('And', message, status_of_step_1.StatusOfStep.FAILED);
|
|
70
|
+
throw new Error(message);
|
|
71
|
+
}
|
|
72
|
+
async goto(url, page = puppeteer_1.default.defaultPage) {
|
|
73
|
+
await page.goto(url);
|
|
74
|
+
log_service_1.default.push('Then', `I go to the '${url}' page`, status_of_step_1.StatusOfStep.PASSED);
|
|
75
|
+
}
|
|
76
|
+
async type(field, value, page = puppeteer_1.default.defaultPage) {
|
|
77
|
+
try {
|
|
78
|
+
await page.waitForSelector(field, {
|
|
79
|
+
timeout: this.defaultTimeout
|
|
80
|
+
});
|
|
81
|
+
await page.type(field, value);
|
|
82
|
+
let elementName = await page.$eval(field, (e) => e.textContent);
|
|
83
|
+
if (!elementName || elementName === ' ')
|
|
84
|
+
elementName = field;
|
|
85
|
+
log_service_1.default.push('Then', `I type '${value}' into the '${elementName}' field`, status_of_step_1.StatusOfStep.PASSED);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const msg = `I type '${value}' into the '${field}' field`;
|
|
89
|
+
log_service_1.default.push('Then', msg, status_of_step_1.StatusOfStep.FAILED);
|
|
90
|
+
throw new Error(msg);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async waitForNetwork(page = puppeteer_1.default.defaultPage) {
|
|
94
|
+
let message = 'I wait for the page to load';
|
|
95
|
+
try {
|
|
96
|
+
await page.waitForNetworkIdle();
|
|
97
|
+
log_service_1.default.push('Then', message, status_of_step_1.StatusOfStep.PASSED);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
log_service_1.default.push('Then', message, status_of_step_1.StatusOfStep.FAILED);
|
|
101
|
+
throw new Error(message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async timeout(timeout = this.defaultTimeout, page = puppeteer_1.default.defaultPage) {
|
|
105
|
+
await page.waitForTimeout(timeout);
|
|
106
|
+
}
|
|
107
|
+
async waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer_1.default.defaultPage, log_message = true) {
|
|
108
|
+
const message = `I check for the '${selector}' element to be ${option}`;
|
|
109
|
+
try {
|
|
110
|
+
await page.waitForSelector(selector, {
|
|
111
|
+
[option]: true,
|
|
112
|
+
timeout: time
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (log_message) {
|
|
117
|
+
log_service_1.default.push('And', message, status_of_step_1.StatusOfStep.FAILED);
|
|
118
|
+
}
|
|
119
|
+
throw new Error(message);
|
|
120
|
+
}
|
|
121
|
+
if (log_message) {
|
|
122
|
+
log_service_1.default.push('And', message, status_of_step_1.StatusOfStep.PASSED);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async click(selector, logMessages = true, page = puppeteer_1.default.defaultPage) {
|
|
126
|
+
try {
|
|
127
|
+
await page.waitForSelector(selector, {
|
|
128
|
+
timeout: this.defaultTimeout
|
|
129
|
+
});
|
|
130
|
+
let elementName = await page.$eval(selector, (e) => e.textContent);
|
|
131
|
+
if (!elementName || elementName === ' ')
|
|
132
|
+
elementName = selector;
|
|
133
|
+
await page.click(selector);
|
|
134
|
+
log_service_1.default.push('Then', `I click on the '${elementName}'`, status_of_step_1.StatusOfStep.PASSED);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
const msg = `I click on the '${selector}'`;
|
|
138
|
+
log_service_1.default.push('Then', msg, status_of_step_1.StatusOfStep.FAILED);
|
|
139
|
+
throw new Error(msg);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async urlContains(selector, page = puppeteer_1.default.defaultPage) {
|
|
143
|
+
const url = page.url();
|
|
144
|
+
let message = `I am on the ${selector} page`;
|
|
145
|
+
if (!url.includes(selector)) {
|
|
146
|
+
log_service_1.default.push('And', message, status_of_step_1.StatusOfStep.FAILED);
|
|
147
|
+
throw new Error(message);
|
|
148
|
+
}
|
|
149
|
+
log_service_1.default.push('And', message, status_of_step_1.StatusOfStep.PASSED);
|
|
150
|
+
}
|
|
151
|
+
async pressEnter(page = puppeteer_1.default.defaultPage) {
|
|
152
|
+
await page.keyboard.press('Enter');
|
|
153
|
+
}
|
|
154
|
+
async clickAndWaitForPageToBeCreated(selector, page = puppeteer_1.default.defaultPage) {
|
|
155
|
+
const nav = new Promise(res => page.browser().on('targetcreated', res));
|
|
156
|
+
await this.click(selector);
|
|
157
|
+
await nav;
|
|
158
|
+
}
|
|
159
|
+
async closeLastPage(page = puppeteer_1.default.defaultPage) {
|
|
160
|
+
const pages = await page.browser().pages();
|
|
161
|
+
await pages[pages.length - 1].close();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.FunctionHelper = FunctionHelper;
|
|
165
|
+
exports.default = new FunctionHelper();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UploadModel } from "../auxta/models/upload.model";
|
|
2
|
+
import puppeteer_core from 'puppeteer-core';
|
|
3
|
+
export declare class Puppeteer {
|
|
4
|
+
defaultPage: puppeteer_core.Page;
|
|
5
|
+
private browser;
|
|
6
|
+
startBrowser(): Promise<void>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
run(event: any, callback: any, featureName?: string, scenarioName?: string, uploadModel?: UploadModel, close?: boolean): Promise<void>;
|
|
9
|
+
runRPA(event: any, callback: any, close?: boolean): Promise<any>;
|
|
10
|
+
private static setupHeader;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: Puppeteer;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Puppeteer = void 0;
|
|
7
|
+
const chrome_aws_lambda_1 = __importDefault(require("chrome-aws-lambda"));
|
|
8
|
+
const log_service_1 = __importDefault(require("../auxta/services/log.service"));
|
|
9
|
+
const screenshot_helper_1 = require("../auxta/utilities/screenshot.helper");
|
|
10
|
+
const report_hook_1 = require("../auxta/hooks/report.hook");
|
|
11
|
+
const AuxTA_1 = __importDefault(require("../AuxTA"));
|
|
12
|
+
const status_of_step_1 = require("../auxta/enums/status-of.step");
|
|
13
|
+
const config_1 = require("./../auxta/configs/config");
|
|
14
|
+
const report_service_1 = require("../auxta/services/report.service");
|
|
15
|
+
class Puppeteer {
|
|
16
|
+
async startBrowser() {
|
|
17
|
+
let args = [
|
|
18
|
+
'--start-maximized',
|
|
19
|
+
'--no-sandbox',
|
|
20
|
+
'--disable-setuid-sandbox',
|
|
21
|
+
'--disable-dev-shm-usage',
|
|
22
|
+
'--single-process'
|
|
23
|
+
];
|
|
24
|
+
if (process.env.ENVIRONMENT != 'LOCAL')
|
|
25
|
+
args.push(`--window-size=${config_1.config.screenWidth},${config_1.config.screenHeight}`);
|
|
26
|
+
this.browser = await chrome_aws_lambda_1.default.puppeteer.launch({
|
|
27
|
+
executablePath: process.env.ENVIRONMENT === 'LOCAL' ? undefined : await chrome_aws_lambda_1.default.executablePath,
|
|
28
|
+
args,
|
|
29
|
+
ignoreDefaultArgs: ["--enable-automation"],
|
|
30
|
+
defaultViewport: process.env.ENVIRONMENT === 'LOCAL' ? null : {
|
|
31
|
+
width: config_1.config.screenWidth,
|
|
32
|
+
height: config_1.config.screenHeight
|
|
33
|
+
},
|
|
34
|
+
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chrome_aws_lambda_1.default.headless
|
|
35
|
+
});
|
|
36
|
+
this.defaultPage = (await this.browser.pages())[0];
|
|
37
|
+
await this.defaultPage.goto(config_1.config.baseURL, { waitUntil: 'networkidle0' });
|
|
38
|
+
await this.defaultPage.waitForNetworkIdle();
|
|
39
|
+
}
|
|
40
|
+
async close() {
|
|
41
|
+
if (this.browser) {
|
|
42
|
+
let pages = await this.browser.pages();
|
|
43
|
+
await Promise.all(pages.map((page) => page.close()));
|
|
44
|
+
await this.browser.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async run(event, callback, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel, close) {
|
|
48
|
+
try {
|
|
49
|
+
if (uploadModel === undefined)
|
|
50
|
+
uploadModel = AuxTA_1.default.getUploadModel();
|
|
51
|
+
if (close === undefined)
|
|
52
|
+
close = Puppeteer.setupHeader(event, uploadModel);
|
|
53
|
+
let screenshotBuffer;
|
|
54
|
+
let errMessage;
|
|
55
|
+
let statusCode = 200;
|
|
56
|
+
let consoleStack = [];
|
|
57
|
+
try {
|
|
58
|
+
await log_service_1.default.push('When', `Starting puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
|
|
59
|
+
await this.startBrowser();
|
|
60
|
+
this.defaultPage.on('console', message => consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
61
|
+
.on('pageerror', ({ message }) => consoleStack.push(message))
|
|
62
|
+
.on('response', response => consoleStack.push(`${response.status()} ${response.url()}`))
|
|
63
|
+
.on('requestfailed', request => consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`));
|
|
64
|
+
await callback(event);
|
|
65
|
+
log_service_1.default.push('When', `Finished puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.log("Error", err);
|
|
69
|
+
errMessage = err;
|
|
70
|
+
statusCode = 500;
|
|
71
|
+
screenshotBuffer = await (0, screenshot_helper_1.captureScreenshot)();
|
|
72
|
+
log_service_1.default.push('When', `Finished puppeteer process`, status_of_step_1.StatusOfStep.FAILED);
|
|
73
|
+
await (0, report_service_1.postNotificationsOnFail)(uploadModel);
|
|
74
|
+
}
|
|
75
|
+
let url = this.defaultPage.url();
|
|
76
|
+
if (close)
|
|
77
|
+
await this.close();
|
|
78
|
+
await (0, report_hook_1.onTestEnd)(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
|
|
79
|
+
currentPageUrl: url,
|
|
80
|
+
console: consoleStack,
|
|
81
|
+
error: errMessage
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
console.log("Lib error:", e);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
log_service_1.default.clear();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async runRPA(event, callback, close) {
|
|
92
|
+
let errMessage;
|
|
93
|
+
try {
|
|
94
|
+
if (close === undefined) {
|
|
95
|
+
if (event.queryStringParameters.close) {
|
|
96
|
+
close = event.queryStringParameters.close === "true";
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
close = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let consoleStack = [];
|
|
103
|
+
try {
|
|
104
|
+
await log_service_1.default.push('When', `Starting puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
|
|
105
|
+
await this.startBrowser();
|
|
106
|
+
this.defaultPage.on('console', message => consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
107
|
+
.on('pageerror', ({ message }) => consoleStack.push(message))
|
|
108
|
+
.on('response', response => consoleStack.push(`${response.status()} ${response.url()}`))
|
|
109
|
+
.on('requestfailed', request => consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`));
|
|
110
|
+
await callback(event);
|
|
111
|
+
log_service_1.default.push('When', `Finished puppeteer process`, status_of_step_1.StatusOfStep.PASSED);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
errMessage = err;
|
|
115
|
+
log_service_1.default.push('When', `Finished puppeteer process`, status_of_step_1.StatusOfStep.FAILED);
|
|
116
|
+
return errMessage;
|
|
117
|
+
}
|
|
118
|
+
if (close)
|
|
119
|
+
await this.close();
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.log("Lib error:", e);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
log_service_1.default.clear();
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
static setupHeader(event, uploadModel) {
|
|
130
|
+
let close = true;
|
|
131
|
+
if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {
|
|
132
|
+
const body = JSON.parse(event.body);
|
|
133
|
+
uploadModel.reportId = body.reportId;
|
|
134
|
+
uploadModel.nextSuites = body.nextSuites;
|
|
135
|
+
}
|
|
136
|
+
else if (event.queryStringParameters.close) {
|
|
137
|
+
close = event.queryStringParameters.close === "true";
|
|
138
|
+
}
|
|
139
|
+
return close;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.Puppeteer = Puppeteer;
|
|
143
|
+
exports.default = new Puppeteer();
|