From 1993480fa66d885b62022db98c23d6ee49a504d8 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Mon, 12 Sep 2022 13:47:58 +0200 Subject: [PATCH] check page is closed or not before inputing user info with try catch --- src/workers/CommandorPage.js | 40 +++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index f1a5633..9034ea7 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -101,13 +101,22 @@ class CommandorPage { } async chooseCountry(page) { - await page.locator(COUNTRY_ID).focus(); - await delay(getRandomWaitTime()) - await page.click(COUNTRY_ID); - await delay(getRandomWaitTime()) - await page.selectOption(COUNTRY_ID, 'FR'); - await delay(getRandomWaitTime()) - // await page.click(COUNTRY_ID); + if (!page.isClosed()) { + try { + + + await page.locator(COUNTRY_ID).focus(); + await delay(getRandomWaitTime()) + await page.click(COUNTRY_ID); + await delay(getRandomWaitTime()) + await page.selectOption(COUNTRY_ID, 'FR'); + await delay(getRandomWaitTime()) + } catch (e) { + console.log(e); + this.isTerminated = true; + } + // await page.click(COUNTRY_ID); + } } async fillEmail(page) { @@ -124,11 +133,18 @@ class CommandorPage { async inputName(page) { await page.locator(LAST_NAME).focus() await delay(getRandomWaitTime()) - if (!page.isClosed()) { - await page.locator(LAST_NAME).fill(this.contact.lastName) - await page.locator(FIRST_NAME).focus() - await delay(getRandomWaitTime()) - await page.locator(FIRST_NAME).fill(this.contact.firstName) + try { + + + if (!page.isClosed()) { + await page.locator(LAST_NAME).fill(this.contact.lastName) + await page.locator(FIRST_NAME).focus() + await delay(getRandomWaitTime()) + await page.locator(FIRST_NAME).fill(this.contact.firstName) + } + } catch (e) { + console.log(e); + this.isTerminated = true } }