@auxcode/auxta 1.3.24-beta.6 → 1.3.24
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/README.md +93 -93
- package/build/cjs/AuxTA.d.ts +61 -60
- package/build/cjs/AuxTA.js +152 -150
- package/build/cjs/auxta/configs/config.d.ts +54 -54
- package/build/cjs/auxta/configs/config.js +65 -65
- package/build/cjs/auxta/enums/status-of.step.d.ts +7 -7
- package/build/cjs/auxta/enums/status-of.step.js +11 -11
- package/build/cjs/auxta/helpers/response.helper.d.ts +10 -10
- package/build/cjs/auxta/helpers/response.helper.js +15 -15
- package/build/cjs/auxta/helpers/start.helper.d.ts +1 -1
- package/build/cjs/auxta/helpers/start.helper.js +26 -26
- package/build/cjs/auxta/hooks/report.hook.d.ts +14 -14
- package/build/cjs/auxta/hooks/report.hook.js +66 -66
- package/build/cjs/auxta/models/upload.model.d.ts +32 -32
- package/build/cjs/auxta/models/upload.model.js +75 -75
- package/build/cjs/auxta/services/log.service.d.ts +26 -26
- package/build/cjs/auxta/services/log.service.js +47 -47
- package/build/cjs/auxta/services/report.service.d.ts +36 -36
- package/build/cjs/auxta/services/report.service.js +164 -164
- package/build/cjs/auxta/services/runtime.service.d.ts +16 -16
- package/build/cjs/auxta/services/runtime.service.js +41 -41
- package/build/cjs/auxta/utilities/runtime.helper.d.ts +15 -15
- package/build/cjs/auxta/utilities/runtime.helper.js +19 -19
- package/build/cjs/auxta/utilities/screenshot.helper.d.ts +2 -2
- package/build/cjs/auxta/utilities/screenshot.helper.js +36 -36
- package/build/cjs/auxta/utilities/start-suite.helper.d.ts +17 -17
- package/build/cjs/auxta/utilities/start-suite.helper.js +31 -31
- package/build/cjs/macros/helpers/Aux2faAuth.d.ts +7 -7
- package/build/cjs/macros/helpers/Aux2faAuth.js +29 -29
- package/build/cjs/macros/helpers/AuxGoogleAuth.d.ts +17 -13
- package/build/cjs/macros/helpers/AuxGoogleAuth.js +104 -104
- package/build/cjs/macros/helpers/code.helper.d.ts +21 -27
- package/build/cjs/macros/helpers/code.helper.js +201 -259
- package/build/cjs/macros/helpers/emailHelper.d.ts +23 -0
- package/build/cjs/macros/helpers/emailHelper.js +167 -0
- package/build/cjs/macros/helpers/extend-default-page.d.ts +6 -6
- package/build/cjs/macros/helpers/extend-default-page.js +89 -89
- package/build/cjs/puppeteer/puppeteer.d.ts +25 -25
- package/build/cjs/puppeteer/puppeteer.js +196 -197
- package/build/esm/AuxTA.d.ts +61 -60
- package/build/esm/AuxTA.js +123 -121
- package/build/esm/auxta/configs/config.d.ts +54 -54
- package/build/esm/auxta/configs/config.js +60 -60
- package/build/esm/auxta/enums/status-of.step.d.ts +7 -7
- package/build/esm/auxta/enums/status-of.step.js +8 -8
- package/build/esm/auxta/helpers/response.helper.d.ts +10 -10
- package/build/esm/auxta/helpers/response.helper.js +11 -11
- package/build/esm/auxta/helpers/start.helper.d.ts +1 -1
- package/build/esm/auxta/helpers/start.helper.js +24 -24
- package/build/esm/auxta/hooks/report.hook.d.ts +14 -14
- package/build/esm/auxta/hooks/report.hook.js +58 -58
- package/build/esm/auxta/models/upload.model.d.ts +32 -32
- package/build/esm/auxta/models/upload.model.js +71 -71
- package/build/esm/auxta/services/log.service.d.ts +26 -26
- package/build/esm/auxta/services/log.service.js +43 -43
- package/build/esm/auxta/services/report.service.d.ts +36 -36
- package/build/esm/auxta/services/report.service.js +150 -150
- package/build/esm/auxta/services/runtime.service.d.ts +16 -16
- package/build/esm/auxta/services/runtime.service.js +37 -37
- package/build/esm/auxta/utilities/runtime.helper.d.ts +15 -15
- package/build/esm/auxta/utilities/runtime.helper.js +15 -15
- package/build/esm/auxta/utilities/screenshot.helper.d.ts +2 -2
- package/build/esm/auxta/utilities/screenshot.helper.js +29 -29
- package/build/esm/auxta/utilities/start-suite.helper.d.ts +17 -17
- package/build/esm/auxta/utilities/start-suite.helper.js +26 -26
- package/build/esm/macros/helpers/Aux2faAuth.d.ts +7 -7
- package/build/esm/macros/helpers/Aux2faAuth.js +25 -25
- package/build/esm/macros/helpers/AuxGoogleAuth.d.ts +17 -13
- package/build/esm/macros/helpers/AuxGoogleAuth.js +100 -100
- package/build/esm/macros/helpers/code.helper.d.ts +21 -27
- package/build/esm/macros/helpers/code.helper.js +194 -252
- package/build/esm/macros/helpers/emailHelper.d.ts +23 -0
- package/build/esm/macros/helpers/emailHelper.js +160 -0
- package/build/esm/macros/helpers/extend-default-page.d.ts +6 -6
- package/build/esm/macros/helpers/extend-default-page.js +82 -82
- package/build/esm/puppeteer/puppeteer.d.ts +25 -25
- package/build/esm/puppeteer/puppeteer.js +188 -189
- package/build/tsconfig-cjs.tsbuildinfo +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -32
|
@@ -1,252 +1,194 @@
|
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
yield this.
|
|
164
|
-
yield loginPage.
|
|
165
|
-
yield
|
|
166
|
-
yield loginPage.
|
|
167
|
-
yield
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
yield
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
yield this.
|
|
189
|
-
yield loginPage.keyboard.press('Enter');
|
|
190
|
-
yield
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
clickInMail(from_name, from_email, subject, body) {
|
|
196
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
-
yield AuxGoogleAuth.setup();
|
|
198
|
-
const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
|
|
199
|
-
userId: "me",
|
|
200
|
-
maxResults: 3
|
|
201
|
-
});
|
|
202
|
-
const messagesIds = res.data.messages;
|
|
203
|
-
if (!messagesIds || messagesIds.length === 0) {
|
|
204
|
-
throw new Error('No messagesIds found.');
|
|
205
|
-
}
|
|
206
|
-
let timeoutCount = 12000;
|
|
207
|
-
yield this.timeout(12000);
|
|
208
|
-
while (timeoutCount <= 60000) {
|
|
209
|
-
for (const messageId of messagesIds) {
|
|
210
|
-
if (messageId.id) {
|
|
211
|
-
const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
|
|
212
|
-
userId: "me",
|
|
213
|
-
id: messageId.id.toString(),
|
|
214
|
-
format: 'FULL'
|
|
215
|
-
});
|
|
216
|
-
if (gmailResponse.data.payload) {
|
|
217
|
-
const message_sender = this.getHeader('from', gmailResponse.data.payload.headers);
|
|
218
|
-
const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
|
|
219
|
-
const message_body = this.getBody(from_name, from_email, subject, gmailResponse);
|
|
220
|
-
if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
|
|
221
|
-
message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
|
|
222
|
-
yield this.log('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.PASSED);
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
yield this.timeout(12000);
|
|
230
|
-
timeoutCount += 12000;
|
|
231
|
-
}
|
|
232
|
-
yield this.log('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
getHeader(value, headers) {
|
|
236
|
-
for (const header of headers) {
|
|
237
|
-
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
238
|
-
return header.value.toLocaleLowerCase();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
getBody(from_name, from_email, subject, gmailResponse) {
|
|
243
|
-
const body = gmailResponse.data.payload.parts[0].body.data;
|
|
244
|
-
if (body) {
|
|
245
|
-
return atob(body).toLocaleLowerCase();
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
export default new FunctionHelper();
|
|
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 = '.', options = {}, 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(options);
|
|
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 new Promise(r => setTimeout(r, 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, { delay: 0 });
|
|
165
|
+
yield loginPage.keyboard.press('Enter');
|
|
166
|
+
yield loginPage.waitForNetworkIdle();
|
|
167
|
+
let isWorkOrPersonalVisible = yield puppeteer.defaultPage.$('div.table');
|
|
168
|
+
if (!!isWorkOrPersonalVisible) {
|
|
169
|
+
yield (yield puppeteer.defaultPage.$$('div.table'))[0].click();
|
|
170
|
+
console.log('Then', 'I clicked Work or school account', StepStatus.PASSED);
|
|
171
|
+
yield puppeteer.defaultPage.waitForNetworkIdle();
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
yield puppeteer.defaultPage.waitForNetworkIdle();
|
|
175
|
+
}
|
|
176
|
+
yield this.waitForSelector('visible', sign_in_button, 60000, loginPage);
|
|
177
|
+
yield this.waitForSelector('visible', password_input, 6000, loginPage);
|
|
178
|
+
try {
|
|
179
|
+
(_a = (yield loginPage.$(password_input))) === null || _a === void 0 ? void 0 : _a.type(password);
|
|
180
|
+
yield this.log('Then', `I type password into the ${password_input}`, StepStatus.PASSED);
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
yield this.log('Then', `I type password into the ${password_input}`, StepStatus.FAILED);
|
|
184
|
+
throw new Error(`I type password into the ${password_input}`);
|
|
185
|
+
}
|
|
186
|
+
yield this.timeout(3000);
|
|
187
|
+
yield loginPage.keyboard.press('Enter');
|
|
188
|
+
yield this.waitForSelector('visible', no_button, 60000, loginPage);
|
|
189
|
+
yield loginPage.keyboard.press('Enter');
|
|
190
|
+
yield loginPage.waitForNetworkIdle();
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export default new FunctionHelper();
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
} | {
|
|
8
|
+
id: string;
|
|
9
|
+
threadId: string;
|
|
10
|
+
link: undefined;
|
|
11
|
+
} | undefined>;
|
|
12
|
+
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
13
|
+
replyEmail(id: string, threadId: string, body: string): Promise<void>;
|
|
14
|
+
private static send;
|
|
15
|
+
private getHeader;
|
|
16
|
+
private getBody;
|
|
17
|
+
private getCurrentUserEmail;
|
|
18
|
+
private getUrl;
|
|
19
|
+
}
|
|
20
|
+
export interface gmailResponse extends gmail_v1.Gmail {
|
|
21
|
+
}
|
|
22
|
+
declare const _default: EmailHelper;
|
|
23
|
+
export default _default;
|
|
@@ -0,0 +1,160 @@
|
|
|
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 { atob } from "buffer";
|
|
13
|
+
import { StepStatus } from "../../AuxTA";
|
|
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.setup();
|
|
19
|
+
const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
|
|
20
|
+
userId: "me",
|
|
21
|
+
maxResults: 3
|
|
22
|
+
});
|
|
23
|
+
const messagesIds = res.data.messages;
|
|
24
|
+
if (!messagesIds || messagesIds.length === 0) {
|
|
25
|
+
throw new Error('No messagesIds found.');
|
|
26
|
+
}
|
|
27
|
+
let timeoutCount = 12000;
|
|
28
|
+
while (timeoutCount <= 60000) {
|
|
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 { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: html_link };
|
|
54
|
+
}
|
|
55
|
+
return { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: undefined };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
yield new Promise(r => setTimeout(r, timeoutCount));
|
|
62
|
+
timeoutCount += 12000;
|
|
63
|
+
}
|
|
64
|
+
yield log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
sendEmail(to, subject, body) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
yield AuxGoogleAuth.setup();
|
|
70
|
+
const options = {
|
|
71
|
+
to: to,
|
|
72
|
+
from: this.getCurrentUserEmail(),
|
|
73
|
+
subject: subject,
|
|
74
|
+
html: body
|
|
75
|
+
};
|
|
76
|
+
yield EmailHelper.send(options);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
replyEmail(id, threadId, body) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
yield AuxGoogleAuth.setup();
|
|
82
|
+
const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
|
|
83
|
+
userId: "me",
|
|
84
|
+
id: id,
|
|
85
|
+
format: 'FULL'
|
|
86
|
+
});
|
|
87
|
+
if (gmailResponse.data.payload) {
|
|
88
|
+
const message_subject = this.getHeader('subject', gmailResponse);
|
|
89
|
+
const message_messageID = this.getHeader('Message-ID', gmailResponse);
|
|
90
|
+
const reply_to = this.getHeader('reply-to', gmailResponse);
|
|
91
|
+
const options = {
|
|
92
|
+
to: reply_to,
|
|
93
|
+
from: this.getCurrentUserEmail(),
|
|
94
|
+
subject: `Re: ${message_subject}`,
|
|
95
|
+
references: message_messageID,
|
|
96
|
+
inReplyTo: [message_messageID],
|
|
97
|
+
html: body
|
|
98
|
+
};
|
|
99
|
+
yield EmailHelper.send(options, threadId);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static send(options, threadId) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const mailComposer = new MailComposer(options);
|
|
106
|
+
const message = yield mailComposer.compile().build();
|
|
107
|
+
const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
108
|
+
yield AuxGoogleAuth.gmailClient.users.messages.send({
|
|
109
|
+
userId: "me",
|
|
110
|
+
requestBody: {
|
|
111
|
+
threadId: threadId,
|
|
112
|
+
raw: encodeMessage
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getHeader(value, headers) {
|
|
118
|
+
for (const header of headers.data.payload.headers) {
|
|
119
|
+
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
120
|
+
return header.value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getBody(subject, gmailResponse) {
|
|
125
|
+
const body = gmailResponse.data.payload.parts[0].body.data;
|
|
126
|
+
if (body) {
|
|
127
|
+
return atob(body);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw new Error(`Email with subject: ${subject} body is empty`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
getCurrentUserEmail() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
yield AuxGoogleAuth.setup();
|
|
136
|
+
const profile = yield AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
|
|
137
|
+
return profile.data.emailAddress;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
getUrl(body) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const links = [];
|
|
143
|
+
const split = body.split('\r\n');
|
|
144
|
+
for (const splitElement of split) {
|
|
145
|
+
if (splitElement.toString().startsWith('https')) {
|
|
146
|
+
links.push(splitElement);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (links.length > 1) {
|
|
150
|
+
return links.sort(function (a, b) {
|
|
151
|
+
return b.length - a.length;
|
|
152
|
+
})[0];
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return links[0];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export default new EmailHelper();
|