Playwright, didn't know I missed it
Introduction
For a recent project I was introduced to Playwright. It promises reliable end-to-end testing for web applications. After initially being skeptical (due to experiences with other test automation tools), I was soon amazed by the ease of use and stability.
In a nutshell
The installation worked flawlessly and the interactive running mode (playwright test --ui
) provides immediate insight into how a test runs. The interactive
generation of code for tests (playwright codegen
) also works very well without generating bloat.
A little caveat
At first I didn’t realize that:
- actions are async (and must therefore be
await
ed) - locators are not async
- locators are lazy
This implies that the following assertions can both be true if you are testing a dynamic page:1
await page.goto('/')
const sections = page.locator('section')
await expect(sections).toHaveCount(1)
await expect(sections).toHaveCount(0)
The above test will pass if there is initially a single section on the page and it is later removed by the tested application. I was surprised!
Conclusion
All in all, Playwright is a pleasant discovery for me!
Notes
- I used TypeScript here, but Playwright supports multiple languages. ⤴