'How do I create an automated API test in Microsoft Playwright?

Is it possible to create API automation tests in Microsoft Playwright? If so how do I create the following POST request as an automated test in Playwright using javascript?

Please note below is just an example.

POST

https://pokeapi.co/api/v2/pokemon-form/1/

BODY

{
   "name":"test"    
}


Solution 1:[1]

Yes you can run API tests with Playwright. It can be done in a standalone way without using the browser context at all, and also possible while using the browser context.

Playwright is quite different from Cypress in this case since cypress always considers all tests as browser tests, but with playwright requests feature, you can run API tests in standalone mode.

You can see all the required information here. https://playwright.dev/docs/test-api-testing

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 amal jayaraj