@auxcode/auxta 0.5.1 → 0.5.5
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.d.ts +43 -0
- package/{src/AuxTA.ts → build/AuxTA.js} +39 -46
- package/build/auxta/configs/config.d.ts +51 -0
- package/build/auxta/configs/config.js +61 -0
- package/build/auxta/enums/status-of.step.d.ts +7 -0
- package/build/auxta/enums/status-of.step.js +8 -0
- package/build/auxta/helpers/response.helper.d.ts +10 -0
- package/{src/auxta/helpers/response.helper.ts → build/auxta/helpers/response.helper.js} +1 -1
- package/build/auxta/helpers/start.helper.d.ts +1 -0
- package/{src/auxta/helpers/start.helper.ts → build/auxta/helpers/start.helper.js} +6 -5
- package/build/auxta/hooks/report.hook.d.ts +4 -0
- package/{src/auxta/hooks/report.hook.ts → build/auxta/hooks/report.hook.js} +17 -24
- package/build/auxta/models/upload.model.d.ts +20 -0
- package/build/auxta/models/upload.model.js +43 -0
- package/build/auxta/services/log.service.d.ts +26 -0
- package/build/auxta/services/log.service.js +43 -0
- package/build/auxta/services/report.service.d.ts +36 -0
- package/build/auxta/services/report.service.js +127 -0
- package/build/auxta/services/runtime.service.d.ts +16 -0
- package/{src/auxta/services/runtime.service.ts → build/auxta/services/runtime.service.js} +14 -28
- package/build/auxta/utilities/runtime.helper.d.ts +15 -0
- package/{src/auxta/utilities/runtime.helper.ts → build/auxta/utilities/runtime.helper.js} +3 -17
- package/build/auxta/utilities/screenshot.helper.d.ts +2 -0
- package/{src/auxta/utilities/screenshot.helper.ts → build/auxta/utilities/screenshot.helper.js} +10 -11
- package/build/auxta/utilities/start-suite.helper.d.ts +1 -0
- package/build/auxta/utilities/start-suite.helper.js +14 -0
- package/build/macros/helpers/code.helper.d.ts +22 -0
- package/{src/macros/helpers/code.helper.ts → build/macros/helpers/code.helper.js} +53 -96
- package/build/puppeteer/puppeteer.d.ts +13 -0
- package/build/puppeteer/puppeteer.js +136 -0
- package/package.json +8 -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,136 @@
|
|
|
1
|
+
import chromium from 'chrome-aws-lambda';
|
|
2
|
+
import log from "../auxta/services/log.service";
|
|
3
|
+
import { captureScreenshot } from "../auxta/utilities/screenshot.helper";
|
|
4
|
+
import { onTestEnd } from "../auxta/hooks/report.hook";
|
|
5
|
+
import auxta from "../AuxTA";
|
|
6
|
+
import { StatusOfStep } from "../auxta/enums/status-of.step";
|
|
7
|
+
import { config } from "./../auxta/configs/config";
|
|
8
|
+
import { postNotificationsOnFail } from "../auxta/services/report.service";
|
|
9
|
+
export class Puppeteer {
|
|
10
|
+
async startBrowser() {
|
|
11
|
+
let args = [
|
|
12
|
+
'--start-maximized',
|
|
13
|
+
'--no-sandbox',
|
|
14
|
+
'--disable-setuid-sandbox',
|
|
15
|
+
'--disable-dev-shm-usage',
|
|
16
|
+
'--single-process'
|
|
17
|
+
];
|
|
18
|
+
if (process.env.ENVIRONMENT != 'LOCAL')
|
|
19
|
+
args.push(`--window-size=${config.screenWidth},${config.screenHeight}`);
|
|
20
|
+
this.browser = await chromium.puppeteer.launch({
|
|
21
|
+
executablePath: process.env.ENVIRONMENT === 'LOCAL' ? undefined : await chromium.executablePath,
|
|
22
|
+
args,
|
|
23
|
+
ignoreDefaultArgs: ["--enable-automation"],
|
|
24
|
+
defaultViewport: process.env.ENVIRONMENT === 'LOCAL' ? null : {
|
|
25
|
+
width: config.screenWidth,
|
|
26
|
+
height: config.screenHeight
|
|
27
|
+
},
|
|
28
|
+
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
|
|
29
|
+
});
|
|
30
|
+
this.defaultPage = (await this.browser.pages())[0];
|
|
31
|
+
await this.defaultPage.goto(config.baseURL, { waitUntil: 'networkidle0' });
|
|
32
|
+
await this.defaultPage.waitForNetworkIdle();
|
|
33
|
+
}
|
|
34
|
+
async close() {
|
|
35
|
+
if (this.browser) {
|
|
36
|
+
let pages = await this.browser.pages();
|
|
37
|
+
await Promise.all(pages.map((page) => page.close()));
|
|
38
|
+
await this.browser.close();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async run(event, callback, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel, close) {
|
|
42
|
+
try {
|
|
43
|
+
if (uploadModel === undefined)
|
|
44
|
+
uploadModel = auxta.getUploadModel();
|
|
45
|
+
if (close === undefined)
|
|
46
|
+
close = Puppeteer.setupHeader(event, uploadModel);
|
|
47
|
+
let screenshotBuffer;
|
|
48
|
+
let errMessage;
|
|
49
|
+
let statusCode = 200;
|
|
50
|
+
let consoleStack = [];
|
|
51
|
+
try {
|
|
52
|
+
await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
|
|
53
|
+
await this.startBrowser();
|
|
54
|
+
this.defaultPage.on('console', message => consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
55
|
+
.on('pageerror', ({ message }) => consoleStack.push(message))
|
|
56
|
+
.on('response', response => consoleStack.push(`${response.status()} ${response.url()}`))
|
|
57
|
+
.on('requestfailed', request => consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`));
|
|
58
|
+
await callback(event);
|
|
59
|
+
log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.log("Error", err);
|
|
63
|
+
errMessage = err;
|
|
64
|
+
statusCode = 500;
|
|
65
|
+
screenshotBuffer = await captureScreenshot();
|
|
66
|
+
log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
|
|
67
|
+
await postNotificationsOnFail(uploadModel);
|
|
68
|
+
}
|
|
69
|
+
let url = this.defaultPage.url();
|
|
70
|
+
if (close)
|
|
71
|
+
await this.close();
|
|
72
|
+
await onTestEnd(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
|
|
73
|
+
currentPageUrl: url,
|
|
74
|
+
console: consoleStack,
|
|
75
|
+
error: errMessage
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.log("Lib error:", e);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
log.clear();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async runRPA(event, callback, close) {
|
|
86
|
+
let errMessage;
|
|
87
|
+
try {
|
|
88
|
+
if (close === undefined) {
|
|
89
|
+
if (event.queryStringParameters.close) {
|
|
90
|
+
close = event.queryStringParameters.close === "true";
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
close = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let consoleStack = [];
|
|
97
|
+
try {
|
|
98
|
+
await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
|
|
99
|
+
await this.startBrowser();
|
|
100
|
+
this.defaultPage.on('console', message => consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
101
|
+
.on('pageerror', ({ message }) => consoleStack.push(message))
|
|
102
|
+
.on('response', response => consoleStack.push(`${response.status()} ${response.url()}`))
|
|
103
|
+
.on('requestfailed', request => consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`));
|
|
104
|
+
await callback(event);
|
|
105
|
+
log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
errMessage = err;
|
|
109
|
+
log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
|
|
110
|
+
return errMessage;
|
|
111
|
+
}
|
|
112
|
+
if (close)
|
|
113
|
+
await this.close();
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
console.log("Lib error:", e);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
log.clear();
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
static setupHeader(event, uploadModel) {
|
|
124
|
+
let close = true;
|
|
125
|
+
if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {
|
|
126
|
+
const body = JSON.parse(event.body);
|
|
127
|
+
uploadModel.reportId = body.reportId;
|
|
128
|
+
uploadModel.nextSuites = body.nextSuites;
|
|
129
|
+
}
|
|
130
|
+
else if (event.queryStringParameters.close) {
|
|
131
|
+
close = event.queryStringParameters.close === "true";
|
|
132
|
+
}
|
|
133
|
+
return close;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export default new Puppeteer();
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auxcode/auxta",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "./build/AuxTA.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"build/"
|
|
8
|
+
],
|
|
6
9
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
10
|
+
"tsc": "tsc -p tsconfig.json",
|
|
11
|
+
"prepublish": "npm run tsc",
|
|
12
|
+
"test": "npm run prepublish & node ./build/AuxTA.js"
|
|
9
13
|
},
|
|
10
14
|
"author": "auxcode",
|
|
11
15
|
"license": "ISC",
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export function setupConfig(jsonConfig: any) {
|
|
2
|
-
if (!jsonConfig.baseURL) throw new Error("baseURL");
|
|
3
|
-
config.baseURL = jsonConfig.baseURL;
|
|
4
|
-
if (!jsonConfig.digitalProduct) throw new Error("digitalProduct");
|
|
5
|
-
config.digitalProduct = jsonConfig.digitalProduct;
|
|
6
|
-
if (!jsonConfig.testsURL) throw new Error("testsURL");
|
|
7
|
-
config.netlifyPath = (process.env.ENVIRONMENT == 'LOCAL') ? 'http://localhost:9999/' : jsonConfig.testsURL;
|
|
8
|
-
if (!jsonConfig.organization) throw new Error("organization");
|
|
9
|
-
config.organization = jsonConfig.organization;
|
|
10
|
-
if (!jsonConfig.token) throw new Error("token");
|
|
11
|
-
config.token = jsonConfig.token;
|
|
12
|
-
if (!jsonConfig.email) throw new Error("email");
|
|
13
|
-
config.auxtaCredentials.email = jsonConfig.email;
|
|
14
|
-
if (!jsonConfig.password) throw new Error("password");
|
|
15
|
-
config.auxtaCredentials.password = jsonConfig.password;
|
|
16
|
-
if (!jsonConfig.suitesList) throw new Error("suitesList");
|
|
17
|
-
config.suitesList = jsonConfig.suitesList;
|
|
18
|
-
if (jsonConfig.timeout) config.timeout = jsonConfig.timeout;
|
|
19
|
-
if (jsonConfig.screenWidth) config.screenWidth = jsonConfig.screenWidth;
|
|
20
|
-
if (jsonConfig.screenHeight) config.screenHeight = jsonConfig.screenHeight;
|
|
21
|
-
return config;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function setupOverrideConfig(overrideConfig: any){
|
|
25
|
-
if (overrideConfig.baseURL) config.baseURL = overrideConfig.baseURL;
|
|
26
|
-
if (overrideConfig.digitalProduct) config.digitalProduct = overrideConfig.digitalProduct;
|
|
27
|
-
if (overrideConfig.screenWidth) config.screenWidth = overrideConfig.screenWidth;
|
|
28
|
-
if (overrideConfig.screenHeight) config.screenHeight = overrideConfig.screenHeight;
|
|
29
|
-
return config;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export let config = {
|
|
33
|
-
auxtaURL: "https://auxta.live/.netlify/functions/",
|
|
34
|
-
baseURL: "",
|
|
35
|
-
siteURL: "",
|
|
36
|
-
organization: "",
|
|
37
|
-
netlifyPath: "",
|
|
38
|
-
digitalProduct: "",
|
|
39
|
-
token: "",
|
|
40
|
-
screenWidth: 1920,
|
|
41
|
-
screenHeight: 1080,
|
|
42
|
-
timeout: 10000,
|
|
43
|
-
suitesList: [],
|
|
44
|
-
auxtaCredentials: {
|
|
45
|
-
email: "",
|
|
46
|
-
password: "",
|
|
47
|
-
},
|
|
48
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export class UploadModel {
|
|
3
|
-
private _reportId: string;
|
|
4
|
-
private _nextSuites: [];
|
|
5
|
-
private _digitalProduct: string;
|
|
6
|
-
private _baseUrl: string;
|
|
7
|
-
private readonly _organization: string;
|
|
8
|
-
private _environment: string;
|
|
9
|
-
|
|
10
|
-
constructor(org: string, baseUrl: string, digitalProduct: string, environment: string) {
|
|
11
|
-
this._reportId = '';
|
|
12
|
-
this._nextSuites = [];
|
|
13
|
-
this._organization = org;
|
|
14
|
-
this._digitalProduct = digitalProduct;
|
|
15
|
-
this._environment = environment;
|
|
16
|
-
this._baseUrl = baseUrl;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get reportId(): string {
|
|
20
|
-
return this._reportId;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set reportId(value: string) {
|
|
24
|
-
this._reportId = value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get nextSuites(): [] {
|
|
28
|
-
return this._nextSuites;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
set nextSuites(value: []) {
|
|
32
|
-
this._nextSuites = value;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get digitalProduct(): string {
|
|
36
|
-
return this._digitalProduct;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
set digitalProduct(value: string) {
|
|
40
|
-
this._digitalProduct = value;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get organization(): string {
|
|
44
|
-
return this._organization;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get baseUrl(): string {
|
|
48
|
-
return this._baseUrl;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
set baseUrl(value: string) {
|
|
52
|
-
this._baseUrl = value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get environment(): string {
|
|
56
|
-
return this._environment;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
set environment(value: string) {
|
|
60
|
-
this._environment = value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { StatusOfStep } from "../enums/status-of.step";
|
|
2
|
-
|
|
3
|
-
export interface Step {
|
|
4
|
-
keyword: string,
|
|
5
|
-
name: string,
|
|
6
|
-
result: {
|
|
7
|
-
status: StatusOfStep,
|
|
8
|
-
duration: number
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class LogSteps {
|
|
13
|
-
private stepLog: Step[] = [];
|
|
14
|
-
private lastStepTime = new Date().getTime();
|
|
15
|
-
public statusCounter = {
|
|
16
|
-
[StatusOfStep.PASSED]: 0,
|
|
17
|
-
[StatusOfStep.FAILED]: 0,
|
|
18
|
-
[StatusOfStep.SKIPPED]: 0,
|
|
19
|
-
[StatusOfStep.SUGGESTION]: 0,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public addSuggestion(text: string) {
|
|
23
|
-
this.statusCounter[StatusOfStep.SUGGESTION]++;
|
|
24
|
-
this.stepLog.push({
|
|
25
|
-
keyword: 'Suggestion', name: text, result:
|
|
26
|
-
{status: StatusOfStep.SUGGESTION, duration: 0}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public clear() {
|
|
31
|
-
this.stepLog = [];
|
|
32
|
-
this.statusCounter = {
|
|
33
|
-
[StatusOfStep.PASSED]: 0,
|
|
34
|
-
[StatusOfStep.FAILED]: 0,
|
|
35
|
-
[StatusOfStep.SKIPPED]: 0,
|
|
36
|
-
[StatusOfStep.SUGGESTION]: 0,
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public push(keyword: string, name: string, status: StatusOfStep) {
|
|
41
|
-
console.log(`System log -- status: ${status} -- : ${name} `);
|
|
42
|
-
this.statusCounter[status]++;
|
|
43
|
-
const currentStep = new Date().getTime();
|
|
44
|
-
this.stepLog.push({keyword, name, result: {status, duration: currentStep - this.lastStepTime}});
|
|
45
|
-
this.lastStepTime = currentStep;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public returnScenarioReport() {
|
|
49
|
-
return this.stepLog;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public getStatusCount(status: StatusOfStep): number {
|
|
53
|
-
return this.statusCounter[status];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const log = new LogSteps();
|
|
58
|
-
export default log;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { Step } from "./log.service";
|
|
3
|
-
import { config } from "../configs/config";
|
|
4
|
-
import { UploadModel } from "../models/upload.model";
|
|
5
|
-
|
|
6
|
-
export interface Feature {
|
|
7
|
-
featureId: string,
|
|
8
|
-
featureName: string,
|
|
9
|
-
featureUri: string,
|
|
10
|
-
status: string,
|
|
11
|
-
scenariosCount: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface Scenario {
|
|
15
|
-
featureId: string,
|
|
16
|
-
featureName: string,
|
|
17
|
-
featureUri: string,
|
|
18
|
-
status: string,
|
|
19
|
-
scenariosCount: number
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Steps {
|
|
23
|
-
failedSteps: number,
|
|
24
|
-
passedSteps: number,
|
|
25
|
-
skippedSteps: number,
|
|
26
|
-
suggestedSteps: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function headers(token: string) {
|
|
30
|
-
return {
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
'cookie': `authToken=${token}`
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function auth() {
|
|
39
|
-
return axios.post(
|
|
40
|
-
config.auxtaURL + 'login',
|
|
41
|
-
config.auxtaCredentials,
|
|
42
|
-
{
|
|
43
|
-
headers: {
|
|
44
|
-
'Content-Type': 'application/json',
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
.then(({data}) => {
|
|
48
|
-
return data.token
|
|
49
|
-
})
|
|
50
|
-
.catch(() => {
|
|
51
|
-
throw new Error("Invalid login credentials")
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function createEmptyReport(body: any): Promise<string> {
|
|
56
|
-
const token = await auth();
|
|
57
|
-
return (await axios.post(
|
|
58
|
-
config.auxtaURL + "create-empty-report",
|
|
59
|
-
{
|
|
60
|
-
environment: body.environment,
|
|
61
|
-
digitalProductName: body.digitalProduct,
|
|
62
|
-
start: new Date(),
|
|
63
|
-
url: body.baseUrl
|
|
64
|
-
},
|
|
65
|
-
headers(token)
|
|
66
|
-
)).data.reportId;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function uploadScenario(stepLog: Step[], scenarioName: string, screenshot?: Buffer, errMessage?: object) {
|
|
70
|
-
let scenarios = [];
|
|
71
|
-
let token = await auth();
|
|
72
|
-
let lastStep = stepLog[stepLog.length - 1];
|
|
73
|
-
const stepLogFormat = JSON.parse(JSON.stringify(stepLog));
|
|
74
|
-
stepLogFormat.pop();
|
|
75
|
-
let output = (await axios.post(
|
|
76
|
-
config.auxtaURL + "create-scenario",
|
|
77
|
-
{
|
|
78
|
-
json: {
|
|
79
|
-
name: scenarioName,
|
|
80
|
-
steps: [
|
|
81
|
-
...stepLogFormat,
|
|
82
|
-
(lastStep!.result.status == 'failed')
|
|
83
|
-
? Object.assign(lastStep, {
|
|
84
|
-
result: {
|
|
85
|
-
...lastStep!.result,
|
|
86
|
-
error_message: JSON.stringify(errMessage)
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
: lastStep,
|
|
90
|
-
{
|
|
91
|
-
keyword: "After",
|
|
92
|
-
result: {
|
|
93
|
-
status: "passed",
|
|
94
|
-
duration: 2678000000
|
|
95
|
-
},
|
|
96
|
-
embeddings: (screenshot) ? [{
|
|
97
|
-
data: screenshot.toString("base64"),
|
|
98
|
-
mime_type: "image/png"
|
|
99
|
-
}] : undefined,
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
headers(token)
|
|
105
|
-
)).data.scenarios;
|
|
106
|
-
scenarios.push({
|
|
107
|
-
scenarioRef: output.scenarioRef,
|
|
108
|
-
name: output.name,
|
|
109
|
-
status: output.status,
|
|
110
|
-
stepsCount: output.stepsCount
|
|
111
|
-
});
|
|
112
|
-
return scenarios;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export async function uploadFeature(scenarioId: any[], scenarioName: string, uri: string, hasFailed: boolean) {
|
|
116
|
-
let token = await auth();
|
|
117
|
-
return (await axios.post(
|
|
118
|
-
config.auxtaURL + "create-feature",
|
|
119
|
-
{
|
|
120
|
-
json: {
|
|
121
|
-
name: scenarioName,
|
|
122
|
-
uri: uri
|
|
123
|
-
},
|
|
124
|
-
scenarios: scenarioId,
|
|
125
|
-
hasFailed: hasFailed
|
|
126
|
-
},
|
|
127
|
-
headers(token)
|
|
128
|
-
)).data;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export async function updateReport(reportId: string, feature: Feature, steps: Steps, isFinal: boolean) {
|
|
132
|
-
let token = await auth();
|
|
133
|
-
await axios.post(
|
|
134
|
-
config.auxtaURL + "update-inprogress-report",
|
|
135
|
-
{
|
|
136
|
-
reportId: reportId,
|
|
137
|
-
isFinal: isFinal,
|
|
138
|
-
data: {
|
|
139
|
-
feature: {
|
|
140
|
-
featureRef: feature.featureId,
|
|
141
|
-
name: feature.featureName,
|
|
142
|
-
uri: feature.featureUri,
|
|
143
|
-
status: feature.status,
|
|
144
|
-
scenariosCount: feature.scenariosCount
|
|
145
|
-
},
|
|
146
|
-
...steps
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
headers(token)
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export async function getReport(reportId: string): Promise<any> {
|
|
154
|
-
let token = await auth();
|
|
155
|
-
return (await axios.post(
|
|
156
|
-
config.auxtaURL + "get-report",
|
|
157
|
-
{reportId: reportId},
|
|
158
|
-
headers(token)
|
|
159
|
-
)).data;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export async function getLastDayResults(): Promise<any> {
|
|
163
|
-
let token = await auth();
|
|
164
|
-
return (await axios.get(
|
|
165
|
-
config.auxtaURL + `get-last-day-results?url=${config.baseURL}`,
|
|
166
|
-
headers(token)
|
|
167
|
-
)).data.results;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export async function postNotifications( body: UploadModel) {
|
|
171
|
-
let token = await auth();
|
|
172
|
-
await axios.post(`${config.auxtaURL}post-notification-after-run-background`, {
|
|
173
|
-
environmentName: body.environment,
|
|
174
|
-
digitalProductName: body.digitalProduct,
|
|
175
|
-
organizationName: body.organization,
|
|
176
|
-
reportId: body.reportId,
|
|
177
|
-
}, headers(token));
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
export async function postNotificationsOnFail( body: UploadModel) {
|
|
182
|
-
let token = await auth();
|
|
183
|
-
await axios.post(`${config.auxtaURL}post-notifications-after-case-fail-background`, {
|
|
184
|
-
environmentName: body.environment,
|
|
185
|
-
digitalProductName: body.digitalProduct,
|
|
186
|
-
organizationName: body.organization,
|
|
187
|
-
reportId: body.reportId,
|
|
188
|
-
}, headers(token));
|
|
189
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { config } from "../configs/config";
|
|
3
|
-
|
|
4
|
-
export async function startSuite(suites: string[], reportId?: string) {
|
|
5
|
-
if (suites.length === 0) return;
|
|
6
|
-
const next = suites.shift();
|
|
7
|
-
console.log('Starting next suite: ' + next);
|
|
8
|
-
try{
|
|
9
|
-
await axios.post(
|
|
10
|
-
`${config.netlifyPath}.netlify/functions/${next}?token=${config.token}`,
|
|
11
|
-
{nextSuites: suites, reportId: reportId})
|
|
12
|
-
} catch (e){
|
|
13
|
-
// skip the suite if not found
|
|
14
|
-
await startSuite(suites, reportId);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import chromium from 'chrome-aws-lambda';
|
|
2
|
-
import log from "../auxta/services/log.service";
|
|
3
|
-
import {captureScreenshot} from "../auxta/utilities/screenshot.helper";
|
|
4
|
-
import {onTestEnd} from "../auxta/hooks/report.hook";
|
|
5
|
-
import auxta from "../AuxTA";
|
|
6
|
-
import {StatusOfStep} from "../auxta/enums/status-of.step";
|
|
7
|
-
import {UploadModel} from "../auxta/models/upload.model";
|
|
8
|
-
import puppeteer_core from 'puppeteer-core';
|
|
9
|
-
import {config} from "./../auxta/configs/config";
|
|
10
|
-
import {postNotificationsOnFail} from "../auxta/services/report.service";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export class Puppeteer {
|
|
14
|
-
public defaultPage!: puppeteer_core.Page;
|
|
15
|
-
private browser!: puppeteer_core.Browser;
|
|
16
|
-
|
|
17
|
-
public async startBrowser() {
|
|
18
|
-
let args = [
|
|
19
|
-
'--start-maximized',
|
|
20
|
-
'--no-sandbox',
|
|
21
|
-
'--disable-setuid-sandbox',
|
|
22
|
-
'--disable-dev-shm-usage',
|
|
23
|
-
'--single-process'
|
|
24
|
-
];
|
|
25
|
-
if (process.env.ENVIRONMENT != 'LOCAL')
|
|
26
|
-
args.push(`--window-size=${config.screenWidth},${config.screenHeight}`)
|
|
27
|
-
this.browser = await chromium.puppeteer.launch({
|
|
28
|
-
executablePath: process.env.ENVIRONMENT === 'LOCAL' ? undefined : await chromium.executablePath,
|
|
29
|
-
args,
|
|
30
|
-
ignoreDefaultArgs: ["--enable-automation"],
|
|
31
|
-
defaultViewport: process.env.ENVIRONMENT === 'LOCAL' ? null : {
|
|
32
|
-
width: config.screenWidth,
|
|
33
|
-
height: config.screenHeight
|
|
34
|
-
},
|
|
35
|
-
// Return back to headless for netlify
|
|
36
|
-
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
|
|
37
|
-
});
|
|
38
|
-
this.defaultPage = (await this.browser.pages())[0];
|
|
39
|
-
await this.defaultPage.goto(config.baseURL, {waitUntil: 'networkidle0'})
|
|
40
|
-
await this.defaultPage.waitForNetworkIdle();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public async close() {
|
|
44
|
-
if (this.browser) {
|
|
45
|
-
let pages = await this.browser.pages();
|
|
46
|
-
await Promise.all(pages.map((page: { close: () => any; }) => page.close()));
|
|
47
|
-
await this.browser.close();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async run(event: any, callback: any, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel?: UploadModel, close?: boolean) {
|
|
52
|
-
try {
|
|
53
|
-
if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
|
|
54
|
-
if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
|
|
55
|
-
let screenshotBuffer: Buffer | undefined;
|
|
56
|
-
let errMessage: any;
|
|
57
|
-
let statusCode: number = 200;
|
|
58
|
-
|
|
59
|
-
let consoleStack: any[] = [];
|
|
60
|
-
try {
|
|
61
|
-
await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
|
|
62
|
-
await this.startBrowser()
|
|
63
|
-
this.defaultPage.on('console', message =>
|
|
64
|
-
consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
65
|
-
.on('pageerror', ({message}) => consoleStack.push(message))
|
|
66
|
-
.on('response', response =>
|
|
67
|
-
consoleStack.push(`${response.status()} ${response.url()}`))
|
|
68
|
-
.on('requestfailed', request =>
|
|
69
|
-
consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`))
|
|
70
|
-
await callback(event)
|
|
71
|
-
log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
console.log("Error", err);
|
|
74
|
-
errMessage = err;
|
|
75
|
-
statusCode = 500;
|
|
76
|
-
screenshotBuffer = await captureScreenshot();
|
|
77
|
-
log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
|
|
78
|
-
await postNotificationsOnFail(uploadModel)
|
|
79
|
-
}
|
|
80
|
-
let url = this.defaultPage.url();
|
|
81
|
-
if (close) await this.close();
|
|
82
|
-
|
|
83
|
-
await onTestEnd(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
|
|
84
|
-
currentPageUrl: url,
|
|
85
|
-
console: consoleStack,
|
|
86
|
-
error: errMessage
|
|
87
|
-
});
|
|
88
|
-
} catch (e) {
|
|
89
|
-
console.log("Lib error:", e);
|
|
90
|
-
} finally {
|
|
91
|
-
log.clear();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public async runRPA(event: any, callback: any, close?: boolean) {
|
|
96
|
-
let errMessage: any;
|
|
97
|
-
try {
|
|
98
|
-
if (close === undefined) {
|
|
99
|
-
if (event.queryStringParameters.close) {
|
|
100
|
-
close = event.queryStringParameters.close === "true";
|
|
101
|
-
} else {
|
|
102
|
-
close = true
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
let consoleStack: any[] = [];
|
|
106
|
-
try {
|
|
107
|
-
await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
|
|
108
|
-
await this.startBrowser()
|
|
109
|
-
this.defaultPage.on('console', message =>
|
|
110
|
-
consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
111
|
-
.on('pageerror', ({message}) => consoleStack.push(message))
|
|
112
|
-
.on('response', response =>
|
|
113
|
-
consoleStack.push(`${response.status()} ${response.url()}`))
|
|
114
|
-
.on('requestfailed', request =>
|
|
115
|
-
consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`))
|
|
116
|
-
await callback(event)
|
|
117
|
-
log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
118
|
-
} catch (err) {
|
|
119
|
-
errMessage = err;
|
|
120
|
-
log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
|
|
121
|
-
return errMessage;
|
|
122
|
-
}
|
|
123
|
-
if (close) await this.close();
|
|
124
|
-
} catch (e) {
|
|
125
|
-
console.log("Lib error:", e);
|
|
126
|
-
} finally {
|
|
127
|
-
log.clear();
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private static setupHeader(event: any, uploadModel: UploadModel) {
|
|
133
|
-
let close = true;
|
|
134
|
-
if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {
|
|
135
|
-
const body = JSON.parse(event.body)
|
|
136
|
-
uploadModel.reportId = body.reportId;
|
|
137
|
-
uploadModel.nextSuites = body.nextSuites;
|
|
138
|
-
} else if (event.queryStringParameters.close) {
|
|
139
|
-
close = event.queryStringParameters.close === "true";
|
|
140
|
-
}
|
|
141
|
-
return close;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export default new Puppeteer();
|