generate radmon actions
This commit is contained in:
@@ -71,6 +71,8 @@ function logWithDevice(message, device) {
|
||||
appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message})
|
||||
}
|
||||
|
||||
const searchTexts = ['hermes+rdv+online+paris', 'hermes+rdv+enligne+paris', 'hermes+rdv+en+ligne+paris', 'hermes+rendezvous+en+ligne+paris', 'hermes+appointment+online+paris', 'hermes+appointment+online+paris', 'appointment+hermes+paris+on+line', 'hermes+rendez+vous+online+paris', 'hermes+rendez+vous+paris+en+ligne', 'hermes+rendez+vous+paris+enligne', 'hermes+rendez+vous+paris+online', 'online+appointment+hermes+paris', 'hermes+online+appointment+paris', 'paris+hermes+online+appointment']
|
||||
|
||||
class CommandorPage {
|
||||
constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) {
|
||||
this.contact = contact;
|
||||
@@ -94,6 +96,15 @@ class CommandorPage {
|
||||
this.isAlreadyRefresh = false;
|
||||
}
|
||||
|
||||
|
||||
async openGoogle() {
|
||||
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 openUrlWithAdb("https://www.google.com/search?q=" + item + "&lr=lang_en", this.device)
|
||||
await delay(5 * 1000)
|
||||
await this.acceptCookies();
|
||||
}
|
||||
|
||||
async connect_to_browser(ocrResult) {
|
||||
console.log("connect_to_browser() called");
|
||||
if (this.browser === undefined) {
|
||||
@@ -145,18 +156,25 @@ class CommandorPage {
|
||||
|
||||
async generateRandomActions() {
|
||||
logWithDevice("will reload page", this.device)
|
||||
await this.handleBraveSkipBtn()
|
||||
await delay(1000);
|
||||
let cmd = "input swipe 382 482 382 1682"
|
||||
logWithDevice("will send cmd:" + cmd, this.device)
|
||||
this.device.shell(cmd);
|
||||
await delay(2000);
|
||||
let limit = getRandom()
|
||||
let limit = getRandom() + 1
|
||||
for (let i = 1; i <= limit; i++) {
|
||||
this.device.shell(cmd);
|
||||
await delay(1000);
|
||||
let tapX = 300 + getRandom() * 100 + getRandom() * 10 + getRandom()
|
||||
let tapY = 400 + getRandom() * 100 + getRandom() * 10 + getRandom()
|
||||
await this.tapForDevice(this.device, tapX, tapY)
|
||||
// await this.inputForDevice(this.device, getRandom() + "")
|
||||
await delay(getRandomWaitTime());
|
||||
}
|
||||
await this.clickOnConfirmBtn();
|
||||
for (let i = 1; i <= limit; i++) {
|
||||
let x = 350 + getRandom() * 100
|
||||
let y0 = 600 + getRandom() * 100 + getRandom() * 10 + getRandom() * 1
|
||||
let swipCmd = "input swipe " + x + " " + y0 + " " + x + " 1522"
|
||||
logWithDevice("will send cmd:" + swipCmd, this.device)
|
||||
this.device.shell(swipCmd);
|
||||
await delay(3 * getRandomWaitTime());
|
||||
}
|
||||
// await this.openGoogle()
|
||||
// await delay(3 * getRandomWaitTime());
|
||||
// await this.clickOnConfirmBtn();
|
||||
await this.checkResultWithOcr();
|
||||
}
|
||||
|
||||
@@ -245,8 +263,27 @@ class CommandorPage {
|
||||
|
||||
async acceptCookies() {
|
||||
logWithDevice("will accept Cookies", this.device);
|
||||
if (this.browser.isConnected() && !this.page.isClosed()) {
|
||||
await this.connectBrowserIfNecessary()
|
||||
if (!this.isTerminated && this.browser.isConnected()) {
|
||||
try {
|
||||
logWithDevice("get pages", this.device)
|
||||
// add listeners
|
||||
let pages = await timeout(this.browser.pages(), 5 * 1000);
|
||||
pages.forEach((currentPage) => {
|
||||
if (currentPage.url().includes("google")) {
|
||||
this.page = currentPage;
|
||||
} else {
|
||||
try {
|
||||
if (!this.isTerminated)
|
||||
currentPage.close()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
logWithDevice("this.page.bringToFront();", this.device)
|
||||
await this.page.bringToFront();
|
||||
await delay(2 * 1000);
|
||||
await this.page.evaluate(() => {
|
||||
let buttons = document.getElementsByTagName('button');
|
||||
for (let i = 0; i < buttons.length; i++) {
|
||||
@@ -261,7 +298,6 @@ class CommandorPage {
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,7 +835,7 @@ class CommandorPage {
|
||||
}
|
||||
|
||||
async connectBrowserIfNecessary() {
|
||||
if (!this.browser.isConnected()) {
|
||||
if (this.browser == undefined || !this.browser.isConnected()) {
|
||||
try {
|
||||
this.browser = await puppeteer.connect({
|
||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||
@@ -1159,6 +1195,12 @@ class CommandorPage {
|
||||
await exec(cmd);
|
||||
}
|
||||
|
||||
async inputForDevice(device, text) {
|
||||
let cmd = `adb -s ${device.serial()} shell input text ${text}`
|
||||
logWithDevice("cmd is " + cmd, this.device)
|
||||
await exec(cmd);
|
||||
}
|
||||
|
||||
async clickOnConfirmBtn() {
|
||||
if (this.device.model() === "CPH2219") {
|
||||
this.device.shell("input tap " + 900 + " " + 1532)
|
||||
@@ -1232,21 +1274,21 @@ class CommandorPage {
|
||||
|
||||
async enableDisableAirPlanMode() {
|
||||
logWithDevice("will enable/disable airplane mode", this.device)
|
||||
// try {
|
||||
// // await this.device.shell("cmd connectivity airplane-mode enable")
|
||||
// await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable")
|
||||
// await delay(1000)
|
||||
// await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable")
|
||||
// // await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
// await delay(2000)
|
||||
// } catch (e) {
|
||||
// try {
|
||||
// await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
// } catch (e) {
|
||||
// console.log(e)
|
||||
// }
|
||||
// console.log(e)
|
||||
// }
|
||||
try {
|
||||
// await this.device.shell("cmd connectivity airplane-mode enable")
|
||||
await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable")
|
||||
await delay(1000)
|
||||
await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable")
|
||||
// await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
await delay(2000)
|
||||
} catch (e) {
|
||||
try {
|
||||
await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async tapGoogleDisconnectBtn() {
|
||||
|
||||
@@ -114,6 +114,9 @@ class OCRChecker {
|
||||
return OCRResult.FILL_FIELD
|
||||
} else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) {
|
||||
return OCRResult.RECAPTCHA_ERROR
|
||||
} 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)
|
||||
return OCRResult.BRAVE_PRIVACY_PUB
|
||||
} else if (result.includes(BLOCKED_MSG_EN) || result.includes(BLOCKED_MSG_FR) || result.includes(BLOCKED_MSG_FR_2) || result.includes(BLOCKED_MSG_FR_3)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.BLOCKED
|
||||
@@ -127,9 +130,6 @@ class OCRChecker {
|
||||
} else if (result.includes(BRAVE_NOTIFICATION)) {
|
||||
await this.deleteFile(fileName)
|
||||
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)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.BRAVE_PRIVACY_PUB
|
||||
} else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4) || result.includes(SLIDING_CAPTCHA_FR_5) || result.includes(SLIDING_CAPTCHA_FR_6)) {
|
||||
await this.deleteFile(fileName)
|
||||
if (result.includes(SLIDING_CAPTCHA_LOADING_FR)) {
|
||||
|
||||
Reference in New Issue
Block a user