Open bheemreddy181 opened 1 year ago
You can set the DEBUG=pw:debug
environment variable, which will print the request and response headers to the console. Does that work for you?
@mxschmitt not really - can we add log=all flag for api testing so that it logs both requests and response along with headers and the time taken by these requests ?
Isn't this already what you want?
@mxschmitt no - Can we have both requests and responses logged as well ? like if we have POST request or a PUT request or even with a Get the Response to the console
I mean the request body and the response body to the console.
If you want to see more information about api requests, you can use Playwright tracing, there request and response information are attached: https://playwright.dev/dotnet/docs/trace-viewer
But that is when we use playwright for UI testing but my request is exclusively when we do api testing alone.
Usually you have assertions, which fail then when something goes wrong. e.g. wrong response body received.
Relates https://github.com/microsoft/playwright/issues/18891 which allows tracing for request api contexts.
idea is to print a debug log like above how you print the headers in a similar format print both requests and responses.
Why do we refer to assertions here it doesn't matter when we have chained requests it is very important to look at requests and responses and if we can print them to console it will make life easier for debugging , does that answer the need for this request to be implemented when we print the headers why can't we also print the requests and responses to the console ?
Usually request and response bodies are very large. Most users dont want to see them, since its cluttering their output.
We'll keep this for now open as a feature request to improve debugging for api testing.
Not every time the requests and response bodies are big and that's the reason I was referring to have a flag to print them to console so that it's up to the one who is debugging it.
Any new updates on this ?
I have to agree with @bheemreddy181 - this would be a very useful feature for debugging purposes.
Also would like to have a better api testing solution baked in the framework. You made UI a breeze now pls add API Testing to the roadmap. At least REST
@Kranael we already use playwright for API testing right now. Agree they make things more efficient like adding debugging proxy etc for api testing.
Again if I use specflow as the runnner i can't use the default debug env variable
I also agree with @bheemreddy181 Please help to make the debugging easier for API Testing.
Any new updates on this feature ?
any updates on this feature w.r.t API testing, please?
@aslushnikov @mxschmitt it would be great if we can have some similar functionalities of https://github.com/ladjs/supertest for now really looking into extended debugging capabilities
I agree I think this would be great to have. Ideally have this both for UI and api calls as an reporter that could either print it to console or to file (per test case)
Would love this feature not just in Debug mode....think about it from this perspective....any time a test fails whether UI or API and the failure happens to be on a APIRequestContext....whats the first thing any dev is going to ask?
How did you send the API Request?
They will want to see the URL, Headers, Body, Params, etc etc...
Being able to toggle this on for those that prefer to have this information output to the console would be a bliss. Dont make it a project toggable...should be an options within APIRequestContext.
Same would love to have a feature to print the API request's Body and response's Body as currently im using console.log to print the response body every single time after manually converting the response to json. thats 2 lines every time I wish to see the response in the terminal for each tests.
This is definitely a feature I am waiting for. Could you please add logging of URL, headers, params, body?
Rather than focus on the logging, would it be possible instead to update the APIRequestContext object to support access of the request URI/headers/body? Currently, APIRequestContext allows you to perform HTTP operations but once you use post/get etc. you only have access to the response. Either way, you never have access to the request contents itself.
Alternatively, having an "originalRequest" object available would also be useful, e.g. request.post(url, requestObject).originalRequest
.
This would allow for logging of this to be decided by the Playwright user.
Also it would be cool if the http logs are automatically attached in the test report.
Hello I come from the Cypress world, and it was super easy to do with Cypress. By clicking on a request command in the command log, you can get the full request and response detail in the Console. I used it a lot when writing new tests.
Can we have an ability to log requests and response with the time taken for the requests along with all headers to console embedded in the code itself may be via flag ?