DEV Community 👩‍💻👨‍💻

Terence Pan
Terence Pan

Posted on

Playwright with Cucumber/JUnit 5 - Intro


I recently had to evaluate a bunch of old TestNG/Selenium UI test automation projects that were not maintained at all. We figured it would be a good idea to evaluate a bunch of different options to migrate the tests to an easier to maintain framework. Playwright was one option we considered. This series is to document example code of how our projects were setup.


Playwright like Selenium WebDriver is cross platform, cross browser and available in different languages. But the setup is much easier, you do not have to download web driver binaries and maintain those versions like in Selenium WebDriver.

Playwright many conveniences as compared to Selenium WebDriver. By default Playwright will auto-wait before performing an action like click. On many sites, it may take a few seconds to wait and with Selenium WebDriver, the code may try to click immediately after the site is navigated to. This would cause an exception where the element is not found. Playwright will wait for the element to appear before clicking. Selectors also pierce Shadow DOM which will help with interacting with Shadow DOM elements like Chrome's print dialog or settings navigation.


We also would like to make these tests understandable by business analysts and other nontechnical staff as well. So we can incorporate the Cucumber framework as well to organize the tests. Cucumber is a Behavior Driven Development testing tool which aims to allow tests to be written in plain language and parsed to run test code. The Cucumber tests use Steps which represent user actions and are directly linked to code, in this case Java Playwright code. This has the advantage of allowing nontechnical staff to more easily understand the test deck, possibly make changes and add test scenarios without having to use up developer time.


For this tutorial it is expected you have an IDE like Intellij or Eclipse. For Eclipse, it is recommended you use a plugin: Cucumber Eclipse Plugin. This plugin is maintained by the Cucumber developers. This allows you to step through features to the code and run features through Eclipse. Intellij Ultimate has the plugin installed and enabled by default. If you are using community edition, you will need to install the Cucumber plugin.

So let's get started, I wanted to cover as much ground as I can for what you may need to know for an actual work project so this will be a series. This tutorial covers Intellij and Chrome, but you can easily use Eclipse and Firefox or Edge instead.

As always code is on available on Github

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.