@auxcode/auxta 0.4.7 → 0.4.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.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
package/src/AuxTA.ts CHANGED
@@ -1,13 +1,13 @@
1
- import puppeteer, { Puppeteer } from "./puppeteer/puppeteer";
2
- import { FunctionHelper } from "./macros/helpers/code.helper";
1
+ import puppeteer, {Puppeteer} from "./puppeteer/puppeteer";
2
+ import {FunctionHelper} from "./macros/helpers/code.helper";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
5
  import StatusOfStep from "./auxta/enums/status-of.step";
6
- import { UploadModel } from "./auxta/models/upload.model";
6
+ import {UploadModel} from "./auxta/models/upload.model";
7
7
  import * as dotenv from "dotenv";
8
- import { setupConfig, config as c, setupOverrideConfig } from "./auxta/configs/config";
9
- import { startSuite } from "./auxta/utilities/start-suite.helper";
10
- import { createEmptyReport } from "./auxta/services/report.service";
8
+ import {setupConfig, config as c, setupOverrideConfig} from "./auxta/configs/config";
9
+ import {startSuite} from "./auxta/utilities/start-suite.helper";
10
+ import {createEmptyReport} from "./auxta/services/report.service";
11
11
 
12
12
  dotenv.config();
13
13
 
@@ -41,7 +41,7 @@ class AuxTA extends FunctionHelper {
41
41
  } catch (e) {
42
42
  console.log("Missing field in auxta.json:", e)
43
43
  }
44
- this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct,jsonConfig.environment);
44
+ this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct, jsonConfig.environment);
45
45
  } catch (e) {
46
46
  console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
47
47
  console.log(e);
@@ -58,7 +58,8 @@ class AuxTA extends FunctionHelper {
58
58
  await startSuite(suites, reportId || await createEmptyReport(this.uploadModel));
59
59
  return {statusCode: 204}
60
60
  }
61
- private changeModelData(overrideConfig?: any){
61
+
62
+ private changeModelData(overrideConfig?: any) {
62
63
  if (overrideConfig) {
63
64
  if (overrideConfig.digitalProduct) this.uploadModel.digitalProduct = overrideConfig.digitalProduct
64
65
  if (overrideConfig.environment) this.uploadModel.environment = overrideConfig.environment
@@ -78,6 +79,15 @@ class AuxTA extends FunctionHelper {
78
79
  return this.puppeteer.run(event, callback, feature, scenario)
79
80
  }
80
81
 
82
+ public async startBrowserRPA(event: any, callback: any, baseURL: string) {
83
+ this.changeModelData({
84
+ baseURL: baseURL,
85
+ environment: '',
86
+ digitalProduct: ''
87
+ });
88
+ return this.puppeteer.runRPA(event, callback)
89
+ }
90
+
81
91
  public getUploadModel(): UploadModel {
82
92
  return this.uploadModel;
83
93
  }
@@ -1,13 +1,13 @@
1
1
  import chromium from 'chrome-aws-lambda';
2
2
  import log from "../auxta/services/log.service";
3
- import { captureScreenshot } from "../auxta/utilities/screenshot.helper";
4
- import { onTestEnd } from "../auxta/hooks/report.hook";
3
+ import {captureScreenshot} from "../auxta/utilities/screenshot.helper";
4
+ import {onTestEnd} from "../auxta/hooks/report.hook";
5
5
  import auxta from "../AuxTA";
6
- import { StatusOfStep } from "../auxta/enums/status-of.step";
7
- import { UploadModel } from "../auxta/models/upload.model";
6
+ import {StatusOfStep} from "../auxta/enums/status-of.step";
7
+ import {UploadModel} from "../auxta/models/upload.model";
8
8
  import puppeteer_core from 'puppeteer-core';
9
- import { config } from "./../auxta/configs/config";
10
- import { postNotificationsOnFail } from "../auxta/services/report.service";
9
+ import {config} from "./../auxta/configs/config";
10
+ import {postNotificationsOnFail} from "../auxta/services/report.service";
11
11
 
12
12
 
13
13
  export class Puppeteer {
@@ -49,7 +49,7 @@ export class Puppeteer {
49
49
  }
50
50
 
51
51
  public async run(event: any, callback: any, featureName = 'Test feature', scenarioName = 'Test scenario', uploadModel?: UploadModel, close?: boolean) {
52
- try{
52
+ try {
53
53
  if (uploadModel === undefined) uploadModel = auxta.getUploadModel();
54
54
  if (close === undefined) close = Puppeteer.setupHeader(event, uploadModel)
55
55
  let screenshotBuffer: Buffer | undefined;
@@ -85,13 +85,51 @@ export class Puppeteer {
85
85
  console: consoleStack,
86
86
  error: errMessage
87
87
  });
88
- } catch (e){
88
+ } catch (e) {
89
89
  console.log("Lib error:", e);
90
90
  } finally {
91
91
  log.clear();
92
92
  }
93
93
  }
94
94
 
95
+ public async runRPA(event: any, callback: any, close?: boolean) {
96
+ let errMessage: any;
97
+ try {
98
+ if (close === undefined) {
99
+ if (event.queryStringParameters.close) {
100
+ close = event.queryStringParameters.close === "true";
101
+ } else {
102
+ close = true
103
+ }
104
+ }
105
+ let consoleStack: any[] = [];
106
+ try {
107
+ await log.push('When', `Starting puppeteer process`, StatusOfStep.PASSED);
108
+ await this.startBrowser()
109
+ this.defaultPage.on('console', message =>
110
+ consoleStack.push(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`))
111
+ .on('pageerror', ({message}) => consoleStack.push(message))
112
+ .on('response', response =>
113
+ consoleStack.push(`${response.status()} ${response.url()}`))
114
+ .on('requestfailed', request =>
115
+ consoleStack.push(`${request.failure() !== null ? request.failure()?.errorText : ""} ${request.url()}`))
116
+ await callback(event)
117
+ log.push('When', `Finished puppeteer process`, StatusOfStep.PASSED);
118
+ } catch (err) {
119
+ console.log("Error", err);
120
+ errMessage = err;
121
+ log.push('When', `Finished puppeteer process`, StatusOfStep.FAILED);
122
+ return errMessage;
123
+ }
124
+ if (close) await this.close();
125
+ } catch (e) {
126
+ console.log("Lib error:", e);
127
+ } finally {
128
+ log.clear();
129
+
130
+ }
131
+ }
132
+
95
133
  private static setupHeader(event: any, uploadModel: UploadModel) {
96
134
  let close = true;
97
135
  if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {