Open Sakshamrameshhudiya opened 2 years ago
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 : { "teamIds": "99790", "effectiveDate": "2020-01-01" }
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. Thanks
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: PW docs say:
response.request()
Added in: v1.8
returns: <[Request](https://playwright.dev/docs/api/class-request)>[#](https://playwright.dev/docs/api/class-response#response-request-return)
Returns the matching [Request](https://playwright.dev/docs/api/class-request) object.
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. Currently I cant even retrieve the headers or body from the APIRequestContext object, let alone the APIResponse object.
Hi, The same problem, I did not find a solution how to log the body of the request, exactly the part that was sent, not the response body.
Previously used axios for request in playwright, now using pure playwright. a Axios had a method for logging what was sent, what headers and body. "axios.interceptors.request.use..."
It helps to debug the code, very convenient. For example, I send a POST request where there is a set of variables that are requested in the process for data from other places. Ultimately, there is no understanding of what exactly is sent in the body.
{ "id": 0, "category": { "id": 0, "name": await Users.getUsers(request, 'Andy Warhol', 'rw', token),}, "name": nameState, "tags": [ { "id": 0, "name": nameStateTags } ], "status": await States.getCurrentState(request, 'create', token), }
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!!! How do we vote for this feature to be implemented? I am assuming it is not just leaving a comment here ....
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 I have tried it! looks quite good!!! but this is not valid for runtime tasks, i.e. programmatically accessing request data or debugging
+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:
BrowserContext ctx = PlaywrightResourceFactory.BrowserObj.getInstance().newContext();
APIResponse resp = ctx.request().post("/api/login");
+1 for this!
+1 a lot of different libraries will get you the actual request object back on a response. It would be great to have that for the response on generated by the APIContext.request as well
+1, would definitely be useful to be able to access the request body/headers/etc outside of the trace viewer
+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
+1
+1
+1
+1 having this feature would help us to have better control and back tracking.
+1
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.