diff --git a/clear_data.bat b/clear_data.bat index 871ee5e..08da9a6 100644 --- a/clear_data.bat +++ b/clear_data.bat @@ -247,6 +247,12 @@ adb -s APU7N16321020182 shell pm clear com.android.chrome adb -s APU7N16321020182 shell am set-debug-app --persistent com.android.chrome adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#huawei mate 8 +adb -s emulator-5554 shell pm clear com.android.chrome +adb -s emulator-5554 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5554 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + #1 adb -s 2469c020930c7ece shell pm clear com.android.chrome adb -s 2469c020930c7ece shell am set-debug-app --persistent com.android.chrome @@ -335,4 +341,4 @@ adb -s 5634563639393498 shell am start -n com.android.chrome/com.google.android. #18 adb -s 344d395044413098 shell pm clear com.android.chrome adb -s 344d395044413098 shell am set-debug-app --persistent com.android.chrome -adb -s 344d395044413098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file +adb -s 344d395044413098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main diff --git a/clear_data.sh b/clear_data.sh index bb2c533..58ee5ae 100644 --- a/clear_data.sh +++ b/clear_data.sh @@ -4,9 +4,6 @@ adb -s RQ3005CA88 shell am start -n com.android.chrome/com.google.android.apps.c adb -s J4AXB761H2322WJ shell pm clear com.android.chrome adb -s J4AXB761H2322WJ shell am set-debug-app --persistent com.android.chrome adb -s J4AXB761H2322WJ shell am start -n com.android.chrome/com.google.android.apps.chrome.Main -adb -s e30eb015 shell pm clear com.android.chrome -adb -s e30eb015 shell am set-debug-app --persistent com.android.chrome -adb -s e30eb015 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main adb -s 07f9c883 shell pm clear com.android.chrome adb -s 07f9c883 shell am set-debug-app --persistent com.android.chrome adb -s 07f9c883 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main @@ -55,11 +52,6 @@ adb -s 6c3076e6 shell pm clear com.android.chrome adb -s 6c3076e6 shell am set-debug-app --persistent com.android.chrome adb -s 6c3076e6 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main -#samsung J5 - 2016 -adb -s 774687ff shell pm clear com.android.chrome -adb -s 774687ff shell am set-debug-app --persistent com.android.chrome -adb -s 774687ff shell am start -n com.android.chrome/com.google.android.apps.chrome.Main - #samsung J5 - 2016 adb -s ffa9b2bc shell pm clear com.android.chrome adb -s ffa9b2bc shell am set-debug-app --persistent com.android.chrome @@ -290,4 +282,29 @@ adb -s 192.168.0.27:5555 shell am start -n com.android.chrome/com.google.android #18 adb -s emulator-5560 shell pm clear com.android.chrome adb -s emulator-5560 shell am set-debug-app --persistent com.android.chrome -adb -s emulator-5560 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file +adb -s emulator-5560 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5564 shell pm clear com.android.chrome +adb -s emulator-5564 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5564 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5566 shell pm clear com.android.chrome +adb -s emulator-5566 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5566 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5568 shell pm clear com.android.chrome +adb -s emulator-5568 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5568 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5570 shell pm clear com.android.chrome +adb -s emulator-5570 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5570 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5572 shell pm clear com.android.chrome +adb -s emulator-5572 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5572 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file diff --git a/package.json b/package.json index bb97f21..487d834 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "node-schedule": "^2.1.0", "node-wget": "^0.4.3", "node-xlsx": "^0.21.0", - "playwright": "1.23.0", + "playwright": "^1.32.1", "read-ini-file": "^3.0.1", "uuid": "^9.0.0", "image-size": "^1.0.2", diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index c0ae618..bbc32c9 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -37,7 +37,8 @@ const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again" const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué" const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+" const DEFAULT_STORE = 'faubourg'; -const searchTexts = ['hermes+rdv', 'hermes+rendezvous', 'hermes+appointment', 'hermes+appointment+online', 'appointment+hermes', 'hermes+rendez+vous', 'hermes+rendez+vous+paris', 'online+appointment+hermes', 'hermes+online+appointment', 'paris+hermes+online+appointment'] + +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'] function delay(delayInMs) { return new Promise(resolve => { @@ -82,18 +83,23 @@ class CommandorPage { // Connect to the device. log("loadPage() called"); // await this.device.shell('am force-stop com.android.chrome'); - const context = await this.device.launchBrowser(); - // await context.clearCookies() + try { + this.context = await this.device.launchBrowser(); + // await context.clearCookies() + // Use BrowserContext as usual. + this.page = await this.context.newPage(); + this.page.on("load", (loadedPage) => { + this.onPageLoad(loadedPage) + }) - // Use BrowserContext as usual. - this.page = await context.newPage(); - this.page.on("load", (loadedPage) => { - this.onPageLoad(loadedPage) - }) + this.page.on("response", (response) => { + this.onResponse(response) + }) + } catch (e) { + log(e) + this.isTerminated = true + } - this.page.on("response", (response) => { - this.onResponse(response) - }) try { const item = searchTexts[Math.floor(Math.random() * searchTexts.length)]; await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 90 * 1000}); @@ -104,17 +110,11 @@ class CommandorPage { try { if (this.page.url().includes("google")) this.page.locator('button >> nth=3').click() - // this.page.locator('button:has-text("Tout accepter")').click() } catch (e) { log(e) } - // try { - // this.page.locator('button:has-text("Accept all")').click() - // } catch (e) { - // log(e) - // } try { - this.page.locator(':nth-match(:text("Online Appointment"), 1)').click() + this.page.locator(':nth-match(:text("rendezvousparis"), 1)').click() } catch (e) { log(e) if (!this.page.url().includes(RDV_URL)) { @@ -126,12 +126,18 @@ class CommandorPage { const intervalTask = setInterval(() => { if (this.isTerminated) { log(this.device.model() + ":request terminated, will close device"); - context.close(); + if (this.context !== undefined) + this.context.close(); // this.page.close() - this.device.close() + // this.device.close() clearInterval(intervalTask) cancel() - return context + return this.context + } else { + if (this.page.url() === RDV_URL) { + if (!this.isFillingFields) + this.fillFields(this.page); + } } }, 10 * 1000)//interval of 10 seconds @@ -314,27 +320,36 @@ class CommandorPage { await this.push_message_to_queue(PublishType.SUCCESS) return } - this.captchaSolver = new SolveCaptcha(page); - await this.captchaSolver.start((solution) => { - log("solution is: " + solution); - if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) { - try { - if (!page.isClosed()) { - page.evaluate((solution) => { - let element = document.getElementById("g-recaptcha-response"); - if (element != null) - document.getElementById("g-recaptcha-response").innerHTML = solution; - }, solution) - this.clickValid(); + //check whether there is captcha + let pageContent = await page.content() + let hasCaptcha = pageContent.includes("g-recaptcha-response") + if (hasCaptcha) { + await this.clickCheckbox() + await delay(1000) + this.captchaSolver = new SolveCaptcha(page); + await this.captchaSolver.start((solution) => { + log("solution is: " + solution); + if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) { + try { + if (!page.isClosed()) { + page.evaluate((solution) => { + let element = document.getElementById("g-recaptcha-response"); + if (element != null) + document.getElementById("g-recaptcha-response").innerHTML = solution; + }, solution) + this.clickValid(); + } + } catch (e) { + log(e) + this.isTerminated = true; } - } catch (e) { - log(e) + } else { this.isTerminated = true; } - } else { - this.isTerminated = true; - } - }) + }) + } else { + await this.clickValid(); + } } async isBlocked() { @@ -365,8 +380,8 @@ class CommandorPage { } else { if (currentPage.url() === RDV_URL) { await this.fillFields(this.page); - if (this.isFillingFields) - await this.getErrors() + // if (this.isFillingFields) + // await this.getErrors() } else { if (content.includes(MESSAGE_URL_VALIDATION_FR) || content.includes(MESSAGE_URL_VALIDATION_EN)) { log("successful"); @@ -385,6 +400,20 @@ class CommandorPage { } } + async saveCookies() { + log("saveCookies() called.") + try { + let cookies = await this.page.context().cookies(); + let cookiesInJson = []; + cookies.forEach((cookie) => { + cookiesInJson.push(JSON.stringify(cookie)) + }) + await require("fs").writeFileSync(this.contact.mail + '.txt', cookiesInJson.join('\n')); + } catch (e) { + console.log(e) + } + } + async checkAudioBtn() { let isBlocked = await this.isBlocked() if (!isBlocked) { @@ -423,6 +452,8 @@ class CommandorPage { // log("onResponse with url:" + response.body()) if (rex.test(response.url())) { log("rdv url found:" + response.url()) + // save cookies + await this.saveCookies(); await this.push_message_to_db(PublishType.SUCCESS, response.url()) } } @@ -473,6 +504,15 @@ class CommandorPage { } } + async clickCheckbox() { + try { + // let errorItem = await this.page.click("#recaptcha-anchor > div.recaptcha-checkbox-border") + await this.page.frameLocator('[title="reCAPTCHA"]').getByRole('checkbox', {name: 'I\'m not a robot'}).click(); + } catch (e) { + log(e); + } + } + async handleError(errorContent) { log("handle error:" + errorContent); if (errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE) || errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE_FR)) { diff --git a/start_avds.sh b/start_avds.sh index 5a927e8..162d52d 100644 --- a/start_avds.sh +++ b/start_avds.sh @@ -8,5 +8,5 @@ emulator -avd Pixel_2_API_30_6 & emulator -avd Pixel_2_API_30_7 & emulator -avd Pixel_2_API_30_8 & emulator -avd Pixel_2_API_30_9 & -emulator -avd Pixel_2_API_30_10 & -emulator -avd Pixel_2_API_30_11 & \ No newline at end of file +#emulator -avd Pixel_2_API_30_10 & +#emulator -avd Pixel_2_API_30_11 & \ No newline at end of file