can cancel promis

This commit is contained in:
2022-09-07 21:24:07 +02:00
parent b0d52afc00
commit cdd47327b1
2 changed files with 72 additions and 23 deletions
+33 -15
View File
@@ -1,11 +1,11 @@
const {_android: android} = require("playwright");
const SolveCaptcha = require("./SolveCaptcha");
const ReserveResultPojo = require("../models/ReserveResultPojo");
const PublishType = require("../models/PublishType");
const {aws4} = require("mongodb/src/deps");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
// const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
const COUNTRY_ID = "#phone_country"
const PHONE_NUMBER = "#phone_number"
@@ -17,6 +17,8 @@ const CGU_ID = "#cgu"
const PROCESSING_ID = "#processing"
const PASSPORT_ID = "#passport_id"
const TIME_OUT = 60 * 1000 * 10//10mins
const CONFIRMED_MESSAGE = "Your request for a Leather Goods appointment has been registered"
const CONFIRMED_MESSAGE_FR = "Votre demande de rendez-vous Maroquinerie a bien été enregistrée et nous vous en remercions."
const MESSAGE_URL_VALIDATION_FR = "Nous avons envoyé un lien par e-mail."
@@ -49,31 +51,43 @@ class CommandorPage {
this.device = device;
this.mongoManager = mongoManager;
this.isFillingFields = false;
this.isTerminated = false;
}
async loadPage() {
// Connect to the device.
console.log("loadPage() called");
// --------------------- Browser -----------------------
// Launch Chrome browser.
await this.device.shell('am force-stop com.android.chrome');
const context = await this.device.launchBrowser({command: '--incognito'});
// Use BrowserContext as usual.
this.page = await context.newPage();
this.page.on("load", (loaddePage) => {
this.onPageLoad(loaddePage)
this.page.on("load", (loadedPage) => {
this.onPageLoad(loadedPage)
})
await this.page.goto(RDV_URL);
// await this.fillFields(page)
console.log(await this.page.evaluate(() => window.location.href));
//wait 10 mins
await delay(10 * 60 * 1000);
// Close the device.
await this.device.close();
let cancel
const intervalTask = setInterval(() => {
if (this.isTerminated) {
console.log("request terminated, will close device")
context.close()
// this.page.close()
this.device.close()
clearInterval(intervalTask)
cancel()
return context
}
}, 10 * 1000)//interval of 10 seconds
await new Promise(function (fulfill, reject) {
cancel = function () {
fulfill(Promise.resolve())
}
setTimeout(fulfill, TIME_OUT, 5)
}).then(console.log)
}
async chooseCountry(page) {
@@ -125,7 +139,7 @@ class CommandorPage {
await delay(1000)
await page.click(PREFER_STORE);
await page.selectOption(PREFER_STORE, "faubourg");
await page.click(PREFER_STORE);
// await page.click(PREFER_STORE);
}
@@ -161,6 +175,10 @@ class CommandorPage {
}
async resolveCaptcha(page) {
if (RDV_URL.includes("192")) {
this.isTerminated = true;
return
}
this.captchaSolver = new SolveCaptcha(page);
await this.captchaSolver.start((solution) => {
console.log("solution is: " + solution);