cypress-har-generator
cypress-har-generator copied to clipboard
Request issued by `cy.request` cannot be captured
In generated har file, couldn't see the request/data between a web browser and a web server (XHR) (access token endpoint request, scim endpoint and etc). Is this the limitation of this plugin?
Appreciate any input/workaround to capture the details of the xhr type of request in the har file.
Any update on this question? Is there any way to capture the xhr type of request in the .har file with this plugin?
@Kanapriya the plugin must capture all requests inside your browser session including those which have been sent by cy.request
(see examples). Please provide a reproducible sample repo.
Hey @derevnjuk, I've created a sample repo for your reference.
With the spec, you can see that I've made multiple cy.request
requests but none of them were caught by the cypress-har-generator
. I believe the reason behind this is that cypress doesn't make cy.request
requests from the browser as mentioned here. Also, such requests are not available in the har file that was exported from the chrome browser.
My only question is, the har file generated by the chrome browser shows all the requests that were made during the session whereas the har file generated by cypress-har-generator
shows the requests that were made during the last test of the spec. Why is this so?
@pranavj1001 I am not a developer in this project but have written similar tools for other languages so have experience with the concepts. Hopefully the owners of this project won't mind me answering this question.
This plugin uses the Chrome DevTools Protocol (https://chromedevtools.github.io/devtools-protocol/) to subscribe to events triggered by chrome when HTTP requests are made and received. By keeping track of these events (there are multiple events associated to one request/response), a HAR file can be generated from the available data.
As a result, only requests made by the browser generate these events, hence requests made by the node process such as cy.request
are not captured.
I guess that in theory as the process that is subscribing to the CDP events is the same process that makes the cy.request
, a HAR file could be created that includes these also but they would have to be added to the HAR explicitly.
Whether it is possible for HAR generation code to access a log of cy.request
, I don't know but would definitely be an enhancement request to this plug in.
Just to also say, there may be some confusion over the term XHR
; my AUT makes many XHR
requests after the page has finished loading and they are all captured.
cy.request
is not an XHR
as it is made by the node process not the browser
xhr type request are available in the json file though it not display by importing any of the har file viewer. tried with chrome dev tools, and etc..