@auxcode/auxta 0.2.4 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "0.2.4",
3
+ "version": "0.2.8",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
package/src/AuxTA.ts CHANGED
@@ -38,11 +38,11 @@ class AuxTA extends FunctionHelper {
38
38
  const jsonConfig = JSON.parse(fs.readFileSync(file).toString());
39
39
  try {
40
40
  this.config = setupConfig(jsonConfig)
41
- } catch (e: any) {
42
- console.log("Missing field in auxta.json:", e.message)
41
+ } catch (e) {
42
+ console.log("Missing field in auxta.json:", e)
43
43
  }
44
44
  this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct);
45
- } catch (e: any) {
45
+ } catch (e) {
46
46
  console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
47
47
  console.log(e);
48
48
  process.exit(1);
@@ -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: Buffer, errMessage?: object) {
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);
@@ -42,7 +42,7 @@ export async function onTestEnd(body: any, featureName: string, scenarioName: st
42
42
  console.log(error)
43
43
  }
44
44
  }
45
- if (isFinal) await afterComplete(body.reportId, body);
45
+ if (isFinal) await afterComplete(body);
46
46
  else if (body && body.nextSuites && body.nextSuites[0])
47
47
  try {
48
48
  await startSuite(body.nextSuites, body.reportId);
@@ -50,7 +50,7 @@ export async function onTestEnd(body: any, featureName: string, scenarioName: st
50
50
  }
51
51
  }
52
52
 
53
- export async function afterComplete(reportId: string, body: UploadModel) {
53
+ export async function afterComplete(body: UploadModel) {
54
54
  if (process.env.ENVIRONMENT == "LIVE")
55
- await postNotifications(reportId, body);
55
+ await postNotifications(body);
56
56
  }
@@ -167,12 +167,23 @@ export async function getLastDayResults(): Promise<any> {
167
167
  )).data.results;
168
168
  }
169
169
 
170
- export async function postNotifications(reportId: string, body: UploadModel) {
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-notifications-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
  }
@@ -1,16 +1,19 @@
1
1
  import puppeteer from "../../puppeteer/puppeteer";
2
2
 
3
3
  export async function captureScreenshot() {
4
- const pages = await puppeteer.defaultPage.browser().pages();
5
- if (!pages.length) throw `Browser is closed`;
6
- const lastPage = pages[pages.length - 1];
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
- const screenshotBuffer = await lastPage.screenshot({
9
- fullPage: true,
10
- encoding: 'binary'
11
- }
12
- );
13
- if (Buffer.isBuffer(screenshotBuffer))
14
- return screenshotBuffer;
15
- else throw `Failed to capture buffer screenshot`;
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,20 @@ 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
- await page.type(field, value);
55
- let elementName = await page.$eval(field, (e) => e.textContent);
56
- if (!elementName || elementName === ' ') elementName = field;
57
- log.push('Then', `I type '${value}' into the ${elementName} field`, StatusOfStep.PASSED);
54
+ try{
55
+ await page.type(field, value);
56
+ let elementName = await page.$eval(field, (e) => e.textContent);
57
+ if (!elementName || elementName === ' ') elementName = field;
58
+ log.push('Then', `I type '${value}' into the '${elementName}' field`, StatusOfStep.PASSED);
59
+ } catch (e){
60
+ const msg = `I type '${value}' into the '${field}' field`
61
+ log.push('Then', msg, StatusOfStep.FAILED);
62
+ throw new Error(msg)
63
+ }
58
64
  }
59
65
 
60
66
  public async waitForNetwork(page = puppeteer.defaultPage) {
@@ -83,7 +89,7 @@ export class FunctionHelper {
83
89
  */
84
90
 
85
91
  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}`;
92
+ const message = `I check for the '${selector}' element to be ${option}`;
87
93
  try{
88
94
  await page.waitForSelector(selector, {
89
95
  [option]: true,
@@ -101,7 +107,7 @@ export class FunctionHelper {
101
107
  let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
102
108
  if (!elementName || elementName === ' ') elementName = className;
103
109
  await page.click(className);
104
- log.push('Then', `I click on ${elementName}`, StatusOfStep.PASSED);
110
+ log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
105
111
  }
106
112
 
107
113
  public async urlContains(selector: string) {
@@ -109,7 +115,7 @@ export class FunctionHelper {
109
115
  let message = `I am on the ${selector} page`
110
116
  if (!url.includes(selector)) {
111
117
  log.push('And', message, StatusOfStep.FAILED);
112
- throw new Error(`I am not at the ${selector} page`)
118
+ throw new Error(`I am not at the '${selector}' page`)
113
119
  }
114
120
  log.push('And', message, StatusOfStep.PASSED);
115
121
  }
@@ -7,6 +7,7 @@ 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.NODE_ENV !== 'production' ? undefined : await chromium.executablePath,
28
+ executablePath: process.env.ENVIRONMENT === 'LOCAL' ? undefined : await chromium.executablePath,
28
29
  args,
29
- defaultViewport: process.env.ENVIRONMENT == 'LOCAL' ? null : {
30
+ defaultViewport: process.env.ENVIRONMENT === 'LOCAL' ? null : {
30
31
  width: config.screenWidth,
31
32
  height: config.screenHeight
32
33
  },
@@ -49,8 +50,8 @@ export class Puppeteer {
49
50
  public async run(event: any, callback: any, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel?: UploadModel, close?: boolean) {
50
51
  if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
51
52
  if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
52
- let screenshotBuffer: Buffer;
53
- let errMessage: string | undefined;
53
+ let screenshotBuffer: Buffer | undefined;
54
+ let errMessage: any;
54
55
  let statusCode: number = 200;
55
56
 
56
57
  let consoleStack: any[] = [];
@@ -65,14 +66,14 @@ export class Puppeteer {
65
66
  .on('requestfailed', request =>
66
67
  consoleStack.push(`${request.failure().errorText} ${request.url()}`))
67
68
  await callback(event)
68
- screenshotBuffer = await captureScreenshot();
69
- await log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
70
- } catch (err: any) {
69
+ log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
70
+ } catch (err) {
71
71
  console.log(`Error ${err}`);
72
72
  errMessage = err;
73
73
  statusCode = 500;
74
74
  screenshotBuffer = await captureScreenshot();
75
- await log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
75
+ log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
76
+ await postNotificationsOnFail(uploadModel)
76
77
  }
77
78
  let url = this.defaultPage.url();
78
79
  if (close) await this.close();