Merge branch 'feature/disconnect_after_opening_appointment_url' of bitbucket.org:panleicim/puppeteerjs into feature/disconnect_after_opening_appointment_url
This commit is contained in:
@@ -85,12 +85,12 @@ class CommandorPage {
|
|||||||
async connect_to_browser(ocrResult) {
|
async connect_to_browser(ocrResult) {
|
||||||
console.log("connect_to_browser() called");
|
console.log("connect_to_browser() called");
|
||||||
console.log("browser.isConnected: " + this.browser.isConnected());
|
console.log("browser.isConnected: " + this.browser.isConnected());
|
||||||
// if (!this.browser.isConnected()) {
|
if (!this.browser.isConnected()) {
|
||||||
this.browser = await puppeteer.connect({
|
this.browser = await puppeteer.connect({
|
||||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||||
headless: false, defaultViewport: null
|
headless: false, defaultViewport: null
|
||||||
})
|
})
|
||||||
// }
|
}
|
||||||
let pages = await this.browser.pages();
|
let pages = await this.browser.pages();
|
||||||
// 0 is the last page
|
// 0 is the last page
|
||||||
pages.forEach((currentPage) => {
|
pages.forEach((currentPage) => {
|
||||||
@@ -696,7 +696,9 @@ class CommandorPage {
|
|||||||
disconnectBrowser() {
|
disconnectBrowser() {
|
||||||
try {
|
try {
|
||||||
logWithDevice("will disconnect browser", this.device);
|
logWithDevice("will disconnect browser", this.device);
|
||||||
|
if (this.browser !== undefined) {
|
||||||
this.browser.disconnect();
|
this.browser.disconnect();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
@@ -728,8 +730,12 @@ class CommandorPage {
|
|||||||
checkResult = await this.ocrChecker.get_result();
|
checkResult = await this.ocrChecker.get_result();
|
||||||
}
|
}
|
||||||
while (checkResult === OCRResult.SLIDING_CAPTCHA) {
|
while (checkResult === OCRResult.SLIDING_CAPTCHA) {
|
||||||
await this.slidingCaptcha(async () => {
|
await this.slidingCaptcha(async (isSuccessful) => {
|
||||||
|
if (isSuccessful) {
|
||||||
checkResult = await this.ocrChecker.get_result();
|
checkResult = await this.ocrChecker.get_result();
|
||||||
|
} else {
|
||||||
|
this.isTerminated = true
|
||||||
|
}
|
||||||
// await this.checkResultWithOcr()
|
// await this.checkResultWithOcr()
|
||||||
})
|
})
|
||||||
await delay(10 * 1000)
|
await delay(10 * 1000)
|
||||||
@@ -768,10 +774,11 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
|
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
|
||||||
if (this.browser.isConnected()) {
|
|
||||||
try {
|
try {
|
||||||
let pages = await this.browser.pages();
|
if (this.browser.isConnected()) {
|
||||||
logWithDevice("get pages", this.device)
|
logWithDevice("get pages", this.device)
|
||||||
|
let pages = await this.browser.pages();
|
||||||
|
logWithDevice("get current page", this.device)
|
||||||
pages.forEach((currentPage) => {
|
pages.forEach((currentPage) => {
|
||||||
if (currentPage.url() === RDV_URL) {
|
if (currentPage.url() === RDV_URL) {
|
||||||
this.page = currentPage;
|
this.page = currentPage;
|
||||||
@@ -783,18 +790,17 @@ class CommandorPage {
|
|||||||
// this.page.await
|
// this.page.await
|
||||||
await this.fillFields(this.page)
|
await this.fillFields(this.page)
|
||||||
await delay(2 * 1000);
|
await delay(2 * 1000);
|
||||||
} catch (e) {
|
}
|
||||||
|
} catch
|
||||||
|
(e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
this.isTerminated = true
|
this.isTerminated = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if (!this.browser.isConnected()) {
|
|
||||||
// this.isTerminated = true;
|
|
||||||
// }
|
|
||||||
break;
|
break;
|
||||||
case OCRResult.SUCCESS:
|
case
|
||||||
|
OCRResult.SUCCESS:
|
||||||
// reconnect to page and get url
|
// reconnect to page and get url
|
||||||
if (!this.isTerminated) {
|
if (!this.isTerminated) {
|
||||||
await this.connect_to_browser(OCRResult.SUCCESS)
|
await this.connect_to_browser(OCRResult.SUCCESS)
|
||||||
@@ -805,44 +811,64 @@ class CommandorPage {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OCRResult.RECAPTCHA_ERROR:
|
case
|
||||||
|
OCRResult.RECAPTCHA_ERROR
|
||||||
|
:
|
||||||
this.isTerminated = true;
|
this.isTerminated = true;
|
||||||
break;
|
break;
|
||||||
case OCRResult.TO_SKIP:
|
case
|
||||||
|
OCRResult.TO_SKIP
|
||||||
|
:
|
||||||
logWithDevice("TO_SKIP", this.device)
|
logWithDevice("TO_SKIP", this.device)
|
||||||
this.device.shell("input tap " + 488 + " " + 1848)
|
this.device.shell("input tap " + 488 + " " + 1848)
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
break;
|
break;
|
||||||
case OCRResult.TO_REFRESH:
|
case
|
||||||
|
OCRResult.TO_REFRESH
|
||||||
|
:
|
||||||
await this.connect_to_browser(OCRResult.TO_REFRESH)
|
await this.connect_to_browser(OCRResult.TO_REFRESH)
|
||||||
break;
|
break;
|
||||||
case OCRResult.BLOCKED:
|
case
|
||||||
|
OCRResult.BLOCKED
|
||||||
|
:
|
||||||
await this.resetBrowser();
|
await this.resetBrowser();
|
||||||
break;
|
break;
|
||||||
case OCRResult.ONLINE_APPOINTMENT:
|
case
|
||||||
|
OCRResult.ONLINE_APPOINTMENT
|
||||||
|
:
|
||||||
await this.clickOnlineAppointment();
|
await this.clickOnlineAppointment();
|
||||||
break;
|
break;
|
||||||
case OCRResult.CONFIRM_RESEND_FORM:
|
case
|
||||||
|
OCRResult.CONFIRM_RESEND_FORM
|
||||||
|
:
|
||||||
// logWithDevice("CONFIRM_RESEND_FORM", this.device)
|
// logWithDevice("CONFIRM_RESEND_FORM", this.device)
|
||||||
// await this.checkResultWithOcr();
|
// await this.checkResultWithOcr();
|
||||||
break;
|
break;
|
||||||
case OCRResult.PAGE_OPTIMIZATION:
|
case
|
||||||
|
OCRResult.PAGE_OPTIMIZATION
|
||||||
|
:
|
||||||
logWithDevice("PAGE_OPTIMIZATION", this.device)
|
logWithDevice("PAGE_OPTIMIZATION", this.device)
|
||||||
await this.skipOptimizationPage();
|
await this.skipOptimizationPage();
|
||||||
await this.checkResultWithOcr();
|
await this.checkResultWithOcr();
|
||||||
break;
|
break;
|
||||||
case OCRResult.GOOGLE_DISCONNECT:
|
case
|
||||||
|
OCRResult.GOOGLE_DISCONNECT
|
||||||
|
:
|
||||||
logWithDevice("GOOGLE_DISCONNECT", this.device)
|
logWithDevice("GOOGLE_DISCONNECT", this.device)
|
||||||
this.device.shell("input tap " + 411 + " " + 2100)
|
this.device.shell("input tap " + 411 + " " + 2100)
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
await this.checkResultWithOcr();
|
await this.checkResultWithOcr();
|
||||||
break
|
break
|
||||||
case OCRResult.NEED_TO_CLICK_LATE_BTN:
|
case
|
||||||
|
OCRResult.NEED_TO_CLICK_LATE_BTN
|
||||||
|
:
|
||||||
await this.tapLaterBtn()
|
await this.tapLaterBtn()
|
||||||
this.firstStart = true;
|
this.firstStart = true;
|
||||||
await this.loadPage()
|
await this.loadPage()
|
||||||
break;
|
break;
|
||||||
case OCRResult.CLOSED:
|
case
|
||||||
|
OCRResult.CLOSED
|
||||||
|
:
|
||||||
await this.closePage();
|
await this.closePage();
|
||||||
// this.isTerminated = true;
|
// this.isTerminated = true;
|
||||||
break;
|
break;
|
||||||
@@ -850,8 +876,18 @@ class CommandorPage {
|
|||||||
await delay(5000);
|
await delay(5000);
|
||||||
checkResult = this.ocrChecker.get_result();
|
checkResult = this.ocrChecker.get_result();
|
||||||
}
|
}
|
||||||
if (checkResult === undefined) {
|
|
||||||
await delay(5000);
|
if (checkResult
|
||||||
|
|
||||||
|
===
|
||||||
|
undefined
|
||||||
|
) {
|
||||||
|
await
|
||||||
|
|
||||||
|
delay(
|
||||||
|
5000
|
||||||
|
)
|
||||||
|
;
|
||||||
checkResult = this.ocrChecker.get_result();
|
checkResult = this.ocrChecker.get_result();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user