@auxcode/auxta 0.2.6 → 0.3.0
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
|
@@ -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);
|
|
@@ -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
|
}
|
|
@@ -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,
|
|
@@ -101,7 +110,7 @@ export class FunctionHelper {
|
|
|
101
110
|
let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
102
111
|
if (!elementName || elementName === ' ') elementName = className;
|
|
103
112
|
await page.click(className);
|
|
104
|
-
log.push('Then', `I click on ${elementName}`, StatusOfStep.PASSED);
|
|
113
|
+
log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
public async urlContains(selector: string) {
|
|
@@ -109,7 +118,7 @@ export class FunctionHelper {
|
|
|
109
118
|
let message = `I am on the ${selector} page`
|
|
110
119
|
if (!url.includes(selector)) {
|
|
111
120
|
log.push('And', message, StatusOfStep.FAILED);
|
|
112
|
-
throw new Error(`I am not at the ${selector} page`)
|
|
121
|
+
throw new Error(`I am not at the '${selector}' page`)
|
|
113
122
|
}
|
|
114
123
|
log.push('And', message, StatusOfStep.PASSED);
|
|
115
124
|
}
|
|
@@ -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) {
|