add support for LinkValidator
This commit is contained in:
@@ -30,6 +30,7 @@ REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0
|
||||
const PLAY_AUDIO_BTN_ID = ".audio-captcha-play-button"
|
||||
const homedir = require('os').homedir();
|
||||
const CAPTCHA_CONTAINER = "#captcha-container";
|
||||
|
||||
function delay(delayInMs) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
@@ -62,44 +63,49 @@ class LinkValidator {
|
||||
// Connect to the device.
|
||||
log("loadPage() called for url " + this.urlToValidate);
|
||||
// await this.device.shell('am force-stop com.android.chrome');
|
||||
const context = await this.device.launchBrowser();
|
||||
// await context.clearCookies()
|
||||
|
||||
// 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)
|
||||
})
|
||||
try {
|
||||
await this.page.goto(this.urlToValidate, {timeout: 90 * 1000});
|
||||
const context = await this.device.launchBrowser();
|
||||
// await context.clearCookies()
|
||||
|
||||
// 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)
|
||||
})
|
||||
try {
|
||||
await this.page.goto(this.urlToValidate, {timeout: 90 * 1000});
|
||||
} catch (e) {
|
||||
log(e)
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
let cancel
|
||||
const intervalTask = setInterval(() => {
|
||||
if (this.isTerminated) {
|
||||
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(log)
|
||||
} catch (e) {
|
||||
log(e)
|
||||
this.isTerminated = true
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
let cancel
|
||||
const intervalTask = setInterval(() => {
|
||||
if (this.isTerminated) {
|
||||
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(log)
|
||||
}
|
||||
|
||||
async onPageLoad(currentPage) {
|
||||
|
||||
Reference in New Issue
Block a user