A modern look at two tried-and-tested test tools
Test automation is essential today - and two tools are at the top of the list: Playwright vs Selenium.
Both offer comprehensive options for the automation of web applications.
We made the switch from Selenium to Playwright in an internal project. In this article, we share our most important learnings and experiences.
Playwright in check: What can the Microsoft tool do?
Playwright is a modern framework from Microsoft for end-to-end tests in web applications. It supports JavaScript, TypeScript, Python, .NET and Java.
A big plus point: tests can be run in parallel in Chromium, Firefox and WebKit.
Integration in Java
This is how Playwright can be integrated into Java:
<dependency> <groupId>com.microsoft.playwright</groupId> <artifactId>playwright</artifactId> <version>1.51.0</version> </dependency>
A simple example to get you started:
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
page.navigate("http://playwright.dev");
System.out.println(page.title());
}
Locators and assertions in Playwright
Playwright recognizes elements via so-called locators - either via CSS or with built-in methods such as getByLabel and getByText:
page.getByLabel("User Name").fill("John");
page.getByText("Test");
page.locator(".my-custom-css-class");
These locators can then be used to perform certain assertions, such as a count or similar, to validate that an exact number of elements are present on the website.
Examples of assertions:
assertThat(page.locator(".title")).containsText("substring");
assertThat(page.locator(".title")).isEnabled();
assertThat(page.locator(".title")).hasCount(1);
Advantage: These assertions are part of Playwright and come with retry and auto-wait mechanisms.
This significantly reduces test flakiness and makes tests more robust.
Our experience with Playwright vs Selenium
What convinced us:
- The built-in retry mechanism in Playwright made our tests much more stable.
- Less manual configuration - more stability out of the box.
- No ExpectedConditions as in Selenium (e.g. ExpectedConditions.elementToBeClickable)
On the other hand:
- The Playwright community is even smaller.
- Selenium is an established tool with a large community and many resources.
Also important:
Selenium is not a framework, but a browser automation tool.
This means more setup work - especially at the beginning, but also a much more powerful range of functions.1
Conclusion: The right test tool for your use case
For fast, lean testing and a modern developer experience, Playwright currently has a clear advantage.
Initial tests can be developed with just a few lines of code. In addition, tests can run in parallel in different browsers - which enables broader and faster test coverage.
However, those who rely on a mature community, many years of experience and comprehensive features will continue to do well with Selenium.
Selenium remains a strong choice, especially for large or complex automation tasks.
More know-how?
Read more about our software projects on blog.doubleslash.de


