@auxcode/auxta 0.1.3 → 0.1.4
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
CHANGED
package/src/AuxTA.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import puppeteer, { Puppeteer } from "./puppeteer/puppeteer";
|
|
2
|
-
import { FunctionHelper } from "./macros/helpers/code.helper";
|
|
3
|
-
import f from "./macros/helpers/code.helper";
|
|
4
|
-
import run from "./auxta/run";
|
|
5
|
-
import { Log } from "./auxta/services/log.service";
|
|
6
|
-
import defaultLog from "./auxta/services/log.service";
|
|
2
|
+
import f, { FunctionHelper } from "./macros/helpers/code.helper";
|
|
7
3
|
import path from "path";
|
|
8
4
|
import fs from "fs";
|
|
9
5
|
import { StepStatusEnum } from "./auxta/enums/step-status.enum";
|
|
10
6
|
import { UploadModel } from "./auxta/models/upload.model";
|
|
11
7
|
import * as dotenv from "dotenv";
|
|
12
|
-
import { setupConfig } from "./auxta/configs/config";
|
|
8
|
+
import { config, setupConfig } from "./auxta/configs/config";
|
|
9
|
+
import { startSuite } from "./auxta/utilities/start-suite.helper";
|
|
10
|
+
import { createEmptyReport } from "./auxta/services/report.service";
|
|
13
11
|
|
|
14
12
|
dotenv.config();
|
|
15
13
|
|
|
16
14
|
class AuxTA {
|
|
17
15
|
public puppeteer: Puppeteer = puppeteer;
|
|
18
|
-
public
|
|
19
|
-
public run: Function = run;
|
|
20
|
-
public logger: Log.LogSteps = defaultLog;
|
|
16
|
+
public functions: FunctionHelper = f;
|
|
21
17
|
|
|
22
18
|
private readonly uploadModel: UploadModel;
|
|
23
19
|
|
|
@@ -25,22 +21,48 @@ class AuxTA {
|
|
|
25
21
|
let file;
|
|
26
22
|
try {
|
|
27
23
|
//todo find a better way to load the file
|
|
28
|
-
|
|
24
|
+
let currentDir = "../"
|
|
25
|
+
while (true) {
|
|
26
|
+
file = path.join(__dirname, currentDir, "auxta.json");
|
|
27
|
+
try {
|
|
28
|
+
fs.accessSync(file, fs.constants.R_OK | fs.constants.W_OK)
|
|
29
|
+
break;
|
|
30
|
+
} catch {
|
|
31
|
+
currentDir += "../"
|
|
32
|
+
if (currentDir.length >= 30) {
|
|
33
|
+
process.exit(1);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
29
38
|
const jsonConfig = JSON.parse(fs.readFileSync(file).toString());
|
|
30
39
|
try {
|
|
31
40
|
setupConfig(jsonConfig)
|
|
32
|
-
} catch (e) {
|
|
33
|
-
|
|
34
|
-
process.exit(1);
|
|
41
|
+
} catch (e: any) {
|
|
42
|
+
console.log("Missing field in auxta.json:", e.message)
|
|
35
43
|
}
|
|
36
44
|
this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct);
|
|
37
|
-
} catch (e) {
|
|
45
|
+
} catch (e: any) {
|
|
38
46
|
console.log("Missing or corrupted config: suitesList.json. Searching in location:", file)
|
|
39
47
|
console.log(e);
|
|
40
48
|
process.exit(1);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
|
|
52
|
+
public async run(event: any) {
|
|
53
|
+
const model = this.getUploadModel();
|
|
54
|
+
let token: string = event.queryStringParameters.token;
|
|
55
|
+
let reportId: string | undefined = event.queryStringParameters.reportId;
|
|
56
|
+
if (token !== config.token) return {statusCode: 401, message: 'Unauthorized'}
|
|
57
|
+
const suites = config.suitesList.slice(0);
|
|
58
|
+
await startSuite(suites, reportId || await createEmptyReport(model));
|
|
59
|
+
return {statusCode: 204}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public startBrowser(event: any, callback: any, feature: string, scenario: string) {
|
|
63
|
+
this.puppeteer.run(event, callback, feature, scenario)
|
|
64
|
+
}
|
|
65
|
+
|
|
44
66
|
public getUploadModel(): UploadModel {
|
|
45
67
|
return this.uploadModel;
|
|
46
68
|
}
|
|
@@ -50,11 +72,7 @@ export const StepStatus = StepStatusEnum;
|
|
|
50
72
|
|
|
51
73
|
const auxta: AuxTA = new AuxTA();
|
|
52
74
|
|
|
53
|
-
export const auxtaLogger = auxta.logger;
|
|
54
|
-
export const auxtaPuppeteer = auxta.puppeteer;
|
|
55
|
-
export const auxtaSuggest = auxta.logger.addSuggestion;
|
|
56
|
-
export const auxtaLog = auxta.logger.push;
|
|
57
75
|
export const auxtaRun = auxta.run;
|
|
58
|
-
export const auxtaFunc = auxta.
|
|
76
|
+
export const auxtaFunc = auxta.functions;
|
|
59
77
|
|
|
60
78
|
export default auxta;
|
|
@@ -1,46 +1,52 @@
|
|
|
1
1
|
import { StepStatusEnum } from "../enums/step-status.enum";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export interface Step {
|
|
4
|
+
keyword: string,
|
|
5
|
+
name: string,
|
|
6
|
+
result: {
|
|
7
|
+
status: StepStatusEnum,
|
|
8
|
+
duration: number
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class LogSteps {
|
|
13
|
+
private stepLog: Step[] = [];
|
|
14
|
+
private lastStepTime = new Date().getTime();
|
|
15
|
+
public statusCounter = {
|
|
16
|
+
[StepStatusEnum.PASSED]: 0,
|
|
17
|
+
[StepStatusEnum.FAILED]: 0,
|
|
18
|
+
[StepStatusEnum.SKIPPED]: 0,
|
|
19
|
+
[StepStatusEnum.SUGGESTION]: 0,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public addSuggestion(text: string) {
|
|
23
|
+
this.statusCounter[StepStatusEnum.SUGGESTION]++;
|
|
24
|
+
this.stepLog.push({
|
|
25
|
+
keyword: 'Suggestion', name: text, result:
|
|
26
|
+
{status: StepStatusEnum.SUGGESTION, duration: 0}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public clear() {
|
|
31
|
+
this.stepLog = [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public push(keyword: string, name: string, status: StepStatusEnum) {
|
|
35
|
+
console.log(`System log -- status: ${status} -- : ${name} `);
|
|
36
|
+
this.statusCounter[status]++;
|
|
37
|
+
const currentStep = new Date().getTime();
|
|
38
|
+
this.stepLog.push({keyword, name, result: {status, duration: currentStep - this.lastStepTime}});
|
|
39
|
+
this.lastStepTime = currentStep;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public returnScenarioReport() {
|
|
43
|
+
return this.stepLog;
|
|
11
44
|
}
|
|
12
45
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private statusCounter = {
|
|
16
|
-
[StepStatusEnum.PASSED]: 0,
|
|
17
|
-
[StepStatusEnum.FAILED]: 0,
|
|
18
|
-
[StepStatusEnum.SKIPPED]: 0,
|
|
19
|
-
[StepStatusEnum.SUGGESTION]: 0,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public addSuggestion(text: string) {
|
|
23
|
-
this.push('Suggest', text, StepStatusEnum.SUGGESTION, 1000000);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public clear() {
|
|
27
|
-
this.stepLog = [];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public push(keyword: string, name: string, status: StepStatusEnum, duration: number) {
|
|
31
|
-
console.log(`System log -- status: ${status} -- : ${name} `);
|
|
32
|
-
this.statusCounter[status] = this.statusCounter[status] + 1;
|
|
33
|
-
this.stepLog.push({ keyword: keyword, name: name, result: { status: status, duration: duration } });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public returnScenarioReport() {
|
|
37
|
-
return this.stepLog;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public getStatusCount(status: StepStatusEnum): number{
|
|
41
|
-
return this.statusCounter[status];
|
|
42
|
-
}
|
|
46
|
+
public getStatusCount(status: StepStatusEnum): number {
|
|
47
|
+
return this.statusCounter[status];
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
const log = new LogSteps();
|
|
52
|
+
export default log;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import {
|
|
2
|
+
import { Step } from "./log.service";
|
|
3
3
|
import { config } from "../configs/config";
|
|
4
4
|
import UploadModel from "../models/upload.model";
|
|
5
5
|
|
|
@@ -62,7 +62,7 @@ export async function createEmptyReport(body: any): Promise<string> {
|
|
|
62
62
|
)).data.reportId;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export async function uploadScenario(stepLog:
|
|
65
|
+
export async function uploadScenario(stepLog: Step[], scenarioName: string, screenshot?: Buffer, errMessage?: string) {
|
|
66
66
|
let scenarios = [];
|
|
67
67
|
let token = await auth();
|
|
68
68
|
let lastStep = stepLog[stepLog.length - 1];
|
|
@@ -5,6 +5,14 @@ import { StepStatusEnum } from "../../auxta/enums/step-status.enum";
|
|
|
5
5
|
export class FunctionHelper {
|
|
6
6
|
public readonly timeout: number = Number(process.env.AUXTA_TIMEOUT);
|
|
7
7
|
|
|
8
|
+
public log(keyword: string, name: string, status: StepStatusEnum){
|
|
9
|
+
log.push(keyword, name, status)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public suggest(name: string){
|
|
13
|
+
log.addSuggestion(name)
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
public async clickByText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
9
17
|
await page.waitForTimeout(this.timeout);
|
|
10
18
|
const splitedQuotes = text.replace(/'/g, `', "'", '`)
|
|
@@ -12,10 +20,10 @@ export class FunctionHelper {
|
|
|
12
20
|
const [linkHandlers] = await page.$x(`//${selector}[. = ${escapedText}]`);
|
|
13
21
|
|
|
14
22
|
if (linkHandlers) {
|
|
15
|
-
log.push('And', `I click ${selector} with text ${text}`, StepStatusEnum.PASSED
|
|
23
|
+
log.push('And', `I click ${selector} with text ${text}`, StepStatusEnum.PASSED);
|
|
16
24
|
await linkHandlers.click();
|
|
17
25
|
} else {
|
|
18
|
-
log.push('And', `I click ${selector} with text ${text}`, StepStatusEnum.FAILED
|
|
26
|
+
log.push('And', `I click ${selector} with text ${text}`, StepStatusEnum.FAILED);
|
|
19
27
|
throw new Error(`Link not found: ${text}`);
|
|
20
28
|
}
|
|
21
29
|
}
|
|
@@ -25,14 +33,26 @@ export class FunctionHelper {
|
|
|
25
33
|
const escapedText = `concat('${splitedQuotes}', '')`;
|
|
26
34
|
const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${escapedText}]`);
|
|
27
35
|
if (linkHandlers.length > 0) {
|
|
28
|
-
log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.PASSED
|
|
36
|
+
log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.PASSED);
|
|
29
37
|
return true;
|
|
30
38
|
} else {
|
|
31
|
-
log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.FAILED
|
|
39
|
+
log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.FAILED);
|
|
32
40
|
throw new Error(`Link not found: ${text}`);
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
|
|
44
|
+
public async goto(page: string) {
|
|
45
|
+
await puppeteer.defaultPage.goto(page);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async type(field: string, value: string) {
|
|
49
|
+
await puppeteer.defaultPage.type(field, value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async waitForNetwork() {
|
|
53
|
+
await puppeteer.defaultPage.waitForNetworkIdle();
|
|
54
|
+
}
|
|
55
|
+
|
|
36
56
|
/**
|
|
37
57
|
* Waiting for selector with timeout 60000
|
|
38
58
|
*
|
|
@@ -58,10 +78,10 @@ export class FunctionHelper {
|
|
|
58
78
|
public async urlContains(selector: string) {
|
|
59
79
|
const url = puppeteer.defaultPage.url();
|
|
60
80
|
if (!url.includes(selector)) {
|
|
61
|
-
await log.push('And', `I am on the ${selector} page`, StepStatusEnum.FAILED
|
|
81
|
+
await log.push('And', `I am on the ${selector} page`, StepStatusEnum.FAILED);
|
|
62
82
|
throw new Error(`I am not at the ${selector} page`)
|
|
63
83
|
}
|
|
64
|
-
await log.push('And', `I am on the ${selector} page`, StepStatusEnum.PASSED
|
|
84
|
+
await log.push('And', `I am on the ${selector} page`, StepStatusEnum.PASSED);
|
|
65
85
|
}
|
|
66
86
|
|
|
67
87
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import chromium from 'chrome-aws-lambda';
|
|
2
2
|
import log from "../auxta/services/log.service";
|
|
3
|
-
import { returnImage } from '../auxta/helpers/response.helper';
|
|
4
3
|
import { captureScreenshot } from "../auxta/utilities/screenshot.helper";
|
|
5
4
|
import { AfterEach } from "../auxta/hooks/report.hook";
|
|
6
5
|
import auxta from "../AuxTA";
|
|
@@ -26,25 +25,13 @@ export class Puppeteer {
|
|
|
26
25
|
// Return back to headless for commit
|
|
27
26
|
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
|
|
28
27
|
});
|
|
29
|
-
this.defaultPage = await this.browser.
|
|
28
|
+
this.defaultPage = (await this.browser.pages())[0];
|
|
30
29
|
await this.defaultPage.setViewport({
|
|
31
30
|
width: 1440,
|
|
32
31
|
height: 900
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
public async goto(page: string) {
|
|
37
|
-
await this.defaultPage.goto(page);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public async type(field: string, value: string) {
|
|
41
|
-
await this.defaultPage.type(field, value);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public async waitForNetwork() {
|
|
45
|
-
await this.defaultPage.waitForNetworkIdle();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
35
|
public async close() {
|
|
49
36
|
if (this.browser) {
|
|
50
37
|
let pages = await this.browser.pages();
|
|
@@ -53,7 +40,7 @@ export class Puppeteer {
|
|
|
53
40
|
}
|
|
54
41
|
}
|
|
55
42
|
|
|
56
|
-
public async run(event: any, callback: any,
|
|
43
|
+
public async run(event: any, callback: any, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel?: UploadModel, close?: boolean) {
|
|
57
44
|
if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
|
|
58
45
|
if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
|
|
59
46
|
let screenshotBuffer: Buffer;
|
|
@@ -61,23 +48,21 @@ export class Puppeteer {
|
|
|
61
48
|
let statusCode: number = 200;
|
|
62
49
|
|
|
63
50
|
try {
|
|
64
|
-
await log.push('When', `Starting puppeteer process`, StepStatusEnum.PASSED
|
|
51
|
+
await log.push('When', `Starting puppeteer process`, StepStatusEnum.PASSED);
|
|
65
52
|
await this.startBrowser()
|
|
66
53
|
await callback(event)
|
|
67
54
|
screenshotBuffer = await captureScreenshot();
|
|
68
|
-
await log.push('When', `Finished puppeteer process`, StepStatusEnum.PASSED
|
|
55
|
+
await log.push('When', `Finished puppeteer process`, StepStatusEnum.PASSED);
|
|
69
56
|
} catch (err: any) {
|
|
70
|
-
console.log(`
|
|
57
|
+
console.log(`Error ${err}`);
|
|
71
58
|
errMessage = err;
|
|
72
59
|
statusCode = 500;
|
|
73
60
|
screenshotBuffer = await captureScreenshot();
|
|
74
|
-
await log.push('When', `Finished puppeteer process`, StepStatusEnum.FAILED
|
|
61
|
+
await log.push('When', `Finished puppeteer process`, StepStatusEnum.FAILED);
|
|
75
62
|
}
|
|
76
63
|
if (close) await this.close();
|
|
77
64
|
|
|
78
|
-
await AfterEach(uploadModel,
|
|
79
|
-
|
|
80
|
-
return returnImage(statusCode, screenshotBuffer);
|
|
65
|
+
await AfterEach(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, errMessage);
|
|
81
66
|
}
|
|
82
67
|
|
|
83
68
|
private static setupHeader(event: any, uploadModel: UploadModel) {
|
package/src/auxta/run.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createEmptyReport } from "./services/report.service";
|
|
2
|
-
import { startSuite } from "./utilities/start-suite.helper";
|
|
3
|
-
import auxta from "../AuxTA";
|
|
4
|
-
import { config } from "./configs/config";
|
|
5
|
-
|
|
6
|
-
export default async function run(event: any) {
|
|
7
|
-
const model = auxta.getUploadModel();
|
|
8
|
-
let token: string = event.queryStringParameters.token;
|
|
9
|
-
let reportId: string | undefined = event.queryStringParameters.reportId;
|
|
10
|
-
if (token !== config.token) return {statusCode: 401, message: 'Unauthorized'}
|
|
11
|
-
const suites = config.suitesList.slice(0);
|
|
12
|
-
await startSuite(suites, reportId || await createEmptyReport(model));
|
|
13
|
-
return {statusCode: 204}
|
|
14
|
-
}
|