use adb to open url

This commit is contained in:
2023-10-28 17:02:09 +02:00
parent 0f56670774
commit 8160ca02f3
4 changed files with 79 additions and 72 deletions
-4
View File
@@ -9,10 +9,6 @@ class ExcelUtil {
workSheetsFromFile[0].data.forEach(
(info, index, list) => {
if (index > 0 && info.length > 0) {
// console.log(info)
if (info[0].includes("Aijing")) {
console.log("found");
}
let name = info[0].trim().split(" ")
let firstName = name[1];
let lastName = name[0];
+9 -1
View File
@@ -33,6 +33,14 @@ function cmdExecute(command) {
});
}
async function openUrlWithAdb(url, device) {
// do not continue if device is blocked
console.log("load url on device " + device.model() + " url=" + url)
let cmd = "adb -s " + device.serial() + " shell am start -a android.intent.action.VIEW -d " + url
let output = await cmdExecute(cmd);
console.log(`stdout: ${output}`);
}
async function findText(imgPath) {
// Load images
let cmd = `${baseDir}/venv/bin/python ${baseDir}/MacOCR.py ${imgPath}`
@@ -41,4 +49,4 @@ async function findText(imgPath) {
return stdOut
}
module.exports = findText
module.exports = {findText, openUrlWithAdb}
+69 -65
View File
@@ -8,6 +8,7 @@ const GeoCaptchaSolver = require("./GeoCaptchaSolver");
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
const OCRChecker = require("./OCRChecker");
const {exec} = require("child_process");
const {openUrlWithAdb} = require("../utiles/CmdUtils");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
const BLANK_URL = "about:blank"
@@ -137,8 +138,6 @@ class CommandorPage {
this.page = currentPage
}
})
// this.page = pages[pages.length - 1];
// this.page = pages[0];
logWithDevice("pageUrl is " + this.page.url(), this.device)
// this.page = pages[pages.length - 1];
switch (ocrResult) {
@@ -184,7 +183,7 @@ class CommandorPage {
// 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(4 * 1000);
} catch (e) {
console.log(e)
@@ -196,25 +195,25 @@ class CommandorPage {
logWithDevice("browser.isConnected is " + this.browser.isConnected(), this.device);
}
try {
logWithDevice("connecting to browser:" + this.port, this.device);
while (this.browser === undefined || !this.browser.isConnected()) {
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();
// this.page = pages[0];
this.page = await this.browser.newPage();
this.page.on("load", (loadedPage) => {
this.onPageLoad(loadedPage);
})
this.page.on("response", (response) => {
this.onResponse(response)
})
await delay(3 * 1000);
}
// logWithDevice("connecting to browser:" + this.port, this.device);
// while (this.browser === undefined || !this.browser.isConnected()) {
// 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();
// // this.page = pages[0];
// this.page = await this.browser.newPage();
//
// this.page.on("load", (loadedPage) => {
// this.onPageLoad(loadedPage);
// })
//
// this.page.on("response", (response) => {
// this.onResponse(response)
// })
// await delay(3 * 1000);
// }
} catch (e) {
logWithDevice("failed to connect to device", this.device)
console.log(e)
@@ -222,26 +221,28 @@ class CommandorPage {
await this.checkResultWithOcr()
this.isTerminated = true
}
if (this.page !== undefined) {
try {
logWithDevice("will open google", this.device)
if (!this.isTerminated) {
const item = searchTexts[Math.floor(Math.random() * searchTexts.length)];
await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 30 * 1000});
}
// await this.page.goto(RDV_URL, {timeout: 90 * 1000});
} catch (e) {
log(e)
this.isTerminated = true
}
await this.acceptCookies();
await this.enableDisableAirPlanMode();
await delay(10 * 1000);
// await this.checkResultWithOcr()
await this.clickOnlineAppointment();
} else {
this.isTerminated = true;
}
// if (this.page !== undefined) {
// try {
// logWithDevice("will open google", this.device)
// if (!this.isTerminated) {
// const item = searchTexts[Math.floor(Math.random() * searchTexts.length)];
// await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 30 * 1000});
// }
// // await this.page.goto(RDV_URL, {timeout: 90 * 1000});
// } catch (e) {
// log(e)
// this.isTerminated = true
// }
// await this.acceptCookies();
await this.enableDisableAirPlanMode();
// await delay(10 * 1000);
await openUrlWithAdb(RDV_URL, this.device)
await delay(5000)
await this.checkResultWithOcr()
// await this.clickOnlineAppointment();
// } else {
// this.isTerminated = true;
// }
let cancel
const intervalTask = setInterval(async () => {
@@ -913,6 +914,7 @@ class CommandorPage {
await this.connect_to_browser(checkResult)
break;
case OCRResult.FILL_FIELD:
logWithDevice("FILL_FIELD", this.device)
if (this.browser === undefined || !this.browser.isConnected()) {
logWithDevice("trying to connect to browser", this.device)
try {
@@ -951,27 +953,27 @@ class CommandorPage {
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
try {
if (this.browser.isConnected()) {
logWithDevice("get pages", this.device)
let pages = await this.browser.pages();
logWithDevice("get current page", this.device)
try {
pages.forEach((currentPage) => {
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} else {
// try {
// if (!currentPage.isClosed()) {
// currentPage.close()
// }
// } catch (e) {
// console.log(e)
// }
}
})
} catch (e) {
this.isTerminated = true
console.log(e)
}
// logWithDevice("get pages", this.device)
// let pages = await this.browser.pages();
logWithDevice("will use old page", this.device)
// try {
// pages.forEach((currentPage) => {
// if (currentPage.url() === RDV_URL) {
// this.page = currentPage;
// } else {
// // try {
// // if (!currentPage.isClosed()) {
// // currentPage.close()
// // }
// // } catch (e) {
// // console.log(e)
// // }
// }
// })
// } catch (e) {
// this.isTerminated = true
// console.log(e)
// }
logWithDevice("this.page.bringToFront();", this.device)
await this.page.bringToFront();
// this.page = pages;
@@ -1018,7 +1020,7 @@ class CommandorPage {
await this.tapForDevice(this.device, 530, 970)
} else if (this.device.model() === "ONEPLUS A6000") {
await this.device.shell("input tap " + 530 + " " + 1064)
} else if (this.device.model() === "M2006C3LG") {
} else if (this.device.model() === "M2006C3LG" || this.device.model() === "220233L2G") {
await this.tapForDevice(this.device, 350, 777)
} else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") {
await this.tapForDevice(this.device, 500, 1200)
@@ -1151,7 +1153,7 @@ class CommandorPage {
await this.device.shell("input tap " + 558 + " " + 1160)
} else if (model === "MI 5s") {
await this.tapForDevice(this.device, 530, 1000)
} else if (model === "M2006C3LG") {
} else if (model === "M2006C3LG" || model === "220233L2G") {
await this.tapForDevice(this.device, 360, 777)
} else if (model === "ONEPLUS A6000") {
await this.device.shell("input tap " + 530 + " " + 1106)
@@ -1279,6 +1281,8 @@ class CommandorPage {
await this.tapForDevice(this.device, 411, 2020)
} else if (this.browserPackageName.includes("brave") && this.device.model() === "M2006C3LG") {//redmi 9a
await this.tapForDevice(this.device, 411, 1300)
} else if (this.browserPackageName.includes("brave") && this.device.model() === "220233L2G") {//redmi 9a
await this.tapForDevice(this.device, 411, 1300)
} else {
await this.tapForDevice(this.device, 411, 2100)
}
+1 -2
View File
@@ -2,7 +2,7 @@ const {v4: uuidv4} = require("uuid");
const OCRResult = require("../models/OCRResult");
const fs = require("fs");
const {exec} = require("child_process");
const findText = require("../utiles/CmdUtils");
const {findText} = require("../utiles/CmdUtils");
function delay(delayInMs) {
return new Promise(resolve => {
@@ -96,7 +96,6 @@ class OCRChecker {
return OCRResult.CHOOSE_POSITION
} else if (result.includes(BRAVE_VPN_SKIP)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
return OCRResult.BRAVE_VPN_SKIP
} else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5)) {
await this.deleteFile(fileName)