@auxcode/auxta 0.2.1 → 0.2.5
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 +31 -15
- package/src/auxta/configs/config.ts +7 -0
- package/src/auxta/enums/{step-status.enum.ts → status-of.step.ts} +2 -2
- package/src/auxta/hooks/report.hook.ts +10 -15
- package/src/auxta/models/upload.model.ts +17 -5
- package/src/auxta/services/log.service.ts +10 -10
- package/src/auxta/services/report.service.ts +1 -1
- package/src/auxta/utilities/start-suite.helper.ts +1 -2
- package/src/macros/helpers/code.helper.ts +31 -24
- package/src/puppeteer/puppeteer.ts +23 -9
package/package.json
CHANGED
package/src/AuxTA.ts
CHANGED
|
@@ -2,10 +2,10 @@ import puppeteer, { Puppeteer } from "./puppeteer/puppeteer";
|
|
|
2
2
|
import { FunctionHelper } from "./macros/helpers/code.helper";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
|
-
import
|
|
5
|
+
import StatusOfStep from "./auxta/enums/status-of.step";
|
|
6
6
|
import { UploadModel } from "./auxta/models/upload.model";
|
|
7
7
|
import * as dotenv from "dotenv";
|
|
8
|
-
import { config,
|
|
8
|
+
import { setupConfig, config as c, setupOverrideConfig } from "./auxta/configs/config";
|
|
9
9
|
import { startSuite } from "./auxta/utilities/start-suite.helper";
|
|
10
10
|
import { createEmptyReport } from "./auxta/services/report.service";
|
|
11
11
|
|
|
@@ -13,6 +13,7 @@ dotenv.config();
|
|
|
13
13
|
|
|
14
14
|
class AuxTA extends FunctionHelper {
|
|
15
15
|
public puppeteer: Puppeteer = puppeteer;
|
|
16
|
+
public config = c;
|
|
16
17
|
|
|
17
18
|
private readonly uploadModel: UploadModel;
|
|
18
19
|
|
|
@@ -36,30 +37,45 @@ class AuxTA extends FunctionHelper {
|
|
|
36
37
|
}
|
|
37
38
|
const jsonConfig = JSON.parse(fs.readFileSync(file).toString());
|
|
38
39
|
try {
|
|
39
|
-
setupConfig(jsonConfig)
|
|
40
|
-
} catch (e
|
|
41
|
-
console.log("Missing field in auxta.json:", e
|
|
40
|
+
this.config = setupConfig(jsonConfig)
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.log("Missing field in auxta.json:", e)
|
|
42
43
|
}
|
|
43
44
|
this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct);
|
|
44
|
-
} catch (e
|
|
45
|
+
} catch (e) {
|
|
45
46
|
console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
|
|
46
47
|
console.log(e);
|
|
47
48
|
process.exit(1);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
public async run(event: any) {
|
|
52
|
-
|
|
53
|
-
let token: string = event.queryStringParameters.token;
|
|
52
|
+
public async run(event: any, overrideConfig?: any) {
|
|
53
|
+
this.changeModelData(overrideConfig);
|
|
54
54
|
let reportId: string | undefined = event.queryStringParameters.reportId;
|
|
55
|
-
if (token !== config.token)
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
if (process.env.ENVIRONMENT === 'LIVE' && event.queryStringParameters.token !== this.config.token)
|
|
56
|
+
return {statusCode: 401, message: 'Unauthorized'}
|
|
57
|
+
const suites = this.config.suitesList.slice(0);
|
|
58
|
+
await startSuite(suites, reportId || await createEmptyReport(this.uploadModel));
|
|
58
59
|
return {statusCode: 204}
|
|
59
60
|
}
|
|
61
|
+
private changeModelData(overrideConfig?: any){
|
|
62
|
+
if (overrideConfig) {
|
|
63
|
+
if (overrideConfig.digitalProduct) this.uploadModel.digitalProduct = overrideConfig.digitalProduct
|
|
64
|
+
if (overrideConfig.environment) this.uploadModel.environment = overrideConfig.environment
|
|
65
|
+
if (overrideConfig.baseUrl) this.uploadModel.baseUrl = overrideConfig.baseUrl
|
|
66
|
+
this.config = setupOverrideConfig(overrideConfig)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
60
69
|
|
|
61
|
-
public startBrowser(event: any, callback: any, feature: string, scenario: string) {
|
|
62
|
-
this.
|
|
70
|
+
public async startBrowser(event: any, callback: any, feature: string, scenario: string, overrideConfig?: any, singleFeature = false) {
|
|
71
|
+
this.changeModelData(overrideConfig);
|
|
72
|
+
if (singleFeature) {
|
|
73
|
+
if (process.env.ENVIRONMENT === 'LIVE' && event.queryStringParameters.token !== this.config.token)
|
|
74
|
+
return {statusCode: 401, message: 'Unauthorized'}
|
|
75
|
+
this.uploadModel.reportId = await createEmptyReport(this.uploadModel);
|
|
76
|
+
this.uploadModel.nextSuites = [];
|
|
77
|
+
}
|
|
78
|
+
return this.puppeteer.run(event, callback, feature, scenario)
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
public getUploadModel(): UploadModel {
|
|
@@ -67,7 +83,7 @@ class AuxTA extends FunctionHelper {
|
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
export const StepStatus =
|
|
86
|
+
export const StepStatus = StatusOfStep;
|
|
71
87
|
|
|
72
88
|
const auxta: AuxTA = new AuxTA();
|
|
73
89
|
|
|
@@ -18,6 +18,13 @@ export function setupConfig(jsonConfig: any) {
|
|
|
18
18
|
if (jsonConfig.timeout) config.timeout = jsonConfig.timeout;
|
|
19
19
|
if (jsonConfig.screenWidth) config.screenWidth = jsonConfig.screenWidth;
|
|
20
20
|
if (jsonConfig.screenHeight) config.screenHeight = jsonConfig.screenHeight;
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setupOverrideConfig(overrideConfig: any){
|
|
25
|
+
if (overrideConfig.baseURL) config.baseURL = overrideConfig.baseURL;
|
|
26
|
+
if (overrideConfig.digitalProduct) config.digitalProduct = overrideConfig.digitalProduct;
|
|
27
|
+
return config;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
export let config = {
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
uploadScenario
|
|
10
10
|
} from '../services/report.service';
|
|
11
11
|
import { startSuite } from '../utilities/start-suite.helper';
|
|
12
|
-
import {
|
|
12
|
+
import { StatusOfStep } from "../enums/status-of.step";
|
|
13
13
|
import { UploadModel } from "../models/upload.model";
|
|
14
14
|
|
|
15
|
-
export async function
|
|
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);
|
|
@@ -29,10 +29,10 @@ export async function AfterEach(body: any, featureName: string, scenarioName: st
|
|
|
29
29
|
scenariosCount: featureRes.scenariosCount
|
|
30
30
|
}
|
|
31
31
|
const stepCounts: Steps = {
|
|
32
|
-
failedSteps: log.getStatusCount(
|
|
33
|
-
passedSteps: log.getStatusCount(
|
|
34
|
-
skippedSteps: log.getStatusCount(
|
|
35
|
-
suggestedSteps: log.getStatusCount(
|
|
32
|
+
failedSteps: log.getStatusCount(StatusOfStep.FAILED),
|
|
33
|
+
passedSteps: log.getStatusCount(StatusOfStep.PASSED),
|
|
34
|
+
skippedSteps: log.getStatusCount(StatusOfStep.SKIPPED),
|
|
35
|
+
suggestedSteps: log.getStatusCount(StatusOfStep.SUGGESTION)
|
|
36
36
|
}
|
|
37
37
|
isFinal = (!(body.nextSuites && body.nextSuites.length > 0));
|
|
38
38
|
await updateReport(body.reportId, feature, stepCounts, isFinal);
|
|
@@ -42,20 +42,15 @@ export async function AfterEach(body: any, featureName: string, scenarioName: st
|
|
|
42
42
|
console.log(error)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
if (isFinal) await
|
|
46
|
-
else if (body && body.nextSuites && body.nextSuites
|
|
45
|
+
if (isFinal) await afterComplete(body.reportId, body);
|
|
46
|
+
else if (body && body.nextSuites && body.nextSuites[0])
|
|
47
47
|
try {
|
|
48
48
|
await startSuite(body.nextSuites, body.reportId);
|
|
49
49
|
} catch {
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export async function
|
|
54
|
-
if (process.env.ENVIRONMENT == "LIVE")
|
|
53
|
+
export async function afterComplete(reportId: string, body: UploadModel) {
|
|
54
|
+
if (process.env.ENVIRONMENT == "LIVE")
|
|
55
55
|
await postNotifications(reportId, body);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function sleep(ms: number) {
|
|
60
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
61
56
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
export class UploadModel {
|
|
3
3
|
private _reportId: string;
|
|
4
4
|
private _nextSuites: [];
|
|
5
|
-
private
|
|
6
|
-
private
|
|
5
|
+
private _digitalProduct: string;
|
|
6
|
+
private _baseUrl: string;
|
|
7
7
|
private readonly _organization: string;
|
|
8
|
-
private
|
|
8
|
+
private _environment: string;
|
|
9
9
|
|
|
10
10
|
constructor(org: string, baseUrl: string, digitalProduct: string) {
|
|
11
11
|
this._reportId = '';
|
|
@@ -36,15 +36,27 @@ export class UploadModel {
|
|
|
36
36
|
return this._digitalProduct;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
set digitalProduct(value: string) {
|
|
40
|
+
this._digitalProduct = value;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
get organization(): string {
|
|
44
44
|
return this._organization;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
get baseUrl(): string {
|
|
48
|
+
return this._baseUrl;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set baseUrl(value: string) {
|
|
52
|
+
this._baseUrl = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
get environment(): string {
|
|
48
56
|
return this._environment;
|
|
49
57
|
}
|
|
58
|
+
|
|
59
|
+
set environment(value: string) {
|
|
60
|
+
this._environment = value;
|
|
61
|
+
}
|
|
50
62
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StatusOfStep } from "../enums/status-of.step";
|
|
2
2
|
|
|
3
3
|
export interface Step {
|
|
4
4
|
keyword: string,
|
|
5
5
|
name: string,
|
|
6
6
|
result: {
|
|
7
|
-
status:
|
|
7
|
+
status: StatusOfStep,
|
|
8
8
|
duration: number
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -13,17 +13,17 @@ export class LogSteps {
|
|
|
13
13
|
private stepLog: Step[] = [];
|
|
14
14
|
private lastStepTime = new Date().getTime();
|
|
15
15
|
public statusCounter = {
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
16
|
+
[StatusOfStep.PASSED]: 0,
|
|
17
|
+
[StatusOfStep.FAILED]: 0,
|
|
18
|
+
[StatusOfStep.SKIPPED]: 0,
|
|
19
|
+
[StatusOfStep.SUGGESTION]: 0,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
public addSuggestion(text: string) {
|
|
23
|
-
this.statusCounter[
|
|
23
|
+
this.statusCounter[StatusOfStep.SUGGESTION]++;
|
|
24
24
|
this.stepLog.push({
|
|
25
25
|
keyword: 'Suggestion', name: text, result:
|
|
26
|
-
{status:
|
|
26
|
+
{status: StatusOfStep.SUGGESTION, duration: 0}
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -31,7 +31,7 @@ export class LogSteps {
|
|
|
31
31
|
this.stepLog = [];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
public push(keyword: string, name: string, status:
|
|
34
|
+
public push(keyword: string, name: string, status: StatusOfStep) {
|
|
35
35
|
console.log(`System log -- status: ${status} -- : ${name} `);
|
|
36
36
|
this.statusCounter[status]++;
|
|
37
37
|
const currentStep = new Date().getTime();
|
|
@@ -43,7 +43,7 @@ export class LogSteps {
|
|
|
43
43
|
return this.stepLog;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
public getStatusCount(status:
|
|
46
|
+
public getStatusCount(status: StatusOfStep): number {
|
|
47
47
|
return this.statusCounter[status];
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -66,7 +66,7 @@ export async function createEmptyReport(body: any): Promise<string> {
|
|
|
66
66
|
)).data.reportId;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export async function uploadScenario(stepLog: Step[], scenarioName: string, screenshot?: Buffer, errMessage?:
|
|
69
|
+
export async function uploadScenario(stepLog: Step[], scenarioName: string, screenshot?: Buffer, errMessage?: object) {
|
|
70
70
|
let scenarios = [];
|
|
71
71
|
let token = await auth();
|
|
72
72
|
let lastStep = stepLog[stepLog.length - 1];
|
|
@@ -3,9 +3,8 @@ 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
|
-
console.log(suites,reportId);
|
|
7
6
|
return axios.post(
|
|
8
|
-
`${config.netlifyPath}.netlify/functions/${suites.shift()}`,
|
|
7
|
+
`${config.netlifyPath}.netlify/functions/${suites.shift()}?token=${config.token}`,
|
|
9
8
|
{ nextSuites: suites, reportId: reportId}
|
|
10
9
|
);
|
|
11
10
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import log from "../../auxta/services/log.service";
|
|
2
2
|
import puppeteer from "../../puppeteer/puppeteer";
|
|
3
|
-
import {
|
|
3
|
+
import { StatusOfStep } from "../../auxta/enums/status-of.step";
|
|
4
4
|
import { config } from "../../auxta/configs/config";
|
|
5
5
|
|
|
6
6
|
export class FunctionHelper {
|
|
7
7
|
public readonly defaultTimeout: number = config.timeout;
|
|
8
8
|
|
|
9
|
-
public log(keyword: string, name: string, status:
|
|
9
|
+
public log(keyword: string, name: string, status: StatusOfStep){
|
|
10
10
|
log.push(keyword, name, status)
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -25,44 +25,51 @@ export class FunctionHelper {
|
|
|
25
25
|
|
|
26
26
|
const message = `I click on the ${text} ${selector}`;
|
|
27
27
|
if (linkHandlers) {
|
|
28
|
-
log.push('Then', message,
|
|
28
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
29
29
|
await linkHandlers.click();
|
|
30
30
|
} else {
|
|
31
|
-
log.push('Then', message,
|
|
31
|
+
log.push('Then', message, StatusOfStep.FAILED);
|
|
32
32
|
throw new Error(`Link not found: ${text}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
public async waitForSelectorWithText(selector: string, text: string) {
|
|
37
|
-
const linkHandlers = await
|
|
36
|
+
public async waitForSelectorWithText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
37
|
+
const linkHandlers = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
38
38
|
const message = `I check for ${text}`;
|
|
39
39
|
if (linkHandlers.length > 0) {
|
|
40
|
-
log.push('And', message,
|
|
40
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
41
41
|
return true;
|
|
42
42
|
} else {
|
|
43
|
-
log.push('And', message,
|
|
43
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
44
44
|
throw new Error(`Link not found: ${text}`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
public async goto(
|
|
49
|
-
await
|
|
50
|
-
log.push('Then', `I go to the ${
|
|
48
|
+
public async goto(url: string, page = puppeteer.defaultPage) {
|
|
49
|
+
await page.goto(url);
|
|
50
|
+
log.push('Then', `I go to the ${url} page`, StatusOfStep.PASSED);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
public async type(field: string, value: string) {
|
|
54
|
-
await
|
|
55
|
-
let elementName = await
|
|
53
|
+
public async type(field: string, value: string, page = puppeteer.defaultPage) {
|
|
54
|
+
await page.type(field, value);
|
|
55
|
+
let elementName = await page.$eval(field, (e) => e.textContent);
|
|
56
56
|
if (!elementName || elementName === ' ') elementName = field;
|
|
57
|
-
log.push('Then', `I type '${value}' into the ${elementName} field`,
|
|
57
|
+
log.push('Then', `I type '${value}' into the ${elementName} field`, StatusOfStep.PASSED);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
public async waitForNetwork() {
|
|
61
|
-
|
|
60
|
+
public async waitForNetwork(page = puppeteer.defaultPage) {
|
|
61
|
+
let message = 'I wait for the page to load'
|
|
62
|
+
try{
|
|
63
|
+
await page.waitForNetworkIdle();
|
|
64
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
65
|
+
} catch (e){
|
|
66
|
+
log.push('Then', message, StatusOfStep.FAILED);
|
|
67
|
+
throw new Error(message)
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
public async timeout(timeout = this.defaultTimeout) {
|
|
65
|
-
await
|
|
71
|
+
public async timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
72
|
+
await page.waitForTimeout(timeout);
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
/**
|
|
@@ -83,10 +90,10 @@ export class FunctionHelper {
|
|
|
83
90
|
timeout: time
|
|
84
91
|
});
|
|
85
92
|
} catch (e){
|
|
86
|
-
log.push('And', message,
|
|
93
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
87
94
|
throw new Error(message)
|
|
88
95
|
}
|
|
89
|
-
log.push('And', message,
|
|
96
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
90
97
|
}
|
|
91
98
|
|
|
92
99
|
public async click(className: string, page = puppeteer.defaultPage) {
|
|
@@ -94,17 +101,17 @@ export class FunctionHelper {
|
|
|
94
101
|
let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
95
102
|
if (!elementName || elementName === ' ') elementName = className;
|
|
96
103
|
await page.click(className);
|
|
97
|
-
log.push('Then', `I click on ${elementName}`,
|
|
104
|
+
log.push('Then', `I click on ${elementName}`, StatusOfStep.PASSED);
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
public async urlContains(selector: string) {
|
|
101
108
|
const url = puppeteer.defaultPage.url();
|
|
102
109
|
let message = `I am on the ${selector} page`
|
|
103
110
|
if (!url.includes(selector)) {
|
|
104
|
-
log.push('And', message,
|
|
111
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
105
112
|
throw new Error(`I am not at the ${selector} page`)
|
|
106
113
|
}
|
|
107
|
-
log.push('And', message,
|
|
114
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import chromium from 'chrome-aws-lambda';
|
|
2
2
|
import log from "../auxta/services/log.service";
|
|
3
3
|
import { captureScreenshot } from "../auxta/utilities/screenshot.helper";
|
|
4
|
-
import {
|
|
4
|
+
import { onTestEnd } from "../auxta/hooks/report.hook";
|
|
5
5
|
import auxta from "../AuxTA";
|
|
6
|
-
import {
|
|
6
|
+
import { StatusOfStep } from "../auxta/enums/status-of.step";
|
|
7
7
|
import { UploadModel } from "../auxta/models/upload.model";
|
|
8
8
|
import puppeteer_core from 'puppeteer-core';
|
|
9
9
|
import { config } from "./../auxta/configs/config";
|
|
@@ -34,7 +34,7 @@ export class Puppeteer {
|
|
|
34
34
|
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
|
|
35
35
|
});
|
|
36
36
|
this.defaultPage = (await this.browser.pages())[0];
|
|
37
|
-
await this.defaultPage.goto(config.baseURL)
|
|
37
|
+
await this.defaultPage.goto(config.baseURL, {waitUntil: 'networkidle0'})
|
|
38
38
|
await this.defaultPage.waitForNetworkIdle();
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -50,25 +50,39 @@ export class Puppeteer {
|
|
|
50
50
|
if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
|
|
51
51
|
if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
|
|
52
52
|
let screenshotBuffer: Buffer;
|
|
53
|
-
let errMessage:
|
|
53
|
+
let errMessage: any;
|
|
54
54
|
let statusCode: number = 200;
|
|
55
55
|
|
|
56
|
+
let consoleStack: any[] = [];
|
|
56
57
|
try {
|
|
57
|
-
await log.push('When', `Starting puppeteer process`,
|
|
58
|
+
await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
|
|
58
59
|
await this.startBrowser()
|
|
60
|
+
this.defaultPage.on('console', message =>
|
|
61
|
+
consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
62
|
+
.on('pageerror', ({message}) => consoleStack.push(message))
|
|
63
|
+
.on('response', response =>
|
|
64
|
+
consoleStack.push(`${response.status()} ${response.url()}`))
|
|
65
|
+
.on('requestfailed', request =>
|
|
66
|
+
consoleStack.push(`${request.failure().errorText} ${request.url()}`))
|
|
59
67
|
await callback(event)
|
|
60
68
|
screenshotBuffer = await captureScreenshot();
|
|
61
|
-
await log.push('When', `Finished puppeteer process`,
|
|
62
|
-
} catch (err
|
|
69
|
+
await log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
70
|
+
} catch (err) {
|
|
63
71
|
console.log(`Error ${err}`);
|
|
64
72
|
errMessage = err;
|
|
65
73
|
statusCode = 500;
|
|
66
74
|
screenshotBuffer = await captureScreenshot();
|
|
67
|
-
await log.push('When', `Finished puppeteer process`,
|
|
75
|
+
await log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
|
|
68
76
|
}
|
|
77
|
+
let url = this.defaultPage.url();
|
|
69
78
|
if (close) await this.close();
|
|
70
79
|
|
|
71
|
-
await
|
|
80
|
+
await onTestEnd(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
|
|
81
|
+
currentPageUrl: url,
|
|
82
|
+
console: consoleStack,
|
|
83
|
+
error: errMessage
|
|
84
|
+
});
|
|
85
|
+
log.clear();
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
private static setupHeader(event: any, uploadModel: UploadModel) {
|