Codeceptjs + Puppeteer. How to catch fast requests
Hi everyone, I’m a QA engineer for one of the leading online stores. When I came to work for this company, the main task I was faced with was to build the architecture for UI autotests, and for a number of reasons I chose the Codeceptjs framework, using Puppeteer. In this article, I would like to talk about a problem I encountered in working with the requests, and how I solved it.
I think you must be familiar with the method, waitForRequest, in Codeceptjs.
It’s really cool, but sometimes it doesn’t work.
My problem was that waitForRequest doesn’t capture the request quick enough and my test always fails when I click the button and am awaiting the request; but I can see the required request in the network console when I perform my actions in the browser manually.
I came to the conclusion that I need to start catching the request before I execute any action leading to the sending of this request. So, I wrote to my helper with the methods that I needed. Since I mainly caught requests by clicking on some element (button), (you can write similar methods to open a specific page or to perform another action), my helper looks like this:
Great. I catch all requests, but now I need my request. I implemented the method:
My scenario looks like:
instead of:
I.click(myElement);
I.waitForRequest(…);
So I solved my problem and the test is passed!
Thank you for reading to the end, I hope my article will help you