diff --git a/src/appointment.js b/src/appointment.js index 0043735..774c63d 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -13,7 +13,7 @@ let collectionName = formatDate(new Date()) // device_to_excludes = ["47e7e36b", "e30eb015"] // device_to_excludes = ["47e7e36b"] // device_to_excludes = ["J4AXB761H2322WJ"] -device_to_excludes = ["47e7e36b", "07fbd156", "R9TR608ZLKJ", "heuklr55wo8tfyvw"] +device_to_excludes = ["07fbd156", "R9TR608ZLKJ", "heuklr55wo8tfyvw"] attributedPorts = [] const device_port_info = new Map(); startPort = 9000 @@ -199,6 +199,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT } // start chrome device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main") + // device.shell("am start -n com.brave.browser/com.google.android.apps.chrome.Main") return attributedPort } diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index a0d0000..ba3e64c 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -12,7 +12,8 @@ const { const GeoCaptchaSolver = require("./GeoCaptchaSolver"); const SlidingCaptchaSolver = require("./SlidingCaptchaSolver"); const OCRChecker = require("./OCRChecker"); -const crypto = require("crypto"); +const {browser} = require("yarn/lib/cli"); +const {disconnect} = require("mongoose"); // 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" @@ -71,6 +72,8 @@ class CommandorPage { this.selectedStore = selectedStore; this.choosedStore = selectedStore; this.port = port; + // this.browserPackageName = "com.brave.browser"; + this.browserPackageName = "com.android.chrome"; this.isFillingFields = false; this.isTerminated = false; this.cguChecked = false; @@ -163,6 +166,8 @@ class CommandorPage { this.isTerminated = true } await this.acceptCookies(); + await this.enableDisableAirPlanMode(); + await delay(10 * 1000); await this.clickOnlineAppointment(); await delay(2000); await this.clickOnlineAppointment(); @@ -211,15 +216,16 @@ class CommandorPage { console.log("will click on the button") await button.click(); } - if (this.page.url() === RDV_URL) { - if (!this.isFillingFields) - await this.fillFields(this.page, false); + if (this.firstStart) { + this.disconnectBrowser() } + // if (this.page.url() === RDV_URL) { + // if (!this.isFillingFields) + // await this.fillFields(this.page, false); + // } } catch (e) { log(e) - // if (!this.page.url().includes(RDV_URL)) { - // this.isTerminated = true; - // } + await this.checkResultWithOcr(); } } @@ -425,7 +431,7 @@ class CommandorPage { if (!this.isFillingFields) { this.isFillingFields = true; if (airePlanMode) { - await this.enableDisableAirPlanMode(); + // await this.enableDisableAirPlanMode(); } await this.chooseStore(page); await this.inputName(page); @@ -669,9 +675,9 @@ class CommandorPage { this.isPhoneInput = false; this.isPasspordInput = false; // this.disconnectBrowser(); - await this.device.shell("pm clear com.android.chrome") + await this.device.shell("pm clear " + this.browserPackageName) await delay(1000) - await this.device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main") + await this.device.shell("am start -n " + this.browserPackageName + "/com.google.android.apps.chrome.Main") await delay(2000); this.isTerminated = true; // await this.checkResultWithOcr(); @@ -684,6 +690,7 @@ class CommandorPage { disconnectBrowser() { try { + logWithDevice("will disconnect browser", this.device); this.browser.disconnect(); } catch (e) { console.log(e) @@ -697,6 +704,7 @@ class CommandorPage { let checkResult = await ocrChecker.get_result(); console.log(checkResult); while (checkResult === OCRResult.RECHECK) { + logWithDevice("will recheck OCR", this.device) await delay(4000) logWithDevice("will recheck OCR", this.device) checkResult = await ocrChecker.get_result(); @@ -710,6 +718,15 @@ class CommandorPage { } switch (checkResult) { case OCRResult.FILL_FIELD: + console.log("browser.isConnected: " + this.browser.isConnected()); + if (!this.browser.isConnected()) { + this.browser = await puppeteer.connect({ + browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser", + headless: false, defaultViewport: null + }) + let pages = await this.browser.pages(); + this.page = pages[0]; + } await this.fillFields(this.page) break; case OCRResult.SUCCESS: @@ -750,11 +767,20 @@ class CommandorPage { await delay(5000); checkResult = ocrChecker.get_result(); } + if (checkResult === undefined) { + await delay(5000); + checkResult = ocrChecker.get_result(); + } } async tapLaterBtn() { logWithDevice("tapLaterBtn", this.device) - this.device.shell("input tap " + 385 + " " + 2050) + let model = this.device.model(); + log("model is " + model); + if (model === "CPH2219") { + this.device.shell("input tap " + 385 + " " + 1930) + } else + this.device.shell("input tap " + 385 + " " + 2050) await delay(2000); }