This thread is trying to answer question "What are the benefits of using axios library vs Playwright for API testing?"
I've got a suite of 1400+ api tests using only playwright api methods, have no issues, suite is fast, the built in test runner and reports with trace files make debugging easy. I haven't used axios directly but I'm pretty sure that's whats being used underneath the playwright implementation.
@rajucheers Saving axios response to state but you can also run states with Playwright api For e.g saving responses to States and calling them in tests
export const ReportsState = { //API createdDashboardId: {} as string, createdDashboardTitle: {} as string, createdWidgetName:{} as string,
//E2E
createdFakeWidgetName: {} as string,
createdFakeDashboardName: {} as string,
updatedFakeWidgetName: {} as string,
fakeQuadrantNumber: {} as any
}
We use axios within our playwright framework to do our api handling / calls. I've built out two similar services that utilize axios vs playwright api tools and found that axios provides a little more speed and better async handling for some of our specific api endpoints that require multiple steps.
For easier troubleshooting I'd recommend Playwright's APIRequestContext (request
or page.request
) since its API requests and responses are included in Playwright's trace files. I don't think that's the case with axios.
https://playwright.dev/docs/trace-viewer-intro
Hmm, it seems that Plawright has its own fetch implementation: https://github.com/microsoft/playwright/blob/2f4acbb001f5e057de243fedc075b37bcc7719a7/packages/playwright-core/src/server/fetch.ts
The main benefit for me is how easy we can create AXIOS API clients based on OpenApi documentation using swagger-typescript-api
I have used it in two projects and it has been easy to maintain and develop, you can check this examples:
https://github.com/pajdekPL/pw_structure/
With PW and TS we can probably at least use typing: https://openapi-ts.dev/introduction
Axios API calls won't get included into the Playwright trace files. The APIRequestContext (request / page.request) API calls will get included.
The trace files and trace viewer are incredibly useful tools for troubleshooting, and it's a waste to have to miss that.
I would advocate for using Playwright's built-in APIRequestContext any day. https://playwright.dev/docs/trace-viewer-intro
I've been dabbling with this, but no where ready, even have a postman collection reader... 🙂 All part of a large tool set i've been working on.
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].