mardi 19 juin 2018

How to increase Navigation Timeout when running Puppeteer tests with Jest

I have a small suite of tests based on Puppeteer with Jest, and I can't get rid of the following problem: when I am running a single specific test (ex: yarn test myscenario.test.js) everything works just fine; the problem occurs when I am running the entire test suite (about 20 tests) using yarn test command, some of my tests are failing with following error:

Navigation Timeout Exceeded: 30000ms exceeded at Promise.then (node_modules/puppeteer/lib/NavigatorWatcher.js:73:21)

The thing is that all my tests already have a specific timeout already set (99999 ms !!) and a single test is executed in about 6-7 seconds. My guess is that when the entire test suite is running, there is a global navigation timeout which exceeds the limits of 30000ms.

Is there any way to override this global Navigation Timeout limit?

Here is how one of my tests (myscenario.test.js) looks like (which iterates through a JSON file and navigates to various URLs where executes some simple actions):

const puppeteer = require('puppeteer')
const propertiesReader = require('properties-reader')
const jsonReader = require("fs")
const prop = propertiesReader('./resources/config.ini')
const tealiumTags = JSON.parse(jsonReader.readFileSync('./resources/tealium-tags.json', 'utf8'))

let browser
let page

beforeEach (async () => {
    browser = await puppeteer.launch({headless: true, args: ['--start-maximized']});
    page = await browser.newPage();
    await page.setViewport({ width: 1920, height: 1080 })
  })

afterEach (() => {
    browser.close()
  })

describe('Decline all Tealium tags', () => {
 
    for (let brand in tealiumTags) {
      if (tealiumTags.hasOwnProperty(brand)) {
        
        let brandUrl = tealiumTags[brand].url

        test('Decline all Tealium tags for ' + brandUrl, async () => {
          
          console.log("---------------------------------------")
          console.log("Decline all Tealium tags for " + brandUrl)
          await page.goto("https://www." + brandUrl, { waitUntil: 'domcontentloaded' })
          await page.waitForSelector(prop.get('DECLINE_COOKIES_BUTTON'))
          await page.click(prop.get('DECLINE_COOKIES_BUTTON'))    
          await page.waitForNavigation({waitUntil: 'domcontentloaded'})

          let utag = await page.evaluate(() => window.utag["send"])

          expect(Object.keys(utag).length).toEqual(0)

        }, 99999)
      }
    }
})

Any hint on this matter would be much appreciated, thanks!

Aucun commentaire:

Enregistrer un commentaire