try to handle error

This commit is contained in:
2022-09-09 10:30:42 +02:00
parent 3557a2ed90
commit 374a8d22f2
5 changed files with 73 additions and 9 deletions
+1 -1
View File
@@ -3,4 +3,4 @@ adb -s 76a3ac8d shell am set-debug-app --persistent com.android.chrome
adb -s 76a3ac8d shell am start -n com.android.chrome/com.google.android.apps.chrome.Main adb -s 76a3ac8d shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
adb -s 07f9c883 shell pm clear com.android.chrome adb -s 07f9c883 shell pm clear com.android.chrome
adb -s 07f9c883 shell am set-debug-app --persistent com.android.chrome adb -s 07f9c883 shell am set-debug-app --persistent com.android.chrome
adb -s 07f9c883 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main adb -s 07f9c883 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
+21
View File
@@ -0,0 +1,21 @@
const {_android: android} = require('playwright');
const CLEARDATACOMMAND = "pm clear com.android.chrome"
const SET_DEBUGABLE = "am set-debug-app --persistent com.android.chrome"
const START_CHROME = "am start -n com.android.chrome/com.google.android.apps.chrome.Main"
android.devices().then(deviceList => {
deviceList.forEach(async (device) => {
console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`);
await clearChromeDataForDevice(device)
})
})
async function clearChromeDataForDevice(device) {
console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`);
await device.shell(CLEARDATACOMMAND)
await device.shell(SET_DEBUGABLE)
await device.shell(START_CHROME)
}
module.exports = clearChromeDataForDevice
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 KiB

+51 -8
View File
@@ -4,8 +4,9 @@ const SolveCaptcha = require("./SolveCaptcha");
const ReserveResultPojo = require("../models/ReserveResultPojo"); const ReserveResultPojo = require("../models/ReserveResultPojo");
const PublishType = require("../models/PublishType"); const PublishType = require("../models/PublishType");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html" const RDV_URL = "http://192.168.1.16:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; // const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
BLANK_URL = "about:blank"
const COUNTRY_ID = "#phone_country" const COUNTRY_ID = "#phone_country"
const PHONE_NUMBER = "#phone_number" const PHONE_NUMBER = "#phone_number"
@@ -192,28 +193,42 @@ class CommandorPage {
page.evaluate((solution) => { page.evaluate((solution) => {
document.getElementById("g-recaptcha-response").innerHTML = solution; document.getElementById("g-recaptcha-response").innerHTML = solution;
}, solution) }, solution)
this.clickValid() this.clickValid();
}) })
} }
async onPageLoad(currentPage) { async onPageLoad(currentPage) {
let content = await currentPage.content(); let content = await currentPage.content();
let captcha_url = "geo.captcha-delivery.com/captcha" let captcha_url = "geo.captcha-delivery.com/captcha";
if (content.toString().includes(captcha_url)) { if (content.toString().includes(captcha_url)) {
console.log("we are blocked") this.checkAudioBtn();
console.log("we are blocked");
} else { } else {
if (currentPage.url() === RDV_URL) { if (currentPage.url() === RDV_URL) {
await this.fillFields(this.page) await this.fillFields(this.page);
} else { } else {
if (content.includes(MESSAGE_URL_VALIDATION_FR)) { if (content.includes(MESSAGE_URL_VALIDATION_FR)) {
console.log("successful") console.log("successful");
await this.push_message_to_queue(PublishType.SUCCESS) await this.push_message_to_queue(PublishType.SUCCESS);
} else {
// try to get errors
this.getErrors()
} }
} }
} }
} }
checkAudioBtn() {
let iframe = this.page.querySelector("iframe").contentFrame();
let audioBtn = iframe.querySelector("#captcha__audio__button");
if (audioBtn) {
console.log("audioBtn found")
} else {
console.log("audioBtn not found")
}
}
async onResponse(response) { async onResponse(response) {
let rex = new RegExp(REGEX_RDV_URL) let rex = new RegExp(REGEX_RDV_URL)
if (rex.test(response.url)) { if (rex.test(response.url)) {
@@ -236,6 +251,34 @@ class CommandorPage {
} }
getErrors() {
if (this.page.url() === BLANK_URL) {
this.isTerminated = true;
} else {
try {
let errorItem = this.page.querySelector("div.alert");
if (errorItem) {
let errorContent = errorItem.innerHTML;
console.log("error:" + errorContent);
this.handleError(errorContent);
}
} catch (e) {
console.log(e);
}
}
}
handleError(errorContent) {
if (errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE) || errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE_FR)) {
this.isTerminated = true;
} else if (errorContent.includes(TOO_MANY_REQUEST_ERROR_MESSAGE) || errorContent.includes(TOO_MANY_REQUEST_ERROR_MESSAGE_FR)) {
// todo, add contact to black list
this.isTerminated = true;
} else if (errorContent.includes(CAPTCHA_ERROR_MESSAGE) || errorContent.includes(CAPTCHA_ERROR_MESSAGE_FR)) {
this.isTerminated = true;
}
}
} }
module.exports = CommandorPage module.exports = CommandorPage