question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

waitForRequest doesn't capture request quick enough

See original GitHub issue

I use puppeteer for running click tests on a web application. A couple of test cases require me to find out whether or not a network request is sent to fetch a file from server. To do this I use puppeteer’s waitForRequest method.

However the requests aren’t captured consistently. On multiple occasions the command times out which results in a failed test. The chrome dev tools on the other hand capture the request while the test is running.

In verbose mode I get this feedback in console

I wait for request "http://localhost:4200/assets/img/cursor/zoom-in.cur"
[1] Error | TimeoutError: Timeout exceeded while waiting for event
Emitted | step.failed (I wait for request "http://localhost:4200/assets/img/cursor/zoom-in.cur")
Emitted | step.finish (I wait for request "http://localhost:4200/assets/img/cursor/zoom-in.cur")
[1] Error | TimeoutError: Timeout exceeded while waiting for event

This is the test scenario

I.click('.zoom');
I.waitForRequest("http://localhost:4200/assets/img/cursor/zoom-in.cur")
I.seeElement(".zoom-menu");

Details

  • CodeceptJS version: 2.02
  • NodeJS Version: 9.11.2
  • Operating System: Windows 10 (1809)
  • Configuration file:
exports.config = {
  tests: './codecept-tests/*.js',
  timeout: 10000,
  output: './output',
  helpers:
  {
    Puppeteer:
    {
      url: 'http://localhost',
      show: true,
      windowSize: '1280x720',
      chrome:
      {
        defaultViewport: { width: 1280, height: 720 }
      }
    }
  },
  include: {},
  bootstrap: false,
  mocha: {},
  name: 'frontend',
  plugins: { screenshotOnFail: { enabled: true } }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

3reactions
Meekohicommented, Feb 19, 2020

fwiw I do like:

await Promise.all([
  I.click('.zoom'),
  I.waitForRequest("http://localhost:4200/assets/img/cursor/zoom-in.cur"),
])
3reactions
inigo-martincommented, Nov 21, 2019

In my case, the problem was that the Application was firing the Request before the waitForRequest took place. So it never catched the Request.

That is because Puppeteer waits 100ms (by Default) after actions like click, doubleClick or PressKey.

Puppeteer Config waitForAction

To solve the issue, I just had to set this waitForAction parameter to 0:

exports.config = {
    tests: './integration/*_test.js',
    output: './integration/output',
    helpers: {
        Puppeteer: {
            url: 'http://localhost:3040',
            restart: false,
            show: true,
            windowSize: '1280x960',
            waitForAction: 0,
            chrome: {
                defaultViewport: {
                    width: 1280,
                    height: 800,
                },
            },
        },
        MockRequest: {},
    },
    include: {},
    bootstrap: null,
    mocha: {
        reporterOptions: {
            reportDir: './integration/output',
        },
    },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

waitForRequest doesn't capture request quick enough #1464
To do this I use puppeteer's waitForRequest method. However the requests aren't captured consistently. On multiple occasions the command times ...
Read more >
waitForRequest doesn't capture request quick enough
I use puppeteer for running click tests on a web application. A couple of test cases require me to find out whether or...
Read more >
Codeceptjs + Puppeteer. How to catch fast requests - Medium
My problem was that waitForRequest doesn't capture the request quick enough and my test always fails when I click the button and am...
Read more >
Python Requests: Don't wait for request to finish - Stack Overflow
Here's a hacky way to do it: try: requests.get("http://127.0.0.1:8000/test/",timeout=0.0000000001) except requests.exceptions.ReadTimeout: pass.
Read more >
Browser - MarketSquare
Browser library is a browser automation library for Robot Framework. This is the keyword documentation for Browser library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found