@auxcode/auxta 0.5.1 → 0.5.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.
Files changed (39) hide show
  1. package/build/AuxTA.d.ts +43 -0
  2. package/{src/AuxTA.ts → build/AuxTA.js} +39 -46
  3. package/build/auxta/configs/config.d.ts +51 -0
  4. package/build/auxta/configs/config.js +61 -0
  5. package/build/auxta/enums/status-of.step.d.ts +7 -0
  6. package/build/auxta/enums/status-of.step.js +8 -0
  7. package/build/auxta/helpers/response.helper.d.ts +10 -0
  8. package/{src/auxta/helpers/response.helper.ts → build/auxta/helpers/response.helper.js} +1 -1
  9. package/build/auxta/helpers/start.helper.d.ts +1 -0
  10. package/{src/auxta/helpers/start.helper.ts → build/auxta/helpers/start.helper.js} +6 -5
  11. package/build/auxta/hooks/report.hook.d.ts +4 -0
  12. package/{src/auxta/hooks/report.hook.ts → build/auxta/hooks/report.hook.js} +17 -24
  13. package/build/auxta/models/upload.model.d.ts +20 -0
  14. package/build/auxta/models/upload.model.js +43 -0
  15. package/build/auxta/services/log.service.d.ts +26 -0
  16. package/build/auxta/services/log.service.js +43 -0
  17. package/build/auxta/services/report.service.d.ts +36 -0
  18. package/build/auxta/services/report.service.js +127 -0
  19. package/build/auxta/services/runtime.service.d.ts +16 -0
  20. package/{src/auxta/services/runtime.service.ts → build/auxta/services/runtime.service.js} +14 -28
  21. package/build/auxta/utilities/runtime.helper.d.ts +15 -0
  22. package/{src/auxta/utilities/runtime.helper.ts → build/auxta/utilities/runtime.helper.js} +3 -17
  23. package/build/auxta/utilities/screenshot.helper.d.ts +2 -0
  24. package/{src/auxta/utilities/screenshot.helper.ts → build/auxta/utilities/screenshot.helper.js} +10 -11
  25. package/build/auxta/utilities/start-suite.helper.d.ts +1 -0
  26. package/build/auxta/utilities/start-suite.helper.js +14 -0
  27. package/build/macros/helpers/code.helper.d.ts +22 -0
  28. package/{src/macros/helpers/code.helper.ts → build/macros/helpers/code.helper.js} +53 -96
  29. package/build/puppeteer/puppeteer.d.ts +13 -0
  30. package/build/puppeteer/puppeteer.js +136 -0
  31. package/package.json +8 -4
  32. package/src/auxta/configs/config.ts +0 -48
  33. package/src/auxta/enums/status-of.step.ts +0 -7
  34. package/src/auxta/models/upload.model.ts +0 -62
  35. package/src/auxta/services/log.service.ts +0 -58
  36. package/src/auxta/services/report.service.ts +0 -189
  37. package/src/auxta/utilities/start-suite.helper.ts +0 -16
  38. package/src/puppeteer/puppeteer.ts +0 -145
  39. package/tsconfig.json +0 -65
@@ -0,0 +1,127 @@
1
+ import axios from "axios";
2
+ import { config } from "../configs/config";
3
+ function headers(token) {
4
+ return {
5
+ headers: {
6
+ 'Content-Type': 'application/json',
7
+ 'cookie': `authToken=${token}`
8
+ }
9
+ };
10
+ }
11
+ async function auth() {
12
+ return axios.post(config.auxtaURL + 'login', config.auxtaCredentials, {
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ }
16
+ })
17
+ .then(({ data }) => {
18
+ return data.token;
19
+ })
20
+ .catch(() => {
21
+ throw new Error("Invalid login credentials");
22
+ });
23
+ }
24
+ export async function createEmptyReport(body) {
25
+ const token = await auth();
26
+ return (await axios.post(config.auxtaURL + "create-empty-report", {
27
+ environment: body.environment,
28
+ digitalProductName: body.digitalProduct,
29
+ start: new Date(),
30
+ url: body.baseUrl
31
+ }, headers(token))).data.reportId;
32
+ }
33
+ export async function uploadScenario(stepLog, scenarioName, screenshot, errMessage) {
34
+ let scenarios = [];
35
+ let token = await auth();
36
+ let lastStep = stepLog[stepLog.length - 1];
37
+ const stepLogFormat = JSON.parse(JSON.stringify(stepLog));
38
+ stepLogFormat.pop();
39
+ let output = (await axios.post(config.auxtaURL + "create-scenario", {
40
+ json: {
41
+ name: scenarioName,
42
+ steps: [
43
+ ...stepLogFormat,
44
+ (lastStep.result.status == 'failed')
45
+ ? Object.assign(lastStep, {
46
+ result: {
47
+ ...lastStep.result,
48
+ error_message: JSON.stringify(errMessage)
49
+ }
50
+ })
51
+ : lastStep,
52
+ {
53
+ keyword: "After",
54
+ result: {
55
+ status: "passed",
56
+ duration: 2678000000
57
+ },
58
+ embeddings: (screenshot) ? [{
59
+ data: screenshot.toString("base64"),
60
+ mime_type: "image/png"
61
+ }] : undefined,
62
+ }
63
+ ],
64
+ }
65
+ }, headers(token))).data.scenarios;
66
+ scenarios.push({
67
+ scenarioRef: output.scenarioRef,
68
+ name: output.name,
69
+ status: output.status,
70
+ stepsCount: output.stepsCount
71
+ });
72
+ return scenarios;
73
+ }
74
+ export async function uploadFeature(scenarioId, scenarioName, uri, hasFailed) {
75
+ let token = await auth();
76
+ return (await axios.post(config.auxtaURL + "create-feature", {
77
+ json: {
78
+ name: scenarioName,
79
+ uri: uri
80
+ },
81
+ scenarios: scenarioId,
82
+ hasFailed: hasFailed
83
+ }, headers(token))).data;
84
+ }
85
+ export async function updateReport(reportId, feature, steps, isFinal) {
86
+ let token = await auth();
87
+ await axios.post(config.auxtaURL + "update-inprogress-report", {
88
+ reportId: reportId,
89
+ isFinal: isFinal,
90
+ data: {
91
+ feature: {
92
+ featureRef: feature.featureId,
93
+ name: feature.featureName,
94
+ uri: feature.featureUri,
95
+ status: feature.status,
96
+ scenariosCount: feature.scenariosCount
97
+ },
98
+ ...steps
99
+ }
100
+ }, headers(token));
101
+ }
102
+ export async function getReport(reportId) {
103
+ let token = await auth();
104
+ return (await axios.post(config.auxtaURL + "get-report", { reportId: reportId }, headers(token))).data;
105
+ }
106
+ export async function getLastDayResults() {
107
+ let token = await auth();
108
+ return (await axios.get(config.auxtaURL + `get-last-day-results?url=${config.baseURL}`, headers(token))).data.results;
109
+ }
110
+ export async function postNotifications(body) {
111
+ let token = await auth();
112
+ await axios.post(`${config.auxtaURL}post-notification-after-run-background`, {
113
+ environmentName: body.environment,
114
+ digitalProductName: body.digitalProduct,
115
+ organizationName: body.organization,
116
+ reportId: body.reportId,
117
+ }, headers(token));
118
+ }
119
+ export async function postNotificationsOnFail(body) {
120
+ let token = await auth();
121
+ await axios.post(`${config.auxtaURL}post-notifications-after-case-fail-background`, {
122
+ environmentName: body.environment,
123
+ digitalProductName: body.digitalProduct,
124
+ organizationName: body.organization,
125
+ reportId: body.reportId,
126
+ }, headers(token));
127
+ }
@@ -0,0 +1,16 @@
1
+ export interface RunTime {
2
+ duration: String;
3
+ startTime: Date;
4
+ endTime: Date;
5
+ }
6
+ export declare class Runtime {
7
+ private start;
8
+ private end;
9
+ private runtime;
10
+ constructor(s: Date, e: Date);
11
+ private calculateDuration;
12
+ private splitAtDecimanlMinutes;
13
+ private splitAtDecimanlHours;
14
+ private formatRuntime;
15
+ returnRuntime(): RunTime;
16
+ }
@@ -1,51 +1,37 @@
1
- export interface RunTime {
2
- duration: String,
3
- startTime: Date,
4
- endTime: Date,
5
- }
6
-
7
1
  export class Runtime {
8
- private start: Date;
9
-
10
- private end: Date;
11
-
12
- private runtime!: RunTime;
13
-
14
- constructor(s: Date, e: Date) {
2
+ constructor(s, e) {
15
3
  this.start = s;
16
4
  this.end = e;
17
5
  }
18
-
19
- private calculateDuration() {
6
+ calculateDuration() {
20
7
  let currentTime = new Date;
21
8
  let duration = currentTime.getTime() - this.start.getTime();
22
9
  return duration;
23
10
  }
24
-
25
- private splitAtDecimanlMinutes(time: number) {
11
+ splitAtDecimanlMinutes(time) {
26
12
  let minutes = time.toFixed(2).toString().split('.');
27
13
  return `${minutes[0]}m ${(Number(minutes[1]) / 100 * 60).toFixed(0)}s`;
28
14
  }
29
-
30
- private splitAtDecimanlHours(time: number) {
15
+ splitAtDecimanlHours(time) {
31
16
  let hours = time.toFixed(2).toString().split('.');
32
17
  let minutes = (Number(hours[1]) / 100 * 60).toFixed(2).toString().split('.');
33
18
  return `${hours[0]}h ${minutes[0]}m ${(Number(minutes[1]) / 100 * 60).toFixed(0)}s`;
34
19
  }
35
-
36
- private formatRuntime(duration: number) {
37
- if(duration / 1000 < 60) return `${(duration / 1000).toFixed(0)}s`
20
+ formatRuntime(duration) {
21
+ if (duration / 1000 < 60)
22
+ return `${(duration / 1000).toFixed(0)}s`;
38
23
  else {
39
- if(duration / 60000 < 60) return this.splitAtDecimanlMinutes(duration / 60000);
40
- else return this.splitAtDecimanlHours(duration / 3600000);
24
+ if (duration / 60000 < 60)
25
+ return this.splitAtDecimanlMinutes(duration / 60000);
26
+ else
27
+ return this.splitAtDecimanlHours(duration / 3600000);
41
28
  }
42
29
  }
43
-
44
- public returnRuntime() : RunTime {
30
+ returnRuntime() {
45
31
  let duration = this.formatRuntime(this.calculateDuration());
46
32
  let startTime = this.start;
47
33
  let endTime = this.end;
48
- this.runtime = { duration, startTime, endTime }
34
+ this.runtime = { duration, startTime, endTime };
49
35
  return this.runtime;
50
36
  }
51
- }
37
+ }
@@ -0,0 +1,15 @@
1
+ import { RunTime } from "../services/runtime.service";
2
+ export declare class CalculateRuntime {
3
+ private runtime;
4
+ startTimeSeconds: string;
5
+ startTimeMinutes: string;
6
+ startTimeHours: string;
7
+ startTimeDay: string;
8
+ startTimeMonth: string;
9
+ endTimeSeconds: string;
10
+ endTimeMinutes: string;
11
+ endTimeHours: string;
12
+ endTimeDay: string;
13
+ endTimeMonth: string;
14
+ constructor(r: RunTime);
15
+ }
@@ -1,29 +1,15 @@
1
- import { RunTime } from "../services/runtime.service";
2
-
3
1
  export class CalculateRuntime {
4
- private runtime: RunTime;
5
- public startTimeSeconds: string;
6
- public startTimeMinutes: string;
7
- public startTimeHours: string;
8
- public startTimeDay: string;
9
- public startTimeMonth: string;
10
- public endTimeSeconds: string;
11
- public endTimeMinutes: string;
12
- public endTimeHours: string;
13
- public endTimeDay: string;
14
- public endTimeMonth: string;
15
- constructor(r: RunTime){
2
+ constructor(r) {
16
3
  this.runtime = r;
17
- this.startTimeSeconds = (this.runtime.startTime.getSeconds() < 10) ? `0${this.runtime.startTime.getSeconds()}` : `${this.runtime.startTime.getSeconds()}`
4
+ this.startTimeSeconds = (this.runtime.startTime.getSeconds() < 10) ? `0${this.runtime.startTime.getSeconds()}` : `${this.runtime.startTime.getSeconds()}`;
18
5
  this.startTimeMinutes = (this.runtime.startTime.getMinutes() < 10) ? `0${this.runtime.startTime.getMinutes()}` : `${this.runtime.startTime.getMinutes()}`;
19
6
  this.startTimeHours = (this.runtime.startTime.getHours() < 10) ? `0${this.runtime.startTime.getHours()}` : `${this.runtime.startTime.getHours()}`;
20
7
  this.startTimeDay = (this.runtime.startTime.getDate() < 10) ? `0${this.runtime.startTime.getDate()}` : `${this.runtime.startTime.getDate()}`;
21
8
  this.startTimeMonth = (this.runtime.startTime.getMonth() + 1 < 10) ? `0${this.runtime.startTime.getMonth() + 1}` : `${this.runtime.startTime.getMonth() + 1}`;
22
-
23
9
  this.endTimeSeconds = (this.runtime.endTime.getSeconds() < 10) ? `0${this.runtime.endTime.getSeconds()}` : `${this.runtime.endTime.getSeconds()}`;
24
10
  this.endTimeMinutes = (this.runtime.endTime.getMinutes() < 10) ? `0${this.runtime.endTime.getMinutes()}` : `${this.runtime.endTime.getMinutes()}`;
25
11
  this.endTimeHours = (this.runtime.endTime.getHours() < 10) ? `0${this.runtime.endTime.getHours()}` : `${this.runtime.endTime.getHours()}`;
26
12
  this.endTimeDay = (this.runtime.endTime.getDate() < 10) ? `0${this.runtime.endTime.getDate()}` : `${this.runtime.endTime.getDate()}`;
27
13
  this.endTimeMonth = (this.runtime.endTime.getMonth() + 1 < 10) ? `0${this.runtime.endTime.getMonth() + 1}` : `${this.runtime.endTime.getMonth() + 1}`;
28
14
  }
29
- }
15
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function captureScreenshot(): Promise<Buffer | undefined>;
@@ -1,19 +1,18 @@
1
- import puppeteer from "../../puppeteer/puppeteer";
2
-
1
+ import puppeteer from "../../puppeteer/puppeteer";
3
2
  export async function captureScreenshot() {
4
- try{
3
+ try {
5
4
  const pages = await puppeteer.defaultPage.browser().pages();
6
- if (!pages.length) return undefined;
5
+ if (!pages.length)
6
+ return undefined;
7
7
  const lastPage = pages[pages.length - 1] || puppeteer.defaultPage;
8
-
9
8
  const screenshotBuffer = await lastPage.screenshot({
10
- fullPage: true,
11
- encoding: 'binary'
12
- }
13
- );
9
+ fullPage: true,
10
+ encoding: 'binary'
11
+ });
14
12
  if (Buffer.isBuffer(screenshotBuffer))
15
13
  return screenshotBuffer;
16
- } catch (e){
17
14
  }
18
- return undefined
15
+ catch (e) {
16
+ }
17
+ return undefined;
19
18
  }
@@ -0,0 +1 @@
1
+ export declare function startSuite(suites: string[], reportId?: string): Promise<void>;
@@ -0,0 +1,14 @@
1
+ import axios from 'axios';
2
+ import { config } from "../configs/config";
3
+ export async function startSuite(suites, reportId) {
4
+ if (suites.length === 0)
5
+ return;
6
+ const next = suites.shift();
7
+ console.log('Starting next suite: ' + next);
8
+ try {
9
+ await axios.post(`${config.netlifyPath}.netlify/functions/${next}?token=${config.token}`, { nextSuites: suites, reportId: reportId });
10
+ }
11
+ catch (e) {
12
+ await startSuite(suites, reportId);
13
+ }
14
+ }
@@ -0,0 +1,22 @@
1
+ import { StatusOfStep } from "../../auxta/enums/status-of.step";
2
+ export declare class FunctionHelper {
3
+ readonly defaultTimeout: number;
4
+ log(keyword: string, name: string, status: StatusOfStep): void;
5
+ suggest(name: string): void;
6
+ private getEscapedText;
7
+ clickByText(selector: string, text: string, page?: import("puppeteer-core").Page, dotOrText?: string): Promise<void>;
8
+ clickByTextWithClass(class_selector: string, class_name: string, selector: string, text: string, page?: import("puppeteer-core").Page, dotOrText?: string): Promise<void>;
9
+ waitForSelectorWithText(selector: string, text: string, page?: import("puppeteer-core").Page, dotOrText?: string): Promise<boolean>;
10
+ goto(url: string, page?: import("puppeteer-core").Page): Promise<void>;
11
+ type(field: string, value: string, page?: import("puppeteer-core").Page): Promise<void>;
12
+ waitForNetwork(page?: import("puppeteer-core").Page): Promise<void>;
13
+ timeout(timeout?: number, page?: import("puppeteer-core").Page): Promise<void>;
14
+ waitForSelector(option: string, selector: string, time?: number, page?: import("puppeteer-core").Page, log_message?: boolean): Promise<void>;
15
+ click(selector: string, logMessages?: boolean, page?: import("puppeteer-core").Page): Promise<void>;
16
+ urlContains(selector: string, page?: import("puppeteer-core").Page): Promise<void>;
17
+ pressEnter(page?: import("puppeteer-core").Page): Promise<void>;
18
+ clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer-core").Page): Promise<void>;
19
+ closeLastPage(page?: import("puppeteer-core").Page): Promise<void>;
20
+ }
21
+ declare const _default: FunctionHelper;
22
+ export default _default;
@@ -2,55 +2,51 @@ import log from "../../auxta/services/log.service";
2
2
  import puppeteer from "../../puppeteer/puppeteer";
3
3
  import { StatusOfStep } from "../../auxta/enums/status-of.step";
4
4
  import { config } from "../../auxta/configs/config";
5
-
6
5
  export class FunctionHelper {
7
- public readonly defaultTimeout: number = config.timeout;
8
-
9
- public log(keyword: string, name: string, status: StatusOfStep) {
10
- log.push(keyword, name, status)
11
- }
12
-
13
- public suggest(name: string) {
14
- log.addSuggestion(name)
15
- }
16
-
17
- private getEscapedText(text: string) {
18
- const splitedQuotes = text.replace(/'/g, `', "'", '`)
6
+ constructor() {
7
+ this.defaultTimeout = config.timeout;
8
+ }
9
+ log(keyword, name, status) {
10
+ log.push(keyword, name, status);
11
+ }
12
+ suggest(name) {
13
+ log.addSuggestion(name);
14
+ }
15
+ getEscapedText(text) {
16
+ const splitedQuotes = text.replace(/'/g, `', "'", '`);
19
17
  return `concat('${splitedQuotes}', '')`;
20
18
  }
21
-
22
- public async clickByText(selector: string, text: string, page = puppeteer.defaultPage, dotOrText = '.') {
19
+ async clickByText(selector, text, page = puppeteer.defaultPage, dotOrText = '.') {
23
20
  const message = `I click on the '${text}' '${selector}'`;
24
21
  try {
25
22
  const [linkHandlers] = await page.$x(`//${selector}[${dotOrText} = ${this.getEscapedText(text)}]`);
26
-
27
23
  if (linkHandlers) {
28
24
  await linkHandlers.click();
29
25
  log.push('Then', message, StatusOfStep.PASSED);
30
26
  return;
31
27
  }
32
- } catch (e) {
28
+ }
29
+ catch (e) {
33
30
  }
34
31
  log.push('Then', message, StatusOfStep.FAILED);
35
32
  throw new Error(message);
36
33
  }
37
- public async clickByTextWithClass(class_selector: string, class_name: string, selector: string, text: string, page = puppeteer.defaultPage, dotOrText = '.') {
34
+ async clickByTextWithClass(class_selector, class_name, selector, text, page = puppeteer.defaultPage, dotOrText = '.') {
38
35
  const message = `I click on the '${text}' '${selector}'`;
39
36
  try {
40
37
  const [linkHandlers] = await page.$x(`//${class_selector}[contains(@class,${this.getEscapedText(class_name)})]//${selector}[${dotOrText} = ${this.getEscapedText(text)}]`);
41
-
42
38
  if (linkHandlers) {
43
39
  await linkHandlers.click();
44
40
  log.push('Then', message, StatusOfStep.PASSED);
45
41
  return;
46
42
  }
47
- } catch (e) {
43
+ }
44
+ catch (e) {
48
45
  }
49
46
  log.push('Then', message, StatusOfStep.FAILED);
50
47
  throw new Error(message);
51
48
  }
52
- //div[contains(@class,"mat-menu-content")]//button
53
- public async waitForSelectorWithText(selector: string, text: string, page = puppeteer.defaultPage, dotOrText = '.') {
49
+ async waitForSelectorWithText(selector, text, page = puppeteer.defaultPage, dotOrText = '.') {
54
50
  const message = `I check for '${text}' on the current page`;
55
51
  try {
56
52
  await page.waitForSelector(selector, {
@@ -61,141 +57,102 @@ export class FunctionHelper {
61
57
  log.push('And', message, StatusOfStep.PASSED);
62
58
  return true;
63
59
  }
64
- } catch (e) {
60
+ }
61
+ catch (e) {
65
62
  }
66
63
  log.push('And', message, StatusOfStep.FAILED);
67
64
  throw new Error(message);
68
65
  }
69
-
70
- public async goto(url: string, page = puppeteer.defaultPage) {
66
+ async goto(url, page = puppeteer.defaultPage) {
71
67
  await page.goto(url);
72
68
  log.push('Then', `I go to the '${url}' page`, StatusOfStep.PASSED);
73
69
  }
74
-
75
- public async type(field: string, value: string, page = puppeteer.defaultPage) {
70
+ async type(field, value, page = puppeteer.defaultPage) {
76
71
  try {
77
72
  await page.waitForSelector(field, {
78
73
  timeout: this.defaultTimeout
79
74
  });
80
75
  await page.type(field, value);
81
76
  let elementName = await page.$eval(field, (e) => e.textContent);
82
- if (!elementName || elementName === ' ') elementName = field;
77
+ if (!elementName || elementName === ' ')
78
+ elementName = field;
83
79
  log.push('Then', `I type '${value}' into the '${elementName}' field`, StatusOfStep.PASSED);
84
- } catch (e) {
85
- const msg = `I type '${value}' into the '${field}' field`
80
+ }
81
+ catch (e) {
82
+ const msg = `I type '${value}' into the '${field}' field`;
86
83
  log.push('Then', msg, StatusOfStep.FAILED);
87
- throw new Error(msg)
84
+ throw new Error(msg);
88
85
  }
89
86
  }
90
-
91
- public async waitForNetwork(page = puppeteer.defaultPage) {
92
- let message = 'I wait for the page to load'
87
+ async waitForNetwork(page = puppeteer.defaultPage) {
88
+ let message = 'I wait for the page to load';
93
89
  try {
94
90
  await page.waitForNetworkIdle();
95
91
  log.push('Then', message, StatusOfStep.PASSED);
96
- } catch (e) {
92
+ }
93
+ catch (e) {
97
94
  log.push('Then', message, StatusOfStep.FAILED);
98
- throw new Error(message)
95
+ throw new Error(message);
99
96
  }
100
97
  }
101
-
102
- public async timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
98
+ async timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
103
99
  await page.waitForTimeout(timeout);
104
100
  }
105
-
106
- /**
107
- * Waiting for selector with timeout 60000
108
- *
109
- * @function waitForSelector
110
- * @param {string} option - visible, hidden
111
- * @param selector - class to select
112
- * @param time
113
- * @param page
114
- * @param log_message
115
- */
116
-
117
- public async waitForSelector(option: string, selector: string, time: number = this.defaultTimeout, page = puppeteer.defaultPage, log_message = true) {
101
+ async waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer.defaultPage, log_message = true) {
118
102
  const message = `I check for the '${selector}' element to be ${option}`;
119
103
  try {
120
104
  await page.waitForSelector(selector, {
121
105
  [option]: true,
122
106
  timeout: time
123
107
  });
124
- } catch (e) {
108
+ }
109
+ catch (e) {
125
110
  if (log_message) {
126
111
  log.push('And', message, StatusOfStep.FAILED);
127
112
  }
128
- throw new Error(message)
113
+ throw new Error(message);
129
114
  }
130
115
  if (log_message) {
131
116
  log.push('And', message, StatusOfStep.PASSED);
132
117
  }
133
118
  }
134
-
135
- public async click(selector: string, logMessages = true, page = puppeteer.defaultPage) {
119
+ async click(selector, logMessages = true, page = puppeteer.defaultPage) {
136
120
  try {
137
121
  await page.waitForSelector(selector, {
138
122
  timeout: this.defaultTimeout
139
123
  });
140
124
  let elementName = await page.$eval(selector, (e) => e.textContent);
141
- if (!elementName || elementName === ' ') elementName = selector;
125
+ if (!elementName || elementName === ' ')
126
+ elementName = selector;
142
127
  await page.click(selector);
143
128
  log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
144
- } catch (e) {
129
+ }
130
+ catch (e) {
145
131
  const msg = `I click on the '${selector}'`;
146
132
  log.push('Then', msg, StatusOfStep.FAILED);
147
- throw new Error(msg)
133
+ throw new Error(msg);
148
134
  }
149
135
  }
150
-
151
- public async urlContains(selector: string, page = puppeteer.defaultPage) {
136
+ async urlContains(selector, page = puppeteer.defaultPage) {
152
137
  const url = page.url();
153
- let message = `I am on the ${selector} page`
138
+ let message = `I am on the ${selector} page`;
154
139
  if (!url.includes(selector)) {
155
140
  log.push('And', message, StatusOfStep.FAILED);
156
- throw new Error(message)
141
+ throw new Error(message);
157
142
  }
158
143
  log.push('And', message, StatusOfStep.PASSED);
159
144
  }
160
-
161
- public async pressEnter(page = puppeteer.defaultPage) {
145
+ async pressEnter(page = puppeteer.defaultPage) {
162
146
  await page.keyboard.press('Enter');
163
147
  }
164
-
165
- public async waitForPageToBeCreated(selector: string,page = puppeteer.defaultPage) {
148
+ async clickAndWaitForPageToBeCreated(selector, page = puppeteer.defaultPage) {
166
149
  const nav = new Promise(res => page.browser().on('targetcreated', res));
167
150
  await this.click(selector);
168
151
  await nav;
169
152
  }
170
-
171
- //TODO work in progress
172
- /*
173
- private async microsoftLogin(button: string, email: string, password: string) {
174
- const email_input = 'input[type="email"]';
175
- const password_input = 'input[type="password"]';
176
- const no_button = 'input[type="button"]';
177
- // click on login button
178
- const nav = new Promise(res => puppeteer.defaultPage.browser().on('targetcreated', res));
179
- await this.click(button);
180
- await nav;
181
- const pages = await puppeteer.defaultPage.browser().pages();
182
- const loginPage = pages[pages.length - 1];
183
- // enter password and submit
184
- await this.waitForSelector('visible', email_input, 60000, loginPage);
185
- await this.type(email_input, email, loginPage);
186
- await this.pressEnter(loginPage);
187
- await this.waitForNetwork(loginPage);
188
- // enter password and submit
189
- await this.waitForSelector('visible', password_input, 60000, loginPage);
190
- await this.type(password_input, password, loginPage);
191
- await this.pressEnter(loginPage);
192
- await this.waitForNetwork(loginPage);
193
- // press no
194
- await this.waitForSelector('visible', no_button, 60000, loginPage);
195
- await this.click(no_button, true, loginPage);
196
- await this.waitForNetwork(loginPage);
197
- }*/
198
-
153
+ async closeLastPage(page = puppeteer.defaultPage) {
154
+ const pages = await page.browser().pages();
155
+ await pages[pages.length - 1].close();
156
+ }
199
157
  }
200
-
201
158
  export default new FunctionHelper();
@@ -0,0 +1,13 @@
1
+ import { UploadModel } from "../auxta/models/upload.model";
2
+ import puppeteer_core from 'puppeteer-core';
3
+ export declare class Puppeteer {
4
+ defaultPage: puppeteer_core.Page;
5
+ private browser;
6
+ startBrowser(): Promise<void>;
7
+ close(): Promise<void>;
8
+ run(event: any, callback: any, featureName?: string, scenarioName?: string, uploadModel?: UploadModel, close?: boolean): Promise<void>;
9
+ runRPA(event: any, callback: any, close?: boolean): Promise<any>;
10
+ private static setupHeader;
11
+ }
12
+ declare const _default: Puppeteer;
13
+ export default _default;