From f44b83375da0e93ee9789911d1b19ee76e34a908 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Wed, 4 Dec 2024 15:58:09 +0100 Subject: [PATCH] support new version --- src/workers/CommandorPage.js | 54 +++++++++++++++++++++--------------- src/workers/OCRChecker.js | 10 +++++-- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index cb2164c..5f218dd 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -11,6 +11,7 @@ const {exec} = require("child_process"); const {openUrlWithAdb} = require("../utiles/CmdUtils"); const RequestDataPojo = require("../models/RequestDataPojo"); const {REQUEST_DATA_OBJECT, TEST_QUEUE} = require("../queue/Sender"); +const {page} = require("yarn/lib/cli"); // const RDV_URL = "http://192.168.0.44:8000/test_appointment.html" const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; const BLANK_URL = "about:blank" @@ -50,6 +51,12 @@ function getRandom() { return Math.floor(Math.random() * 3); } +function getRandomId() { + let _list = [PASSPORT_ID, EMAIL_ID, FIRST_NAME, LAST_NAME]; + let index = Math.floor(Math.random() * _list.length); + return _list[index]; +} + function getRandomWaitTime() { return getRandom() * 1000 } @@ -401,12 +408,12 @@ class CommandorPage { // await page.focus(LAST_NAME); await delay(getRandomWaitTime()); console.log("will clear surname field"); - await page.evaluate(() => { - let field = document.getElementById("surname"); - if (field) { - field.value = "" - } - }) + // await page.evaluate(() => { + // let field = document.getElementById("surname"); + // if (field) { + // field.value = "" + // } + // }) await delay(1000); // await page.keyboard.type(this.contact.lastName); await page.evaluate((lastName) => { @@ -422,7 +429,6 @@ class CommandorPage { let field = document.getElementById("name"); if (field) { field.value = firstName; - // field.value = "" } }, this.contact.firstName) // await page.keyboard.type(this.contact.firstName); @@ -505,10 +511,8 @@ class CommandorPage { document.querySelector("#cgu").checked = true } }); - // await page.click(CGU_ID); await delay(getRandomWaitTime()); await page.focus(PROCESSING_ID); - // await page.click(PROCESSING_ID) await page.evaluate(() => { if (!document.querySelector("#processing").checked) { document.querySelector("#processing").checked = true @@ -581,8 +585,12 @@ class CommandorPage { } } + async clickValid() { logWithDevice("clickValid() called.", this.device); + let _id_to_click = getRandomId() + await this.page.click(_id_to_click) + await delay(getRandomWaitTime()) this.isFillingFields = false try { @@ -612,7 +620,7 @@ class CommandorPage { this.contact.firstName = raw.firstName } await this.page.evaluate(() => { - document.getElementsByClassName("btn")[0].click(); + document.getElementsByTagName("button")[1].click(); }) if (this.firstStart) { this.disconnectBrowser(); @@ -889,18 +897,20 @@ class CommandorPage { this.isTerminated = true; break; case OCRResult.SLIDING_CAPTCHA: - logWithDevice("will call this.slidingCaptcha()", this.device) - await this.slidingCaptcha(async (isSuccessful) => { - logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device) - console.log(checkResult); - if (isSuccessful) { - await delay(5 * 1000) - // checkResult = await this.ocrChecker.get_result(); - await this.checkResultWithOcr() - } else { - await this.checkResultWithOcr() - } - }) + this.isAlreadyRefresh = true; + await this.generateRandomActions() + // logWithDevice("will call this.slidingCaptcha()", this.device) + // await this.slidingCaptcha(async (isSuccessful) => { + // logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device) + // console.log(checkResult); + // if (isSuccessful) { + // await delay(5 * 1000) + // // checkResult = await this.ocrChecker.get_result(); + // await this.checkResultWithOcr() + // } else { + // await this.checkResultWithOcr() + // } + // }) // await delay(5 * 1000) break; case OCRResult.FILL_FIELD: diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index 0d3af93..21cef39 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -17,6 +17,7 @@ const NO_INTERNET_FR_2 = "Aucun accès à Internet" const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave" const MESSAGE_URL_VALIDATION_FR = "Vous recevrez un email de validation" const MESSAGE_URL_VALIDATION_FR_2 = "Merci de votre intérêt pour notre Maison" +const MESSAGE_URL_VALIDATION_FR_3 = "vous allez recevoir un courriel de notre part" const SSL_CERT_ERROR = " Votre connexion n'est pas privée" const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" const WRONG_PHONE_NUMBER = "Veuillez renseigner vote numéro de téléphone" @@ -47,7 +48,7 @@ const MESSAGE_FILL_FIELD_FR = "Demande de rendez-vous pour" const MESSAGE_FILL_FIELD_FR_2 = "des champs de données doivent étre complétés" const MESSAGE_FILL_FIELD_FR_3 = "Sans préféré" const MESSAGE_FILL_FIELD_FR_4 = "Magasin préféré" -const MESSAGE_FILL_FIELD_FR_5 = "email vous sera envoyé pour vous" +const MESSAGE_FILL_FIELD_FR_5 = "demande de rendez-vous pour le" const MESSAGE_FILL_FIELD_FR_6 = "Prénom* Téléphone*" const WELCOME_MESSAGE_FR = "Bienvenue dans Chrome" const WELCOME_MESSAGE_FR_2 = "Chrome Connectez-vous" @@ -100,7 +101,10 @@ class OCRChecker { try { let result = await findText(fileName) console.log(result) - if (result.includes(MESSAGE_URL_VALIDATION_EN) || result.includes(MESSAGE_URL_VALIDATION_FR) || result.includes(MESSAGE_URL_VALIDATION_FR_2)) { + if (result.includes(MESSAGE_URL_VALIDATION_EN) + || result.includes(MESSAGE_URL_VALIDATION_FR) + || result.toLowerCase().includes(MESSAGE_URL_VALIDATION_FR_3) + || result.includes(MESSAGE_URL_VALIDATION_FR_2)) { await this.deleteFile(fileName) return OCRResult.SUCCESS } else if (result.includes(BRAVE_NOTIFICATION)) { @@ -121,7 +125,7 @@ class OCRChecker { } else if (result.includes(WRONG_PHONE_NUMBER)) { await this.deleteFile(fileName) return OCRResult.WRONG_PHONE_NUMBER - } else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5) || result.includes(MESSAGE_FILL_FIELD_FR_6)) { + } else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.toLowerCase().includes(MESSAGE_FILL_FIELD_FR_5) || result.includes(MESSAGE_FILL_FIELD_FR_6)) { await this.deleteFile(fileName) return OCRResult.FILL_FIELD } else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) {