diff --git a/clear_data.sh b/clear_data.sh index 8042464..d1cef5c 100644 --- a/clear_data.sh +++ b/clear_data.sh @@ -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 07f9c883 shell pm clear 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 \ No newline at end of file +adb -s 07f9c883 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main diff --git a/device_manager.js b/device_manager.js new file mode 100644 index 0000000..432ef37 --- /dev/null +++ b/device_manager.js @@ -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 \ No newline at end of file diff --git a/src/device.png b/src/device.png deleted file mode 100644 index e48e67a..0000000 Binary files a/src/device.png and /dev/null differ diff --git a/src/page.png b/src/page.png deleted file mode 100644 index 7bd9578..0000000 Binary files a/src/page.png and /dev/null differ diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 4f08cfa..869c035 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -4,8 +4,9 @@ const SolveCaptcha = require("./SolveCaptcha"); const ReserveResultPojo = require("../models/ReserveResultPojo"); const PublishType = require("../models/PublishType"); -// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html" -const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; +const RDV_URL = "http://192.168.1.16:8000/test_appointment.html" +// const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; +BLANK_URL = "about:blank" const COUNTRY_ID = "#phone_country" const PHONE_NUMBER = "#phone_number" @@ -192,28 +193,42 @@ class CommandorPage { page.evaluate((solution) => { document.getElementById("g-recaptcha-response").innerHTML = solution; }, solution) - this.clickValid() + this.clickValid(); }) } async onPageLoad(currentPage) { 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)) { - console.log("we are blocked") + this.checkAudioBtn(); + console.log("we are blocked"); } else { if (currentPage.url() === RDV_URL) { - await this.fillFields(this.page) + await this.fillFields(this.page); } else { if (content.includes(MESSAGE_URL_VALIDATION_FR)) { - console.log("successful") - await this.push_message_to_queue(PublishType.SUCCESS) + console.log("successful"); + 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) { let rex = new RegExp(REGEX_RDV_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 \ No newline at end of file