@auxcode/auxta 0.1.4 → 0.1.8
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 +5 -8
- package/src/auxta/enums/step-status.enum.ts +1 -0
- package/src/auxta/hooks/report.hook.ts +1 -1
- package/src/auxta/models/upload.model.ts +0 -2
- package/src/auxta/services/report.service.ts +1 -1
- package/src/auxta/utilities/screenshot.helper.ts +4 -3
- package/src/macros/helpers/code.helper.ts +24 -14
- package/src/puppeteer/puppeteer.ts +5 -5
package/package.json
CHANGED
package/src/AuxTA.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import puppeteer, { Puppeteer } from "./puppeteer/puppeteer";
|
|
2
|
-
import
|
|
2
|
+
import { FunctionHelper } from "./macros/helpers/code.helper";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
|
-
import
|
|
5
|
+
import StepStatusEnum from "./auxta/enums/step-status.enum";
|
|
6
6
|
import { UploadModel } from "./auxta/models/upload.model";
|
|
7
7
|
import * as dotenv from "dotenv";
|
|
8
8
|
import { config, setupConfig } from "./auxta/configs/config";
|
|
@@ -11,13 +11,13 @@ import { createEmptyReport } from "./auxta/services/report.service";
|
|
|
11
11
|
|
|
12
12
|
dotenv.config();
|
|
13
13
|
|
|
14
|
-
class AuxTA {
|
|
14
|
+
class AuxTA extends FunctionHelper {
|
|
15
15
|
public puppeteer: Puppeteer = puppeteer;
|
|
16
|
-
public functions: FunctionHelper = f;
|
|
17
16
|
|
|
18
17
|
private readonly uploadModel: UploadModel;
|
|
19
18
|
|
|
20
19
|
constructor() {
|
|
20
|
+
super();
|
|
21
21
|
let file;
|
|
22
22
|
try {
|
|
23
23
|
//todo find a better way to load the file
|
|
@@ -50,7 +50,7 @@ class AuxTA {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public async run(event: any) {
|
|
53
|
-
const model = this.
|
|
53
|
+
const model = this.uploadModel;
|
|
54
54
|
let token: string = event.queryStringParameters.token;
|
|
55
55
|
let reportId: string | undefined = event.queryStringParameters.reportId;
|
|
56
56
|
if (token !== config.token) return {statusCode: 401, message: 'Unauthorized'}
|
|
@@ -72,7 +72,4 @@ export const StepStatus = StepStatusEnum;
|
|
|
72
72
|
|
|
73
73
|
const auxta: AuxTA = new AuxTA();
|
|
74
74
|
|
|
75
|
-
export const auxtaRun = auxta.run;
|
|
76
|
-
export const auxtaFunc = auxta.functions;
|
|
77
|
-
|
|
78
75
|
export default auxta;
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '../services/report.service';
|
|
11
11
|
import { startSuite } from '../utilities/start-suite.helper';
|
|
12
12
|
import { StepStatusEnum } from "../enums/step-status.enum";
|
|
13
|
-
import UploadModel from "../models/upload.model";
|
|
13
|
+
import { UploadModel } from "../models/upload.model";
|
|
14
14
|
|
|
15
15
|
export async function AfterEach(body: any, featureName: string, scenarioName: string, statusCode: number, screenshotBuffer: Buffer, errMessage?: string) {
|
|
16
16
|
let isFinal: boolean = false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { Step } from "./log.service";
|
|
3
3
|
import { config } from "../configs/config";
|
|
4
|
-
import UploadModel from "../models/upload.model";
|
|
4
|
+
import { UploadModel } from "../models/upload.model";
|
|
5
5
|
|
|
6
6
|
export interface Feature {
|
|
7
7
|
featureId: string,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import puppeteer from "../../puppeteer/puppeteer";
|
|
2
2
|
|
|
3
3
|
export async function captureScreenshot() {
|
|
4
|
-
const pages = await
|
|
4
|
+
const pages = await puppeteer.defaultPage.browser().pages();
|
|
5
|
+
if (!pages.length) throw `Browser is closed`;
|
|
5
6
|
const lastPage = pages[pages.length - 1];
|
|
6
7
|
|
|
7
8
|
const screenshotBuffer = await lastPage.screenshot({
|
|
@@ -9,7 +10,7 @@ export async function captureScreenshot() {
|
|
|
9
10
|
encoding: 'binary'
|
|
10
11
|
}
|
|
11
12
|
);
|
|
12
|
-
if (Buffer.isBuffer(screenshotBuffer))
|
|
13
|
+
if (Buffer.isBuffer(screenshotBuffer))
|
|
13
14
|
return screenshotBuffer;
|
|
14
15
|
else throw `Failed to capture buffer screenshot`;
|
|
15
16
|
}
|
|
@@ -3,7 +3,7 @@ import puppeteer from "../../puppeteer/puppeteer";
|
|
|
3
3
|
import { StepStatusEnum } from "../../auxta/enums/step-status.enum";
|
|
4
4
|
|
|
5
5
|
export class FunctionHelper {
|
|
6
|
-
public readonly
|
|
6
|
+
public readonly defaultTimeout: number = Number(process.env.AUXTA_TIMEOUT);
|
|
7
7
|
|
|
8
8
|
public log(keyword: string, name: string, status: StepStatusEnum){
|
|
9
9
|
log.push(keyword, name, status)
|
|
@@ -12,26 +12,27 @@ export class FunctionHelper {
|
|
|
12
12
|
public suggest(name: string){
|
|
13
13
|
log.addSuggestion(name)
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
private getEscapedText(text: string){
|
|
17
|
+
const splitedQuotes = text.replace(/'/g, `', "'", '`)
|
|
18
|
+
return `concat('${splitedQuotes}', '')`;
|
|
19
|
+
}
|
|
15
20
|
|
|
16
21
|
public async clickByText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
17
|
-
await page.waitForTimeout(this.
|
|
18
|
-
const
|
|
19
|
-
const escapedText = `concat('${splitedQuotes}', '')`;
|
|
20
|
-
const [linkHandlers] = await page.$x(`//${selector}[. = ${escapedText}]`);
|
|
22
|
+
await page.waitForTimeout(this.defaultTimeout);
|
|
23
|
+
const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
21
24
|
|
|
22
25
|
if (linkHandlers) {
|
|
23
|
-
log.push('And', `I click ${
|
|
26
|
+
log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.PASSED);
|
|
24
27
|
await linkHandlers.click();
|
|
25
28
|
} else {
|
|
26
|
-
log.push('And', `I click ${
|
|
29
|
+
log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.FAILED);
|
|
27
30
|
throw new Error(`Link not found: ${text}`);
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
public async waitForSelectorWithText(selector: string, text: string) {
|
|
32
|
-
const
|
|
33
|
-
const escapedText = `concat('${splitedQuotes}', '')`;
|
|
34
|
-
const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${escapedText}]`);
|
|
35
|
+
const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
35
36
|
if (linkHandlers.length > 0) {
|
|
36
37
|
log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.PASSED);
|
|
37
38
|
return true;
|
|
@@ -43,16 +44,23 @@ export class FunctionHelper {
|
|
|
43
44
|
|
|
44
45
|
public async goto(page: string) {
|
|
45
46
|
await puppeteer.defaultPage.goto(page);
|
|
47
|
+
log.push('And', `I go to the ${page} page`, StepStatusEnum.PASSED);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
public async type(field: string, value: string) {
|
|
49
51
|
await puppeteer.defaultPage.type(field, value);
|
|
52
|
+
const elementName = await puppeteer.defaultPage.$eval(field, (e) => e.textContent);
|
|
53
|
+
log.push('And', `I type '${value}' into the ${elementName} field`, StepStatusEnum.PASSED);
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
public async waitForNetwork() {
|
|
53
57
|
await puppeteer.defaultPage.waitForNetworkIdle();
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
public async timeout(timeout = this.defaultTimeout) {
|
|
61
|
+
await puppeteer.defaultPage.waitForTimeout(timeout);
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
/**
|
|
57
65
|
* Waiting for selector with timeout 60000
|
|
58
66
|
*
|
|
@@ -63,7 +71,7 @@ export class FunctionHelper {
|
|
|
63
71
|
* @param page
|
|
64
72
|
*/
|
|
65
73
|
|
|
66
|
-
public async waitForSelector(option: string, selector: string, time: number = this.
|
|
74
|
+
public async waitForSelector(option: string, selector: string, time: number = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
67
75
|
await page.waitForSelector(selector, {
|
|
68
76
|
[option]: true,
|
|
69
77
|
timeout: time
|
|
@@ -71,17 +79,19 @@ export class FunctionHelper {
|
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
public async click(className: string, page = puppeteer.defaultPage) {
|
|
74
|
-
await page.waitForTimeout(this.
|
|
82
|
+
await page.waitForTimeout(this.defaultTimeout);
|
|
83
|
+
const elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
75
84
|
await page.click(className);
|
|
85
|
+
log.push('Then', `I click on ${elementName}`, StepStatusEnum.PASSED);
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
public async urlContains(selector: string) {
|
|
79
89
|
const url = puppeteer.defaultPage.url();
|
|
80
90
|
if (!url.includes(selector)) {
|
|
81
|
-
|
|
91
|
+
log.push('And', `I am on the ${selector} page`, StepStatusEnum.FAILED);
|
|
82
92
|
throw new Error(`I am not at the ${selector} page`)
|
|
83
93
|
}
|
|
84
|
-
|
|
94
|
+
log.push('And', `I am on the ${selector} page`, StepStatusEnum.PASSED);
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
}
|
|
@@ -6,6 +6,8 @@ import auxta from "../AuxTA";
|
|
|
6
6
|
import { StepStatusEnum } from "../auxta/enums/step-status.enum";
|
|
7
7
|
import { UploadModel } from "../auxta/models/upload.model";
|
|
8
8
|
import puppeteer_core from 'puppeteer-core';
|
|
9
|
+
import { config } from "./../auxta/configs/config";
|
|
10
|
+
|
|
9
11
|
|
|
10
12
|
export class Puppeteer {
|
|
11
13
|
public defaultPage!: puppeteer_core.Page;
|
|
@@ -21,15 +23,13 @@ export class Puppeteer {
|
|
|
21
23
|
'--disable-dev-shm-usage',
|
|
22
24
|
'--single-process'
|
|
23
25
|
],
|
|
24
|
-
defaultViewport:
|
|
26
|
+
defaultViewport: null,
|
|
25
27
|
// Return back to headless for commit
|
|
26
28
|
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
|
|
27
29
|
});
|
|
28
30
|
this.defaultPage = (await this.browser.pages())[0];
|
|
29
|
-
await this.defaultPage.
|
|
30
|
-
|
|
31
|
-
height: 900
|
|
32
|
-
});
|
|
31
|
+
await this.defaultPage.goto(config.baseURL)
|
|
32
|
+
await this.defaultPage.waitForNetworkIdle();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
public async close() {
|