-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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] Allow accessing request body and headers when performing http request #16239
Comments
what is pojo? I'm not completely following this request, could you give us an example what you are trying to do? You want to see which extraHttpHeaders are set on a request context? |
Hey Team, I actually want to debug what exact request body I am setting in json format in APIRequestContext |
what do you mean with json format? Could you provide a code example? |
by json format i mean i want to know what request is set in request context ? example : |
Fair enough, so we can make a feature request out of it and call it "Access request object when performing http requests". This would allow you to access headers, body, etc. |
can you please give me and code example in java so as to how fetch these details or if there is some link to refer or something in playwright docuement. |
It's not possible yet. |
Are we thinking of implementing this? I feel this should be a must for debugging if the request body or any other parameter is incorrectly set. If possible, can we also add a logging or trace feature to hit specific requestcontext API. If these features are added this would make it really powerful and a competitor to rest assured. |
Usually you already know which request body you pass into, so you kinda have it. Mostly you care about the response instead, not saying its a bad feature to have, depending on the upvotes we'll implement it. |
Agree that this would be nice for debugging. According to your docs its already possible for page:
Could be great for API debugging so I can be sure my headers have worked correctly, especially if the body or headers passed to APIRequestContext.post() have runtime variables. |
Hi, Previously used axios for request in playwright, now using pure playwright. a It helps to debug the code, very convenient.
|
yeah for my previous project we went with supertest for api calls. We made that design decision over 1 1/2 years ago. Now new job and new project, I thought I'd give the native PW api requests another go, thinking they have improved in some way. I was wrong, and will be using supertest again in the new project. |
Another +1 for "please add this". I can log in via the API I'm supposed to test in literally every other language and dialect of JavaScript/TypeScript I've tried, but can't make it work in a Playwright API test and I can't even make sure that it's sending the data I asked it to. To the person earlier who said that we should know what data we're sending - I know what data I'm telling Playwright to send, I have no idea what data Playwright is actually sending. That's why we need this feature. |
Hello 👋 Any news regarding this? We also need this badly 🙏 |
Hi! And we really need it! 🙏 |
Up! I also need! unless I will need to use third party like chai-http but I dont like this idea |
Hi! And we really need it too, it's so hard to debug now! 🙏 |
yes, please, it is a major debug feature!!! |
Hey fellas, I realized that we can get this info on Trace Viewer! Just go to the line of the API request and you will have all the info about what we need |
Yep, we can use Trace viewer for trace fail script. It's very helpful |
Trace viewer is for UI testing, right? Our problem is for API testing, we just have the "request" response, not the full browser |
@tongilcoto Trace viewer can use for api too, please try to use this for api |
Thank you very much @lucy-mfv |
+1 for access to request context for better debugging. I'm getting a "415 Unsupported media type" http error from a POST request and I can not get the request header field "content-type" to verify if it's correctly being set to 'application/json'. And because these APIs are being executed against the BrowserContext without actually opening a new Page object, TraceViewer is not helpful either. Pesudo code:
|
+1 please provide this, it such an odd thing to be lacking |
Another vote to please add! I can do it with trace viewer, but it's a very heavy-weight solution and, as others have pointed out, this is pretty standard on other API tools. But I want to do my UI testing and API testing in concert, and I could really use this information for debugging. Thanks. |
+1 vote for having this feature |
+1 |
+1 here! Pls add this feat! @mxschmitt |
+1 |
2 similar comments
+1 |
+1 |
+1 |
+1 having this feature would help us to have better control and back tracking. |
+1 |
1 similar comment
+1 |
+1 |
We are really looking forward to this, we would like to have access to actual raw response object on the APIREQUESTCONTEXT |
That sounds like a different feature. Could you open a feature request and elaborate on what's missing from the existing response object? |
We would like to be able to listen to on('resposnse', callback) on the request |
I'm confused. Are you talking about API requests made in your test code, or browser-issued requests? |
And what is |
@Skn0tt pls dont forget accessing request query params. It should be possible to extract it from params object. Body from data and header from extraHttpHeaders Params is also very important. Thank you in Advance! |
oh and it would be perfect if we can access also request method like request.operation() (or method) -> return ."PUT" for example |
@Kranael could you elaborate on your usecase? If you're using |
The usecase would be to not build some wrapper class. We would have all information accessable on the request object like we have with response. We do contract testing for example. We build a function for it.
today we cannot use it just with request because it needs header, body, params and we cannot access it. So we would need
It works but having all information of the request sent on the request object itself would really help to make clean code. So somthing like: With this all information is concentrated in the request object like it is with response. |
@Skn0tt i am primarily interested in building an object like this which playwright internally does and stores in har tracing
i tried to do this in the PR by exposing the event externally but unfortunately PR got closed |
@Skn0tt @pavelfeldman do you think there is any risk in using this kind of approach to capture the data?
so is user makes
|
I am trying invoking an API via playwright and I am setting extraheaders via playwright = Playwright.create();
return playwright.request().newContext(new APIRequest.NewContextOptions()
.setBaseURL(TeamCityEnvironmentVariable("APIBaseUrl"))
.setExtraHTTPHeaders(headers));
and also adding request body to it via pojo classes but I am not able to see what headers and request body is set onces response is given by API.
The text was updated successfully, but these errors were encountered: