correction on the exceptions

This commit is contained in:
Lei PAN
2023-08-11 13:04:12 +02:00
parent 7e0001523d
commit 26a7364d2b
2 changed files with 81 additions and 54 deletions
+6
View File
@@ -0,0 +1,6 @@
const DeviceExcludeMode = {
NINE: Symbol("NINE"),
THREE: Symbol("THREE"),
FOUR: Symbol("FOUR")
}
module.exports = DeviceExcludeMode
+75 -54
View File
@@ -8,7 +8,6 @@ const puppeteer = require('puppeteer');
const GeoCaptchaSolver = require("./GeoCaptchaSolver"); const GeoCaptchaSolver = require("./GeoCaptchaSolver");
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver"); const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
const OCRChecker = require("./OCRChecker"); const OCRChecker = require("./OCRChecker");
const {main, elephant} = require("yarn/lib/cli");
const {exec} = require("child_process"); const {exec} = require("child_process");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html" // const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
@@ -252,7 +251,7 @@ class CommandorPage {
async acceptCookies() { async acceptCookies() {
logWithDevice("will accept Cookies", this.device); logWithDevice("will accept Cookies", this.device);
if (this.browser.isConnected()) { if (this.browser.isConnected() && !this.page.isClosed()) {
try { try {
await this.page.evaluate(() => { await this.page.evaluate(() => {
let buttons = document.getElementsByTagName('button'); let buttons = document.getElementsByTagName('button');
@@ -277,10 +276,10 @@ class CommandorPage {
if (this.browser.isConnected() && !this.isTerminated) { if (this.browser.isConnected() && !this.isTerminated) {
try { try {
if (!this.isCountryChoosen) { if (!this.isCountryChoosen) {
await page.focus(COUNTRY_ID); // await page.focus(COUNTRY_ID);
await delay(getRandomWaitTime()) // await delay(getRandomWaitTime())
await page.click(COUNTRY_ID); // await page.click(COUNTRY_ID);
await delay(getRandomWaitTime()) // await delay(getRandomWaitTime())
await page.select(COUNTRY_ID, 'FR'); await page.select(COUNTRY_ID, 'FR');
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
this.isCountryChoosen = true; this.isCountryChoosen = true;
@@ -361,7 +360,7 @@ class CommandorPage {
try { try {
logWithDevice("input name called with this.browser.isConnected=" + this.browser.isConnected(), this.device) logWithDevice("input name called with this.browser.isConnected=" + this.browser.isConnected(), this.device)
logWithDevice("input name called with this.isNameInput=" + this.isNameInput, this.device) logWithDevice("input name called with this.isNameInput=" + this.isNameInput, this.device)
if (this.browser.isConnected() && !this.isTerminated) { if (this.browser.isConnected() && !this.isTerminated && !this.page.isClosed()) {
if (!this.isNameInput) { if (!this.isNameInput) {
await page.focus(LAST_NAME); await page.focus(LAST_NAME);
await delay(getRandomWaitTime()); await delay(getRandomWaitTime());
@@ -394,7 +393,8 @@ class CommandorPage {
} }
} }
} catch (e) { } catch (e) {
log(e); logWithDevice("exception while inputting name", this.device)
console.log(e);
this.isTerminated = true this.isTerminated = true
} }
} }
@@ -460,7 +460,7 @@ class CommandorPage {
async checkCGU(page) { async checkCGU(page) {
logWithDevice("checkCGU", this.device) logWithDevice("checkCGU", this.device)
try { try {
if (this.browser.isConnected() && !this.isTerminated) { if (this.browser.isConnected() && !this.isTerminated && !this.page.isClosed()) {
if (!this.cguChecked) { if (!this.cguChecked) {
await page.focus(CGU_ID); await page.focus(CGU_ID);
await page.evaluate(() => { await page.evaluate(() => {
@@ -516,11 +516,11 @@ class CommandorPage {
logWithDevice("fillFields called for contact: " + this.contact.mail, this.device) logWithDevice("fillFields called for contact: " + this.contact.mail, this.device)
logWithDevice("this.isFillingFields: " + this.isFillingFields, this.device); logWithDevice("this.isFillingFields: " + this.isFillingFields, this.device);
logWithDevice("this.isTerminated: " + this.isTerminated, this.device); logWithDevice("this.isTerminated: " + this.isTerminated, this.device);
if (!this.isFillingFields && !this.isTerminated) { if (!this.isFillingFields && !this.isTerminated && !this.page.isClosed()) {
this.isFillingFields = true; this.isFillingFields = true;
await this.chooseStore(page); await this.chooseStore(page);
await this.inputName(page); await this.inputName(page);
await this.chooseCountry(page); // await this.chooseCountry(page);
await this.inputPhoneNumber(page) await this.inputPhoneNumber(page)
await this.fillEmail(page) await this.fillEmail(page)
await this.inputPassportId(page) await this.inputPassportId(page)
@@ -528,13 +528,13 @@ class CommandorPage {
let pageContent = await page.content() let pageContent = await page.content()
let hasCaptcha = pageContent.includes("g-recaptcha-response") let hasCaptcha = pageContent.includes("g-recaptcha-response")
if (hasCaptcha) { if (hasCaptcha) {
await this.resolveCaptcha(page) await this.resolveCaptcha(page);
await delay(10 * 1000) await delay(getRandomWaitTime());
this.isFillingFields = false this.isFillingFields = false;
} else { } else {
this.isFillingFields = false await delay(getRandomWaitTime())
await delay(2 * 1000)
await this.clickValid(); await this.clickValid();
this.isFillingFields = false
} }
} }
} }
@@ -544,7 +544,7 @@ class CommandorPage {
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
try { try {
if (!this.page.isClosed()) { if (!this.page.isClosed()) {
if (!this.isTerminated) { if (!this.isTerminated && !this.page.isClosed()) {
this.page.evaluate(() => { this.page.evaluate(() => {
let element = document.getElementsByClassName("btn")[0]; let element = document.getElementsByClassName("btn")[0];
if (typeof element !== 'undefined') if (typeof element !== 'undefined')
@@ -559,31 +559,32 @@ class CommandorPage {
logWithDevice("will click on valid button", this.device); logWithDevice("will click on valid button", this.device);
logWithDevice("isTerminated is " + this.isTerminated, this.device); logWithDevice("isTerminated is " + this.isTerminated, this.device);
if (!this.isTerminated) { if (!this.isTerminated) {
let raw = await this.getRawAppointmentInfo(this.page) if (!this.page.isClosed()) {
if (raw.email !== undefined) { let raw = await this.getRawAppointmentInfo(this.page)
this.contact.mail = raw.email if (raw.email !== undefined) {
} this.contact.mail = raw.email
if (raw.passportNumber !== undefined) { }
this.contact.passportNumber = raw.passportNumber if (raw.passportNumber !== undefined) {
} this.contact.passportNumber = raw.passportNumber
if (raw.lastName !== undefined) { }
this.contact.lastName = raw.lastName if (raw.lastName !== undefined) {
} this.contact.lastName = raw.lastName
if (raw.phoneNumber !== undefined) { }
this.contact.phoneNumber = raw.phoneNumber if (raw.phoneNumber !== undefined) {
} this.contact.phoneNumber = raw.phoneNumber
if (raw.firstName !== undefined) { }
this.contact.firstName = raw.firstName if (raw.firstName !== undefined) {
} this.contact.firstName = raw.firstName
await this.page.evaluate(() => { }
document.getElementsByClassName("btn")[0].click(); await this.page.evaluate(() => {
}) document.getElementsByClassName("btn")[0].click();
if (this.firstStart) { })
this.disconnectBrowser(); if (this.firstStart) {
await this.checkResultWithOcr(); this.disconnectBrowser();
await this.checkResultWithOcr();
}
} }
} }
} catch (e) { } catch (e) {
log(e); log(e);
await this.checkResultWithOcr() await this.checkResultWithOcr()
@@ -865,13 +866,22 @@ class CommandorPage {
let pages = await this.browser.pages(); let pages = await this.browser.pages();
// let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL) // let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL)
// this.page = needPages[0] // this.page = needPages[0]
pages.forEach((currentPage) => { try {
if (currentPage.url() === RDV_URL) { pages.forEach((currentPage) => {
this.page = currentPage; if (currentPage.url() === RDV_URL) {
} else { this.page = currentPage;
currentPage.close() } else {
} try {
}) currentPage.close()
} catch (e) {
console.log(e)
}
}
})
} catch (e) {
this.isTerminated = true;
console.log(e)
}
logWithDevice("this.page.bringToFront();", this.device) logWithDevice("this.page.bringToFront();", this.device)
await this.page.bringToFront(); await this.page.bringToFront();
@@ -890,13 +900,24 @@ class CommandorPage {
logWithDevice("get current page", this.device) logWithDevice("get current page", this.device)
// let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL) // let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL)
// this.page = needPages[0] // this.page = needPages[0]
pages.forEach((currentPage) => { try {
if (currentPage.url() === RDV_URL) { pages.forEach((currentPage) => {
this.page = currentPage; if (currentPage.url() === RDV_URL) {
} else { this.page = currentPage;
currentPage.close() } else {
} try {
}) if (!currentPage.isClosed()) {
currentPage.close()
}
} catch (e) {
console.log(e)
}
}
})
} catch (e) {
this.isTerminated = true
console.log(e)
}
logWithDevice("this.page.bringToFront();", this.device) logWithDevice("this.page.bringToFront();", this.device)
await this.page.bringToFront(); await this.page.bringToFront();
// this.page = pages; // this.page = pages;