by emmanueloga_ · 1y ago · 0 comments
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.--
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:
await invoiceDetailPage.selectCustomer(page, 'Acme');
await invoiceDetailPage.selectCustomerPoNumber(page, '1234567890');
await invoiceDetailPage.setCustomerReleaseNumber(page, '987654321');
...10-15 more lines
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.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.
---
await page.getStartedLink.click()
expect(page.installationHeadline).toBeVisible()
Is much more readable, and on typing "page." you will see what props on your PO are available.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).
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
As usually, there is a balance to be found.