Merge branch 'master' into feature/macOcr
This commit is contained in:
@@ -91,6 +91,30 @@ class CommandorPage {
|
||||
this.firstStart = true;
|
||||
}
|
||||
|
||||
async getActivePage(browser, timeout) {
|
||||
const start = new Date().getTime();
|
||||
while (new Date().getTime() - start < timeout) {
|
||||
logWithDevice("get pages", this.device)
|
||||
let pages = await browser.pages();
|
||||
try {
|
||||
pages.forEach((currentPage) => {
|
||||
if (currentPage.url() === RDV_URL) {
|
||||
return currentPage;
|
||||
} else {
|
||||
try {
|
||||
currentPage.close()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
this.isTerminated = true;
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
throw "Unable to get active page";
|
||||
}
|
||||
|
||||
async connect_to_browser(ocrResult) {
|
||||
console.log("connect_to_browser() called");
|
||||
@@ -193,7 +217,6 @@ class CommandorPage {
|
||||
}
|
||||
} catch (e) {
|
||||
logWithDevice("failed to connect to device", this.device)
|
||||
|
||||
console.log(e)
|
||||
// await this.resetBrowser()
|
||||
await this.checkResultWithOcr()
|
||||
@@ -214,6 +237,7 @@ class CommandorPage {
|
||||
await this.acceptCookies();
|
||||
await this.enableDisableAirPlanMode();
|
||||
await delay(10 * 1000);
|
||||
// await this.checkResultWithOcr()
|
||||
await this.clickOnlineAppointment();
|
||||
} else {
|
||||
this.isTerminated = true;
|
||||
@@ -262,13 +286,8 @@ class CommandorPage {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
// if (this.page.url() === RDV_URL) {
|
||||
// if (!this.isFillingFields)
|
||||
// await this.fillFields(this.page, false);
|
||||
// }
|
||||
} catch (e) {
|
||||
log(e)
|
||||
console.log(e)
|
||||
await this.checkResultWithOcr();
|
||||
}
|
||||
}
|
||||
@@ -680,10 +699,11 @@ class CommandorPage {
|
||||
try {
|
||||
let content = await this.page.content();
|
||||
let captcha_url = "geo.captcha-delivery.com/captcha";
|
||||
if (content.toString().includes(captcha_url)) {
|
||||
await this.checkResultWithOcr()
|
||||
logWithDevice("发现datadome", this.device);
|
||||
} else if (content.includes("502 Bad Gateway")) {
|
||||
// if (content.toString().includes(captcha_url)) {
|
||||
// await this.checkResultWithOcr()
|
||||
// logWithDevice("发现datadome", this.device);
|
||||
// } else
|
||||
if (content.includes("502 Bad Gateway")) {
|
||||
logWithDevice("502 Bad Gateway found", this.device)
|
||||
await this.page.reload()
|
||||
} else if (this.page.url().includes("sorry")) {
|
||||
@@ -728,8 +748,8 @@ class CommandorPage {
|
||||
|
||||
async slidingCaptcha(onResult) {
|
||||
logWithDevice("slidingCaptcha", this.device);
|
||||
if (this.device.model() === "MI 5s") {
|
||||
let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 295`
|
||||
if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD") {
|
||||
let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 195`
|
||||
await exec(cmd);
|
||||
await delay(1000);
|
||||
}
|
||||
@@ -857,9 +877,14 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async checkResultWithOcr() {
|
||||
logWithDevice("checkResultWithOcr() called.", this.device)
|
||||
await delay(4000);
|
||||
if (this.device.model() === "M2006C3LG")
|
||||
await delay(6000);
|
||||
else {
|
||||
await delay(4000);
|
||||
}
|
||||
let checkResult = await this.ocrChecker.get_result();
|
||||
console.log(checkResult);
|
||||
while (checkResult === OCRResult.RECHECK || checkResult === OCRResult.NO_INTERNET) {
|
||||
@@ -888,7 +913,6 @@ class CommandorPage {
|
||||
await this.connect_to_browser(checkResult)
|
||||
break;
|
||||
case OCRResult.FILL_FIELD:
|
||||
// console.log("browser.isConnected: " + this.browser.isConnected());
|
||||
if (this.browser === undefined || !this.browser.isConnected()) {
|
||||
logWithDevice("trying to connect to browser", this.device)
|
||||
try {
|
||||
@@ -930,8 +954,6 @@ class CommandorPage {
|
||||
logWithDevice("get pages", this.device)
|
||||
let pages = await this.browser.pages();
|
||||
logWithDevice("get current page", this.device)
|
||||
// let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL)
|
||||
// this.page = needPages[0]
|
||||
try {
|
||||
pages.forEach((currentPage) => {
|
||||
if (currentPage.url() === RDV_URL) {
|
||||
@@ -994,10 +1016,11 @@ class CommandorPage {
|
||||
case OCRResult.BRAVE_PRIVACY:
|
||||
if (this.device.model() === "MI 5s") {
|
||||
await this.tapForDevice(this.device, 530, 970)
|
||||
// await this.device.shell("input tap " + 530 + " " + 970)
|
||||
} else if (this.device.model() === "ONEPLUS A6000")
|
||||
} else if (this.device.model() === "ONEPLUS A6000") {
|
||||
await this.device.shell("input tap " + 530 + " " + 1064)
|
||||
else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") {
|
||||
} else if (this.device.model() === "M2006C3LG") {
|
||||
await this.tapForDevice(this.device, 350, 777)
|
||||
} else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") {
|
||||
await this.tapForDevice(this.device, 500, 1200)
|
||||
await this.tapForDevice(this.device, 500, 1120)
|
||||
} else
|
||||
@@ -1037,6 +1060,12 @@ class CommandorPage {
|
||||
await this.tapForDevice(this.device, 300, 1700)
|
||||
await this.checkResultWithOcr();
|
||||
break;
|
||||
case OCRResult.BRAVE_VPN_SKIP:
|
||||
logWithDevice("BRAVE_VPN_SKIP", this.device)
|
||||
if (this.device.model() === "M2006C3LG") {
|
||||
await this.tapForDevice(this.device, 580, 445)
|
||||
}
|
||||
break;
|
||||
case OCRResult.TO_SKIP
|
||||
:
|
||||
logWithDevice("TO_SKIP", this.device)
|
||||
@@ -1122,6 +1151,8 @@ class CommandorPage {
|
||||
await this.device.shell("input tap " + 558 + " " + 1160)
|
||||
} else if (model === "MI 5s") {
|
||||
await this.tapForDevice(this.device, 530, 1000)
|
||||
} else if (model === "M2006C3LG") {
|
||||
await this.tapForDevice(this.device, 360, 777)
|
||||
} else if (model === "ONEPLUS A6000") {
|
||||
await this.device.shell("input tap " + 530 + " " + 1106)
|
||||
} else {
|
||||
@@ -1246,6 +1277,8 @@ class CommandorPage {
|
||||
await this.tapForDevice(this.device, 411, 2020)
|
||||
} else if (this.browserPackageName.includes("brave") && this.device.model() === "21091116C") {
|
||||
await this.tapForDevice(this.device, 411, 2020)
|
||||
} else if (this.browserPackageName.includes("brave") && this.device.model() === "M2006C3LG") {//redmi 9a
|
||||
await this.tapForDevice(this.device, 411, 1300)
|
||||
} else {
|
||||
await this.tapForDevice(this.device, 411, 2100)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user