From 6d58a39fc97397b0ae274732dc14cfe7b506df88 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Sat, 17 Feb 2024 12:06:25 +0100 Subject: [PATCH] add serial number and random actions --- src/models/ReserveResultPojo.js | 2 ++ src/workers/CommandorPage.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/models/ReserveResultPojo.js b/src/models/ReserveResultPojo.js index b3a2f58..219a896 100644 --- a/src/models/ReserveResultPojo.js +++ b/src/models/ReserveResultPojo.js @@ -15,6 +15,7 @@ class ReserveResultPojo { this.email = mail; this.type = type; this.source_from = "" + this.serial = "" this.hostName = hostName this.created_at = new Date().toLocaleString() } @@ -30,6 +31,7 @@ class ReserveResultPojo { url: this.url, store_type: this.storeType, source_from: this.source_from, + serial: this.serial, created_at: this.created_at, hostName: this.hostName } diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 6354e0f..e64919a 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -91,6 +91,7 @@ class CommandorPage { this.isCountryChoosen = false; this.isPhoneInput = false; this.firstStart = true; + this.isAlreadyRefresh = false; } async connect_to_browser(ocrResult) { @@ -142,6 +143,23 @@ class CommandorPage { } } + async generateRandomActions() { + logWithDevice("will reload page", this.device) + await this.handleBraveSkipBtn() + await delay(1000); + let cmd = "input swipe 382 482 382 1682" + logWithDevice("will send cmd:" + cmd, this.device) + this.device.shell(cmd); + await delay(2000); + let limit = getRandom() + for (let i = 1; i <= limit; i++) { + this.device.shell(cmd); + await delay(1000); + } + await this.clickOnConfirmBtn(); + await this.checkResultWithOcr(); + } + async checkIfSuccessful() { let content = await this.page.content(); if (content.includes(MESSAGE_URL_VALIDATION_FR) || content.includes(MESSAGE_URL_VALIDATION_EN)) { @@ -167,7 +185,9 @@ class CommandorPage { } // await this.acceptCookies(); await this.enableDisableAirPlanMode(); - // await delay(10 * 1000); + // await openUrlWithAdb("https://www.google.fr", this.device) + // await delay(2 * 1000) + await openUrlWithAdb(RDV_URL, this.device) await delay(10 * 1000) await this.checkResultWithOcr() @@ -715,6 +735,7 @@ class CommandorPage { // save to mongoDb let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType); reserve.source_from = this.device.model(); + reserve.serial = this.device.serial(); await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) if (!this.page.isClosed()) { try { @@ -1036,7 +1057,12 @@ class CommandorPage { case OCRResult.BLOCKED : - await this.resetBrowser(); + if (this.isAlreadyRefresh) { + await this.resetBrowser(); + } else { + this.isAlreadyRefresh = true; + await this.generateRandomActions() + } break; case OCRResult.ONLINE_APPOINTMENT