check null in SlidingCaptchaSolver.js

This commit is contained in:
Lei PAN
2023-05-27 16:58:53 +02:00
parent 4de3bf606c
commit 9751637a1d
4 changed files with 59 additions and 30 deletions
+2
View File
@@ -11,6 +11,8 @@ const OCRResult = {
RECHECK: Symbol("RECHECK"),
CLOSED: Symbol("CLOSED"),
TERMINAED: Symbol("TERMINAED"),
GOOGLE_DISCONNECT: Symbol("GOOGLE_DISCONNECT"),
TO_SKIP: Symbol("TO_SKIP"),
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
}
module.exports = OCRResult
+46 -25
View File
@@ -120,6 +120,7 @@ class CommandorPage {
logWithDevice("will send cmd:" + cmd, this.device)
this.device.shell(cmd);
await delay(3000);
await this.clickOnConfirmBtn();
await this.checkResultWithOcr();
// }
// }
@@ -187,9 +188,9 @@ class CommandorPage {
await this.enableDisableAirPlanMode();
await delay(10 * 1000);
await this.clickOnlineAppointment();
await delay(2000);
if (!this.isTerminated)
await this.clickOnlineAppointment();
// await delay(2000);
// if (!this.isTerminated)
// await this.clickOnlineAppointment();
} else {
this.isTerminated = true;
}
@@ -198,7 +199,7 @@ class CommandorPage {
const intervalTask = setInterval(() => {
if (this.isTerminated) {
log(this.device.model() + ":request terminated, send cancel()");
this.resetBrowser();
// this.resetBrowser();
clearInterval(intervalTask)
cancel()
// return this.browser
@@ -221,11 +222,16 @@ class CommandorPage {
console.log("button is " + button)
if (button) {
console.log("will click on the button")
try {
await button.click();
}
if (this.firstStart) {
this.disconnectBrowser()
}
} catch (e) {
console.log(e)
}
}
// if (this.page.url() === RDV_URL) {
// if (!this.isFillingFields)
// await this.fillFields(this.page, false);
@@ -285,7 +291,7 @@ class CommandorPage {
await delay(getRandomWaitTime())
console.log("will clear email field");
await page.evaluate(() => {
let field = document.getElementById("#email");
let field = document.getElementById("email");
if (field) {
field.value = ""
}
@@ -307,7 +313,7 @@ class CommandorPage {
await page.focus(PHONE_NUMBER);
console.log("will clear phone_number field");
await page.evaluate(() => {
let field = document.getElementById("#phone_number");
let field = document.getElementById("phone_number");
if (field) {
field.value = ""
}
@@ -334,7 +340,7 @@ class CommandorPage {
await delay(getRandomWaitTime());
console.log("will clear surname field");
await page.evaluate(() => {
let field = document.getElementById("#surname");
let field = document.getElementById("surname");
if (field) {
field.value = ""
}
@@ -345,7 +351,7 @@ class CommandorPage {
await delay(getRandomWaitTime());
console.log("will clear name field");
await page.evaluate(() => {
let field = document.getElementById("#name");
let field = document.getElementById("name");
if (field) {
field.value = ""
}
@@ -368,7 +374,7 @@ class CommandorPage {
await delay(getRandomWaitTime());
console.log("will clear passport_id field");
await page.evaluate(() => {
let field = document.getElementById("#passport_id");
let field = document.getElementById("passport_id");
if (field) {
field.value = ""
}
@@ -473,8 +479,7 @@ class CommandorPage {
document.getElementsByClassName("btn")[0].click();
})
if (this.firstStart) {
logWithDevice("will disconnect browser", this.device);
this.browser.disconnect();
this.disconnectBrowser();
await this.checkResultWithOcr();
}
} catch (e) {
@@ -679,8 +684,8 @@ class CommandorPage {
// this.disconnectBrowser();
await this.device.shell("pm clear " + this.browserPackageName)
await delay(1000)
await this.device.shell("am start -n " + this.browserPackageName + "/com.google.android.apps.chrome.Main")
await delay(2000);
// await this.device.shell("am start -n " + this.browserPackageName + "/com.google.android.apps.chrome.Main")
// await delay(2000);
this.isTerminated = true;
// await this.checkResultWithOcr();
}
@@ -719,7 +724,7 @@ class CommandorPage {
break;
case OCRResult.FILL_FIELD:
console.log("browser.isConnected: " + this.browser.isConnected());
while (!this.browser.isConnected()) {
if (!this.browser.isConnected()) {
logWithDevice("trying to connect to browser", this.device)
try {
this.browser = await puppeteer.connect({
@@ -735,14 +740,16 @@ class CommandorPage {
await this.page.bringToFront();
// this.page = pages;
// this.page.await
await this.fillFields(this.page)
await delay(2 * 1000);
} catch (e) {
console.log(e)
this.isTerminated = true
}
}
await this.fillFields(this.page)
// if (!this.browser.isConnected()) {
// this.isTerminated = true;
// }
break;
case OCRResult.SUCCESS:
// reconnect to page and get url
@@ -758,6 +765,11 @@ class CommandorPage {
case OCRResult.RECAPTCHA_ERROR:
this.isTerminated = true;
break;
case OCRResult.TO_SKIP:
logWithDevice("TO_SKIP", this.device)
this.device.shell("input tap " + 488 + " " + 1848)
await delay(2000);
break;
case OCRResult.TO_REFRESH:
await this.connect_to_browser(OCRResult.TO_REFRESH)
break;
@@ -768,13 +780,8 @@ class CommandorPage {
await this.clickOnlineAppointment();
break;
case OCRResult.CONFIRM_RESEND_FORM:
logWithDevice("CONFIRM_RESEND_FORM", this.device)
if (this.device.model() === "CPH2219") {
this.device.shell("input tap " + 870 + " " + 1532)
} else
this.device.shell("input tap " + 884 + " " + 1543)
await delay(2000);
await this.checkResultWithOcr();
// logWithDevice("CONFIRM_RESEND_FORM", this.device)
// await this.checkResultWithOcr();
break;
case OCRResult.PAGE_OPTIMIZATION:
logWithDevice("PAGE_OPTIMIZATION", this.device)
@@ -782,7 +789,13 @@ class CommandorPage {
await delay(2000);
this.device.shell("input tap " + 800 + " " + 2215)
await delay(1000);
checkResult = this.ocrChecker.get_result();
await this.checkResultWithOcr();
break;
case OCRResult.GOOGLE_DISCONNECT:
logWithDevice("GOOGLE_DISCONNECT", this.device)
this.device.shell("input tap " + 411 + " " + 2100)
await delay(2000);
await this.checkResultWithOcr();
break
case OCRResult.NEED_TO_CLICK_LATE_BTN:
await this.tapLaterBtn()
@@ -803,6 +816,14 @@ class CommandorPage {
}
}
async clickOnConfirmBtn() {
if (this.device.model() === "CPH2219") {
this.device.shell("input tap " + 900 + " " + 1532)
} else
this.device.shell("input tap " + 933 + " " + 1538)
await delay(2000);
}
async closePage() {
await this.resetBrowser();
// while (!this.browser.isConnected()) {
+7 -1
View File
@@ -36,7 +36,9 @@ const PAGE_OPTIMIZATION_CHROME_FR_5 = "Avec la mesure des performance"
const ONLINE_APPOINTMENT = "Online Appointment"
const CONFIRM_RESEND_FORM_FR = "Confirmer le nouvel envoi"
const CLOSED_MESSAGE_FR = "Depuis plus de 130 ans"
const ABOUT_BLANK = " about:blank"
const DIALOG_TO_SKIP = "facilement les commandes"
const ABOUT_BLANK = "about:blank"
const GOOGLE_DISCONNECT_FR = "Rester déconnecté"
async function convertImageToWhiteBlack(image_path) {
const image = await Jimp.read(image_path);
@@ -90,6 +92,10 @@ class OCRChecker {
return OCRResult.CLOSED
} else if (result.includes(ABOUT_BLANK)) {
return OCRResult.TERMINAED
} else if (result.includes(DIALOG_TO_SKIP)) {
return OCRResult.TO_SKIP
} else if (result.includes(GOOGLE_DISCONNECT_FR)) {
return OCRResult.GOOGLE_DISCONNECT
}
} catch (e) {
console.log(e)
+1 -1
View File
@@ -54,7 +54,7 @@ class SlidingCaptchaSolver {
let targetPosition = detectedPositionList.filter((positionInfo) => {
return positionInfo.label === "target"
})[0]
if (startPosition !== undefined) {
if (startPosition !== undefined && targetPosition !== undefined) {
let y0 = (startPosition.y2 + startPosition.y1) / 2.0;
let x0 = (startPosition.x2 + startPosition.x1) / 2.0;
let y1 = (targetPosition.y2 + targetPosition.y1) / 2.0;