Updated: Sep 14, 2020
I run into a situation were the API test was passing correctly and E2E tests too, but the app was doing over calls to the backend, and we end up with a server down.
I was forced to check XHR requests of the app and see which actions produce duplicated XHR requests and infinite loops.
This done by hand was a nightmare. I realized that the app was doing a lot of requests to the app, and check each one by hand for each action was not a good idea.
How this can be done automatically ?
I found this utility for selenium https://github.com/lightbody/browsermob-proxy that at first look great.
First off you have to modify your driver in order to be able to use it, and then you can check requests.
The first implementation of this looked slow and ended up with a tedious code to handle the request.
Puppeteer and intercepted requests
Now the little boy puppeteer comes in action, a "new" tool for automating that gives a lot more options than selenium.
Puppeteer has a great API to handle the request in the browser. So as simple as this:
We can block all XHR of type images to load the page faster.
This is a lot faster and easy than build with browser mob and selenium really.
The helper method created for puppeteer is this one, that can store duplicated requests and console errors in a file.
And this is a basic use case
Final notes about puppeteer
The control that puppeteer offers is impressive, can handle requests really easy and console error.
Is really more fast than selenium finding and interacting with web elements