use adb insead of playwright

This commit is contained in:
Lei PAN
2023-10-21 18:21:36 +02:00
parent 04e1dbbee7
commit dda926bdcd
2 changed files with 27 additions and 8 deletions
+16 -3
View File
@@ -981,7 +981,12 @@ class CommandorPage {
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 else
await this.device.shell("input tap " + 500 + " " + 1120) try {
await this.tapForDevice(this.device, 500, 1120)
// await this.device.shell("input tap " + 500 + " " + 1120)
} catch (e) {
console.log(e)
}
await delay(2000); await delay(2000);
await this.checkResultWithOcr(); await this.checkResultWithOcr();
break; break;
@@ -1092,13 +1097,21 @@ class CommandorPage {
} else if (model === "ONEPLUS A6000") { } else if (model === "ONEPLUS A6000") {
await this.device.shell("input tap " + 530 + " " + 1106) await this.device.shell("input tap " + 530 + " " + 1106)
} else { } else {
await this.device.shell("input tap " + 470 + " " + 1160) logWithDevice("handleBraveSkipBtn", this.device)
await this.tapForDevice(this.device, 470, 1160)
// await this.device.shell("input tap " + 470 + " " + 1160)
} }
await delay(2000); await delay(2000);
await this.device.shell("input tap " + 455 + " " + 1920) await this.tapForDevice(this.device, 455, 1920)
// await this.device.shell("input tap " + 455 + " " + 1920)
await delay(1000); await delay(1000);
} }
async tapForDevice(device, x, y) {
let cmd = `adb -s ${device.serial()} shell input tap ${x} ${y}`
await exec(cmd);
}
async clickOnConfirmBtn() { async clickOnConfirmBtn() {
if (this.device.model() === "CPH2219") { if (this.device.model() === "CPH2219") {
this.device.shell("input tap " + 900 + " " + 1532) this.device.shell("input tap " + 900 + " " + 1532)
+11 -5
View File
@@ -3,6 +3,7 @@ const tesseract = require("node-tesseract-ocr");
const OCRResult = require("../models/OCRResult"); const OCRResult = require("../models/OCRResult");
const Jimp = require('jimp'); const Jimp = require('jimp');
const fs = require("fs"); const fs = require("fs");
const {exec} = require("child_process");
function delay(delayInMs) { function delay(delayInMs) {
return new Promise(resolve => { return new Promise(resolve => {
@@ -69,7 +70,8 @@ const BRAVE_SKIP_DEFAULT_PAGE_2 = "définissant Brave"
const BRAVE_SKIP_PRIVACY_PAGE = "Partagez des informations" const BRAVE_SKIP_PRIVACY_PAGE = "Partagez des informations"
const BRAVE_SKIP_PRIVACY_PAGE_2 = "Partagez des renseignements" const BRAVE_SKIP_PRIVACY_PAGE_2 = "Partagez des renseignements"
async function convertImageToWhiteBlack(image_path) { async function convertImageToWhiteBlack(image_path, device) {
console.log("convertImageToWhiteBlack for " + device.serial())
const image = await Jimp.read(image_path); const image = await Jimp.read(image_path);
image.grayscale().write(image_path + ".wb"); image.grayscale().write(image_path + ".wb");
return image_path + ".wb"; return image_path + ".wb";
@@ -90,7 +92,7 @@ class OCRChecker {
async get_result() { async get_result() {
let fileName = await this.take_screen_shot() let fileName = await this.take_screen_shot()
let screenShot = await convertImageToWhiteBlack(fileName); let screenShot = await convertImageToWhiteBlack(fileName, this.device);
await delay(1000) await delay(1000)
try { try {
let result = await tesseract let result = await tesseract
@@ -172,9 +174,11 @@ class OCRChecker {
await this.deleteFile(screenShot) await this.deleteFile(screenShot)
return OCRResult.BRAVE_NOTIFICATION return OCRResult.BRAVE_NOTIFICATION
} else if (result.includes(BRAVE_SKIP_PUB) || result.includes(BRAVE_SKIP_PUB_2) || result.includes(BRAVE_SKIP_PUB_3) || result.includes(BRAVE_SKIP_PUB_4) || result.includes(BRAVE_SKIP_PUB_5)) { } else if (result.includes(BRAVE_SKIP_PUB) || result.includes(BRAVE_SKIP_PUB_2) || result.includes(BRAVE_SKIP_PUB_3) || result.includes(BRAVE_SKIP_PUB_4) || result.includes(BRAVE_SKIP_PUB_5)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
return OCRResult.BRAVE_PRIVACY_PUB return OCRResult.BRAVE_PRIVACY_PUB
} else { } else {
return OCRResult.TERMINAED return OCRResult.TERMINAED``
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@@ -194,8 +198,10 @@ class OCRChecker {
async take_screen_shot() { async take_screen_shot() {
let name = this.get_file_name() let name = this.get_file_name()
console.log("will take screenshot for " + this.device.model() + ":" + this.device.serial()) console.log("will take screenshot for " + this.device.model() + ":" + this.device.serial())
await this.device.screenshot({path: name}); let stdout1 = await exec("adb -s " + this.device.serial() + " exec-out screencap -p > " + name)
await delay(3000); await delay(5000);
console.log(`stdout: ${stdout1}`);
// await this.device.screenshot({path: name});
return name return name
} }
} }