remove playwright

This commit is contained in:
2024-09-24 13:59:18 +02:00
parent 0115ad7139
commit 32f8b9812d
7 changed files with 153 additions and 138 deletions
+81
View File
@@ -0,0 +1,81 @@
const {exec} = require("child_process");
DEVICE_REGEX = "(^[a-z0-9A-Z]*) .* model:([a-z0-9A-Z_]+)"
async function devices() {
return new Promise((resolve, reject) => {
exec("adb devices -l", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
let lines = stdout.split("\n");
let result = [];
for (let i = 1; i < lines.length; i++) {
currentLine = lines[i]
console.log("currentLine is " + currentLine)
if (currentLine.length > 0) {
const o = currentLine.split('\t')
findResult = currentLine.match(DEVICE_REGEX)
console.log(findResult)
try{
result.push(new AndroidDevice(findResult[1], findResult[2]));}
catch(e){
console.log(e)}
console.log(result[i])
}
}
resolve(result);
}
);
})
}
class AndroidDevice {
constructor(serial, model) {
this.serial = serial
this.model = model
}
async swipeForDevice(x0, y0, x1, y1) {
let cmd = `input swipe ${x0} ${y0} ${x1} ${y1}`
await this.shell(cmd);
}
async tapForDevice(x, y) {
let cmd = `input tap ${x} ${y}`
console.log("cmd is " + cmd)
try {
await this.shell(cmd);
} catch (e) {
console.log(e)
}
}
shell(cmd) {
return new Promise((resolve, reject) => {
exec("adb -s " + this.serial + " shell " + cmd, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
reject(error);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
reject(stderr);
return;
}
console.log(`stdout: ${stdout}`);
resolve(stdout);
}
);
})
}
}
module.exports = {AndroidDevice, devices}