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

[Question] Is there a way to access the payload for a PUT request method? #5735

Closed
resaldiv opened this issue Mar 5, 2021 · 11 comments · Fixed by #5736
Closed

[Question] Is there a way to access the payload for a PUT request method? #5735

resaldiv opened this issue Mar 5, 2021 · 11 comments · Fixed by #5736

Comments

@resaldiv
Copy link
Member

resaldiv commented Mar 5, 2021

Hi!

I'm writing a playwright test that intercepts a PUT request and I want to verify that the request payload contains the expected data. I've tried to access the payload like this:

let payload;
let saveCalled = false;

page.on("request", (request) => {
  if (request.url() === requestUrl && request.method() === "PUT") {
    payload = request.postDataJSON();
    saveCalled = true;
  }
});

/*****
*
* Trigger save call
*
*/

expect(saveCalled).toBeTruthy();
expect(payload).not.toBeNull(); // test fails

Even though it enters the if condition and I see the payload in the browser, the postDataJSON() returns null.

I believe that postData() and postDataJSON() only works for POST methods. If that's true, is there a way I can access the request payload for a PUT request method and what would be the right approach to do it?

Thank you.

@pavelfeldman
Copy link
Member

What about request.postDataBuffer()? It could be that your request does not set the content-type request header and Playwright can't know it is JSON.

@resaldiv
Copy link
Member Author

resaldiv commented Mar 5, 2021

Thank you for your answer Pavel. I tried using request.postDataBuffer() and it returns null. I wonder if it has anything to do that the request method is PUT?

Also, thank you for the solution. I will try this when it gets merged.

@pavelfeldman
Copy link
Member

Looks like not yet addressed. PUT should not matter, adding a test for it.

@pavelfeldman
Copy link
Member

Could you share more about your use case? I added a test for PUT specifically and it passed. I wonder if there is something special about your setup. Could you print request headers?

@resaldiv
Copy link
Member Author

Thanks for adding a PUT test. I want to validate that the Azure Storage SDKs are being called correctly from our app using PUT requests. In order to do it, I'm trying to intercept and test this call: https://docs.microsoft.com/en-us/rest/api/storageservices/put-range

@yury-s
Copy link
Member

yury-s commented Mar 10, 2021

Could you share part of the code that sends the request?

@avodovnik
Copy link
Contributor

@resaldiv Feel free to reopen this issue if the problem is still there, providing some sample code for us to figure out how to go about reproducing it.

@BarrBozzO
Copy link

Facing issue decsribed above.
PUT request payload can't accessed with postData or postDataJSON or postDataBuffer

@misharosa
Copy link

Is there some progress in fixing that problem? @BarrBozzO

@ivester
Copy link

ivester commented Mar 22, 2024

I'm facing the same issue

@pishiko
Copy link

pishiko commented Apr 18, 2024

In my case I am using PUT multipart/form-data for file updates, which is deprecated, so I found it impossible to get form-data with playwright's API.

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

Successfully merging a pull request may close this issue.

8 participants