playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Make Debugging easy for API Testing

Open bheemreddy181 opened this issue 3 years ago • 25 comments

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 ?

bheemreddy181 avatar Nov 21 '22 02:11 bheemreddy181

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 avatar Nov 21 '22 23:11 mxschmitt

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

bheemreddy181 avatar Nov 22 '22 02:11 bheemreddy181

Isn't this already what you want?

image

mxschmitt avatar Nov 30 '22 17:11 mxschmitt

@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 avatar Nov 30 '22 17:11 bheemreddy181

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

bheemreddy181 avatar Nov 30 '22 17:11 bheemreddy181

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

mxschmitt avatar Dec 01 '22 22:12 mxschmitt

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

bheemreddy181 avatar Dec 01 '22 22:12 bheemreddy181

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.

mxschmitt avatar Dec 02 '22 18:12 mxschmitt

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

bheemreddy181 avatar Dec 02 '22 19:12 bheemreddy181

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 ?

bheemreddy181 avatar Dec 04 '22 02:12 bheemreddy181

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.

mxschmitt avatar Dec 05 '22 19:12 mxschmitt

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 avatar Dec 05 '22 19:12 bheemreddy181

Any new updates on this ?

bheemreddy181 avatar Mar 23 '23 04:03 bheemreddy181

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

nigeljamesstevenson avatar Mar 23 '23 11:03 nigeljamesstevenson

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 avatar Mar 23 '23 12:03 Kranael

@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 avatar Mar 24 '23 02:03 bheemreddy181

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

bheemreddy181 avatar Mar 27 '23 20:03 bheemreddy181

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

winnie-sg avatar Apr 16 '23 12:04 winnie-sg

Any new updates on this feature ?

bheemreddy181 avatar Jun 26 '23 13:06 bheemreddy181

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

Guru426 avatar Jun 27 '23 18:06 Guru426

@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

bheemreddy181 avatar Jun 27 '23 18:06 bheemreddy181

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)

marcusNumminen avatar Aug 15 '23 09:08 marcusNumminen

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.

NonfriPax8 avatar Dec 19 '23 18:12 NonfriPax8

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.

VenilThegn avatar Mar 14 '24 08:03 VenilThegn

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

marcinrak avatar Apr 30 '24 11:04 marcinrak