microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.19k stars 3.62k forks source link

[Feature] Make Debugging easy for API Testing #19177

Open bheemreddy181 opened 1 year ago

bheemreddy181 commented 1 year ago

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 ?

mxschmitt commented 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?

bheemreddy181 commented 1 year ago

@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 ?

mxschmitt commented 1 year ago

Isn't this already what you want?

image
bheemreddy181 commented 1 year ago

@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

bheemreddy181 commented 1 year ago

I mean the request body and the response body to the console.

mxschmitt commented 1 year ago

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

bheemreddy181 commented 1 year ago

But that is when we use playwright for UI testing but my request is exclusively when we do api testing alone.

mxschmitt commented 1 year ago

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.

bheemreddy181 commented 1 year ago

idea is to print a debug log like above how you print the headers in a similar format print both requests and responses.

bheemreddy181 commented 1 year ago

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 ?

mxschmitt commented 1 year ago

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.

bheemreddy181 commented 1 year ago

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.

bheemreddy181 commented 1 year ago

Any new updates on this ?

nigeljamesstevenson commented 1 year ago

I have to agree with @bheemreddy181 - this would be a very useful feature for debugging purposes.

Kranael commented 1 year ago

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

bheemreddy181 commented 1 year ago

@Kranael we already use playwright for API testing right now. Agree they make things more efficient like adding debugging proxy etc for api testing.

bheemreddy181 commented 1 year ago

Again if I use specflow as the runnner i can't use the default debug env variable

winnie-sg commented 1 year ago

I also agree with @bheemreddy181 Please help to make the debugging easier for API Testing.

bheemreddy181 commented 1 year ago

Any new updates on this feature ?

Guru426 commented 1 year ago

any updates on this feature w.r.t API testing, please?

bheemreddy181 commented 1 year ago

@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

marcusNumminen commented 1 year ago

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)

NonfriPax8 commented 9 months ago

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.

VenilThegn commented 7 months ago

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.

marcinrak commented 5 months ago

This is definitely a feature I am waiting for. Could you please add logging of URL, headers, params, body?

avaeroh commented 2 months ago

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.

syeikhanugrah commented 2 months ago

Also it would be cool if the http logs are automatically attached in the test report.

sboursault commented 3 weeks ago

Hello I come from the Cypress world, and it was super easy to do with Cypress. image 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.