add more logs

This commit is contained in:
Lei PAN
2023-06-13 21:21:21 +02:00
parent 577ca37c24
commit 1e512f4909
+45 -17
View File
@@ -57,7 +57,7 @@ function log(message) {
}
function logWithDevice(message, device) {
appointmentLogger.log({level: "info", message: device.model() + ":" + message})
appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message})
}
class CommandorPage {
@@ -134,10 +134,16 @@ class CommandorPage {
}
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")
await delay(5 * 1000);
} catch (e) {
console.log(e)
this.isTerminated = true;
}
// Connect to the device.
logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device);
if (this.browser) {
logWithDevice("browser.isConnected is " + this.browser.isConnected(), this.device);
}
@@ -262,7 +268,8 @@ class CommandorPage {
}
async chooseCountry(page) {
if (this.browser.isConnected()) {
logWithDevice("chooseCountry", this.device)
if (this.browser.isConnected() && !this.isTerminated) {
try {
if (!this.isCountryChoosen) {
await page.focus(COUNTRY_ID);
@@ -281,8 +288,9 @@ class CommandorPage {
}
async fillEmail(page) {
logWithDevice("fillEmail", this.device)
try {
if (this.browser.isConnected()) {
if (this.browser.isConnected() && !this.isTerminated) {
if (!this.isEmailFilled) {
await page.focus(EMAIL_ID);
await delay(getRandomWaitTime())
@@ -304,8 +312,10 @@ class CommandorPage {
}
async inputPhoneNumber(page) {
logWithDevice("inputPhoneNumber", this.device)
try {
if (this.browser.isConnected()) {
if (this.browser.isConnected() && !this.isTerminated) {
if (!this.isPhoneInput) {
await page.focus(PHONE_NUMBER);
console.log("will clear phone_number field");
@@ -328,10 +338,12 @@ class CommandorPage {
}
async inputName(page) {
logWithDevice("inputName", this.device)
await delay(getRandomWaitTime());
try {
logWithDevice("input name called with this.browser.isConnected=" + this.browser.isConnected(), 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) {
await page.focus(LAST_NAME);
await delay(getRandomWaitTime());
@@ -343,7 +355,13 @@ class CommandorPage {
}
})
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 delay(getRandomWaitTime());
console.log("will clear name field");
@@ -364,8 +382,9 @@ class CommandorPage {
}
async inputPassportId(page) {
logWithDevice("inputPassportId", this.device)
try {
if (this.browser.isConnected()) {
if (this.browser.isConnected() && !this.isTerminated) {
if (!this.isPasspordInput) {
await page.focus(PASSPORT_ID);
await delay(getRandomWaitTime());
@@ -389,8 +408,9 @@ class CommandorPage {
}
async checkCGU(page) {
logWithDevice("checkCGU", this.device)
try {
if (this.browser.isConnected()) {
if (this.browser.isConnected() && !this.isTerminated) {
if (!this.cguChecked) {
await page.focus(CGU_ID);
await page.evaluate(() => {
@@ -417,12 +437,14 @@ class CommandorPage {
}
async chooseStore(page) {
logWithDevice("chooseStore", this.device)
await delay(getRandomWaitTime())
try {
if (this.browser.isConnected()) {
if (!this.page.isClosed() && !this.isTerminated) {
if (this.selectedStore !== "random") {
page.focus(PREFER_STORE);
await delay(1000)
page.click(PREFER_STORE);
// page.focus(PREFER_STORE);
await delay(500)
// page.click(PREFER_STORE);
let stores = this.selectedStore.split(":")
this.choosedStore = stores[Math.floor(Math.random() * stores.length)]
await page.select(PREFER_STORE, this.choosedStore);
@@ -436,9 +458,9 @@ class CommandorPage {
async fillFields(page, airePlanMode) {
log("fillFields called for contact: " + this.contact.mail)
log("this.isFillingFields: " + this.isFillingFields);
if (!this.isFillingFields) {
logWithDevice("fillFields called for contact: " + this.contact.mail, this.device)
logWithDevice("this.isFillingFields: " + this.isFillingFields, this.device);
if (!this.isFillingFields && !this.isTerminated) {
this.isFillingFields = true;
if (airePlanMode) {
// await this.enableDisableAirPlanMode();
@@ -496,11 +518,13 @@ class CommandorPage {
}
async resolveCaptcha(page) {
logWithDevice("resolveCaptcha", this.device)
if (RDV_URL.includes("192")) {
// await this.push_message_to_queue(PublishType.SUCCESS)
await delay(100000)
return
}
try {
//check whether there is captcha
let pageContent = await page.content()
let hasCaptcha = pageContent.includes("g-recaptcha-response")
@@ -512,7 +536,7 @@ class CommandorPage {
logWithDevice("solution is: " + solution, this.device);
if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) {
try {
if (!page.isClosed()) {
if (!page.isClosed() && !this.isTerminated) {
if (this.browser.isConnected()) {
page.evaluate((solution) => {
let element = document.getElementById("g-recaptcha-response");
@@ -533,6 +557,10 @@ class CommandorPage {
} else {
await this.clickValid();
}
} catch (e) {
console.log(e)
this.isTerminated = true;
}
}
async onPageLoad(currentPage) {