use adb to start browser

This commit is contained in:
Lei PAN
2023-10-25 08:59:46 +02:00
parent cc868e0110
commit 00d70cd00f
3 changed files with 39 additions and 32 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
"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",
"playwright": "^1.32.1", "playwright": "^1.39.0",
"puppeteer": "^15.5.0", "puppeteer": "^15.5.0",
"read-ini-file": "^3.0.1", "read-ini-file": "^3.0.1",
"uuid": "^9.0.0", "uuid": "^9.0.0",
+19 -18
View File
@@ -16,7 +16,7 @@ let excludeMode = DeviceExcludeMode.SIX
let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"] let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"] let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"]
let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"] let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"]
let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h"] let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156"]
let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"] let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"]
let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"] let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"]
attributedPorts = [] attributedPorts = []
@@ -80,12 +80,12 @@ async function filterBlacklistedContacts(contactList) {
return contactsToBook; return contactsToBook;
} }
async function needToBook(contact, mongoManager) { async function needToBook(contact, mongoManager, alreadyBooked) {
console.log("check contact with email " + contact.mail) console.log("check contact with email " + contact.mail)
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); // let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
// let blackListItems = await mongoManager.getAllBlackedListItems(); // let blackListItems = await mongoManager.getAllBlackedListItems();
let blackListItems = []; let blackListItems = [];
let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments(); // let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments();
let needToBook = true; let needToBook = true;
await alreadyBooked.forEach((bookedItem) => { await alreadyBooked.forEach((bookedItem) => {
if (bookedItem.email === contact.mail) { if (bookedItem.email === contact.mail) {
@@ -106,26 +106,27 @@ async function needToBook(contact, mongoManager) {
} }
}) })
} }
if (needToBook) { // if (needToBook) {
await alreadyAcceptedItems.forEach((acceptedItem) => { // await alreadyAcceptedItems.forEach((acceptedItem) => {
if (acceptedItem.email === contact.mail) { // if (acceptedItem.email === contact.mail) {
console.log("=====handle already accepted item===="); // console.log("=====handle already accepted item====");
console.log("accepted_at is " + acceptedItem.accepted_at); // console.log("accepted_at is " + acceptedItem.accepted_at);
console.log("accepted email is " + acceptedItem.email); // console.log("accepted email is " + acceptedItem.email);
needToBook = acceptedItem.accepted_at + NINETY_DAYS_IN_S <= (new Date()) / 1000; // needToBook = acceptedItem.accepted_at + NINETY_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) { // if (!needToBook) {
console.log("already accepted appointment --> skip"); // console.log("already accepted appointment --> skip");
} // }
} // }
}) // })
} // }
return needToBook return needToBook
} }
async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) { async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) {
console.log(`model: ${device.model()}`); console.log(`model: ${device.model()}`);
console.log(`serial: ${device.serial()}`); console.log(`serial: ${device.serial()}`);
if (await needToBook(contactPojo, mongoManager)) { let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
if (await needToBook(contactPojo, mongoManager, alreadyBooked)) {
let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port); let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
//read contacts form excel //read contacts form excel
return await commandor.loadPage(); return await commandor.loadPage();
+19 -13
View File
@@ -146,7 +146,7 @@ class CommandorPage {
async loadPage() { async loadPage() {
logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device); logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device);
try { try {
await this.device.shell("am start -n " + this.browserPackageName + "/com.google.android.apps.chrome.Main") await this.startPage(this.device, this.browserPackageName + "/com.google.android.apps.chrome.Main")
await delay(5 * 1000); await delay(5 * 1000);
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@@ -201,9 +201,6 @@ 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);
// if (!this.isTerminated)
// await this.clickOnlineAppointment();
} else { } else {
this.isTerminated = true; this.isTerminated = true;
} }
@@ -1002,9 +999,9 @@ class CommandorPage {
await this.checkResultWithOcr(); await this.checkResultWithOcr();
break; break;
case OCRResult.BRAVE_PRIVACY_PUB: case OCRResult.BRAVE_PRIVACY_PUB:
if (this.device.model() === "MI 5s") if (this.device.model() === "MI 5s") {
await this.device.shell("input tap " + 60 + " " + 1400) await this.tapForDevice(this.device, 60, 1400)
else } else
await this.tapForDevice(this.device, 455, 1920) await this.tapForDevice(this.device, 455, 1920)
await delay(2000); await delay(2000);
await this.checkResultWithOcr(); await this.checkResultWithOcr();
@@ -1016,7 +1013,8 @@ class CommandorPage {
else if (this.device.model() === "22041219PG") else if (this.device.model() === "22041219PG")
await this.device.shell("input tap " + 530 + " " + 1600) await this.device.shell("input tap " + 530 + " " + 1600)
else else
await this.device.shell("input tap " + 500 + " " + 1680) await this.tapForDevice(this.device, 500, 1680)
// await this.device.shell("input tap " + 500 + " " + 1680)
await delay(2000); await delay(2000);
await this.checkResultWithOcr(); await this.checkResultWithOcr();
break; break;
@@ -1230,9 +1228,9 @@ class CommandorPage {
async tapGoogleDisconnectBtn() { async tapGoogleDisconnectBtn() {
if (this.device.model() === "MI 5s") { if (this.device.model() === "MI 5s") {
if (this.browserPackageName.includes("brave")) if (this.browserPackageName.includes("brave")) {
await this.device.shell("input tap " + 535 + " " + 1629) await this.tapForDevice(this.device, 535, 1629)
else } else
await this.device.shell("input tap " + 550 + " " + 1740) await this.device.shell("input tap " + 550 + " " + 1740)
} else { } else {
if (this.browserPackageName.includes("brave") && this.device.model() === "CPH2219") { if (this.browserPackageName.includes("brave") && this.device.model() === "CPH2219") {
@@ -1243,11 +1241,19 @@ class CommandorPage {
await this.device.shell("input tap " + 411 + " " + 1970) await this.device.shell("input tap " + 411 + " " + 1970)
} else if (this.browserPackageName.includes("brave") && this.device.model() === "22041219PG") { } else if (this.browserPackageName.includes("brave") && this.device.model() === "22041219PG") {
await this.device.shell("input tap " + 411 + " " + 2020) await this.device.shell("input tap " + 411 + " " + 2020)
} else } else {
await this.device.shell("input tap " + 411 + " " + 2100) await this.tapForDevice(this.device, 411, 2100)
}
// await this.device.shell("input tap " + 411 + " " + 2100)
} }
await delay(2000); await delay(2000);
} }
async startPage(device, activity) {
let cmd = `adb -s ${device.serial()} shell am start -n ${activity}`
logWithDevice("cmd is " + cmd, this.device)
await exec(cmd);
}
} }
module module