If we transition from Cypress to Playwright, should we stick with our test-id approach or switch to using getByRole?

In our engaging Ask Me Anything webinar with @utchbe, Susan Lee raised an interesting question regarding transitioning to Playwright:

“If a product already has a solid implementation of test-ids, as in our case where we’re considering moving from Cypress to Playwright, would you recommend continuing with test-id usage or switching to getByRole for most things?”

Similarly, L S asked:

"In Playwright, would you say it is better to use a lot of testIds or rather use locators like getByRole whenever possible? "

This question addresses a common concern about best practices in test automation, especially when shifting between frameworks. Your perspectives on leveraging existing test-id patterns versus adopting different querying methods in Playwright would be beneficial.

I’d say that’s each responsible automators’ choice.

  • getByRole
  • has the advantage of using accessible elements and not relying on customization;
  • forces the development of better HTML and accessibility;
  • the disadvantage is, your application might be crappy and you’ll have to rely on many ‘page.locators’ css/xpath;
  • using roles requires one to learn the w3 accessibility elements and then how to manipulate and chain them;
  • getById
  • if it’s already coded and there’s a deterministic no new knowledge required way of transitioning or using;
  • the disadvantage is, it avoids several weird coding patterns and behaviors maybe your app might have;

However I’m not convinced that fixing HTML and UI issues should be done while implementing automated checks. People can set aside time for that and focus their testing on it.