add more logs
This commit is contained in:
@@ -57,7 +57,7 @@ function log(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function logWithDevice(message, device) {
|
function logWithDevice(message, device) {
|
||||||
appointmentLogger.log({level: "info", message: device.model() + ":" + message})
|
appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message})
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommandorPage {
|
class CommandorPage {
|
||||||
@@ -134,10 +134,16 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadPage() {
|
async loadPage() {
|
||||||
|
logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device);
|
||||||
|
try {
|
||||||
this.device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main")
|
this.device.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main")
|
||||||
await delay(5 * 1000);
|
await delay(5 * 1000);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
this.isTerminated = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to the device.
|
// Connect to the device.
|
||||||
logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device);
|
|
||||||
if (this.browser) {
|
if (this.browser) {
|
||||||
logWithDevice("browser.isConnected is " + this.browser.isConnected(), this.device);
|
logWithDevice("browser.isConnected is " + this.browser.isConnected(), this.device);
|
||||||
}
|
}
|
||||||
@@ -262,7 +268,8 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async chooseCountry(page) {
|
async chooseCountry(page) {
|
||||||
if (this.browser.isConnected()) {
|
logWithDevice("chooseCountry", this.device)
|
||||||
|
if (this.browser.isConnected() && !this.isTerminated) {
|
||||||
try {
|
try {
|
||||||
if (!this.isCountryChoosen) {
|
if (!this.isCountryChoosen) {
|
||||||
await page.focus(COUNTRY_ID);
|
await page.focus(COUNTRY_ID);
|
||||||
@@ -281,8 +288,9 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fillEmail(page) {
|
async fillEmail(page) {
|
||||||
|
logWithDevice("fillEmail", this.device)
|
||||||
try {
|
try {
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected() && !this.isTerminated) {
|
||||||
if (!this.isEmailFilled) {
|
if (!this.isEmailFilled) {
|
||||||
await page.focus(EMAIL_ID);
|
await page.focus(EMAIL_ID);
|
||||||
await delay(getRandomWaitTime())
|
await delay(getRandomWaitTime())
|
||||||
@@ -304,8 +312,10 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async inputPhoneNumber(page) {
|
async inputPhoneNumber(page) {
|
||||||
|
logWithDevice("inputPhoneNumber", this.device)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected() && !this.isTerminated) {
|
||||||
if (!this.isPhoneInput) {
|
if (!this.isPhoneInput) {
|
||||||
await page.focus(PHONE_NUMBER);
|
await page.focus(PHONE_NUMBER);
|
||||||
console.log("will clear phone_number field");
|
console.log("will clear phone_number field");
|
||||||
@@ -328,10 +338,12 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async inputName(page) {
|
async inputName(page) {
|
||||||
|
logWithDevice("inputName", this.device)
|
||||||
|
await delay(getRandomWaitTime());
|
||||||
try {
|
try {
|
||||||
logWithDevice("input name called with this.browser.isConnected=" + this.browser.isConnected(), this.device)
|
logWithDevice("input name called with this.browser.isConnected=" + this.browser.isConnected(), this.device)
|
||||||
logWithDevice("input name called with this.isNameInput=" + this.isNameInput, this.device)
|
logWithDevice("input name called with this.isNameInput=" + this.isNameInput, this.device)
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected() && !this.isTerminated) {
|
||||||
if (!this.isNameInput) {
|
if (!this.isNameInput) {
|
||||||
await page.focus(LAST_NAME);
|
await page.focus(LAST_NAME);
|
||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
@@ -343,7 +355,13 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
await delay(1000);
|
await delay(1000);
|
||||||
await page.keyboard.type(this.contact.lastName);
|
// await page.keyboard.type(this.contact.lastName);
|
||||||
|
await page.evaluate((lastName) => {
|
||||||
|
let field = document.getElementById("surname");
|
||||||
|
if (field) {
|
||||||
|
field.value = lastName
|
||||||
|
}
|
||||||
|
}, this.contact.lastName)
|
||||||
await page.focus(FIRST_NAME);
|
await page.focus(FIRST_NAME);
|
||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
console.log("will clear name field");
|
console.log("will clear name field");
|
||||||
@@ -364,8 +382,9 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async inputPassportId(page) {
|
async inputPassportId(page) {
|
||||||
|
logWithDevice("inputPassportId", this.device)
|
||||||
try {
|
try {
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected() && !this.isTerminated) {
|
||||||
if (!this.isPasspordInput) {
|
if (!this.isPasspordInput) {
|
||||||
await page.focus(PASSPORT_ID);
|
await page.focus(PASSPORT_ID);
|
||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
@@ -389,8 +408,9 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkCGU(page) {
|
async checkCGU(page) {
|
||||||
|
logWithDevice("checkCGU", this.device)
|
||||||
try {
|
try {
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected() && !this.isTerminated) {
|
||||||
if (!this.cguChecked) {
|
if (!this.cguChecked) {
|
||||||
await page.focus(CGU_ID);
|
await page.focus(CGU_ID);
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
@@ -417,12 +437,14 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async chooseStore(page) {
|
async chooseStore(page) {
|
||||||
|
logWithDevice("chooseStore", this.device)
|
||||||
|
await delay(getRandomWaitTime())
|
||||||
try {
|
try {
|
||||||
if (this.browser.isConnected()) {
|
if (!this.page.isClosed() && !this.isTerminated) {
|
||||||
if (this.selectedStore !== "random") {
|
if (this.selectedStore !== "random") {
|
||||||
page.focus(PREFER_STORE);
|
// page.focus(PREFER_STORE);
|
||||||
await delay(1000)
|
await delay(500)
|
||||||
page.click(PREFER_STORE);
|
// page.click(PREFER_STORE);
|
||||||
let stores = this.selectedStore.split(":")
|
let stores = this.selectedStore.split(":")
|
||||||
this.choosedStore = stores[Math.floor(Math.random() * stores.length)]
|
this.choosedStore = stores[Math.floor(Math.random() * stores.length)]
|
||||||
await page.select(PREFER_STORE, this.choosedStore);
|
await page.select(PREFER_STORE, this.choosedStore);
|
||||||
@@ -436,9 +458,9 @@ class CommandorPage {
|
|||||||
|
|
||||||
|
|
||||||
async fillFields(page, airePlanMode) {
|
async fillFields(page, airePlanMode) {
|
||||||
log("fillFields called for contact: " + this.contact.mail)
|
logWithDevice("fillFields called for contact: " + this.contact.mail, this.device)
|
||||||
log("this.isFillingFields: " + this.isFillingFields);
|
logWithDevice("this.isFillingFields: " + this.isFillingFields, this.device);
|
||||||
if (!this.isFillingFields) {
|
if (!this.isFillingFields && !this.isTerminated) {
|
||||||
this.isFillingFields = true;
|
this.isFillingFields = true;
|
||||||
if (airePlanMode) {
|
if (airePlanMode) {
|
||||||
// await this.enableDisableAirPlanMode();
|
// await this.enableDisableAirPlanMode();
|
||||||
@@ -496,11 +518,13 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async resolveCaptcha(page) {
|
async resolveCaptcha(page) {
|
||||||
|
logWithDevice("resolveCaptcha", this.device)
|
||||||
if (RDV_URL.includes("192")) {
|
if (RDV_URL.includes("192")) {
|
||||||
// await this.push_message_to_queue(PublishType.SUCCESS)
|
// await this.push_message_to_queue(PublishType.SUCCESS)
|
||||||
await delay(100000)
|
await delay(100000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
//check whether there is captcha
|
//check whether there is captcha
|
||||||
let pageContent = await page.content()
|
let pageContent = await page.content()
|
||||||
let hasCaptcha = pageContent.includes("g-recaptcha-response")
|
let hasCaptcha = pageContent.includes("g-recaptcha-response")
|
||||||
@@ -512,7 +536,7 @@ class CommandorPage {
|
|||||||
logWithDevice("solution is: " + solution, this.device);
|
logWithDevice("solution is: " + solution, this.device);
|
||||||
if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) {
|
if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) {
|
||||||
try {
|
try {
|
||||||
if (!page.isClosed()) {
|
if (!page.isClosed() && !this.isTerminated) {
|
||||||
if (this.browser.isConnected()) {
|
if (this.browser.isConnected()) {
|
||||||
page.evaluate((solution) => {
|
page.evaluate((solution) => {
|
||||||
let element = document.getElementById("g-recaptcha-response");
|
let element = document.getElementById("g-recaptcha-response");
|
||||||
@@ -533,6 +557,10 @@ class CommandorPage {
|
|||||||
} else {
|
} else {
|
||||||
await this.clickValid();
|
await this.clickValid();
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
this.isTerminated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPageLoad(currentPage) {
|
async onPageLoad(currentPage) {
|
||||||
|
|||||||
Reference in New Issue
Block a user