API Automation testing with Cypress and Playwright.
We are going to compare one scenario using two different frameworks: Cypress and Playwright.
For our experiment, I will be using this site: https://conduit.bondaracademy.com/.
Let's imagine we have the following test case:
Here is the code for Cypress (with Cypress API plugin) :
A few interesting details:
You can find the full repo here : https://github.com/EvgeniiDolzhenko/cypress-conduit-api .
It's designed for a specific user, but feel free to run it on your end, as the 'cypress.env.json' file with credentials is available for public use. You might discover some more interesting examples.
Let's compare Playwright's code using the same test scenario:
Recommended by LinkedIn
I would like to highlight some details:
Here is the test.ts file:
Full repo is here : https://github.com/EvgeniiDolzhenko/playwright-conduit-api-ui (still in progress) .
Conclusion:
Both options look interesting to me. My opinion is that it's easier to set up a global hook in Cypress, and the Cypress API plugin allows you to monitor everything that's happening in open mode, which I find to be a significant advantage for Cypress. I hope Playwright will implement something similar in the future.
On the other hand, Playwright offers an amazing fixture feature that allows you to centralize your pages in one place, which is definitely a great advantage. Additionally, the await/async logic in Playwright seems more readable and compact compared to Cypress (.its, .then, etc.).
What do you think? Which option did you prefer more?
P.S.
Perhaps some things could have been done differently, and there is always room for improvement, but I believe some of you will find this information helpful.
Thank you.
Eugene Dolzhenko , after 9mo of your article , there is now available a Playwright api plugin to see results in the console UI, Trace viewer, and HTML report 🙂 https://github.com/sclavijosuero/pw-api-plugin
Amazing article, loved reading it. Keep up
Exciting article Eugene! I feel like Cypress is a more mature solution at the moment, Playwright however can boast of some features that Cypress currently does not have. In general Playwright looks very promising.
Rainer Cruz Laury P. Guerrero