check null in SlidingCaptchaSolver.js
This commit is contained in:
@@ -11,6 +11,8 @@ const OCRResult = {
|
|||||||
RECHECK: Symbol("RECHECK"),
|
RECHECK: Symbol("RECHECK"),
|
||||||
CLOSED: Symbol("CLOSED"),
|
CLOSED: Symbol("CLOSED"),
|
||||||
TERMINAED: Symbol("TERMINAED"),
|
TERMINAED: Symbol("TERMINAED"),
|
||||||
|
GOOGLE_DISCONNECT: Symbol("GOOGLE_DISCONNECT"),
|
||||||
|
TO_SKIP: Symbol("TO_SKIP"),
|
||||||
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
|
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
|
||||||
}
|
}
|
||||||
module.exports = OCRResult
|
module.exports = OCRResult
|
||||||
@@ -120,6 +120,7 @@ class CommandorPage {
|
|||||||
logWithDevice("will send cmd:" + cmd, this.device)
|
logWithDevice("will send cmd:" + cmd, this.device)
|
||||||
this.device.shell(cmd);
|
this.device.shell(cmd);
|
||||||
await delay(3000);
|
await delay(3000);
|
||||||
|
await this.clickOnConfirmBtn();
|
||||||
await this.checkResultWithOcr();
|
await this.checkResultWithOcr();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -187,9 +188,9 @@ class CommandorPage {
|
|||||||
await this.enableDisableAirPlanMode();
|
await this.enableDisableAirPlanMode();
|
||||||
await delay(10 * 1000);
|
await delay(10 * 1000);
|
||||||
await this.clickOnlineAppointment();
|
await this.clickOnlineAppointment();
|
||||||
await delay(2000);
|
// await delay(2000);
|
||||||
if (!this.isTerminated)
|
// if (!this.isTerminated)
|
||||||
await this.clickOnlineAppointment();
|
// await this.clickOnlineAppointment();
|
||||||
} else {
|
} else {
|
||||||
this.isTerminated = true;
|
this.isTerminated = true;
|
||||||
}
|
}
|
||||||
@@ -198,7 +199,7 @@ class CommandorPage {
|
|||||||
const intervalTask = setInterval(() => {
|
const intervalTask = setInterval(() => {
|
||||||
if (this.isTerminated) {
|
if (this.isTerminated) {
|
||||||
log(this.device.model() + ":request terminated, send cancel()");
|
log(this.device.model() + ":request terminated, send cancel()");
|
||||||
this.resetBrowser();
|
// this.resetBrowser();
|
||||||
clearInterval(intervalTask)
|
clearInterval(intervalTask)
|
||||||
cancel()
|
cancel()
|
||||||
// return this.browser
|
// return this.browser
|
||||||
@@ -221,11 +222,16 @@ class CommandorPage {
|
|||||||
console.log("button is " + button)
|
console.log("button is " + button)
|
||||||
if (button) {
|
if (button) {
|
||||||
console.log("will click on the button")
|
console.log("will click on the button")
|
||||||
|
try {
|
||||||
await button.click();
|
await button.click();
|
||||||
}
|
|
||||||
if (this.firstStart) {
|
if (this.firstStart) {
|
||||||
this.disconnectBrowser()
|
this.disconnectBrowser()
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if (this.page.url() === RDV_URL) {
|
// if (this.page.url() === RDV_URL) {
|
||||||
// if (!this.isFillingFields)
|
// if (!this.isFillingFields)
|
||||||
// await this.fillFields(this.page, false);
|
// await this.fillFields(this.page, false);
|
||||||
@@ -285,7 +291,7 @@ class CommandorPage {
|
|||||||
await delay(getRandomWaitTime())
|
await delay(getRandomWaitTime())
|
||||||
console.log("will clear email field");
|
console.log("will clear email field");
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
let field = document.getElementById("#email");
|
let field = document.getElementById("email");
|
||||||
if (field) {
|
if (field) {
|
||||||
field.value = ""
|
field.value = ""
|
||||||
}
|
}
|
||||||
@@ -307,7 +313,7 @@ class CommandorPage {
|
|||||||
await page.focus(PHONE_NUMBER);
|
await page.focus(PHONE_NUMBER);
|
||||||
console.log("will clear phone_number field");
|
console.log("will clear phone_number field");
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
let field = document.getElementById("#phone_number");
|
let field = document.getElementById("phone_number");
|
||||||
if (field) {
|
if (field) {
|
||||||
field.value = ""
|
field.value = ""
|
||||||
}
|
}
|
||||||
@@ -334,7 +340,7 @@ class CommandorPage {
|
|||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
console.log("will clear surname field");
|
console.log("will clear surname field");
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
let field = document.getElementById("#surname");
|
let field = document.getElementById("surname");
|
||||||
if (field) {
|
if (field) {
|
||||||
field.value = ""
|
field.value = ""
|
||||||
}
|
}
|
||||||
@@ -345,7 +351,7 @@ class CommandorPage {
|
|||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
console.log("will clear name field");
|
console.log("will clear name field");
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
let field = document.getElementById("#name");
|
let field = document.getElementById("name");
|
||||||
if (field) {
|
if (field) {
|
||||||
field.value = ""
|
field.value = ""
|
||||||
}
|
}
|
||||||
@@ -368,7 +374,7 @@ class CommandorPage {
|
|||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
console.log("will clear passport_id field");
|
console.log("will clear passport_id field");
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
let field = document.getElementById("#passport_id");
|
let field = document.getElementById("passport_id");
|
||||||
if (field) {
|
if (field) {
|
||||||
field.value = ""
|
field.value = ""
|
||||||
}
|
}
|
||||||
@@ -473,8 +479,7 @@ class CommandorPage {
|
|||||||
document.getElementsByClassName("btn")[0].click();
|
document.getElementsByClassName("btn")[0].click();
|
||||||
})
|
})
|
||||||
if (this.firstStart) {
|
if (this.firstStart) {
|
||||||
logWithDevice("will disconnect browser", this.device);
|
this.disconnectBrowser();
|
||||||
this.browser.disconnect();
|
|
||||||
await this.checkResultWithOcr();
|
await this.checkResultWithOcr();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -679,8 +684,8 @@ class CommandorPage {
|
|||||||
// this.disconnectBrowser();
|
// this.disconnectBrowser();
|
||||||
await this.device.shell("pm clear " + this.browserPackageName)
|
await this.device.shell("pm clear " + this.browserPackageName)
|
||||||
await delay(1000)
|
await delay(1000)
|
||||||
await this.device.shell("am start -n " + this.browserPackageName + "/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();
|
||||||
}
|
}
|
||||||
@@ -719,7 +724,7 @@ class CommandorPage {
|
|||||||
break;
|
break;
|
||||||
case OCRResult.FILL_FIELD:
|
case OCRResult.FILL_FIELD:
|
||||||
console.log("browser.isConnected: " + this.browser.isConnected());
|
console.log("browser.isConnected: " + this.browser.isConnected());
|
||||||
while (!this.browser.isConnected()) {
|
if (!this.browser.isConnected()) {
|
||||||
logWithDevice("trying to connect to browser", this.device)
|
logWithDevice("trying to connect to browser", this.device)
|
||||||
try {
|
try {
|
||||||
this.browser = await puppeteer.connect({
|
this.browser = await puppeteer.connect({
|
||||||
@@ -735,14 +740,16 @@ class CommandorPage {
|
|||||||
await this.page.bringToFront();
|
await this.page.bringToFront();
|
||||||
// this.page = pages;
|
// this.page = pages;
|
||||||
// this.page.await
|
// this.page.await
|
||||||
|
await this.fillFields(this.page)
|
||||||
await delay(2 * 1000);
|
await delay(2 * 1000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
this.isTerminated = true
|
this.isTerminated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
await this.fillFields(this.page)
|
// if (!this.browser.isConnected()) {
|
||||||
|
// this.isTerminated = true;
|
||||||
|
// }
|
||||||
break;
|
break;
|
||||||
case OCRResult.SUCCESS:
|
case OCRResult.SUCCESS:
|
||||||
// reconnect to page and get url
|
// reconnect to page and get url
|
||||||
@@ -758,6 +765,11 @@ class CommandorPage {
|
|||||||
case OCRResult.RECAPTCHA_ERROR:
|
case OCRResult.RECAPTCHA_ERROR:
|
||||||
this.isTerminated = true;
|
this.isTerminated = true;
|
||||||
break;
|
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:
|
case OCRResult.TO_REFRESH:
|
||||||
await this.connect_to_browser(OCRResult.TO_REFRESH)
|
await this.connect_to_browser(OCRResult.TO_REFRESH)
|
||||||
break;
|
break;
|
||||||
@@ -768,13 +780,8 @@ class CommandorPage {
|
|||||||
await this.clickOnlineAppointment();
|
await this.clickOnlineAppointment();
|
||||||
break;
|
break;
|
||||||
case OCRResult.CONFIRM_RESEND_FORM:
|
case OCRResult.CONFIRM_RESEND_FORM:
|
||||||
logWithDevice("CONFIRM_RESEND_FORM", this.device)
|
// logWithDevice("CONFIRM_RESEND_FORM", this.device)
|
||||||
if (this.device.model() === "CPH2219") {
|
// await this.checkResultWithOcr();
|
||||||
this.device.shell("input tap " + 870 + " " + 1532)
|
|
||||||
} else
|
|
||||||
this.device.shell("input tap " + 884 + " " + 1543)
|
|
||||||
await delay(2000);
|
|
||||||
await this.checkResultWithOcr();
|
|
||||||
break;
|
break;
|
||||||
case OCRResult.PAGE_OPTIMIZATION:
|
case OCRResult.PAGE_OPTIMIZATION:
|
||||||
logWithDevice("PAGE_OPTIMIZATION", this.device)
|
logWithDevice("PAGE_OPTIMIZATION", this.device)
|
||||||
@@ -782,7 +789,13 @@ class CommandorPage {
|
|||||||
await delay(2000);
|
await delay(2000);
|
||||||
this.device.shell("input tap " + 800 + " " + 2215)
|
this.device.shell("input tap " + 800 + " " + 2215)
|
||||||
await delay(1000);
|
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
|
break
|
||||||
case OCRResult.NEED_TO_CLICK_LATE_BTN:
|
case OCRResult.NEED_TO_CLICK_LATE_BTN:
|
||||||
await this.tapLaterBtn()
|
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() {
|
async closePage() {
|
||||||
await this.resetBrowser();
|
await this.resetBrowser();
|
||||||
// while (!this.browser.isConnected()) {
|
// while (!this.browser.isConnected()) {
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ const PAGE_OPTIMIZATION_CHROME_FR_5 = "Avec la mesure des performance"
|
|||||||
const ONLINE_APPOINTMENT = "Online Appointment"
|
const ONLINE_APPOINTMENT = "Online Appointment"
|
||||||
const CONFIRM_RESEND_FORM_FR = "Confirmer le nouvel envoi"
|
const CONFIRM_RESEND_FORM_FR = "Confirmer le nouvel envoi"
|
||||||
const CLOSED_MESSAGE_FR = "Depuis plus de 130 ans"
|
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) {
|
async function convertImageToWhiteBlack(image_path) {
|
||||||
const image = await Jimp.read(image_path);
|
const image = await Jimp.read(image_path);
|
||||||
@@ -90,6 +92,10 @@ class OCRChecker {
|
|||||||
return OCRResult.CLOSED
|
return OCRResult.CLOSED
|
||||||
} else if (result.includes(ABOUT_BLANK)) {
|
} else if (result.includes(ABOUT_BLANK)) {
|
||||||
return OCRResult.TERMINAED
|
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) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class SlidingCaptchaSolver {
|
|||||||
let targetPosition = detectedPositionList.filter((positionInfo) => {
|
let targetPosition = detectedPositionList.filter((positionInfo) => {
|
||||||
return positionInfo.label === "target"
|
return positionInfo.label === "target"
|
||||||
})[0]
|
})[0]
|
||||||
if (startPosition !== undefined) {
|
if (startPosition !== undefined && targetPosition !== undefined) {
|
||||||
let y0 = (startPosition.y2 + startPosition.y1) / 2.0;
|
let y0 = (startPosition.y2 + startPosition.y1) / 2.0;
|
||||||
let x0 = (startPosition.x2 + startPosition.x1) / 2.0;
|
let x0 = (startPosition.x2 + startPosition.x1) / 2.0;
|
||||||
let y1 = (targetPosition.y2 + targetPosition.y1) / 2.0;
|
let y1 = (targetPosition.y2 + targetPosition.y1) / 2.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user