@auxcode/auxta 0.2.7 → 0.3.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/hooks/report.hook.ts +1 -1
- package/src/auxta/services/report.service.ts +2 -2
- package/src/auxta/utilities/screenshot.helper.ts +14 -11
- package/src/auxta/utilities/start-suite.helper.ts +1 -0
- package/src/macros/helpers/code.helper.ts +29 -14
- package/src/puppeteer/puppeteer.ts +3 -4
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ import { startSuite } from '../utilities/start-suite.helper';
|
|
|
12
12
|
import { StatusOfStep } from "../enums/status-of.step";
|
|
13
13
|
import { UploadModel } from "../models/upload.model";
|
|
14
14
|
|
|
15
|
-
export async function onTestEnd(body: any, featureName: string, scenarioName: string, statusCode: number, screenshotBuffer
|
|
15
|
+
export async function onTestEnd(body: any, featureName: string, scenarioName: string, statusCode: number, screenshotBuffer?: Buffer, errMessage?: object) {
|
|
16
16
|
let isFinal: boolean = false;
|
|
17
17
|
if (process.env.ENVIRONMENT == "LIVE") {
|
|
18
18
|
console.log('asc ' + errMessage);
|
|
@@ -169,7 +169,7 @@ export async function getLastDayResults(): Promise<any> {
|
|
|
169
169
|
|
|
170
170
|
export async function postNotifications( body: UploadModel) {
|
|
171
171
|
let token = await auth();
|
|
172
|
-
await axios.post(`${config.auxtaURL}post-
|
|
172
|
+
await axios.post(`${config.auxtaURL}post-notification-after-run-background`, {
|
|
173
173
|
environmentName: body.environment,
|
|
174
174
|
digitalProductName: body.digitalProduct,
|
|
175
175
|
organizationName: body.organization,
|
|
@@ -180,7 +180,7 @@ export async function postNotifications( body: UploadModel) {
|
|
|
180
180
|
|
|
181
181
|
export async function postNotificationsOnFail( body: UploadModel) {
|
|
182
182
|
let token = await auth();
|
|
183
|
-
await axios.post(`${config.auxtaURL}post-
|
|
183
|
+
await axios.post(`${config.auxtaURL}post-notifications-after-case-fail-background`, {
|
|
184
184
|
environmentName: body.environment,
|
|
185
185
|
digitalProductName: body.digitalProduct,
|
|
186
186
|
organizationName: body.organization,
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import puppeteer from "../../puppeteer/puppeteer";
|
|
2
2
|
|
|
3
3
|
export async function captureScreenshot() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
try{
|
|
5
|
+
const pages = await puppeteer.defaultPage.browser().pages();
|
|
6
|
+
if (!pages.length) return undefined;
|
|
7
|
+
const lastPage = pages[pages.length - 1] || puppeteer.defaultPage;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const screenshotBuffer = await lastPage.screenshot({
|
|
10
|
+
fullPage: true,
|
|
11
|
+
encoding: 'binary'
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
if (Buffer.isBuffer(screenshotBuffer))
|
|
15
|
+
return screenshotBuffer;
|
|
16
|
+
} catch (e){
|
|
17
|
+
}
|
|
18
|
+
return undefined
|
|
16
19
|
}
|
|
@@ -3,6 +3,7 @@ import { config } from "../configs/config";
|
|
|
3
3
|
|
|
4
4
|
export function startSuite(suites: string[], reportId?: string) {
|
|
5
5
|
console.log('Starting next suite: ' + suites[0]);
|
|
6
|
+
//todo on error, end the test
|
|
6
7
|
return axios.post(
|
|
7
8
|
`${config.netlifyPath}.netlify/functions/${suites.shift()}?token=${config.token}`,
|
|
8
9
|
{ nextSuites: suites, reportId: reportId}
|
|
@@ -23,7 +23,7 @@ export class FunctionHelper {
|
|
|
23
23
|
await page.waitForTimeout(this.defaultTimeout);
|
|
24
24
|
const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
25
25
|
|
|
26
|
-
const message = `I click on the ${text} ${selector}`;
|
|
26
|
+
const message = `I click on the '${text}' '${selector}'`;
|
|
27
27
|
if (linkHandlers) {
|
|
28
28
|
log.push('Then', message, StatusOfStep.PASSED);
|
|
29
29
|
await linkHandlers.click();
|
|
@@ -35,7 +35,7 @@ export class FunctionHelper {
|
|
|
35
35
|
|
|
36
36
|
public async waitForSelectorWithText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
37
37
|
const linkHandlers = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
38
|
-
const message = `I check for ${text}`;
|
|
38
|
+
const message = `I check for '${text}' on the current page`;
|
|
39
39
|
if (linkHandlers.length > 0) {
|
|
40
40
|
log.push('And', message, StatusOfStep.PASSED);
|
|
41
41
|
return true;
|
|
@@ -47,14 +47,23 @@ export class FunctionHelper {
|
|
|
47
47
|
|
|
48
48
|
public async goto(url: string, page = puppeteer.defaultPage) {
|
|
49
49
|
await page.goto(url);
|
|
50
|
-
log.push('Then', `I go to the ${url} page`, StatusOfStep.PASSED);
|
|
50
|
+
log.push('Then', `I go to the '${url}' page`, StatusOfStep.PASSED);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
public async type(field: string, value: string, page = puppeteer.defaultPage) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
try{
|
|
55
|
+
await page.waitForSelector(field, {
|
|
56
|
+
timeout: this.defaultTimeout
|
|
57
|
+
});
|
|
58
|
+
await page.type(field, value);
|
|
59
|
+
let elementName = await page.$eval(field, (e) => e.textContent);
|
|
60
|
+
if (!elementName || elementName === ' ') elementName = field;
|
|
61
|
+
log.push('Then', `I type '${value}' into the '${elementName}' field`, StatusOfStep.PASSED);
|
|
62
|
+
} catch (e){
|
|
63
|
+
const msg = `I type '${value}' into the '${field}' field`
|
|
64
|
+
log.push('Then', msg, StatusOfStep.FAILED);
|
|
65
|
+
throw new Error(msg)
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
public async waitForNetwork(page = puppeteer.defaultPage) {
|
|
@@ -83,7 +92,7 @@ export class FunctionHelper {
|
|
|
83
92
|
*/
|
|
84
93
|
|
|
85
94
|
public async waitForSelector(option: string, selector: string, time: number = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
86
|
-
const message = `I check for the ${selector} element to be ${option}`;
|
|
95
|
+
const message = `I check for the '${selector}' element to be ${option}`;
|
|
87
96
|
try{
|
|
88
97
|
await page.waitForSelector(selector, {
|
|
89
98
|
[option]: true,
|
|
@@ -97,11 +106,17 @@ export class FunctionHelper {
|
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
public async click(className: string, page = puppeteer.defaultPage) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
try{
|
|
110
|
+
await page.waitForSelector(className);
|
|
111
|
+
let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
112
|
+
if (!elementName || elementName === ' ') elementName = className;
|
|
113
|
+
await page.click(className);
|
|
114
|
+
log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
|
|
115
|
+
} catch (e){
|
|
116
|
+
const msg = `I click on the '${className}'`;
|
|
117
|
+
log.push('Then', msg, StatusOfStep.FAILED);
|
|
118
|
+
throw new Error(msg)
|
|
119
|
+
}
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
public async urlContains(selector: string) {
|
|
@@ -109,7 +124,7 @@ export class FunctionHelper {
|
|
|
109
124
|
let message = `I am on the ${selector} page`
|
|
110
125
|
if (!url.includes(selector)) {
|
|
111
126
|
log.push('And', message, StatusOfStep.FAILED);
|
|
112
|
-
throw new Error(`I am not at the ${selector} page`)
|
|
127
|
+
throw new Error(`I am not at the '${selector}' page`)
|
|
113
128
|
}
|
|
114
129
|
log.push('And', message, StatusOfStep.PASSED);
|
|
115
130
|
}
|
|
@@ -50,7 +50,7 @@ export class Puppeteer {
|
|
|
50
50
|
public async run(event: any, callback: any, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel?: UploadModel, close?: boolean) {
|
|
51
51
|
if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
|
|
52
52
|
if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
|
|
53
|
-
let screenshotBuffer: Buffer;
|
|
53
|
+
let screenshotBuffer: Buffer | undefined;
|
|
54
54
|
let errMessage: any;
|
|
55
55
|
let statusCode: number = 200;
|
|
56
56
|
|
|
@@ -66,7 +66,6 @@ export class Puppeteer {
|
|
|
66
66
|
.on('requestfailed', request =>
|
|
67
67
|
consoleStack.push(`${request.failure().errorText} ${request.url()}`))
|
|
68
68
|
await callback(event)
|
|
69
|
-
screenshotBuffer = await captureScreenshot();
|
|
70
69
|
log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
71
70
|
} catch (err) {
|
|
72
71
|
console.log(`Error ${err}`);
|
|
@@ -89,8 +88,8 @@ export class Puppeteer {
|
|
|
89
88
|
|
|
90
89
|
private static setupHeader(event: any, uploadModel: UploadModel) {
|
|
91
90
|
let close = true;
|
|
92
|
-
if (process.env.ENVIRONMENT !== 'LOCAL') {
|
|
93
|
-
const body = JSON.parse(event.body)
|
|
91
|
+
if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {
|
|
92
|
+
const body = JSON.parse(event.body)
|
|
94
93
|
uploadModel.reportId = body.reportId;
|
|
95
94
|
uploadModel.nextSuites = body.nextSuites;
|
|
96
95
|
} else if (event.queryStringParameters.close) {
|