@auxcode/auxta 1.3.52-beta.0 → 1.3.52-beta.1
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/build/esm/AuxTA.d.ts +62 -0
- package/build/esm/AuxTA.js +125 -0
- package/build/esm/auxta/configs/config.d.ts +57 -0
- package/build/esm/auxta/configs/config.js +64 -0
- package/build/esm/auxta/enums/status-of.step.d.ts +7 -0
- package/build/esm/auxta/enums/status-of.step.js +8 -0
- package/build/esm/auxta/helpers/response.helper.d.ts +10 -0
- package/build/esm/auxta/helpers/response.helper.js +11 -0
- package/build/esm/auxta/helpers/start.helper.d.ts +1 -0
- package/build/esm/auxta/helpers/start.helper.js +24 -0
- package/build/esm/auxta/hooks/report.hook.d.ts +14 -0
- package/build/esm/auxta/hooks/report.hook.js +59 -0
- package/build/esm/auxta/models/upload.model.d.ts +35 -0
- package/build/esm/auxta/models/upload.model.js +78 -0
- package/build/esm/auxta/services/log.service.d.ts +31 -0
- package/build/esm/auxta/services/log.service.js +57 -0
- package/build/esm/auxta/services/report.service.d.ts +31 -0
- package/build/esm/auxta/services/report.service.js +168 -0
- package/build/esm/auxta/services/runtime.service.d.ts +16 -0
- package/build/esm/auxta/services/runtime.service.js +37 -0
- package/build/esm/auxta/utilities/runtime.helper.d.ts +15 -0
- package/build/esm/auxta/utilities/runtime.helper.js +15 -0
- package/build/esm/auxta/utilities/screenshot.helper.d.ts +4 -0
- package/build/esm/auxta/utilities/screenshot.helper.js +51 -0
- package/build/esm/auxta/utilities/start-suite.helper.d.ts +17 -0
- package/build/esm/auxta/utilities/start-suite.helper.js +26 -0
- package/build/esm/macros/helpers/Aux2faAuth.d.ts +7 -0
- package/build/esm/macros/helpers/Aux2faAuth.js +25 -0
- package/build/esm/macros/helpers/AuxGoogleAuth.d.ts +22 -0
- package/build/esm/macros/helpers/AuxGoogleAuth.js +190 -0
- package/build/esm/macros/helpers/code.helper.d.ts +23 -0
- package/build/esm/macros/helpers/code.helper.js +218 -0
- package/build/esm/macros/helpers/emailHelper.d.ts +19 -0
- package/build/esm/macros/helpers/emailHelper.js +170 -0
- package/build/esm/macros/helpers/extend-default-page.d.ts +6 -0
- package/build/esm/macros/helpers/extend-default-page.js +82 -0
- package/build/esm/puppeteer/puppeteer.d.ts +25 -0
- package/build/esm/puppeteer/puppeteer.js +203 -0
- package/build/tsconfig-cjs.tsbuildinfo +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +5 -5
- /package/build/{AuxTA.d.ts → cjs/AuxTA.d.ts} +0 -0
- /package/build/{AuxTA.js → cjs/AuxTA.js} +0 -0
- /package/build/{auxta → cjs/auxta}/configs/config.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/configs/config.js +0 -0
- /package/build/{auxta → cjs/auxta}/enums/status-of.step.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/enums/status-of.step.js +0 -0
- /package/build/{auxta → cjs/auxta}/helpers/response.helper.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/helpers/response.helper.js +0 -0
- /package/build/{auxta → cjs/auxta}/helpers/start.helper.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/helpers/start.helper.js +0 -0
- /package/build/{auxta → cjs/auxta}/hooks/report.hook.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/hooks/report.hook.js +0 -0
- /package/build/{auxta → cjs/auxta}/models/upload.model.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/models/upload.model.js +0 -0
- /package/build/{auxta → cjs/auxta}/services/log.service.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/services/log.service.js +0 -0
- /package/build/{auxta → cjs/auxta}/services/report.service.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/services/report.service.js +0 -0
- /package/build/{auxta → cjs/auxta}/services/runtime.service.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/services/runtime.service.js +0 -0
- /package/build/{auxta → cjs/auxta}/utilities/runtime.helper.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/utilities/runtime.helper.js +0 -0
- /package/build/{auxta → cjs/auxta}/utilities/screenshot.helper.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/utilities/screenshot.helper.js +0 -0
- /package/build/{auxta → cjs/auxta}/utilities/start-suite.helper.d.ts +0 -0
- /package/build/{auxta → cjs/auxta}/utilities/start-suite.helper.js +0 -0
- /package/build/{macros → cjs/macros}/helpers/Aux2faAuth.d.ts +0 -0
- /package/build/{macros → cjs/macros}/helpers/Aux2faAuth.js +0 -0
- /package/build/{macros → cjs/macros}/helpers/AuxGoogleAuth.d.ts +0 -0
- /package/build/{macros → cjs/macros}/helpers/AuxGoogleAuth.js +0 -0
- /package/build/{macros → cjs/macros}/helpers/code.helper.d.ts +0 -0
- /package/build/{macros → cjs/macros}/helpers/code.helper.js +0 -0
- /package/build/{macros → cjs/macros}/helpers/emailHelper.d.ts +0 -0
- /package/build/{macros → cjs/macros}/helpers/emailHelper.js +0 -0
- /package/build/{macros → cjs/macros}/helpers/extend-default-page.d.ts +0 -0
- /package/build/{macros → cjs/macros}/helpers/extend-default-page.js +0 -0
- /package/build/{puppeteer → cjs/puppeteer}/puppeteer.d.ts +0 -0
- /package/build/{puppeteer → cjs/puppeteer}/puppeteer.js +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
import { captureScreenshotPage } from "../../auxta/utilities/screenshot.helper";
|
|
17
|
+
import { compareScreenshots } from "../../auxta/services/report.service";
|
|
18
|
+
export class FunctionHelper extends ExtendDefaultPage {
|
|
19
|
+
log(keyword, name, status, screenshot) {
|
|
20
|
+
log.push(keyword, name, status, screenshot);
|
|
21
|
+
}
|
|
22
|
+
screenshot(page = puppeteer.defaultPage) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const screenshotBuffer = yield captureScreenshotPage(page);
|
|
25
|
+
if (screenshotBuffer) {
|
|
26
|
+
return screenshotBuffer.toString('base64');
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
screenshotCompare(key, page = puppeteer.defaultPage) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (process.env.ENVIRONMENT !== 'LOCAL') {
|
|
33
|
+
const screenshotBuffer = yield captureScreenshotPage(page);
|
|
34
|
+
if (screenshotBuffer) {
|
|
35
|
+
const screenshot = screenshotBuffer.toString('base64');
|
|
36
|
+
yield compareScreenshots(key, screenshot);
|
|
37
|
+
log.push('Then', `I compare screenshots with key ${key}`, StatusOfStep.PASSED, screenshot, key);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
log.push('Then', `I compare screenshots with key ${key}`, StatusOfStep.PASSED, undefined, key);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
suggest(name) {
|
|
46
|
+
log.addSuggestion(name);
|
|
47
|
+
}
|
|
48
|
+
getEscapedText(text) {
|
|
49
|
+
const splitedQuotes = text.replace(/'/g, `', "'", '`);
|
|
50
|
+
return `concat('${splitedQuotes}', '')`;
|
|
51
|
+
}
|
|
52
|
+
clickByText(selector, text, dotOrText = '.', options = {}, page = puppeteer.defaultPage, time = this.defaultTimeout, log_message = true) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const message = `I clicked on the '${text}' '${selector}'`;
|
|
55
|
+
try {
|
|
56
|
+
const [linkHandlers] = yield page.$x(`//${selector}[contains(${dotOrText},"${text}")]`);
|
|
57
|
+
if (linkHandlers) {
|
|
58
|
+
yield linkHandlers.click(options);
|
|
59
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
if (log_message) {
|
|
64
|
+
log.push('And', `${message}, but it didn't appear in ${time / 1000} seconds.`, StatusOfStep.FAILED);
|
|
65
|
+
}
|
|
66
|
+
throw new Error(message);
|
|
67
|
+
}
|
|
68
|
+
if (log_message) {
|
|
69
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
clickByTextWithClass(class_selector, class_name, selector, text, dotOrText = '.', page = puppeteer.defaultPage) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const message = `I click on the '${text}' '${selector}'`;
|
|
76
|
+
try {
|
|
77
|
+
const [linkHandlers] = yield page.$x(`//${class_selector}[contains(@class,${this.getEscapedText(class_name)})]//${selector}[contains(${dotOrText},"${text}")]`);
|
|
78
|
+
if (linkHandlers) {
|
|
79
|
+
yield linkHandlers.click();
|
|
80
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
}
|
|
86
|
+
log.push('Then', message, StatusOfStep.FAILED);
|
|
87
|
+
throw new Error(message);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
waitForSelectorWithText(selector, text, dotOrText = '.', page = puppeteer.defaultPage) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const message = `I check for '${text}' on the current page`;
|
|
93
|
+
try {
|
|
94
|
+
yield page.waitForSelector(selector, {
|
|
95
|
+
timeout: this.defaultTimeout
|
|
96
|
+
});
|
|
97
|
+
const linkHandlers = yield page.$x(`//${selector}[contains(${dotOrText},"${text}")]`);
|
|
98
|
+
if (linkHandlers.length > 0) {
|
|
99
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
}
|
|
105
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
106
|
+
throw new Error(message);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
yield new Promise(r => setTimeout(r, timeout));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer.defaultPage, log_message = true) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const message = `I checked for the '${selector}' element to be ${option}`;
|
|
117
|
+
try {
|
|
118
|
+
yield page.waitForSelector(selector, {
|
|
119
|
+
[option]: true,
|
|
120
|
+
timeout: time
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
if (log_message) {
|
|
125
|
+
log.push('And', `${message}, but it didn't appear in ${time / 1000} seconds.`, StatusOfStep.FAILED);
|
|
126
|
+
}
|
|
127
|
+
throw new Error(message);
|
|
128
|
+
}
|
|
129
|
+
if (log_message) {
|
|
130
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
urlContains(selector, page = puppeteer.defaultPage) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const url = page.url();
|
|
137
|
+
let message = `I am on the ${selector} page`;
|
|
138
|
+
if (!url.includes(selector)) {
|
|
139
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
140
|
+
throw new Error(message);
|
|
141
|
+
}
|
|
142
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
pressEnter(page = puppeteer.defaultPage) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
yield page.keyboard.press('Enter');
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
emulate(phone_name, page = puppeteer.defaultPage) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const phone = KnownDevices[phone_name];
|
|
153
|
+
yield page.emulate(phone);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
restartBrowser() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
yield puppeteer.close();
|
|
159
|
+
yield puppeteer.startBrowser();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
clickAndWaitForPageToBeCreated(selector, page = puppeteer.defaultPage) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
const nav = new Promise(res => page.browser().on('targetcreated', res));
|
|
165
|
+
yield page.click(selector);
|
|
166
|
+
yield nav;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
closeLastPage(page = puppeteer.defaultPage) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const pages = yield page.browser().pages();
|
|
172
|
+
yield pages[pages.length - 1].close();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
microsoftLogin(button, email, password, page = puppeteer.defaultPage) {
|
|
176
|
+
var _a;
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const email_input = 'input[type="email"]';
|
|
179
|
+
const password_input = 'input[type="password"]';
|
|
180
|
+
const next_button = 'input[value="Next"]';
|
|
181
|
+
const sign_in_button = 'input[value="Sign in"]';
|
|
182
|
+
const no_button = 'input.ext-secondary';
|
|
183
|
+
yield this.clickAndWaitForPageToBeCreated(button, page);
|
|
184
|
+
const pages = yield page.browser().pages();
|
|
185
|
+
const loginPage = pages[pages.length - 1];
|
|
186
|
+
yield this.extend_page_functions(loginPage);
|
|
187
|
+
yield loginPage.waitForNetworkIdle();
|
|
188
|
+
yield this.waitForSelector('visible', next_button, 60000, loginPage);
|
|
189
|
+
yield loginPage.type(email_input, email, { delay: 0 });
|
|
190
|
+
yield loginPage.keyboard.press('Enter');
|
|
191
|
+
yield loginPage.waitForNetworkIdle();
|
|
192
|
+
let isWorkOrPersonalVisible = yield page.$('div.table');
|
|
193
|
+
if (!!isWorkOrPersonalVisible) {
|
|
194
|
+
yield (yield page.$$('div.table'))[0].click();
|
|
195
|
+
console.log('Then', 'I clicked Work or school account', StepStatus.PASSED);
|
|
196
|
+
yield page.waitForNetworkIdle();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
yield page.waitForNetworkIdle();
|
|
200
|
+
}
|
|
201
|
+
yield this.waitForSelector('visible', sign_in_button, 60000, loginPage);
|
|
202
|
+
yield this.waitForSelector('visible', password_input, 6000, loginPage);
|
|
203
|
+
try {
|
|
204
|
+
(_a = (yield loginPage.$(password_input))) === null || _a === void 0 ? void 0 : _a.type(password);
|
|
205
|
+
yield this.log('Then', `I type password into the ${password_input}`, StepStatus.PASSED);
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
yield this.log('Then', `I type password into the ${password_input}`, StepStatus.FAILED);
|
|
209
|
+
throw new Error(`I type password into the ${password_input}`);
|
|
210
|
+
}
|
|
211
|
+
yield this.timeout(3000);
|
|
212
|
+
yield loginPage.keyboard.press('Enter');
|
|
213
|
+
yield this.waitForSelector('visible', no_button, 60000, loginPage);
|
|
214
|
+
yield loginPage.keyboard.press('Enter');
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
export default new FunctionHelper();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { gmail_v1 } from "googleapis";
|
|
2
|
+
export declare class EmailHelper {
|
|
3
|
+
verifyEmail(from_name: string, from_email: string, subject: string, body: string, link?: boolean): Promise<{
|
|
4
|
+
id: string;
|
|
5
|
+
threadId: string;
|
|
6
|
+
link: string;
|
|
7
|
+
} | undefined>;
|
|
8
|
+
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
9
|
+
replyEmail(id: string, threadId: string, body: string): Promise<void>;
|
|
10
|
+
private static send;
|
|
11
|
+
private getHeader;
|
|
12
|
+
private getBody;
|
|
13
|
+
private getCurrentUserEmail;
|
|
14
|
+
private getUrl;
|
|
15
|
+
}
|
|
16
|
+
export interface gmailResponse extends gmail_v1.Gmail {
|
|
17
|
+
}
|
|
18
|
+
declare const _default: EmailHelper;
|
|
19
|
+
export default _default;
|
|
@@ -0,0 +1,170 @@
|
|
|
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 { AuxGoogleAuth } from "./AuxGoogleAuth";
|
|
12
|
+
import { StepStatus } from "../../AuxTA";
|
|
13
|
+
const base64 = require('js-base64');
|
|
14
|
+
const MailComposer = require('nodemailer/lib/mail-composer');
|
|
15
|
+
export class EmailHelper {
|
|
16
|
+
verifyEmail(from_name, from_email, subject, body, link = false) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
yield AuxGoogleAuth.setupHeadless();
|
|
19
|
+
let timeoutCount = 12000;
|
|
20
|
+
while (timeoutCount <= 60000) {
|
|
21
|
+
const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
|
|
22
|
+
userId: "me",
|
|
23
|
+
maxResults: 3
|
|
24
|
+
});
|
|
25
|
+
const messagesIds = res.data.messages;
|
|
26
|
+
if (!messagesIds || messagesIds.length === 0) {
|
|
27
|
+
throw new Error('No messagesIds found.');
|
|
28
|
+
}
|
|
29
|
+
for (const messageId of messagesIds) {
|
|
30
|
+
if (messageId.id) {
|
|
31
|
+
const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
|
|
32
|
+
userId: "me",
|
|
33
|
+
id: messageId.id.toString(),
|
|
34
|
+
format: 'FULL'
|
|
35
|
+
});
|
|
36
|
+
if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
|
|
37
|
+
const message_sender = this.getHeader('from', gmailResponse);
|
|
38
|
+
const message_subject = this.getHeader('subject', gmailResponse);
|
|
39
|
+
const message_body = this.getBody(subject, gmailResponse);
|
|
40
|
+
if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
|
|
41
|
+
message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().includes(body.toLocaleLowerCase())) {
|
|
42
|
+
log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.PASSED);
|
|
43
|
+
yield AuxGoogleAuth.gmailClient.users.messages.modify({
|
|
44
|
+
userId: "me",
|
|
45
|
+
id: gmailResponse.data.id,
|
|
46
|
+
requestBody: {
|
|
47
|
+
'addLabelIds': [],
|
|
48
|
+
'removeLabelIds': ['UNREAD']
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (link) {
|
|
52
|
+
const html_link = yield this.getUrl(message_body);
|
|
53
|
+
return {
|
|
54
|
+
id: gmailResponse.data.id,
|
|
55
|
+
threadId: gmailResponse.data.threadId,
|
|
56
|
+
link: html_link
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: '' };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
yield new Promise(r => setTimeout(r, timeoutCount));
|
|
66
|
+
timeoutCount += 12000;
|
|
67
|
+
}
|
|
68
|
+
yield log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
sendEmail(to, subject, body) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
yield AuxGoogleAuth.setupHeadless();
|
|
74
|
+
const options = {
|
|
75
|
+
to: to,
|
|
76
|
+
from: this.getCurrentUserEmail(),
|
|
77
|
+
subject: subject,
|
|
78
|
+
html: body
|
|
79
|
+
};
|
|
80
|
+
yield EmailHelper.send(options);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
replyEmail(id, threadId, body) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield AuxGoogleAuth.setupHeadless();
|
|
86
|
+
const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
|
|
87
|
+
userId: "me",
|
|
88
|
+
id: id,
|
|
89
|
+
format: 'FULL'
|
|
90
|
+
});
|
|
91
|
+
if (gmailResponse.data.payload) {
|
|
92
|
+
const message_subject = this.getHeader('subject', gmailResponse);
|
|
93
|
+
const message_messageID = this.getHeader('Message-ID', gmailResponse);
|
|
94
|
+
const reply_to = this.getHeader('reply-to', gmailResponse);
|
|
95
|
+
const options = {
|
|
96
|
+
to: reply_to,
|
|
97
|
+
from: this.getCurrentUserEmail(),
|
|
98
|
+
subject: `Re: ${message_subject}`,
|
|
99
|
+
references: message_messageID,
|
|
100
|
+
inReplyTo: [message_messageID],
|
|
101
|
+
html: body
|
|
102
|
+
};
|
|
103
|
+
yield EmailHelper.send(options, threadId);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
static send(options, threadId) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const mailComposer = new MailComposer(options);
|
|
110
|
+
const message = yield mailComposer.compile().build();
|
|
111
|
+
const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
112
|
+
yield AuxGoogleAuth.gmailClient.users.messages.send({
|
|
113
|
+
userId: "me",
|
|
114
|
+
requestBody: {
|
|
115
|
+
threadId: threadId,
|
|
116
|
+
raw: encodeMessage
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getHeader(value, headers) {
|
|
122
|
+
for (const header of headers.data.payload.headers) {
|
|
123
|
+
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
124
|
+
return header.value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
getBody(subject, gmailResponse) {
|
|
129
|
+
try {
|
|
130
|
+
const body = gmailResponse.data.payload.parts[0].body.data;
|
|
131
|
+
if (body) {
|
|
132
|
+
return base64.decode(body);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
console.log(e);
|
|
140
|
+
throw new Error(`Email with subject: ${subject} body ${gmailResponse.data.payload.parts[0].body.data} is empty`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
getCurrentUserEmail() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
yield AuxGoogleAuth.setupHeadless();
|
|
146
|
+
const profile = yield AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
|
|
147
|
+
return profile.data.emailAddress;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
getUrl(body) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const links = [];
|
|
153
|
+
const split = body.split('\r\n\r\n');
|
|
154
|
+
for (const splitElement of split) {
|
|
155
|
+
if (splitElement.toString().startsWith('https')) {
|
|
156
|
+
links.push(splitElement);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (links.length > 1) {
|
|
160
|
+
return links.sort(function (a, b) {
|
|
161
|
+
return b.length - a.length;
|
|
162
|
+
})[0];
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return links[0];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export default new EmailHelper();
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
this.defaultTimeout = config.timeout;
|
|
20
|
+
const { goto: original_goto, click: original_click, type: original_type, waitForNetworkIdle: original_waitForNetworkIdle } = page;
|
|
21
|
+
page.goto = function goto(url, options) {
|
|
22
|
+
log.push('Then', `I go to the '${url}' page`, StatusOfStep.PASSED);
|
|
23
|
+
return original_goto.apply(page, arguments);
|
|
24
|
+
};
|
|
25
|
+
page.click = function click(selector, options) {
|
|
26
|
+
return __awaiter(this, arguments, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
yield page.waitForSelector(selector, {
|
|
29
|
+
timeout: time
|
|
30
|
+
});
|
|
31
|
+
let elementName = yield page.$eval(selector, (e) => e.textContent);
|
|
32
|
+
if (!elementName || elementName === ' ')
|
|
33
|
+
elementName = selector;
|
|
34
|
+
yield original_click.apply(page, arguments);
|
|
35
|
+
log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
const msg = `I click on the '${selector}'`;
|
|
39
|
+
log.push('Then', msg, StatusOfStep.FAILED);
|
|
40
|
+
throw new Error(msg);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
page.waitForNetworkIdle = function waitForNetworkIdle(selector, option) {
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* () {
|
|
46
|
+
let message = 'I wait for the page to load';
|
|
47
|
+
let result;
|
|
48
|
+
try {
|
|
49
|
+
result = yield original_waitForNetworkIdle.apply(page, arguments);
|
|
50
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
log.push('Then', message, StatusOfStep.FAILED);
|
|
54
|
+
throw new Error(message);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
page.type = function type(field, value) {
|
|
60
|
+
return __awaiter(this, arguments, void 0, function* () {
|
|
61
|
+
try {
|
|
62
|
+
yield page.waitForSelector(field, {
|
|
63
|
+
timeout: time
|
|
64
|
+
});
|
|
65
|
+
yield original_type.apply(page, arguments);
|
|
66
|
+
let elementName = yield page.$eval(field, (e) => e.textContent);
|
|
67
|
+
if (!elementName || elementName === ' ')
|
|
68
|
+
elementName = field;
|
|
69
|
+
log.push('Then', `I type '${value}' into the '${elementName}' field`, StatusOfStep.PASSED);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
const msg = `I type '${value}' into the '${field}' field`;
|
|
73
|
+
log.push('Then', msg, StatusOfStep.FAILED);
|
|
74
|
+
throw new Error(msg);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
return page;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export default new ExtendDefaultPage();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UploadModel } from "../auxta/models/upload.model";
|
|
2
|
+
import puppeteer = require("puppeteer");
|
|
3
|
+
export declare class Puppeteer {
|
|
4
|
+
defaultPage: puppeteer.Page;
|
|
5
|
+
private browser;
|
|
6
|
+
startBrowser(): Promise<void>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
run(event: any, callback: any, featureName?: string, scenarioName?: string, uploadModel?: UploadModel): Promise<{
|
|
9
|
+
nextSuites?: undefined;
|
|
10
|
+
reportId?: undefined;
|
|
11
|
+
currentSuite?: undefined;
|
|
12
|
+
retries?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
nextSuites: string[];
|
|
15
|
+
reportId: string | undefined;
|
|
16
|
+
currentSuite: string | undefined;
|
|
17
|
+
retries: string;
|
|
18
|
+
} | {
|
|
19
|
+
statusCode: number;
|
|
20
|
+
} | undefined>;
|
|
21
|
+
runRPA(event: any, callback: any, uploadModel?: UploadModel, close?: boolean): Promise<any>;
|
|
22
|
+
private static setupHeader;
|
|
23
|
+
}
|
|
24
|
+
declare const _default: Puppeteer;
|
|
25
|
+
export default _default;
|