@auxcode/auxta 1.3.14 → 1.3.16

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 (72) hide show
  1. package/README.md +60 -60
  2. package/package.json +29 -29
  3. package/build/cjs/AuxTA.d.ts +0 -57
  4. package/build/cjs/AuxTA.js +0 -148
  5. package/build/cjs/auxta/configs/config.d.ts +0 -51
  6. package/build/cjs/auxta/configs/config.js +0 -66
  7. package/build/cjs/auxta/enums/status-of.step.d.ts +0 -7
  8. package/build/cjs/auxta/enums/status-of.step.js +0 -11
  9. package/build/cjs/auxta/helpers/response.helper.d.ts +0 -10
  10. package/build/cjs/auxta/helpers/response.helper.js +0 -15
  11. package/build/cjs/auxta/helpers/start.helper.d.ts +0 -1
  12. package/build/cjs/auxta/helpers/start.helper.js +0 -26
  13. package/build/cjs/auxta/hooks/report.hook.d.ts +0 -14
  14. package/build/cjs/auxta/hooks/report.hook.js +0 -66
  15. package/build/cjs/auxta/models/upload.model.d.ts +0 -32
  16. package/build/cjs/auxta/models/upload.model.js +0 -75
  17. package/build/cjs/auxta/services/log.service.d.ts +0 -26
  18. package/build/cjs/auxta/services/log.service.js +0 -47
  19. package/build/cjs/auxta/services/report.service.d.ts +0 -36
  20. package/build/cjs/auxta/services/report.service.js +0 -164
  21. package/build/cjs/auxta/services/runtime.service.d.ts +0 -16
  22. package/build/cjs/auxta/services/runtime.service.js +0 -41
  23. package/build/cjs/auxta/utilities/runtime.helper.d.ts +0 -15
  24. package/build/cjs/auxta/utilities/runtime.helper.js +0 -19
  25. package/build/cjs/auxta/utilities/screenshot.helper.d.ts +0 -2
  26. package/build/cjs/auxta/utilities/screenshot.helper.js +0 -36
  27. package/build/cjs/auxta/utilities/start-suite.helper.d.ts +0 -17
  28. package/build/cjs/auxta/utilities/start-suite.helper.js +0 -31
  29. package/build/cjs/macros/helpers/Aux2faAuth.d.ts +0 -7
  30. package/build/cjs/macros/helpers/Aux2faAuth.js +0 -29
  31. package/build/cjs/macros/helpers/code.helper.d.ts +0 -21
  32. package/build/cjs/macros/helpers/code.helper.js +0 -192
  33. package/build/cjs/macros/helpers/extend-default-page.d.ts +0 -6
  34. package/build/cjs/macros/helpers/extend-default-page.js +0 -88
  35. package/build/cjs/puppeteer/puppeteer.d.ts +0 -25
  36. package/build/cjs/puppeteer/puppeteer.js +0 -200
  37. package/build/esm/AuxTA.d.ts +0 -57
  38. package/build/esm/AuxTA.js +0 -119
  39. package/build/esm/auxta/configs/config.d.ts +0 -51
  40. package/build/esm/auxta/configs/config.js +0 -61
  41. package/build/esm/auxta/enums/status-of.step.d.ts +0 -7
  42. package/build/esm/auxta/enums/status-of.step.js +0 -8
  43. package/build/esm/auxta/helpers/response.helper.d.ts +0 -10
  44. package/build/esm/auxta/helpers/response.helper.js +0 -11
  45. package/build/esm/auxta/helpers/start.helper.d.ts +0 -1
  46. package/build/esm/auxta/helpers/start.helper.js +0 -24
  47. package/build/esm/auxta/hooks/report.hook.d.ts +0 -14
  48. package/build/esm/auxta/hooks/report.hook.js +0 -58
  49. package/build/esm/auxta/models/upload.model.d.ts +0 -32
  50. package/build/esm/auxta/models/upload.model.js +0 -71
  51. package/build/esm/auxta/services/log.service.d.ts +0 -26
  52. package/build/esm/auxta/services/log.service.js +0 -43
  53. package/build/esm/auxta/services/report.service.d.ts +0 -36
  54. package/build/esm/auxta/services/report.service.js +0 -150
  55. package/build/esm/auxta/services/runtime.service.d.ts +0 -16
  56. package/build/esm/auxta/services/runtime.service.js +0 -37
  57. package/build/esm/auxta/utilities/runtime.helper.d.ts +0 -15
  58. package/build/esm/auxta/utilities/runtime.helper.js +0 -15
  59. package/build/esm/auxta/utilities/screenshot.helper.d.ts +0 -2
  60. package/build/esm/auxta/utilities/screenshot.helper.js +0 -29
  61. package/build/esm/auxta/utilities/start-suite.helper.d.ts +0 -17
  62. package/build/esm/auxta/utilities/start-suite.helper.js +0 -26
  63. package/build/esm/macros/helpers/Aux2faAuth.d.ts +0 -7
  64. package/build/esm/macros/helpers/Aux2faAuth.js +0 -25
  65. package/build/esm/macros/helpers/code.helper.d.ts +0 -21
  66. package/build/esm/macros/helpers/code.helper.js +0 -185
  67. package/build/esm/macros/helpers/extend-default-page.d.ts +0 -6
  68. package/build/esm/macros/helpers/extend-default-page.js +0 -81
  69. package/build/esm/puppeteer/puppeteer.d.ts +0 -25
  70. package/build/esm/puppeteer/puppeteer.js +0 -192
  71. package/build/tsconfig-cjs.tsbuildinfo +0 -1
  72. package/build/tsconfig.tsbuildinfo +0 -1
@@ -1,150 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import axios from "axios";
11
- import { config } from "../configs/config";
12
- function headers(token) {
13
- return {
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- 'cookie': `authToken=${token}`
17
- }
18
- };
19
- }
20
- function auth() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- return axios.post(config.auxtaURL + 'login', config.auxtaCredentials, {
23
- headers: {
24
- 'Content-Type': 'application/json',
25
- }
26
- })
27
- .then(({ data }) => {
28
- return data.token;
29
- })
30
- .catch(() => {
31
- throw new Error("Invalid login credentials");
32
- });
33
- });
34
- }
35
- export function createEmptyReport(body) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const token = yield auth();
38
- return (yield axios.post(config.auxtaURL + "create-empty-report", {
39
- environment: body.environment,
40
- digitalProductName: body.digitalProduct,
41
- start: new Date(),
42
- url: body.baseUrl
43
- }, headers(token))).data.reportId;
44
- });
45
- }
46
- export function uploadScenario(stepLog, scenarioName, screenshot, errMessage) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- let scenarios = [];
49
- let token = yield auth();
50
- let lastStep = stepLog[stepLog.length - 1];
51
- const stepLogFormat = JSON.parse(JSON.stringify(stepLog));
52
- stepLogFormat.pop();
53
- let output = (yield axios.post(config.auxtaURL + "create-scenario", {
54
- json: {
55
- name: scenarioName,
56
- steps: [
57
- ...stepLogFormat,
58
- (lastStep.result.status == 'failed')
59
- ? Object.assign(lastStep, {
60
- result: Object.assign(Object.assign({}, lastStep.result), { error_message: JSON.stringify(errMessage) })
61
- })
62
- : lastStep,
63
- {
64
- keyword: "After",
65
- result: {
66
- status: "passed",
67
- duration: 2678000000
68
- },
69
- embeddings: (screenshot) ? [{
70
- data: screenshot.toString("base64"),
71
- mime_type: "image/png"
72
- }] : undefined,
73
- }
74
- ],
75
- }
76
- }, headers(token))).data.scenarios;
77
- scenarios.push({
78
- scenarioRef: output.scenarioRef,
79
- name: output.name,
80
- status: output.status,
81
- stepsCount: output.stepsCount
82
- });
83
- return scenarios;
84
- });
85
- }
86
- export function uploadFeature(scenarioId, scenarioName, uri, hasFailed) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- let token = yield auth();
89
- return (yield axios.post(config.auxtaURL + "create-feature", {
90
- json: {
91
- name: scenarioName,
92
- uri: uri
93
- },
94
- scenarios: scenarioId,
95
- hasFailed: hasFailed
96
- }, headers(token))).data;
97
- });
98
- }
99
- export function updateReport(reportId, feature, steps, isFinal) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- let token = yield auth();
102
- yield axios.post(config.auxtaURL + "update-inprogress-report", {
103
- reportId: reportId,
104
- isFinal: isFinal,
105
- data: Object.assign({ feature: {
106
- featureRef: feature.featureId,
107
- name: feature.featureName,
108
- uri: feature.featureUri,
109
- status: feature.status,
110
- scenariosCount: feature.scenariosCount
111
- } }, steps)
112
- }, headers(token));
113
- });
114
- }
115
- export function getReport(reportId) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- let token = yield auth();
118
- return (yield axios.post(config.auxtaURL + "get-report", { reportId: reportId }, headers(token))).data;
119
- });
120
- }
121
- export function getLastDayResults() {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- let token = yield auth();
124
- return (yield axios.get(config.auxtaURL + `get-last-day-results?url=${config.baseURL}`, headers(token))).data.results;
125
- });
126
- }
127
- export function postNotifications(body) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- let token = yield auth();
130
- yield axios.post(`${config.auxtaURL}post-notification-after-run-background`, {
131
- environmentName: body.environment,
132
- digitalProductName: body.digitalProduct,
133
- organizationName: body.organization,
134
- reportId: body.reportId,
135
- }, headers(token));
136
- });
137
- }
138
- export function postNotificationsOnFail(body) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- let token = yield auth();
141
- yield axios.post(`${config.auxtaURL}post-notifications-after-case-fail-background`, {
142
- environmentName: body.environment,
143
- digitalProductName: body.digitalProduct,
144
- organizationName: body.organization,
145
- reportId: body.reportId,
146
- featureName: body.featureName,
147
- scenarioName: body.scenarioName
148
- }, headers(token));
149
- });
150
- }
@@ -1,16 +0,0 @@
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,37 +0,0 @@
1
- export class Runtime {
2
- constructor(s, e) {
3
- this.start = s;
4
- this.end = e;
5
- }
6
- calculateDuration() {
7
- let currentTime = new Date;
8
- let duration = currentTime.getTime() - this.start.getTime();
9
- return duration;
10
- }
11
- splitAtDecimanlMinutes(time) {
12
- let minutes = time.toFixed(2).toString().split('.');
13
- return `${minutes[0]}m ${(Number(minutes[1]) / 100 * 60).toFixed(0)}s`;
14
- }
15
- splitAtDecimanlHours(time) {
16
- let hours = time.toFixed(2).toString().split('.');
17
- let minutes = (Number(hours[1]) / 100 * 60).toFixed(2).toString().split('.');
18
- return `${hours[0]}h ${minutes[0]}m ${(Number(minutes[1]) / 100 * 60).toFixed(0)}s`;
19
- }
20
- formatRuntime(duration) {
21
- if (duration / 1000 < 60)
22
- return `${(duration / 1000).toFixed(0)}s`;
23
- else {
24
- if (duration / 60000 < 60)
25
- return this.splitAtDecimanlMinutes(duration / 60000);
26
- else
27
- return this.splitAtDecimanlHours(duration / 3600000);
28
- }
29
- }
30
- returnRuntime() {
31
- let duration = this.formatRuntime(this.calculateDuration());
32
- let startTime = this.start;
33
- let endTime = this.end;
34
- this.runtime = { duration, startTime, endTime };
35
- return this.runtime;
36
- }
37
- }
@@ -1,15 +0,0 @@
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,15 +0,0 @@
1
- export class CalculateRuntime {
2
- constructor(r) {
3
- this.runtime = r;
4
- this.startTimeSeconds = (this.runtime.startTime.getSeconds() < 10) ? `0${this.runtime.startTime.getSeconds()}` : `${this.runtime.startTime.getSeconds()}`;
5
- this.startTimeMinutes = (this.runtime.startTime.getMinutes() < 10) ? `0${this.runtime.startTime.getMinutes()}` : `${this.runtime.startTime.getMinutes()}`;
6
- this.startTimeHours = (this.runtime.startTime.getHours() < 10) ? `0${this.runtime.startTime.getHours()}` : `${this.runtime.startTime.getHours()}`;
7
- this.startTimeDay = (this.runtime.startTime.getDate() < 10) ? `0${this.runtime.startTime.getDate()}` : `${this.runtime.startTime.getDate()}`;
8
- this.startTimeMonth = (this.runtime.startTime.getMonth() + 1 < 10) ? `0${this.runtime.startTime.getMonth() + 1}` : `${this.runtime.startTime.getMonth() + 1}`;
9
- this.endTimeSeconds = (this.runtime.endTime.getSeconds() < 10) ? `0${this.runtime.endTime.getSeconds()}` : `${this.runtime.endTime.getSeconds()}`;
10
- this.endTimeMinutes = (this.runtime.endTime.getMinutes() < 10) ? `0${this.runtime.endTime.getMinutes()}` : `${this.runtime.endTime.getMinutes()}`;
11
- this.endTimeHours = (this.runtime.endTime.getHours() < 10) ? `0${this.runtime.endTime.getHours()}` : `${this.runtime.endTime.getHours()}`;
12
- this.endTimeDay = (this.runtime.endTime.getDate() < 10) ? `0${this.runtime.endTime.getDate()}` : `${this.runtime.endTime.getDate()}`;
13
- this.endTimeMonth = (this.runtime.endTime.getMonth() + 1 < 10) ? `0${this.runtime.endTime.getMonth() + 1}` : `${this.runtime.endTime.getMonth() + 1}`;
14
- }
15
- }
@@ -1,2 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function captureScreenshot(): Promise<Buffer | undefined>;
@@ -1,29 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import puppeteer from "../../puppeteer/puppeteer";
11
- export function captureScreenshot() {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- try {
14
- const pages = yield puppeteer.defaultPage.browser().pages();
15
- if (!pages.length)
16
- return undefined;
17
- const lastPage = pages[pages.length - 1] || puppeteer.defaultPage;
18
- const screenshotBuffer = yield lastPage.screenshot({
19
- fullPage: true,
20
- encoding: 'binary'
21
- });
22
- if (Buffer.isBuffer(screenshotBuffer))
23
- return screenshotBuffer;
24
- }
25
- catch (e) {
26
- }
27
- return undefined;
28
- });
29
- }
@@ -1,17 +0,0 @@
1
- export declare function startSuite(suites: string[], reportId?: string): Promise<{
2
- nextSuites?: undefined;
3
- reportId?: undefined;
4
- currentSuite?: undefined;
5
- retries?: undefined;
6
- } | {
7
- nextSuites: string[];
8
- reportId: string | undefined;
9
- currentSuite: string | undefined;
10
- retries: string;
11
- }>;
12
- export declare function retrySuite(suites: string[], reportId: string, currentSuite: string, retries: number): Promise<false | {
13
- nextSuites: string[];
14
- reportId: string;
15
- currentSuite: string;
16
- retries: number;
17
- }>;
@@ -1,26 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export function startSuite(suites, reportId) {
11
- return __awaiter(this, void 0, void 0, function* () {
12
- if (suites.length === 0)
13
- return {};
14
- const next = suites.shift();
15
- return { nextSuites: suites, reportId: reportId, currentSuite: next, retries: "0" };
16
- });
17
- }
18
- export function retrySuite(suites, reportId, currentSuite, retries) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- console.log('I repeat again the current suite: ' + currentSuite);
21
- if (retries >= 2) {
22
- return false;
23
- }
24
- return { nextSuites: suites, reportId: reportId, currentSuite: currentSuite, retries: retries };
25
- });
26
- }
@@ -1,7 +0,0 @@
1
- export declare class Aux2faAuth {
2
- authenticator(): any;
3
- verifyToken(token: string): boolean;
4
- private getSecret;
5
- }
6
- declare const _default: Aux2faAuth;
7
- export default _default;
@@ -1,25 +0,0 @@
1
- const twofactor = require("node-2fa");
2
- export class Aux2faAuth {
3
- authenticator() {
4
- const aux2fe_secret = this.getSecret();
5
- return twofactor.generateToken(aux2fe_secret).token;
6
- }
7
- verifyToken(token) {
8
- const aux2fe_secret = this.getSecret();
9
- const result = twofactor.verifyToken(aux2fe_secret, token);
10
- if (result != null) {
11
- if (result.delta == 0) {
12
- return true;
13
- }
14
- }
15
- return false;
16
- }
17
- getSecret() {
18
- const aux2fe_secret = process.env.aux2fe_secret;
19
- if (!aux2fe_secret) {
20
- throw new Error('No 2fe secret set');
21
- }
22
- return aux2fe_secret;
23
- }
24
- }
25
- export default new Aux2faAuth();
@@ -1,21 +0,0 @@
1
- import { StatusOfStep } from "../../auxta/enums/status-of.step";
2
- import { ExtendDefaultPage } from "./extend-default-page";
3
- export declare class FunctionHelper extends ExtendDefaultPage {
4
- log(keyword: string, name: string, status: StatusOfStep): void;
5
- suggest(name: string): void;
6
- private getEscapedText;
7
- clickByText(selector: string, text: string, dotOrText?: string, page?: import("puppeteer").Page, time?: number, log_message?: boolean): Promise<void>;
8
- clickByTextWithClass(class_selector: string, class_name: string, selector: string, text: string, dotOrText?: string, page?: import("puppeteer").Page): Promise<void>;
9
- waitForSelectorWithText(selector: string, text: string, dotOrText?: string, page?: import("puppeteer").Page): Promise<boolean>;
10
- timeout(timeout?: number, page?: import("puppeteer").Page): Promise<void>;
11
- waitForSelector(option: string, selector: string, time?: number, page?: import("puppeteer").Page, log_message?: boolean): Promise<void>;
12
- urlContains(selector: string, page?: import("puppeteer").Page): Promise<void>;
13
- pressEnter(page?: import("puppeteer").Page): Promise<void>;
14
- emulate(phone_name: string, page?: import("puppeteer").Page): Promise<void>;
15
- restartBrowser(): Promise<void>;
16
- clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer").Page): Promise<void>;
17
- closeLastPage(page?: import("puppeteer").Page): Promise<void>;
18
- microsoftLogin(button: string, email: string, password: string): Promise<void>;
19
- }
20
- declare const _default: FunctionHelper;
21
- export default _default;
@@ -1,185 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import log from "../../auxta/services/log.service";
11
- import puppeteer from "../../puppeteer/puppeteer";
12
- import { StatusOfStep } from "../../auxta/enums/status-of.step";
13
- import { StepStatus } from "../../AuxTA";
14
- import { ExtendDefaultPage } from "./extend-default-page";
15
- import { KnownDevices } from "puppeteer";
16
- export class FunctionHelper extends ExtendDefaultPage {
17
- log(keyword, name, status) {
18
- log.push(keyword, name, status);
19
- }
20
- suggest(name) {
21
- log.addSuggestion(name);
22
- }
23
- getEscapedText(text) {
24
- const splitedQuotes = text.replace(/'/g, `', "'", '`);
25
- return `concat('${splitedQuotes}', '')`;
26
- }
27
- clickByText(selector, text, dotOrText = '.', page = puppeteer.defaultPage, time = this.defaultTimeout, log_message = true) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const message = `I clicked on the '${text}' '${selector}'`;
30
- try {
31
- const [linkHandlers] = yield page.$x(`//${selector}[contains(${dotOrText},"${text}")]`);
32
- if (linkHandlers) {
33
- yield linkHandlers.click();
34
- log.push('Then', message, StatusOfStep.PASSED);
35
- }
36
- }
37
- catch (e) {
38
- if (log_message) {
39
- log.push('And', `${message}, but it didn't appear in ${time / 1000} seconds.`, StatusOfStep.FAILED);
40
- }
41
- throw new Error(message);
42
- }
43
- if (log_message) {
44
- log.push('And', message, StatusOfStep.PASSED);
45
- }
46
- });
47
- }
48
- clickByTextWithClass(class_selector, class_name, selector, text, dotOrText = '.', page = puppeteer.defaultPage) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const message = `I click on the '${text}' '${selector}'`;
51
- try {
52
- const [linkHandlers] = yield page.$x(`//${class_selector}[contains(@class,${this.getEscapedText(class_name)})]//${selector}[contains(${dotOrText},"${text}")]`);
53
- if (linkHandlers) {
54
- yield linkHandlers.click();
55
- log.push('Then', message, StatusOfStep.PASSED);
56
- return;
57
- }
58
- }
59
- catch (e) {
60
- }
61
- log.push('Then', message, StatusOfStep.FAILED);
62
- throw new Error(message);
63
- });
64
- }
65
- waitForSelectorWithText(selector, text, dotOrText = '.', page = puppeteer.defaultPage) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const message = `I check for '${text}' on the current page`;
68
- try {
69
- yield page.waitForSelector(selector, {
70
- timeout: this.defaultTimeout
71
- });
72
- const linkHandlers = yield page.$x(`//${selector}[contains(${dotOrText},"${text}")]`);
73
- if (linkHandlers.length > 0) {
74
- log.push('And', message, StatusOfStep.PASSED);
75
- return true;
76
- }
77
- }
78
- catch (e) {
79
- }
80
- log.push('And', message, StatusOfStep.FAILED);
81
- throw new Error(message);
82
- });
83
- }
84
- timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- yield page.waitForTimeout(timeout);
87
- });
88
- }
89
- waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer.defaultPage, log_message = true) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- const message = `I checked for the '${selector}' element to be ${option}`;
92
- try {
93
- yield page.waitForSelector(selector, {
94
- [option]: true,
95
- timeout: time
96
- });
97
- }
98
- catch (e) {
99
- if (log_message) {
100
- log.push('And', `${message}, but it didn't appear in ${time / 1000} seconds.`, StatusOfStep.FAILED);
101
- }
102
- throw new Error(message);
103
- }
104
- if (log_message) {
105
- log.push('And', message, StatusOfStep.PASSED);
106
- }
107
- });
108
- }
109
- urlContains(selector, page = puppeteer.defaultPage) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const url = page.url();
112
- let message = `I am on the ${selector} page`;
113
- if (!url.includes(selector)) {
114
- log.push('And', message, StatusOfStep.FAILED);
115
- throw new Error(message);
116
- }
117
- log.push('And', message, StatusOfStep.PASSED);
118
- });
119
- }
120
- pressEnter(page = puppeteer.defaultPage) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- yield page.keyboard.press('Enter');
123
- });
124
- }
125
- emulate(phone_name, page = puppeteer.defaultPage) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- const phone = KnownDevices[phone_name];
128
- yield page.emulate(phone);
129
- });
130
- }
131
- restartBrowser() {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- yield puppeteer.close();
134
- yield puppeteer.startBrowser();
135
- });
136
- }
137
- clickAndWaitForPageToBeCreated(selector, page = puppeteer.defaultPage) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const nav = new Promise(res => page.browser().on('targetcreated', res));
140
- yield page.click(selector);
141
- yield nav;
142
- });
143
- }
144
- closeLastPage(page = puppeteer.defaultPage) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- const pages = yield page.browser().pages();
147
- yield pages[pages.length - 1].close();
148
- });
149
- }
150
- microsoftLogin(button, email, password) {
151
- var _a;
152
- return __awaiter(this, void 0, void 0, function* () {
153
- const email_input = 'input[type="email"]';
154
- const password_input = 'input[type="password"]';
155
- const next_button = 'input[value="Next"]';
156
- const sign_in_button = 'input[value="Sign in"]';
157
- const no_button = 'input.ext-secondary';
158
- yield this.clickAndWaitForPageToBeCreated(button);
159
- const pages = yield puppeteer.defaultPage.browser().pages();
160
- const loginPage = pages[pages.length - 1];
161
- yield this.extend_page_functions(loginPage);
162
- yield loginPage.waitForNetworkIdle();
163
- yield this.waitForSelector('visible', next_button, 60000, loginPage);
164
- yield loginPage.type(email_input, email);
165
- yield loginPage.keyboard.press('Enter');
166
- yield loginPage.waitForNetworkIdle();
167
- yield this.waitForSelector('visible', sign_in_button, 60000, loginPage);
168
- yield this.waitForSelector('visible', password_input, 6000, loginPage);
169
- try {
170
- (_a = (yield loginPage.$(password_input))) === null || _a === void 0 ? void 0 : _a.type(password);
171
- yield this.log('Then', `I type password into the ${password_input}`, StepStatus.PASSED);
172
- }
173
- catch (e) {
174
- yield this.log('Then', `I type password into the ${password_input}`, StepStatus.FAILED);
175
- throw new Error(`I type password into the ${password_input}`);
176
- }
177
- yield this.timeout(3000);
178
- yield loginPage.keyboard.press('Enter');
179
- yield this.waitForSelector('visible', no_button, 60000, loginPage);
180
- yield loginPage.keyboard.press('Enter');
181
- yield loginPage.waitForNetworkIdle();
182
- });
183
- }
184
- }
185
- export default new FunctionHelper();
@@ -1,6 +0,0 @@
1
- export declare class ExtendDefaultPage {
2
- readonly defaultTimeout: number;
3
- extend_page_functions(page: any, time?: number): Promise<any>;
4
- }
5
- declare const _default: ExtendDefaultPage;
6
- export default _default;
@@ -1,81 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import log from "../../auxta/services/log.service";
11
- import { StatusOfStep } from "../../auxta/enums/status-of.step";
12
- import { config } from "../../auxta/configs/config";
13
- export class ExtendDefaultPage {
14
- constructor() {
15
- this.defaultTimeout = config.timeout;
16
- }
17
- extend_page_functions(page, time = this.defaultTimeout) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const { goto: original_goto, click: original_click, type: original_type, waitForNetworkIdle: original_waitForNetworkIdle } = page;
20
- page.goto = function goto(url, options) {
21
- log.push('Then', `I go to the '${url}' page`, StatusOfStep.PASSED);
22
- return original_goto.apply(page, arguments);
23
- };
24
- page.click = function click(selector, options) {
25
- return __awaiter(this, arguments, void 0, function* () {
26
- try {
27
- yield page.waitForSelector(selector, {
28
- timeout: time
29
- });
30
- let elementName = yield page.$eval(selector, (e) => e.textContent);
31
- if (!elementName || elementName === ' ')
32
- elementName = selector;
33
- yield original_click.apply(page, arguments);
34
- log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
35
- }
36
- catch (e) {
37
- const msg = `I click on the '${selector}'`;
38
- log.push('Then', msg, StatusOfStep.FAILED);
39
- throw new Error(msg);
40
- }
41
- });
42
- };
43
- page.waitForNetworkIdle = function waitForNetworkIdle(selector, option) {
44
- return __awaiter(this, arguments, void 0, function* () {
45
- let message = 'I wait for the page to load';
46
- let result;
47
- try {
48
- result = yield original_waitForNetworkIdle.apply(page, arguments);
49
- log.push('Then', message, StatusOfStep.PASSED);
50
- }
51
- catch (e) {
52
- log.push('Then', message, StatusOfStep.FAILED);
53
- throw new Error(message);
54
- }
55
- return result;
56
- });
57
- };
58
- page.type = function type(field, value) {
59
- return __awaiter(this, arguments, void 0, function* () {
60
- try {
61
- yield page.waitForSelector(field, {
62
- timeout: time
63
- });
64
- yield original_type.apply(page, arguments);
65
- let elementName = yield page.$eval(field, (e) => e.textContent);
66
- if (!elementName || elementName === ' ')
67
- elementName = field;
68
- log.push('Then', `I type '${value}' into the '${elementName}' field`, StatusOfStep.PASSED);
69
- }
70
- catch (e) {
71
- const msg = `I type '${value}' into the '${field}' field`;
72
- log.push('Then', msg, StatusOfStep.FAILED);
73
- throw new Error(msg);
74
- }
75
- });
76
- };
77
- return page;
78
- });
79
- }
80
- }
81
- export default new ExtendDefaultPage();