@auxcode/auxta 0.4.7 → 0.5.1
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/package.json +1 -1
- package/src/AuxTA.ts +43 -29
- package/src/macros/helpers/code.helper.ts +6 -0
- package/src/puppeteer/puppeteer.ts +45 -8
package/package.json
CHANGED
package/src/AuxTA.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import puppeteer, {
|
|
2
|
-
import {
|
|
1
|
+
import puppeteer, {Puppeteer} from "./puppeteer/puppeteer";
|
|
2
|
+
import {FunctionHelper} from "./macros/helpers/code.helper";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import StatusOfStep from "./auxta/enums/status-of.step";
|
|
6
|
-
import {
|
|
6
|
+
import {UploadModel} from "./auxta/models/upload.model";
|
|
7
7
|
import * as dotenv from "dotenv";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import {setupConfig, config as c, setupOverrideConfig} from "./auxta/configs/config";
|
|
9
|
+
import {startSuite} from "./auxta/utilities/start-suite.helper";
|
|
10
|
+
import {createEmptyReport} from "./auxta/services/report.service";
|
|
11
11
|
|
|
12
12
|
dotenv.config();
|
|
13
13
|
|
|
@@ -20,32 +20,36 @@ class AuxTA extends FunctionHelper {
|
|
|
20
20
|
constructor() {
|
|
21
21
|
super();
|
|
22
22
|
let file;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (!process.env.RPA) {
|
|
24
|
+
try {
|
|
25
|
+
let currentDir = ""
|
|
26
|
+
while (true) {
|
|
27
|
+
file = path.join(__dirname, currentDir, "auxta.json");
|
|
28
|
+
if (!fs.existsSync(file)) {
|
|
29
|
+
currentDir += "../"
|
|
30
|
+
if (currentDir.length >= 30) {
|
|
31
|
+
console.log("auxta.json file not found!")
|
|
32
|
+
process.exit(1);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
break;
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const jsonConfig = JSON.parse(fs.readFileSync(file).toString());
|
|
40
|
+
try {
|
|
41
|
+
this.config = setupConfig(jsonConfig)
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.log("Missing field in auxta.json:", e)
|
|
44
|
+
}
|
|
45
|
+
this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct, jsonConfig.environment);
|
|
41
46
|
} catch (e) {
|
|
42
|
-
console.log("Missing
|
|
47
|
+
console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
|
|
48
|
+
console.log(e);
|
|
49
|
+
process.exit(1);
|
|
43
50
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
|
|
47
|
-
console.log(e);
|
|
48
|
-
process.exit(1);
|
|
51
|
+
} else {
|
|
52
|
+
this.uploadModel = new UploadModel('', '', '', '');
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -58,7 +62,8 @@ class AuxTA extends FunctionHelper {
|
|
|
58
62
|
await startSuite(suites, reportId || await createEmptyReport(this.uploadModel));
|
|
59
63
|
return {statusCode: 204}
|
|
60
64
|
}
|
|
61
|
-
|
|
65
|
+
|
|
66
|
+
private changeModelData(overrideConfig?: any) {
|
|
62
67
|
if (overrideConfig) {
|
|
63
68
|
if (overrideConfig.digitalProduct) this.uploadModel.digitalProduct = overrideConfig.digitalProduct
|
|
64
69
|
if (overrideConfig.environment) this.uploadModel.environment = overrideConfig.environment
|
|
@@ -78,6 +83,15 @@ class AuxTA extends FunctionHelper {
|
|
|
78
83
|
return this.puppeteer.run(event, callback, feature, scenario)
|
|
79
84
|
}
|
|
80
85
|
|
|
86
|
+
public async startBrowserRPA(event: any, callback: any, baseURL: string) {
|
|
87
|
+
this.changeModelData({
|
|
88
|
+
baseURL: baseURL,
|
|
89
|
+
environment: '',
|
|
90
|
+
digitalProduct: ''
|
|
91
|
+
});
|
|
92
|
+
return this.puppeteer.runRPA(event, callback)
|
|
93
|
+
}
|
|
94
|
+
|
|
81
95
|
public getUploadModel(): UploadModel {
|
|
82
96
|
return this.uploadModel;
|
|
83
97
|
}
|
|
@@ -162,6 +162,12 @@ export class FunctionHelper {
|
|
|
162
162
|
await page.keyboard.press('Enter');
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
public async waitForPageToBeCreated(selector: string,page = puppeteer.defaultPage) {
|
|
166
|
+
const nav = new Promise(res => page.browser().on('targetcreated', res));
|
|
167
|
+
await this.click(selector);
|
|
168
|
+
await nav;
|
|
169
|
+
}
|
|
170
|
+
|
|
165
171
|
//TODO work in progress
|
|
166
172
|
/*
|
|
167
173
|
private async microsoftLogin(button: string, email: string, password: string) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import chromium from 'chrome-aws-lambda';
|
|
2
2
|
import log from "../auxta/services/log.service";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {captureScreenshot} from "../auxta/utilities/screenshot.helper";
|
|
4
|
+
import {onTestEnd} from "../auxta/hooks/report.hook";
|
|
5
5
|
import auxta from "../AuxTA";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import {StatusOfStep} from "../auxta/enums/status-of.step";
|
|
7
|
+
import {UploadModel} from "../auxta/models/upload.model";
|
|
8
8
|
import puppeteer_core from 'puppeteer-core';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import {config} from "./../auxta/configs/config";
|
|
10
|
+
import {postNotificationsOnFail} from "../auxta/services/report.service";
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
export class Puppeteer {
|
|
@@ -49,7 +49,7 @@ export class Puppeteer {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
public async run(event: any, callback: any, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel?: UploadModel, close?: boolean) {
|
|
52
|
-
try{
|
|
52
|
+
try {
|
|
53
53
|
if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
|
|
54
54
|
if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
|
|
55
55
|
let screenshotBuffer: Buffer | undefined;
|
|
@@ -85,13 +85,50 @@ export class Puppeteer {
|
|
|
85
85
|
console: consoleStack,
|
|
86
86
|
error: errMessage
|
|
87
87
|
});
|
|
88
|
-
} catch (e){
|
|
88
|
+
} catch (e) {
|
|
89
89
|
console.log("Lib error:", e);
|
|
90
90
|
} finally {
|
|
91
91
|
log.clear();
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
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
|
+
|
|
95
132
|
private static setupHeader(event: any, uploadModel: UploadModel) {
|
|
96
133
|
let close = true;
|
|
97
134
|
if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {
|