use adb to start browser

This commit is contained in:
Lei PAN
2023-10-25 16:03:23 +02:00
parent 00d70cd00f
commit fbdc5ad73c
2 changed files with 35 additions and 19 deletions
+35 -14
View File
@@ -55,6 +55,18 @@ function log(message) {
appointmentLogger.log({level: "info", message: message}) appointmentLogger.log({level: "info", message: message})
} }
async function clearApp(device, packageName) {
let cmd = `adb -s ${device.serial()} shell pm clear ${packageName}`
logWithDevice("cmd is " + cmd, device)
await exec(cmd);
}
async function exceutShellCmd(device, cmdToExecut) {
let cmd = `adb -s ${device.serial()} shell ${cmdToExecut}`
logWithDevice("cmd is " + cmd, device)
await exec(cmd);
}
function logWithDevice(message, device) { function logWithDevice(message, device) {
appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message}) appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message})
} }
@@ -146,8 +158,11 @@ 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 {
// let cmd = 'adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
await exceutShellCmd(this.device, " forward tcp:" + this.port + " localabstract:chrome_devtools_remote")
await delay(1 * 1000);
await this.startPage(this.device, 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(4 * 1000);
} catch (e) { } catch (e) {
console.log(e) console.log(e)
this.isTerminated = true; this.isTerminated = true;
@@ -810,7 +825,8 @@ class CommandorPage {
this.isPhoneInput = false; this.isPhoneInput = false;
this.isPasspordInput = false; this.isPasspordInput = false;
// this.disconnectBrowser(); // this.disconnectBrowser();
await this.device.shell("pm clear " + this.browserPackageName) await clearApp(this.device, this.browserPackageName)
// await this.device.shell("pm clear " + this.browserPackageName)
await delay(1000) await delay(1000)
this.isTerminated = true; this.isTerminated = true;
// await this.checkResultWithOcr(); // await this.checkResultWithOcr();
@@ -986,9 +1002,10 @@ class CommandorPage {
// await this.device.shell("input tap " + 530 + " " + 970) // await this.device.shell("input tap " + 530 + " " + 970)
} else if (this.device.model() === "ONEPLUS A6000") } else if (this.device.model() === "ONEPLUS A6000")
await this.device.shell("input tap " + 530 + " " + 1064) await this.device.shell("input tap " + 530 + " " + 1064)
else if (this.device.model() === "KB2003") else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") {
await this.tapForDevice(this.device, 500, 1200) await this.tapForDevice(this.device, 500, 1200)
else await this.tapForDevice(this.device, 500, 1120)
} else
try { try {
await this.tapForDevice(this.device, 500, 1120) await this.tapForDevice(this.device, 500, 1120)
// await this.device.shell("input tap " + 500 + " " + 1120) // await this.device.shell("input tap " + 500 + " " + 1120)
@@ -1008,11 +1025,11 @@ class CommandorPage {
break; break;
case OCRResult.BRAVE_NOTIFICATION: case OCRResult.BRAVE_NOTIFICATION:
logWithDevice("BRAVE_NOTIFICATION", this.device) logWithDevice("BRAVE_NOTIFICATION", this.device)
if (this.device.model() === "21091116C") if (this.device.model() === "21091116C") {
await this.device.shell("input tap " + 540 + " " + 1611) await this.tapForDevice(this.device, 540, 1611)
else if (this.device.model() === "22041219PG") } else if (this.device.model() === "22041219PG") {
await this.device.shell("input tap " + 530 + " " + 1600) await this.tapForDevice(this.device, 530, 1600)
else } else
await this.tapForDevice(this.device, 500, 1680) await this.tapForDevice(this.device, 500, 1680)
// await this.device.shell("input tap " + 500 + " " + 1680) // await this.device.shell("input tap " + 500 + " " + 1680)
await delay(2000); await delay(2000);
@@ -1210,11 +1227,11 @@ class CommandorPage {
async enableDisableAirPlanMode() { async enableDisableAirPlanMode() {
logWithDevice("will enable/disable airplane mode", this.device) logWithDevice("will enable/disable airplane mode", this.device)
try { try {
await this.device.shell("cmd connectivity airplane-mode enable") // await this.device.shell("cmd connectivity airplane-mode enable")
// await this.device.shell("adb shell settings put global airplane_mode_on 1") await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable")
await delay(1000) await delay(1000)
// await this.device.shell("adb shell settings put global airplane_mode_on 0") await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable")
await this.device.shell("cmd connectivity airplane-mode disable") // await this.device.shell("cmd connectivity airplane-mode disable")
await delay(2000) await delay(2000)
} catch (e) { } catch (e) {
try { try {
@@ -1239,8 +1256,12 @@ class CommandorPage {
await this.device.shell("input tap " + 411 + " " + 1977) await this.device.shell("input tap " + 411 + " " + 1977)
} else if (this.browserPackageName.includes("brave") && this.device.model() === "ONEPLUS A6000") { } else if (this.browserPackageName.includes("brave") && this.device.model() === "ONEPLUS A6000") {
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() === "ASUS_X00QD") {
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.tapForDevice(this.device, 411, 2020)
} else if (this.browserPackageName.includes("brave") && this.device.model() === "21091116C") {
await this.tapForDevice(this.device, 411, 2020)
} else { } else {
await this.tapForDevice(this.device, 411, 2100) await this.tapForDevice(this.device, 411, 2100)
} }
-5
View File
@@ -102,11 +102,6 @@ class SlidingCaptchaSolver {
let result = response.data; let result = response.data;
console.log(result); console.log(result);
await callback(result); await callback(result);
// console.log("will delete png file: " + fileName);
// await fs.unlink(fileName, (err) => {
// if (err) throw err;
// console.log(fileName + ' was deleted');
// })
} else { } else {
console.log("error"); console.log("error");
await callback([]); await callback([]);