Hi Everyone, I need to create a API test where i am sending Authorization as Basic auth and access token as Password / content-type -> application/json-patch+json / body -> json . In the bellow images when i am doing the same with correct value in Postman i am successfully hitting the API. But i am not able to understand how to get the same result in Playwright? Can anyone pls help me ?
This thread is trying to answer question "How to create an API test using Playwright with Basic auth and access token?"
I'm 6 articles deep into a guide on using Playwright for API testing, all the information is here for you to learn.
I won't have covered your specific Basic auth scenario, but the pattern I use (due to the application I was testing against) is very similar, using a token
https://playwrightsolutions.com/is-it-possible-to-do-api-testing-with-playwright-the-definitive/
Yeah, I am currently working on an API regression suite to allow my E2E framework as well as raw endpoint tester similar to what you have done. This allows our testers to have the freedom to work with both. I will create a private repo to hit some non-sensitive APIs so people can grab some ideas from my implementation. We have several APIs but at times you only want to test one, so adding some project logic as well some GH actions, which also will be helpful to the community. I will let you know when this available for consumption.
But When i am doing the same thing using postman i am able to create a Bug. authorization Basic Auth/Body as Json/ Content type -> application/json-patch+json
@shublack your original screenshot showed 6 headers in postman (you may not need every single one but may be worth reviewing and including all or some of them in your playwright test if they are required with the application you are interacting with.
One thing that has gotten me in the passed with postman is the "Cookie Jar". Really useful if postman is the only tool you are using, as it will attempt to persist cookies for you automatically, and by default it is on. If you disable the cookie jar (under the request settings) and this will ensure that Postman isn't doing any auth magic behind the scenes.
Another thing you can do in postman is click on the </> code icon on the request and actually review the raw curl request and compare that against what you are sending with playwright.
@shublack I had an issue and it caught us out a few times. Our token provider requires a encrypted form, so in Insomnia it indicates that it is posting a form vs body. In Playwright you have a similar issue that you will need to POST with a form not a data element. TBH I don't remember if we got a 203 or a 400, was a while ago. Maybe try that. If that is the case, POST, PUT and PATCH have the optional data or form, so I ended up wrapping the intricacies to force the author to be explicit on the request calls, made it a lot easier to debug requests.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].