disconnect brower while opening appointment page

This commit is contained in:
Lei PAN
2023-05-25 18:42:34 +02:00
parent 63fd4f42bb
commit 9455aa3d4f
2 changed files with 39 additions and 12 deletions
+2 -1
View File
@@ -13,7 +13,7 @@ let collectionName = formatDate(new Date())
// device_to_excludes = ["47e7e36b", "e30eb015"] // device_to_excludes = ["47e7e36b", "e30eb015"]
// device_to_excludes = ["47e7e36b"] // device_to_excludes = ["47e7e36b"]
// device_to_excludes = ["J4AXB761H2322WJ"] // device_to_excludes = ["J4AXB761H2322WJ"]
device_to_excludes = ["47e7e36b", "07fbd156", "R9TR608ZLKJ", "heuklr55wo8tfyvw"] device_to_excludes = ["07fbd156", "R9TR608ZLKJ", "heuklr55wo8tfyvw"]
attributedPorts = [] attributedPorts = []
const device_port_info = new Map(); const device_port_info = new Map();
startPort = 9000 startPort = 9000
@@ -199,6 +199,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
} }
// start chrome // start chrome
device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main") 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 return attributedPort
} }
+37 -11
View File
@@ -12,7 +12,8 @@ const {
const GeoCaptchaSolver = require("./GeoCaptchaSolver"); const GeoCaptchaSolver = require("./GeoCaptchaSolver");
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver"); const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
const OCRChecker = require("./OCRChecker"); 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 = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
const BLANK_URL = "about:blank" const BLANK_URL = "about:blank"
@@ -71,6 +72,8 @@ class CommandorPage {
this.selectedStore = selectedStore; this.selectedStore = selectedStore;
this.choosedStore = selectedStore; this.choosedStore = selectedStore;
this.port = port; this.port = port;
// this.browserPackageName = "com.brave.browser";
this.browserPackageName = "com.android.chrome";
this.isFillingFields = false; this.isFillingFields = false;
this.isTerminated = false; this.isTerminated = false;
this.cguChecked = false; this.cguChecked = false;
@@ -163,6 +166,8 @@ class CommandorPage {
this.isTerminated = true this.isTerminated = true
} }
await this.acceptCookies(); await this.acceptCookies();
await this.enableDisableAirPlanMode();
await delay(10 * 1000);
await this.clickOnlineAppointment(); await this.clickOnlineAppointment();
await delay(2000); await delay(2000);
await this.clickOnlineAppointment(); await this.clickOnlineAppointment();
@@ -211,15 +216,16 @@ class CommandorPage {
console.log("will click on the button") console.log("will click on the button")
await button.click(); await button.click();
} }
if (this.page.url() === RDV_URL) { if (this.firstStart) {
if (!this.isFillingFields) this.disconnectBrowser()
await this.fillFields(this.page, false);
} }
// if (this.page.url() === RDV_URL) {
// if (!this.isFillingFields)
// await this.fillFields(this.page, false);
// }
} catch (e) { } catch (e) {
log(e) log(e)
// if (!this.page.url().includes(RDV_URL)) { await this.checkResultWithOcr();
// this.isTerminated = true;
// }
} }
} }
@@ -425,7 +431,7 @@ class CommandorPage {
if (!this.isFillingFields) { if (!this.isFillingFields) {
this.isFillingFields = true; this.isFillingFields = true;
if (airePlanMode) { if (airePlanMode) {
await this.enableDisableAirPlanMode(); // await this.enableDisableAirPlanMode();
} }
await this.chooseStore(page); await this.chooseStore(page);
await this.inputName(page); await this.inputName(page);
@@ -669,9 +675,9 @@ class CommandorPage {
this.isPhoneInput = false; this.isPhoneInput = false;
this.isPasspordInput = false; this.isPasspordInput = false;
// this.disconnectBrowser(); // this.disconnectBrowser();
await this.device.shell("pm clear com.android.chrome") await this.device.shell("pm clear " + this.browserPackageName)
await delay(1000) 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); await delay(2000);
this.isTerminated = true; this.isTerminated = true;
// await this.checkResultWithOcr(); // await this.checkResultWithOcr();
@@ -684,6 +690,7 @@ class CommandorPage {
disconnectBrowser() { disconnectBrowser() {
try { try {
logWithDevice("will disconnect browser", this.device);
this.browser.disconnect(); this.browser.disconnect();
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@@ -697,6 +704,7 @@ class CommandorPage {
let checkResult = await ocrChecker.get_result(); let checkResult = await ocrChecker.get_result();
console.log(checkResult); console.log(checkResult);
while (checkResult === OCRResult.RECHECK) { while (checkResult === OCRResult.RECHECK) {
logWithDevice("will recheck OCR", this.device)
await delay(4000) await delay(4000)
logWithDevice("will recheck OCR", this.device) logWithDevice("will recheck OCR", this.device)
checkResult = await ocrChecker.get_result(); checkResult = await ocrChecker.get_result();
@@ -710,6 +718,15 @@ class CommandorPage {
} }
switch (checkResult) { switch (checkResult) {
case OCRResult.FILL_FIELD: 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) await this.fillFields(this.page)
break; break;
case OCRResult.SUCCESS: case OCRResult.SUCCESS:
@@ -750,11 +767,20 @@ class CommandorPage {
await delay(5000); await delay(5000);
checkResult = ocrChecker.get_result(); checkResult = ocrChecker.get_result();
} }
if (checkResult === undefined) {
await delay(5000);
checkResult = ocrChecker.get_result();
}
} }
async tapLaterBtn() { async tapLaterBtn() {
logWithDevice("tapLaterBtn", this.device) 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); await delay(2000);
} }