Playwright — the real Selenium’s successor
Selenium has been a constant companion in my work to varying degrees since 2011, that is, 12 years. That’s a lot of time and in computer technology, it’s a few eras. Since Selenium was created, a lot has happened in the development of websites and a lot is still happening. After such a long time, it’s worth reviewing whether the tools you use are optimal for the current state and if there are better ones, replace them.
What has changed in websites? Firstly, AJAX and JavaScript frameworks have become popular. More is happening dynamically on the client side. We are more frequently dealing with asynchrony. Selenium, on the other hand, is a tool created with the idea of pages where everything is loaded at once and the captured object simply exists and can be used. Of course, as technology developed, Selenium was adapted to current changes, but its basic concept has not changed.
What trends do we currently observe? The same, only even more so. React and similar innovations mean that dynamics and asynchrony occur to an even greater extent. This, in turn, leads to searching for something new.
A few years ago, Puppeteer appeared on the testing scene. It was an interesting project, but I did not consider it a successor to Selenium as it was limited to one language and one browser engine. This is a bit too little to measure up to such a universal tool as Selenium.
The people who created Puppeteer at Google went to Microsoft to create Playwright — something that truly deserves the title of Selenium’s successor. Compared to Puppeteer, Playwright has much greater capabilities. Although the basic language is still JavaScript, the creators have taken care to support many languages, as without this, it is impossible to think of migrating test projects to a new tool.
What is no less important, and perhaps even more important, is that the code is used in a very easy and pleasant way. The code is more concise and understandable. In addition, even when using other programming languages, it is significantly easier to maintain the tests. Playwright is definitely a tool worth paying attention to.
The situation is a bit more complicated when it comes to Python. The recommended library for tests is PyTest. This library supports the Gherkin language only to a limited extent. If someone wants full compatibility with the Cucumber standard, they must use the Behave library. This, in turn, applies an asynchronous approach. This further requires the use of the asynchronous version of the Playwright code. It’s not rocket science, but I’ve seen comments from people who have given up on dealing with such a code.
Advantages of Selenium:
- Selenium has been around for over 18 years and has a huge community of users. This means that there is a wealth of resources and support available for those using the tool.
- Selenium has a wide array of browser and language support. It supports just about all major browsers and popular programming languages, making it a versatile tool that can be used in a variety of environments.
- Selenium also has a number of other tools in its suite, such as Selenium WebDriver, Selenium IDE, and Selenium Grid. These tools provide additional functionality, such as the ability to distribute and run tests in parallel on multiple machines.
Advantages of Playwright:
- Playwright is a newer tool that was released in 2020 by Microsoft. As a result, it includes newer features and capabilities that are more aligned with the modern web.
- Playwright is specifically engineered for end-to-end automated testing of web apps and generally runs very quickly, even for complex testing projects.
- Playwright also has built-in auto-waiting feature which can be a big time-saver and makes it easier to write stable tests.
Disadvantages of Selenium:
- Selenium operates by translating test cases into JSON and sending them to the browser, which then executes the commands and sends an HTTP response back. This architecture can lead to slower test execution times, especially for complex tests.
- Selenium is a relatively old tool and its architecture may not be as well-suited to the modern web as newer tools like Playwright.
Disadvantages of Playwright:
- Playwright is a relatively new tool, which means that its community of users and available resources are not as extensive as Selenium’s. This can make it more difficult to find help and solutions to problems.
- Playwright currently supports fewer browsers and languages than Selenium, which may limit its usefulness in certain environments.
I think that Playwright is very interesting tool, and it will sooner or later became the leader among web automation tools. Ultimately, the choice between the two will depend on the specific needs of your project and team, but the Playwright it is something worth to consider.
The story was originally created by me, but it may contain parts that were created with AI assistance. My original text has been corrected and partially rephrased by Chat Generative Pre-trained Transformer to improve the language.