Rayrun
← Back to Discord Forum

Playwright vs axios

rajucheers
rajucheers

Hello all, is there a benefit we get out of using api testing using axios library vs PW. Appreciate thoughts

This thread is trying to answer question "What are the benefits of using axios library vs Playwright for API testing?"

16 replies

@rajucheers I m using Axios too . With Axios ans State mechanism my tests so speed and more manageable

butchmayhew
butchmayhew

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
rajucheers

interesting thoughts

rajucheers
rajucheers

@yusufozt. , what is State mechanism?

@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

}

By the way axios interceptors are useful

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.

rajucheers
rajucheers

Ok

I used both axios and playwright. One disadvantage that I see with playwrifght. If I use another context to api to add the auth another tracer is added to html reporter.

refactoreric

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

rajucheers
rajucheers

ok

@butchmayhew: 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

Regarding the difference with generating API clients: Probably someone in the community should write OpenAPI client generators for Playwright, then that difference is gone.

@refactoreric: 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.

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.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].