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
+37 -11
View File
@@ -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);
}