Hi Guys I need some help for a scenario
- I have an Array with say filled with Google, Yahoo 100 objects.
- If Google do X
- Else Yahoo do Y
This is easy in say Java Selenium, just loop through with an if statement, and start stop browser, given puppeteer runs async how can I achieve this with Javascript? Also using Jest.
I tried making the foreach loop async to be able to run await but the obvious issue is it launches all the browsers at once.
Would like to avoid .then promise chains for puppeteer.
describe('Sample Test', () => {
let browser
let page
beforeAll(async () => {
browser = await puppeteer.launch()
page = await browser.newPage()
})
afterAll(async () => {
await browser.close()
})
it('should search on google and navigate to domain', async () => {
jest.setTimeout(500000)
let numOfTotalVists = await helpers.getTotalVisits()
numOfTotalVists.forEach(element => {
if (element.includes('Google')) {
browser = puppeteer.launch()
page =browser.newPage()
browser.close()
}
console.log('no')
browser = puppeteer.launch()
page = browser.newPage()
browser.close()
})