Automated UI testing is a valuable component of a test strategy, to check interacting with the software in a similar way to end users.
As part of an overall test strategy that blends human testing with automation, automating at the UI level can be helpful to check that key user workflows keep working as we expect.
Lower level automated tests (e.g. unit tests) are small in scope and are unlikely to catch problems with more sophisticated usage patterns of the software. Higher level tests via the user interface are much larger in scope and have the potential to mitigate the risk of important user workflows becoming broken in production.
There are numerous tools available for facilitating automated UI testing through the browser:
With the latest AI tooling, AI Agents can use Playwright MCP, Playwright CLI, and specialized Test Agents to help write better UI tests.
Read more: Do you know how to use Playwright with your AI Agents?
Playwright allows you to write tests in many popular languages including .NET, Java, Python and JavaScript/TypeScript.
Playwright has a few advantages over Selenium:
//Store the ID of the original windowconst originalWindow = await driver.getWindowHandle();//Check we don't have other windows open alreadyassert((await driver.getAllWindowHandles()).length === 1);//Click the link which opens in a new windowawait driver.findElement(By.linkText('new window')).click();//Wait for the new window or tabawait driver.wait(async () => (await driver.getAllWindowHandles()).length === 2,10000);//Loop through until we find a new window handleconst windows = await driver.getAllWindowHandles();windows.forEach(async handle => {if (handle !== originalWindow) {await driver.switchTo().window(handle);}});//Wait for the new tab to finish loading contentawait driver.wait(until.titleIs('Selenium documentation'), 10000);
❌ Figure: Bad example - Selenium only lets you have one window focused at a time meaning you can't do parallel testing easily
const { chromium } = require('playwright');// Create a Chromium browser instanceconst browser = await chromium.launch();// Create two isolated browser contextsconst userContext = await browser.newContext();const adminContext = await browser.newContext();// Create pages and interact with contexts independently
✅ Figure: Good example - Playwright makes it easy to spin up independent browser contexts for parallel testing
Playwright offers a cool feature that lets developers record actions in the browser to automatically generate the code for tests.
Note: While this feature is useful for learning the syntax and structure of Playwright tests, it should not be used to generate production-quality test code.
Watch Matt Goldman and Andreas Lengkeek from SSW demonstrate the use of Playwright to create a simple UI test in this YouTube video:
Automated UI testing is powerful, but it should still be done with planning.
Modern tools like Playwright and AI Agents have reduced the maintenance pain by helping teams write, debug, and fix tests.
However, UI tests are still slower to run because they interact with the browser and test broader user workflows.
Use them for important workflows.