can close the last page
This commit is contained in:
@@ -13,14 +13,12 @@
|
|||||||
"@nodegui/nodegui": "^0.57.1",
|
"@nodegui/nodegui": "^0.57.1",
|
||||||
"alert": "^5.1.1",
|
"alert": "^5.1.1",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
|
||||||
"mongodb": "^4.9.1",
|
"mongodb": "^4.9.1",
|
||||||
"mongoose": "^6.5.4",
|
"mongoose": "^6.5.4",
|
||||||
"node-schedule": "^2.1.0",
|
"node-schedule": "^2.1.0",
|
||||||
"node-tesseract-ocr": "^2.2.1",
|
"node-tesseract-ocr": "^2.2.1",
|
||||||
"node-wget": "^0.4.3",
|
"node-wget": "^0.4.3",
|
||||||
"node-xlsx": "^0.21.0",
|
"node-xlsx": "^0.21.0",
|
||||||
"opencv4nodejs": "wandenberg/opencv4nodejs",
|
|
||||||
"playwright": "^1.32.1",
|
"playwright": "^1.32.1",
|
||||||
"puppeteer": "^15.5.0",
|
"puppeteer": "^15.5.0",
|
||||||
"read-ini-file": "^3.0.1",
|
"read-ini-file": "^3.0.1",
|
||||||
|
|||||||
@@ -198,7 +198,6 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
|||||||
console.log('Output was:\n', output);
|
console.log('Output was:\n', output);
|
||||||
}
|
}
|
||||||
// start chrome
|
// start chrome
|
||||||
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")
|
// device.shell("am start -n com.brave.browser/com.google.android.apps.chrome.Main")
|
||||||
return attributedPort
|
return attributedPort
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const OCRResult = {
|
|||||||
PAGE_OPTIMIZATION: Symbol("PAGE_OPTIMIZATION"),
|
PAGE_OPTIMIZATION: Symbol("PAGE_OPTIMIZATION"),
|
||||||
CONFIRM_RESEND_FORM: Symbol("CONFIRM_RESEND_FORM"),
|
CONFIRM_RESEND_FORM: Symbol("CONFIRM_RESEND_FORM"),
|
||||||
RECHECK: Symbol("RECHECK"),
|
RECHECK: Symbol("RECHECK"),
|
||||||
|
CLOSED: Symbol("CLOSED"),
|
||||||
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
|
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
|
||||||
}
|
}
|
||||||
module.exports = OCRResult
|
module.exports = OCRResult
|
||||||
@@ -14,6 +14,7 @@ const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
|
|||||||
const OCRChecker = require("./OCRChecker");
|
const OCRChecker = require("./OCRChecker");
|
||||||
const {browser} = require("yarn/lib/cli");
|
const {browser} = require("yarn/lib/cli");
|
||||||
const {disconnect} = require("mongoose");
|
const {disconnect} = require("mongoose");
|
||||||
|
const {execSync} = require("child_process");
|
||||||
// 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"
|
||||||
@@ -81,7 +82,7 @@ class CommandorPage {
|
|||||||
this.isEmailFilled = false;
|
this.isEmailFilled = false;
|
||||||
this.isCountryChoosen = false;
|
this.isCountryChoosen = false;
|
||||||
this.isPhoneInput = false;
|
this.isPhoneInput = false;
|
||||||
this.firstStart = false;
|
this.firstStart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -131,29 +132,39 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadPage() {
|
async loadPage() {
|
||||||
|
this.device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main")
|
||||||
|
await delay(5 * 1000);
|
||||||
// Connect to the device.
|
// Connect to the device.
|
||||||
logWithDevice("loadPage() called, with port:" + this.port, this.device);
|
logWithDevice("loadPage() called, with port:" + this.port, this.device);
|
||||||
|
if (this.browser) {
|
||||||
|
logWithDevice("browser.isConnected is " + this.browser.isConnected(), this.device);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
logWithDevice("connecting to browser:" + this.port, this.device);
|
||||||
|
while (this.browser === undefined || !this.browser.isConnected()) {
|
||||||
this.browser = await puppeteer.connect({
|
this.browser = await puppeteer.connect({
|
||||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||||
headless: false, defaultViewport: null
|
headless: false, defaultViewport: null
|
||||||
})
|
})
|
||||||
|
// let pages = await this.browser.pages();
|
||||||
|
// this.page = pages[0];
|
||||||
this.page = await this.browser.newPage();
|
this.page = await this.browser.newPage();
|
||||||
|
|
||||||
this.page.on("load", (loadedPage) => {
|
this.page.on("load", (loadedPage) => {
|
||||||
this.onPageLoad(loadedPage)
|
this.onPageLoad(loadedPage);
|
||||||
})
|
})
|
||||||
|
|
||||||
this.page.on("response", (response) => {
|
this.page.on("response", (response) => {
|
||||||
this.onResponse(response)
|
this.onResponse(response)
|
||||||
})
|
})
|
||||||
|
await delay(3 * 1000);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.checkResultWithOcr()
|
await this.checkResultWithOcr()
|
||||||
console.log(e)
|
console.log(e)
|
||||||
// this.isTerminated = true
|
// this.isTerminated = true
|
||||||
}
|
}
|
||||||
if (this.page !== undefined) {
|
if (this.page !== undefined) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logWithDevice("will open google", this.device)
|
logWithDevice("will open google", this.device)
|
||||||
if (!this.isTerminated) {
|
if (!this.isTerminated) {
|
||||||
@@ -170,6 +181,7 @@ class CommandorPage {
|
|||||||
await delay(10 * 1000);
|
await delay(10 * 1000);
|
||||||
await this.clickOnlineAppointment();
|
await this.clickOnlineAppointment();
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
|
if (!this.isTerminated)
|
||||||
await this.clickOnlineAppointment();
|
await this.clickOnlineAppointment();
|
||||||
} else {
|
} else {
|
||||||
this.isTerminated = true;
|
this.isTerminated = true;
|
||||||
@@ -191,7 +203,6 @@ class CommandorPage {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// this.page.close()
|
// this.page.close()
|
||||||
// this.device.close()
|
|
||||||
clearInterval(intervalTask)
|
clearInterval(intervalTask)
|
||||||
cancel()
|
cancel()
|
||||||
// return this.browser
|
// return this.browser
|
||||||
@@ -618,7 +629,7 @@ class CommandorPage {
|
|||||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
|
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
|
||||||
reserve.source_from = this.device.model();
|
reserve.source_from = this.device.model();
|
||||||
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
||||||
await this.deleteFromBlackList()
|
// await this.deleteFromBlackList()
|
||||||
// await this.resetBrowser()
|
// await this.resetBrowser()
|
||||||
this.isTerminated = true
|
this.isTerminated = true
|
||||||
}
|
}
|
||||||
@@ -719,19 +730,34 @@ class CommandorPage {
|
|||||||
switch (checkResult) {
|
switch (checkResult) {
|
||||||
case OCRResult.FILL_FIELD:
|
case OCRResult.FILL_FIELD:
|
||||||
console.log("browser.isConnected: " + this.browser.isConnected());
|
console.log("browser.isConnected: " + this.browser.isConnected());
|
||||||
if (!this.browser.isConnected()) {
|
while (!this.browser.isConnected()) {
|
||||||
|
logWithDevice("trying to connect to browser", this.device)
|
||||||
|
// let cmd = 'adb -s ' + this.device.serial() + " forward tcp:" + this.port + " localabstract:chrome_devtools_remote";
|
||||||
|
// console.log("cmd is " + cmd);
|
||||||
|
// const output = execSync(cmd, {encoding: 'utf-8'}); // the default is 'buffer'
|
||||||
|
// console.log('Output was:\n', output);
|
||||||
this.browser = await puppeteer.connect({
|
this.browser = await puppeteer.connect({
|
||||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||||
headless: false, defaultViewport: null
|
headless: false, defaultViewport: null
|
||||||
})
|
})
|
||||||
let pages = await this.browser.pages();
|
let pages = await this.browser.pages();
|
||||||
this.page = pages[0];
|
pages.forEach((currentPage) => {
|
||||||
|
if (currentPage.url() === RDV_URL) {
|
||||||
|
this.page = currentPage;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await this.page.bringToFront();
|
||||||
|
// this.page = pages;
|
||||||
|
// this.page.await
|
||||||
|
await delay(5 * 1000);
|
||||||
}
|
}
|
||||||
await this.fillFields(this.page)
|
await this.fillFields(this.page)
|
||||||
break;
|
break;
|
||||||
case OCRResult.SUCCESS:
|
case OCRResult.SUCCESS:
|
||||||
// reconnect to page and get url
|
// reconnect to page and get url
|
||||||
|
if (!this.isTerminated) {
|
||||||
await this.connect_to_browser(OCRResult.SUCCESS);
|
await this.connect_to_browser(OCRResult.SUCCESS);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OCRResult.RECAPTCHA_ERROR:
|
case OCRResult.RECAPTCHA_ERROR:
|
||||||
this.isTerminated = true;
|
this.isTerminated = true;
|
||||||
@@ -763,6 +789,10 @@ class CommandorPage {
|
|||||||
this.firstStart = true;
|
this.firstStart = true;
|
||||||
await this.loadPage()
|
await this.loadPage()
|
||||||
break;
|
break;
|
||||||
|
case OCRResult.CLOSED:
|
||||||
|
await this.closePage();
|
||||||
|
// this.isTerminated = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
await delay(5000);
|
await delay(5000);
|
||||||
checkResult = ocrChecker.get_result();
|
checkResult = ocrChecker.get_result();
|
||||||
@@ -773,6 +803,25 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async closePage() {
|
||||||
|
while (!this.browser.isConnected()) {
|
||||||
|
logWithDevice("trying to connect to browser", this.device)
|
||||||
|
this.browser = await puppeteer.connect({
|
||||||
|
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||||
|
headless: false, defaultViewport: null
|
||||||
|
})
|
||||||
|
await delay(2 * 1000);
|
||||||
|
}
|
||||||
|
console.log("will close all pages");
|
||||||
|
let pages = await this.browser.pages();
|
||||||
|
await pages[0].close()
|
||||||
|
console.log("page closed");
|
||||||
|
// pages.forEach((currentPage) => {
|
||||||
|
// currentPage.close();
|
||||||
|
// })
|
||||||
|
// await this.browser.close();
|
||||||
|
}
|
||||||
|
|
||||||
async tapLaterBtn() {
|
async tapLaterBtn() {
|
||||||
logWithDevice("tapLaterBtn", this.device)
|
logWithDevice("tapLaterBtn", this.device)
|
||||||
let model = this.device.model();
|
let model = this.device.model();
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ const PAGE_OPTIMIZATION_CHROME_FR_2 = "Vous pouvez modifier vos options a tout m
|
|||||||
const PAGE_OPTIMIZATION_CHROME_FR_3 = "Vous pouvez effectuer des modifications"
|
const PAGE_OPTIMIZATION_CHROME_FR_3 = "Vous pouvez effectuer des modifications"
|
||||||
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"
|
||||||
|
|
||||||
class OCRChecker {
|
class OCRChecker {
|
||||||
|
|
||||||
@@ -72,6 +73,8 @@ class OCRChecker {
|
|||||||
return OCRResult.PAGE_OPTIMIZATION
|
return OCRResult.PAGE_OPTIMIZATION
|
||||||
} else if (result.includes(CONFIRM_RESEND_FORM_FR)) {
|
} else if (result.includes(CONFIRM_RESEND_FORM_FR)) {
|
||||||
return OCRResult.CONFIRM_RESEND_FORM
|
return OCRResult.CONFIRM_RESEND_FORM
|
||||||
|
} else if (result.includes(CLOSED_MESSAGE_FR)) {
|
||||||
|
return OCRResult.CLOSED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user