1

We're starting to write E2E tests using Playwright in Typescript. Up until now, we were using Selenium and we wrote an a abstracation layer, or a a client, that wrapped each Selenium function that were used by our E2E test. You could see, in a simple search in Google, many different clients that different people have written to Selenium API. However, I didn't find even a single client for Playwright and I wonder whether we should implement it or not? Maybe it's because that Playwright already provides a high-level API that is designed to be easy to use and understand.

Our main reasons for that are:

  1. Improved reliability and Stability: Because Playwright wrappers can provide additional functionality, they can help to improve the reliability of automated tests. By making it easier to write tests that are less likely to fail, Playwright wrappers can help to ensure that tests provide accurate and consistent results. i.e.: By using the Playwright function def fill(text: str), we can type a text into a text field. If we write a wrapper for this function that also waits, by default, until the text is displayed, we’ll get more stable results. For that matter, Playwright provides async matches that will wait until the expected condition is met. Playwright encourages to do so, as specified in their documentation: these matchers allows making the tests non-flaky and resilient
  2. Decoupling from Playwright's API: By using a client for Playwright, our test code interacts with the client’s API rather than directly with Playwright's API. If Playwright undergoes significant changes or introduces breaking updates, we’ll only need to update the wrapper to adapt to those changes. The rest of our test code remains unaffected, reducing the effort required to maintain your automation suite. i.e: Selenium introduced many breaking changes in version 4.0 in different functions and components. Luckily, since we’re using a client that is wrapping Selenium API, the test code remained unaffected and we only needed to update the client.
  3. Error Handling and Reporting: A wrapper can implement consistent error handling strategies and provide meaningful error messages when exceptions occur

And therefore, my question, would you recommened to write an abtraction layer over Playwright?

I've tried to find an implementation of an abtraction layer for Playwright in Google but didn't find anything.

2
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented Aug 4, 2023 at 13:29
  • See this, it might be helpful- stackoverflow.com/a/76664504 Commented Aug 5, 2023 at 0:04

1 Answer 1

0

I migrated a large number of e2e tests from selenium to playwright about a year ago. The migration was relatively painless exactly because I already used an abstraction layer in my selenium tests and mostly only had to migrate the layer itself. Based on my experience and assuming that Playwright will evolve by itself and there might be something else in the future I would strongly advice to keep your abstraction layer if possible. I personally use a hierarchy of generic, application specific and page specific page objects that are implemented as TypeScript classes that inherit from each as the abstraction layer. I hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

It is very helpful, thank you! Care to share in a few sentences about the general picture of your architecture? I am strongly interested to understand whether you're also wrapping the elements that are being retrieved after Playwright finds them on the Page. Why? Because they also have functions, right? So you wrapped them also?
No, I'm not wrapping individual elements as my abstraction if much higher. I'm basically using a POM architecture with 3 page levels on its core: a generic page, a application specific page and the individual pages. This is combined with a large number of utility page components that abstract each component that must be tested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.