(no title)
emmanueloga_ | 5 months ago
await page.getStarted(); // what does this actually do?
vs await page.locator('a', { hasText: 'Get started' }).first().click();
await expect(page.locator('h1', { hasText: 'Installation' })).toBeVisible();
The second version is explicit and self-documenting. Tests don't always benefit from aggressive DRY, but I've seen teams adopt POMs to coordinate between SDETs and SWEs.--
sa46|5 months ago
This argument also applies to using a function for abstraction.
I've just written a few dozen e2e tests with Playwright. The code looks like:
Each of those lines is 3 to 20 lines of Playwright code. Aggressive DRY is bad, but Page Object Models are usually worth it to reduce duplication and limit churn from UI changes.zikani_03|5 months ago
Hadn't considered the Page Object Model and will definitely have to consider how to incorporate that for those who want to do things that way.
---
1: https://github.com/zikani03/basi
littlecranky67|5 months ago
Another note on your specific example: You are probably in the US and only have a single-language project. I am a Frontend Contractor in Europe and for the past 10 years didn't have a single project that was single language, hence the "hasText" selector would always be off-limits. Instead, very often we used the react-intl identificator as text content for code execution - which would make the above example look much more unreadable without POs, while with POs the code looks the same (just your PO looks different).
michalc|5 months ago
It was a few years ago, and very AngularJS focused, but I posted something along these lines: https://charemza.name/blog/posts/angularjs/e2e/consider-not-...
In summary: having thing look cleaner at a glance is not helping if you’re (almost) always going to need to do more than glancing
kleyd|5 months ago
pintxo|5 months ago
As usually, there is a balance to be found.
rullopat|5 months ago