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 SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
const OCRChecker = require("./OCRChecker");
const {main, elephant} = require("yarn/lib/cli");
const {exec} = require("child_process");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
@@ -252,7 +251,7 @@ class CommandorPage {
async acceptCookies() {
logWithDevice("will accept Cookies", this.device);
if (this.browser.isConnected()) {
if (this.browser.isConnected() && !this.page.isClosed()) {
try {
await this.page.evaluate(() => {
let buttons = document.getElementsByTagName('button');
@@ -277,10 +276,10 @@ class CommandorPage {
if (this.browser.isConnected() && !this.isTerminated) {
try {
if (!this.isCountryChoosen) {
await page.focus(COUNTRY_ID);
await delay(getRandomWaitTime())
await page.click(COUNTRY_ID);
await delay(getRandomWaitTime())
// await page.focus(COUNTRY_ID);
// await delay(getRandomWaitTime())
// await page.click(COUNTRY_ID);
// await delay(getRandomWaitTime())
await page.select(COUNTRY_ID, 'FR');
await delay(getRandomWaitTime())
this.isCountryChoosen = true;
@@ -361,7 +360,7 @@ class CommandorPage {
try {
logWithDevice("input name called with this.browser.isConnected=" + this.browser.isConnected(), 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) {
await page.focus(LAST_NAME);
await delay(getRandomWaitTime());
@@ -394,7 +393,8 @@ class CommandorPage {
}
}
} catch (e) {
log(e);
logWithDevice("exception while inputting name", this.device)
console.log(e);
this.isTerminated = true
}
}
@@ -460,7 +460,7 @@ class CommandorPage {
async checkCGU(page) {
logWithDevice("checkCGU", this.device)
try {
if (this.browser.isConnected() && !this.isTerminated) {
if (this.browser.isConnected() && !this.isTerminated && !this.page.isClosed()) {
if (!this.cguChecked) {
await page.focus(CGU_ID);
await page.evaluate(() => {
@@ -516,11 +516,11 @@ class CommandorPage {
logWithDevice("fillFields called for contact: " + this.contact.mail, this.device)
logWithDevice("this.isFillingFields: " + this.isFillingFields, 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;
await this.chooseStore(page);
await this.inputName(page);
await this.chooseCountry(page);
// await this.chooseCountry(page);
await this.inputPhoneNumber(page)
await this.fillEmail(page)
await this.inputPassportId(page)
@@ -528,13 +528,13 @@ class CommandorPage {
let pageContent = await page.content()
let hasCaptcha = pageContent.includes("g-recaptcha-response")
if (hasCaptcha) {
await this.resolveCaptcha(page)
await delay(10 * 1000)
this.isFillingFields = false
await this.resolveCaptcha(page);
await delay(getRandomWaitTime());
this.isFillingFields = false;
} else {
this.isFillingFields = false
await delay(2 * 1000)
await delay(getRandomWaitTime())
await this.clickValid();
this.isFillingFields = false
}
}
}
@@ -544,7 +544,7 @@ class CommandorPage {
await delay(getRandomWaitTime())
try {
if (!this.page.isClosed()) {
if (!this.isTerminated) {
if (!this.isTerminated && !this.page.isClosed()) {
this.page.evaluate(() => {
let element = document.getElementsByClassName("btn")[0];
if (typeof element !== 'undefined')
@@ -559,31 +559,32 @@ class CommandorPage {
logWithDevice("will click on valid button", this.device);
logWithDevice("isTerminated is " + this.isTerminated, this.device);
if (!this.isTerminated) {
let raw = await this.getRawAppointmentInfo(this.page)
if (raw.email !== undefined) {
this.contact.mail = raw.email
}
if (raw.passportNumber !== undefined) {
this.contact.passportNumber = raw.passportNumber
}
if (raw.lastName !== undefined) {
this.contact.lastName = raw.lastName
}
if (raw.phoneNumber !== undefined) {
this.contact.phoneNumber = raw.phoneNumber
}
if (raw.firstName !== undefined) {
this.contact.firstName = raw.firstName
}
await this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].click();
})
if (this.firstStart) {
this.disconnectBrowser();
await this.checkResultWithOcr();
if (!this.page.isClosed()) {
let raw = await this.getRawAppointmentInfo(this.page)
if (raw.email !== undefined) {
this.contact.mail = raw.email
}
if (raw.passportNumber !== undefined) {
this.contact.passportNumber = raw.passportNumber
}
if (raw.lastName !== undefined) {
this.contact.lastName = raw.lastName
}
if (raw.phoneNumber !== undefined) {
this.contact.phoneNumber = raw.phoneNumber
}
if (raw.firstName !== undefined) {
this.contact.firstName = raw.firstName
}
await this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].click();
})
if (this.firstStart) {
this.disconnectBrowser();
await this.checkResultWithOcr();
}
}
}
} catch (e) {
log(e);
await this.checkResultWithOcr()
@@ -865,13 +866,22 @@ class CommandorPage {
let pages = await this.browser.pages();
// let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL)
// this.page = needPages[0]
pages.forEach((currentPage) => {
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} else {
currentPage.close()
}
})
try {
pages.forEach((currentPage) => {
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} else {
try {
currentPage.close()
} catch (e) {
console.log(e)
}
}
})
} catch (e) {
this.isTerminated = true;
console.log(e)
}
logWithDevice("this.page.bringToFront();", this.device)
await this.page.bringToFront();
@@ -890,13 +900,24 @@ class CommandorPage {
logWithDevice("get current page", this.device)
// let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL)
// this.page = needPages[0]
pages.forEach((currentPage) => {
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} else {
currentPage.close()
}
})
try {
pages.forEach((currentPage) => {
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} 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)
await this.page.bringToFront();
// this.page = pages;