@auxcode/auxta 1.3.66 → 1.3.68

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.
@@ -16,24 +16,31 @@ exports.captureScreenshotPage = exports.captureScreenshot = void 0;
16
16
  const puppeteer_1 = __importDefault(require("../../puppeteer/puppeteer"));
17
17
  const log_service_1 = __importDefault(require("../services/log.service"));
18
18
  const status_of_step_1 = __importDefault(require("../enums/status-of.step"));
19
+ const RETRY_NUMBERS = 10;
19
20
  function captureScreenshot() {
20
21
  return __awaiter(this, void 0, void 0, function* () {
21
- try {
22
- const pages = yield puppeteer_1.default.defaultPage.browser().pages();
23
- if (!pages.length)
24
- return undefined;
25
- const lastPage = pages[pages.length - 1] || puppeteer_1.default.defaultPage;
26
- const screenshotBuffer = yield lastPage.screenshot({
27
- fullPage: true,
28
- captureBeyondViewport: false,
29
- encoding: 'binary'
30
- });
31
- if (Buffer.isBuffer(screenshotBuffer))
32
- return screenshotBuffer;
33
- }
34
- catch (e) {
35
- log_service_1.default.push('When', e.toString(), status_of_step_1.default.FAILED);
36
- return undefined;
22
+ let count = 0;
23
+ while (count <= RETRY_NUMBERS) {
24
+ try {
25
+ const pages = yield puppeteer_1.default.defaultPage.browser().pages();
26
+ if (!pages.length)
27
+ return undefined;
28
+ const lastPage = pages[pages.length - 1] || puppeteer_1.default.defaultPage;
29
+ const screenshotBuffer = yield lastPage.screenshot({
30
+ fullPage: true,
31
+ captureBeyondViewport: false,
32
+ encoding: 'binary'
33
+ });
34
+ if (Buffer.isBuffer(screenshotBuffer))
35
+ return screenshotBuffer;
36
+ }
37
+ catch (e) {
38
+ if (count == RETRY_NUMBERS) {
39
+ log_service_1.default.push('When', e.toString(), status_of_step_1.default.FAILED);
40
+ return undefined;
41
+ }
42
+ count++;
43
+ }
37
44
  }
38
45
  return undefined;
39
46
  });
@@ -41,19 +48,26 @@ function captureScreenshot() {
41
48
  exports.captureScreenshot = captureScreenshot;
42
49
  function captureScreenshotPage(page) {
43
50
  return __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- const screenshotBuffer = yield page.screenshot({
46
- fullPage: true,
47
- captureBeyondViewport: false,
48
- encoding: 'binary'
49
- });
50
- if (Buffer.isBuffer(screenshotBuffer))
51
- return screenshotBuffer;
52
- }
53
- catch (e) {
54
- log_service_1.default.push('When', e.toString(), status_of_step_1.default.FAILED);
55
- return undefined;
51
+ let count = 0;
52
+ while (count <= RETRY_NUMBERS) {
53
+ try {
54
+ const screenshotBuffer = yield page.screenshot({
55
+ fullPage: true,
56
+ captureBeyondViewport: false,
57
+ encoding: 'binary'
58
+ });
59
+ if (Buffer.isBuffer(screenshotBuffer))
60
+ return screenshotBuffer;
61
+ }
62
+ catch (e) {
63
+ if (count == RETRY_NUMBERS) {
64
+ log_service_1.default.push('When', e.toString(), status_of_step_1.default.FAILED);
65
+ return undefined;
66
+ }
67
+ count++;
68
+ }
56
69
  }
70
+ return undefined;
57
71
  });
58
72
  }
59
73
  exports.captureScreenshotPage = captureScreenshotPage;
@@ -37,58 +37,57 @@ class EmailHelper {
37
37
  if (!messagesIds || messagesIds.length === 0) {
38
38
  throw new Error('No messagesIds found.');
39
39
  }
40
- const runs = [];
41
- let count = 0;
40
+ log_service_1.default.push('Then', `Entering main for`, AuxTA_1.StepStatus.PASSED);
42
41
  for (const messageId of messagesIds) {
43
42
  if (messageId.id) {
44
- runs.push(yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
45
- userId: "me",
46
- id: messageId.id.toString(),
47
- format: 'FULL'
48
- }));
49
- count++;
50
- }
51
- }
52
- log_service_1.default.push('Then', `count ${count}`, AuxTA_1.StepStatus.PASSED);
53
- yield Promise.all(runs);
54
- log_service_1.default.push('Then', `Getting the full details of the emails`, AuxTA_1.StepStatus.PASSED);
55
- for (const gmailResponse of runs) {
56
- if (gmailResponse) {
57
- log_service_1.default.push('Then', `I check payload && id && threadId`, AuxTA_1.StepStatus.PASSED);
58
- if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
59
- const message_sender = this.getHeader('from', gmailResponse);
60
- log_service_1.default.push('Then', `I got message_sender`, AuxTA_1.StepStatus.PASSED);
61
- const message_subject = this.getHeader('subject', gmailResponse);
62
- log_service_1.default.push('Then', `I got message_body`, AuxTA_1.StepStatus.PASSED);
63
- const message_body = this.getBody(subject, gmailResponse);
64
- log_service_1.default.push('Then', `I got message_body`, AuxTA_1.StepStatus.PASSED);
65
- if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
66
- message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().includes(body.toLocaleLowerCase())) {
67
- log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
68
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.modify({
69
- userId: "me",
70
- id: gmailResponse.data.id,
71
- requestBody: {
72
- 'addLabelIds': [],
73
- 'removeLabelIds': ['UNREAD']
74
- }
75
- });
76
- log_service_1.default.push('Then', `I got modify email`, AuxTA_1.StepStatus.PASSED);
77
- if (link) {
78
- const html_link = yield this.getUrl(message_body);
79
- log_service_1.default.push('Then', `I get html lik`, AuxTA_1.StepStatus.PASSED);
80
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.delete({
43
+ let gmailResponse;
44
+ try {
45
+ gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
46
+ userId: "me",
47
+ id: messageId.id.toString(),
48
+ format: 'FULL'
49
+ });
50
+ }
51
+ catch (e) {
52
+ continue;
53
+ }
54
+ if (gmailResponse) {
55
+ log_service_1.default.push('Then', `I check payload && id && threadId`, AuxTA_1.StepStatus.PASSED);
56
+ if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
57
+ const message_sender = this.getHeader('from', gmailResponse);
58
+ log_service_1.default.push('Then', `I got message_sender`, AuxTA_1.StepStatus.PASSED);
59
+ const message_subject = this.getHeader('subject', gmailResponse);
60
+ log_service_1.default.push('Then', `I got message_body`, AuxTA_1.StepStatus.PASSED);
61
+ const message_body = this.getBody(subject, gmailResponse);
62
+ log_service_1.default.push('Then', `I got message_body`, AuxTA_1.StepStatus.PASSED);
63
+ if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
64
+ message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().includes(body.toLocaleLowerCase())) {
65
+ log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
66
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.modify({
81
67
  userId: "me",
82
68
  id: gmailResponse.data.id,
69
+ requestBody: {
70
+ 'addLabelIds': [],
71
+ 'removeLabelIds': ['UNREAD']
72
+ }
83
73
  });
84
- log_service_1.default.push('Then', `I deleted email`, AuxTA_1.StepStatus.PASSED);
85
- return {
86
- id: gmailResponse.data.id,
87
- threadId: gmailResponse.data.threadId,
88
- link: html_link
89
- };
74
+ log_service_1.default.push('Then', `I got modify email`, AuxTA_1.StepStatus.PASSED);
75
+ if (link) {
76
+ const html_link = yield this.getUrl(message_body);
77
+ log_service_1.default.push('Then', `I get html lik`, AuxTA_1.StepStatus.PASSED);
78
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.delete({
79
+ userId: "me",
80
+ id: gmailResponse.data.id,
81
+ });
82
+ log_service_1.default.push('Then', `I deleted email`, AuxTA_1.StepStatus.PASSED);
83
+ return {
84
+ id: gmailResponse.data.id,
85
+ threadId: gmailResponse.data.threadId,
86
+ link: html_link
87
+ };
88
+ }
89
+ return { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: '' };
90
90
  }
91
- return { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: '' };
92
91
  }
93
92
  }
94
93
  }
@@ -42,7 +42,6 @@ class Puppeteer {
42
42
  this.browser = yield puppeteer.default.launch({
43
43
  slowMo: process.env.slowMo ? Number(process.env.slowMo) : 0,
44
44
  executablePath: puppeteer.default.executablePath(),
45
- protocolTimeout: 50000,
46
45
  args,
47
46
  env,
48
47
  ignoreDefaultArgs: ["--enable-automation"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.66",
3
+ "version": "1.3.68",
4
4
  "description": "",
5
5
  "main": "./build/AuxTA.js",
6
6
  "types": "./build/AuxTA.d.ts",