Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Make Debugging easy for API Testing #19177

Open
bheemreddy181 opened this issue Nov 21, 2022 · 28 comments
Open

[Feature] Make Debugging easy for API Testing #19177

bheemreddy181 opened this issue Nov 21, 2022 · 28 comments

Comments

@bheemreddy181
Copy link

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
Copy link
Member

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
Copy link
Author

@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
Copy link
Member

Isn't this already what you want?

image

@bheemreddy181
Copy link
Author

@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
Copy link
Author

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

@mxschmitt mxschmitt transferred this issue from microsoft/playwright-dotnet Nov 30, 2022
@mxschmitt
Copy link
Member

mxschmitt commented Dec 1, 2022

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
Copy link
Author

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

@mxschmitt
Copy link
Member

Usually you have assertions, which fail then when something goes wrong. e.g. wrong response body received.

Relates #18891 which allows tracing for request api contexts.

@bheemreddy181
Copy link
Author

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

@bheemreddy181
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link
Author

Any new updates on this ?

@nigeljamesstevenson
Copy link

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

@Kranael
Copy link

Kranael commented Mar 23, 2023

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
Copy link
Author

@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
Copy link
Author

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

@winnie-sg
Copy link

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

@bheemreddy181
Copy link
Author

Any new updates on this feature ?

@Guru426
Copy link

Guru426 commented Jun 27, 2023

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

@bheemreddy181
Copy link
Author

bheemreddy181 commented Jun 27, 2023

@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
Copy link
Contributor

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
Copy link

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
Copy link

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
Copy link

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

@avaeroh
Copy link

avaeroh commented Jul 18, 2024

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
Copy link

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

@sboursault
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests