use adb to reload page
This commit is contained in:
+1
-2
@@ -4,7 +4,6 @@ const CommandorPage = require("./workers/CommandorPage");
|
||||
const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
||||
const alert = require('alert');
|
||||
const schedule = require("node-schedule");
|
||||
const {execSync} = require("child_process");
|
||||
|
||||
const mongoManager = new MongoManager();
|
||||
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
|
||||
@@ -14,7 +13,7 @@ let collectionName = formatDate(new Date())
|
||||
// device_to_excludes = ["47e7e36b", "e30eb015"]
|
||||
// device_to_excludes = ["47e7e36b"]
|
||||
// device_to_excludes = ["J4AXB761H2322WJ"]
|
||||
device_to_excludes = ["e30eb015", "07fbd156", "hi7ljr5xduyt9pfi"]
|
||||
device_to_excludes = ["47e7e36b", "07fbd156", "R9TR608ZLKJ", "heuklr55wo8tfyvw"]
|
||||
attributedPorts = []
|
||||
const device_port_info = new Map();
|
||||
startPort = 9000
|
||||
|
||||
@@ -5,6 +5,9 @@ const OCRResult = {
|
||||
SLIDING_CAPTCHA: Symbol("SLIDING_CAPTCHA"),
|
||||
FILL_FIELD: Symbol("FILL_FIELD"),
|
||||
NEED_TO_CLICK_LATE_BTN: Symbol("NEED_TO_CLICK_LATE_BTN"),
|
||||
ONLINE_APPOINTMENT: Symbol("Online Appointment"),
|
||||
PAGE_OPTIMIZATION: Symbol("PAGE_OPTIMIZATION"),
|
||||
CONFIRM_RESEND_FORM: Symbol("CONFIRM_RESEND_FORM"),
|
||||
RECHECK: Symbol("RECHECK"),
|
||||
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
|
||||
}
|
||||
|
||||
@@ -83,16 +83,16 @@ class CommandorPage {
|
||||
|
||||
async connect_to_browser(ocrResult) {
|
||||
console.log("connect_to_browser() called");
|
||||
console.log("browser.isConnected: " + this.browser.isConnected());
|
||||
// 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
|
||||
})
|
||||
// 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();
|
||||
// let pages = await this.browser.pages();
|
||||
// 0 is the last page
|
||||
this.page = pages[0];
|
||||
// this.page = pages[0];
|
||||
// this.page = pages[pages.length - 1];
|
||||
switch (ocrResult) {
|
||||
case OCRResult.SUCCESS:
|
||||
@@ -102,11 +102,15 @@ class CommandorPage {
|
||||
break;
|
||||
case OCRResult.TO_REFRESH:
|
||||
logWithDevice("will reload page", this.device)
|
||||
await this.page.reload();
|
||||
await delay(10000);
|
||||
if (!await this.checkIfSuccessful()) {
|
||||
// await this.page.reload();
|
||||
// await delay(10000);
|
||||
// if (!await this.checkIfSuccessful()) {
|
||||
let cmd = "input swipe 382 482 382 1482"
|
||||
logWithDevice("will send cmd:" + cmd, this.device)
|
||||
this.device.shell(cmd);
|
||||
await delay(2000);
|
||||
await this.checkResultWithOcr();
|
||||
}
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -158,23 +162,7 @@ class CommandorPage {
|
||||
this.isTerminated = true
|
||||
}
|
||||
await this.acceptCookies();
|
||||
try {
|
||||
const [button] = await this.page.$x("//a[contains(., 'rendezvousparis')]");
|
||||
console.log("button is " + button)
|
||||
if (button) {
|
||||
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);
|
||||
}
|
||||
} catch (e) {
|
||||
log(e)
|
||||
// if (!this.page.url().includes(RDV_URL)) {
|
||||
// this.isTerminated = true;
|
||||
// }
|
||||
}
|
||||
await this.clickOnlineAppointment();
|
||||
} else {
|
||||
this.isTerminated = true;
|
||||
}
|
||||
@@ -211,7 +199,31 @@ class CommandorPage {
|
||||
}).then(log)
|
||||
}
|
||||
|
||||
async clickOnlineAppointment() {
|
||||
try {
|
||||
logWithDevice("will click on rdv link", this.device);
|
||||
const [button] = await this.page.$x("//a[contains(., 'rendezvousparis')]");
|
||||
console.log("button is " + button)
|
||||
if (button) {
|
||||
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);
|
||||
}
|
||||
} catch (e) {
|
||||
log(e)
|
||||
// if (!this.page.url().includes(RDV_URL)) {
|
||||
// this.isTerminated = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
async acceptCookies() {
|
||||
logWithDevice("will accept Cookies", this.device);
|
||||
if (this.browser.isConnected()) {
|
||||
try {
|
||||
await this.page.evaluate(() => {
|
||||
let buttons = document.getElementsByTagName('button');
|
||||
for (let i = 0; i < buttons.length; i++) {
|
||||
@@ -223,6 +235,11 @@ class CommandorPage {
|
||||
console.log(txt);
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async chooseCountry(page) {
|
||||
@@ -355,7 +372,7 @@ class CommandorPage {
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
this.isTerminated = true;
|
||||
// this.isTerminated = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +399,7 @@ class CommandorPage {
|
||||
}
|
||||
|
||||
async clickValid() {
|
||||
// await this.saveCookies()
|
||||
logWithDevice("clickValid() called.", this.device);
|
||||
await delay(getRandomWaitTime())
|
||||
try {
|
||||
if (!this.page.isClosed()) {
|
||||
@@ -531,10 +548,6 @@ class CommandorPage {
|
||||
// save cookies
|
||||
await this.push_message_to_db(PublishType.SUCCESS, response.url())
|
||||
}
|
||||
// if (response.url().includes("geo.captcha-delivery.com/interstitial")) {
|
||||
// logWithDevice("interstitial: response.status is " + response.status())
|
||||
// await this.setUpCookies()
|
||||
// }
|
||||
}
|
||||
|
||||
async push_message_to_queue(publishType) {
|
||||
@@ -609,16 +622,29 @@ class CommandorPage {
|
||||
this.isEmailFilled = false;
|
||||
this.isCountryChoosen = false;
|
||||
this.isPhoneInput = false;
|
||||
this.browser.disconnect();
|
||||
this.isPasspordInput = false;
|
||||
this.disconnectBrowser();
|
||||
await this.device.shell("pm clear com.android.chrome")
|
||||
await delay(1000)
|
||||
await this.device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main")
|
||||
await delay(5000)
|
||||
await this.checkResultWithOcr();
|
||||
|
||||
await delay(2000);
|
||||
this.isTerminated = true;
|
||||
// await this.checkResultWithOcr();
|
||||
}
|
||||
|
||||
|
||||
canContinue() {
|
||||
return this.browser.isConnected()
|
||||
}
|
||||
|
||||
disconnectBrowser() {
|
||||
try {
|
||||
this.browser.disconnect();
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async checkResultWithOcr() {
|
||||
console.log("checkResultWithOcr() called.")
|
||||
await delay(2000);
|
||||
@@ -654,11 +680,28 @@ class CommandorPage {
|
||||
case OCRResult.BLOCKED:
|
||||
await this.resetBrowser();
|
||||
break;
|
||||
case OCRResult.ONLINE_APPOINTMENT:
|
||||
await this.clickOnlineAppointment();
|
||||
break;
|
||||
case OCRResult.CONFIRM_RESEND_FORM:
|
||||
logWithDevice("CONFIRM_RESEND_FORM", this.device)
|
||||
this.device.shell("input tap " + 871 + " " + 1544)
|
||||
await delay(2000);
|
||||
break;
|
||||
case OCRResult.PAGE_OPTIMIZATION:
|
||||
logWithDevice("PAGE_OPTIMIZATION", this.device)
|
||||
this.device.shell("input tap " + 800 + " " + 2215)
|
||||
await delay(2000);
|
||||
checkResult = ocrChecker.get_result();
|
||||
break
|
||||
case OCRResult.NEED_TO_CLICK_LATE_BTN:
|
||||
await this.tapLaterBtn()
|
||||
this.firstStart = true;
|
||||
await this.loadPage()
|
||||
break;
|
||||
default:
|
||||
await delay(5000);
|
||||
checkResult = ocrChecker.get_result();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,4 +721,5 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommandorPage
|
||||
module
|
||||
.exports = CommandorPage
|
||||
@@ -24,10 +24,14 @@ const BLOCKED_MSG_EN = "have been blocked"
|
||||
const BLOCKED_MSG_FR = "avez été bloqué"
|
||||
const CHECKING_MSG_FR = "Verifying"
|
||||
const ERR_CACHE_MISS = "ERR_CACHE_MISS"
|
||||
const SLIDING_CAPTCHA_FR = "Glissez vers la droite"
|
||||
const SLIDING_CAPTCHA_FR = "Pourquoi cette vérification"
|
||||
const MESSAGE_FILL_FIELD_FR = "Demande de rendez-vous pour"
|
||||
const WELCOME_MESSAGE_FR = "Bienvenue dans Chrome"
|
||||
const PAGE_OPTIMIZATION_CHROME_FR = "Oui, j'accepte"
|
||||
const PAGE_OPTIMIZATION_CHROME_FR = "Vous pouvez changer d'avis a tout moment dans"
|
||||
const PAGE_OPTIMIZATION_CHROME_FR_2 = "Vous pouvez modifier vos options a tout moment"
|
||||
const PAGE_OPTIMIZATION_CHROME_FR_3 = "Vous pouvez effectuer des modifications"
|
||||
const ONLINE_APPOINTMENT = "Online Appointment"
|
||||
const CONFIRM_RESEND_FORM_FR = "Confirmer le nouvel envoi"
|
||||
|
||||
class OCRChecker {
|
||||
|
||||
@@ -62,6 +66,12 @@ class OCRChecker {
|
||||
return OCRResult.FILL_FIELD
|
||||
} else if (result.includes(WELCOME_MESSAGE_FR)) {
|
||||
return OCRResult.NEED_TO_CLICK_LATE_BTN
|
||||
} else if (result.toLowerCase().includes(ONLINE_APPOINTMENT.toLowerCase())) {
|
||||
return OCRResult.ONLINE_APPOINTMENT
|
||||
} else if (result.includes(PAGE_OPTIMIZATION_CHROME_FR) || result.includes(PAGE_OPTIMIZATION_CHROME_FR_2) || result.includes(PAGE_OPTIMIZATION_CHROME_FR_3)) {
|
||||
return OCRResult.PAGE_OPTIMIZATION
|
||||
} else if (result.includes(CONFIRM_RESEND_FORM_FR)) {
|
||||
return OCRResult.CONFIRM_RESEND_FORM
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user