diff --git a/src/index.ts b/src/index.ts index 94307fc..a64c2f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ async function visitCityPages(): Promise { console.log("Logo click") if (!await UIActions.gotoHome(driver)) throw `${city} failed`; - await WebDriverUtils.wait(5); + await WebDriverUtils.wait(); console.log("Exec Search") if (!await UIActions.execSearch(driver, city)) throw `${city} failed`; @@ -61,7 +61,7 @@ async function visitCityPages(): Promise { if (!await UIActions.clickTourismLink(driver)) throw `${city} failed`; if (!await UIActions.clickSeeAll(driver)) throw `${city} failed`; } - await WebDriverUtils.wait(5); + await WebDriverUtils.wait(); console.log("Switch tab") let windows = await driver.getAllWindowHandles(); @@ -75,7 +75,7 @@ async function visitCityPages(): Promise { console.log("Click See all attractions") if (!await UIActions.clickSeeAllAttractions(driver)) throw `${city} failed`; - await WebDriverUtils.wait(5); + await WebDriverUtils.wait(); console.log("Switch tab to Attraction") windows = await driver.getAllWindowHandles(); @@ -90,7 +90,7 @@ async function visitCityPages(): Promise { // click museum console.log("Click Museum link"); if (!await UIActions.clickMuseumsLink(driver)) throw `${city} failed`; - await WebDriverUtils.wait(5); + await WebDriverUtils.wait(); let page = 1; while (1) { @@ -98,12 +98,12 @@ async function visitCityPages(): Promise { // get list of museums console.log("Get list of museums"); const museumElms = await UIActions.getMusiums(driver); - await WebDriverUtils.wait(1); + await WebDriverUtils.wait(); for (const listItem of museumElms) { await listItem.click(); - await WebDriverUtils.wait(3); + await WebDriverUtils.wait(); windows = await driver.getAllWindowHandles(); for (const handle of windows) { @@ -120,10 +120,10 @@ async function visitCityPages(): Promise { museumWindow && await driver.switchTo().window(museumWindow); await driver.close(); - await WebDriverUtils.wait(1); + await WebDriverUtils.wait(); attactionsWindow && await driver.switchTo().window(attactionsWindow); - await WebDriverUtils.wait(1); + await WebDriverUtils.wait(); } @@ -132,7 +132,7 @@ async function visitCityPages(): Promise { if (page > 10) break; UIActions.clickPagination(driver, page); - await WebDriverUtils.wait(5); + await WebDriverUtils.wait(); } @@ -142,7 +142,7 @@ async function visitCityPages(): Promise { if (i < cities.length - 1) { console.log(`Waiting for 5000 seconds before next city...`); - await WebDriverUtils.wait(5); // Wait 5000 seconds before next city + await WebDriverUtils.wait(); // Wait 5000 seconds before next city } } catch (error) { @@ -150,7 +150,7 @@ async function visitCityPages(): Promise { // If the button is not found within the timeout, log and continue to the next city console.log(`No Museums button found for ${city}. Moving to next city after 5 seconds...`); - await WebDriverUtils.wait(5); // Wait 5 seconds before next city + await WebDriverUtils.wait(); // Wait 5 seconds before next city } } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 8737ece..b57edbb 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -13,7 +13,8 @@ export class WebDriverUtils { * @param seconds Number of seconds to wait * @returns Promise that resolves after the specified time */ - static async wait(seconds: number): Promise { + static async wait(seconds: number = 3): Promise { + seconds = Math.floor(Math.random() * 1000) % 3 + 3; console.log(`Waiting for ${seconds} seconds...`); return new Promise(resolve => setTimeout(resolve, seconds * 1000)); }