@auxcode/auxta 0.2.2 → 0.2.6
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 +13 -2
- package/src/auxta/utilities/start-suite.helper.ts +1 -2
- package/src/macros/helpers/code.helper.ts +26 -26
- package/src/puppeteer/puppeteer.ts +16 -13
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,7 +9,7 @@ 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
15
|
export async function onTestEnd(body: any, featureName: string, scenarioName: string, statusCode: number, screenshotBuffer: Buffer, errMessage?: object) {
|
|
@@ -29,10 +29,10 @@ export async function onTestEnd(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 onTestEnd(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);
|
|
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")
|
|
55
|
-
await postNotifications(
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function sleep(ms: number) {
|
|
60
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
53
|
+
export async function afterComplete(body: UploadModel) {
|
|
54
|
+
if (process.env.ENVIRONMENT == "LIVE")
|
|
55
|
+
await postNotifications(body);
|
|
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
|
}
|
|
@@ -167,12 +167,23 @@ export async function getLastDayResults(): Promise<any> {
|
|
|
167
167
|
)).data.results;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
export async function postNotifications(
|
|
170
|
+
export async function postNotifications( body: UploadModel) {
|
|
171
171
|
let token = await auth();
|
|
172
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,
|
|
176
|
-
reportId: reportId,
|
|
176
|
+
reportId: body.reportId,
|
|
177
|
+
}, headers(token));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
export async function postNotificationsOnFail( body: UploadModel) {
|
|
182
|
+
let token = await auth();
|
|
183
|
+
await axios.post(`${config.auxtaURL}post-notification-after-case-fail-background`, {
|
|
184
|
+
environmentName: body.environment,
|
|
185
|
+
digitalProductName: body.digitalProduct,
|
|
186
|
+
organizationName: body.organization,
|
|
187
|
+
reportId: body.reportId,
|
|
177
188
|
}, headers(token));
|
|
178
189
|
}
|
|
@@ -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,51 +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() {
|
|
60
|
+
public async waitForNetwork(page = puppeteer.defaultPage) {
|
|
61
61
|
let message = 'I wait for the page to load'
|
|
62
62
|
try{
|
|
63
|
-
await
|
|
64
|
-
log.push('Then', message,
|
|
63
|
+
await page.waitForNetworkIdle();
|
|
64
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
65
65
|
} catch (e){
|
|
66
|
-
log.push('Then', message,
|
|
66
|
+
log.push('Then', message, StatusOfStep.FAILED);
|
|
67
67
|
throw new Error(message)
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
public async timeout(timeout = this.defaultTimeout) {
|
|
72
|
-
await
|
|
71
|
+
public async timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
72
|
+
await page.waitForTimeout(timeout);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -90,10 +90,10 @@ export class FunctionHelper {
|
|
|
90
90
|
timeout: time
|
|
91
91
|
});
|
|
92
92
|
} catch (e){
|
|
93
|
-
log.push('And', message,
|
|
93
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
94
94
|
throw new Error(message)
|
|
95
95
|
}
|
|
96
|
-
log.push('And', message,
|
|
96
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
public async click(className: string, page = puppeteer.defaultPage) {
|
|
@@ -101,17 +101,17 @@ export class FunctionHelper {
|
|
|
101
101
|
let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
102
102
|
if (!elementName || elementName === ' ') elementName = className;
|
|
103
103
|
await page.click(className);
|
|
104
|
-
log.push('Then', `I click on ${elementName}`,
|
|
104
|
+
log.push('Then', `I click on ${elementName}`, StatusOfStep.PASSED);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
public async urlContains(selector: string) {
|
|
108
108
|
const url = puppeteer.defaultPage.url();
|
|
109
109
|
let message = `I am on the ${selector} page`
|
|
110
110
|
if (!url.includes(selector)) {
|
|
111
|
-
log.push('And', message,
|
|
111
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
112
112
|
throw new Error(`I am not at the ${selector} page`)
|
|
113
113
|
}
|
|
114
|
-
log.push('And', message,
|
|
114
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
}
|
|
@@ -3,10 +3,11 @@ import log from "../auxta/services/log.service";
|
|
|
3
3
|
import { captureScreenshot } from "../auxta/utilities/screenshot.helper";
|
|
4
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";
|
|
10
|
+
import { postNotificationsOnFail } from "../auxta/services/report.service";
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
export class Puppeteer {
|
|
@@ -24,9 +25,9 @@ export class Puppeteer {
|
|
|
24
25
|
if (process.env.ENVIRONMENT != 'LOCAL')
|
|
25
26
|
args.push(`--window-size=${config.screenWidth},${config.screenHeight}`)
|
|
26
27
|
this.browser = await chromium.puppeteer.launch({
|
|
27
|
-
executablePath: process.env.
|
|
28
|
+
executablePath: process.env.ENVIRONMENT === 'LOCAL' ? undefined : await chromium.executablePath,
|
|
28
29
|
args,
|
|
29
|
-
defaultViewport: process.env.ENVIRONMENT
|
|
30
|
+
defaultViewport: process.env.ENVIRONMENT === 'LOCAL' ? null : {
|
|
30
31
|
width: config.screenWidth,
|
|
31
32
|
height: config.screenHeight
|
|
32
33
|
},
|
|
@@ -34,7 +35,7 @@ export class Puppeteer {
|
|
|
34
35
|
headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
|
|
35
36
|
});
|
|
36
37
|
this.defaultPage = (await this.browser.pages())[0];
|
|
37
|
-
await this.defaultPage.goto(config.baseURL)
|
|
38
|
+
await this.defaultPage.goto(config.baseURL, {waitUntil: 'networkidle0'})
|
|
38
39
|
await this.defaultPage.waitForNetworkIdle();
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -50,38 +51,40 @@ export class Puppeteer {
|
|
|
50
51
|
if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
|
|
51
52
|
if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
|
|
52
53
|
let screenshotBuffer: Buffer;
|
|
53
|
-
let errMessage:
|
|
54
|
+
let errMessage: any;
|
|
54
55
|
let statusCode: number = 200;
|
|
55
56
|
|
|
56
|
-
let consoleStack = [];
|
|
57
|
+
let consoleStack: any[] = [];
|
|
57
58
|
try {
|
|
58
|
-
await log.push('When', `Starting puppeteer process`,
|
|
59
|
+
await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
|
|
59
60
|
await this.startBrowser()
|
|
60
|
-
|
|
61
|
+
this.defaultPage.on('console', message =>
|
|
61
62
|
consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
|
|
62
|
-
.on('pageerror', ({
|
|
63
|
+
.on('pageerror', ({message}) => consoleStack.push(message))
|
|
63
64
|
.on('response', response =>
|
|
64
65
|
consoleStack.push(`${response.status()} ${response.url()}`))
|
|
65
66
|
.on('requestfailed', request =>
|
|
66
67
|
consoleStack.push(`${request.failure().errorText} ${request.url()}`))
|
|
67
68
|
await callback(event)
|
|
68
69
|
screenshotBuffer = await captureScreenshot();
|
|
69
|
-
|
|
70
|
-
} catch (err
|
|
70
|
+
log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
|
|
71
|
+
} catch (err) {
|
|
71
72
|
console.log(`Error ${err}`);
|
|
72
73
|
errMessage = err;
|
|
73
74
|
statusCode = 500;
|
|
74
75
|
screenshotBuffer = await captureScreenshot();
|
|
75
|
-
|
|
76
|
+
log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
|
|
77
|
+
await postNotificationsOnFail(uploadModel)
|
|
76
78
|
}
|
|
77
79
|
let url = this.defaultPage.url();
|
|
78
80
|
if (close) await this.close();
|
|
79
|
-
log.clear();
|
|
80
81
|
|
|
81
82
|
await onTestEnd(uploadModel, featureName, scenarioName, statusCode, screenshotBuffer, !errMessage ? undefined : {
|
|
82
83
|
currentPageUrl: url,
|
|
84
|
+
console: consoleStack,
|
|
83
85
|
error: errMessage
|
|
84
86
|
});
|
|
87
|
+
log.clear();
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
private static setupHeader(event: any, uploadModel: UploadModel) {
|