Platform

Solutions

Resources

Platform

Solutions

Resources

Platform

Solutions

Resources

Blog

Web UI Test Automation: Techniques for Modern Web Apps

Rishabh Kumar

Published on

Web UI Test Automation

Table of contents

Lorem ipsum

Lorem ipsum

Lorem ipsum

Lorem ipsum

Lorem ipsum

Web applications are the hardest place to automate a UI. Pages render in pieces, content arrives after the page says it’s loaded, components hide inside shadow roots and iFrames, and every browser does something slightly different. A test that passes on your laptop can fail in the pipeline for reasons that have nothing to do with a defect.



What is Web UI Test Automation?

Web UI test automation is the automated testing of a browser-based application’s user interface. Tests drive a real browser, interact with pages the way users do and check what appears, so every release is verified across the browsers, screen sizes and environments your users actually have.

It covers websites, single-page applications and browser-based business systems, such as Salesforce, Dynamics 365, ServiceNow and SAP Fiori front ends. What makes it distinct from UI automation in general is the browser itself, with its DOM, network, rendering engine and security rules.

For the process side, from what to automate first to a 90-day rollout plan, read our practical guide to UI test automation.



How Automation Tools Control a Browser

Every web automation tool needs a way to tell a browser what to do. Three protocols do most of the work today, and knowing which one your tool uses explains a lot about its behaviour.

Protocol

Used By

How It Works

What It Means for You

WebDriver (W3C standard)

Selenium, WebdriverIO

A standard HTTP interface every major browser implements through its own driver

Works across all major browsers, but each command is a round trip, so waits need care

Chrome DevTools Protocol

Puppeteer, parts of Playwright

A low-level, two-way connection to Chromium browsers

Fast, rich control of network and events, but Chromium-focused

WebDriver BiDi

Newer versions of Selenium, Playwright and others

A newer W3C standard that adds two-way events to WebDriver

Aims to combine cross-browser reach with richer control

You rarely need to work with these directly, but they explain why some tools wait automatically, why some can intercept network traffic and others can’t, and why cross-browser behaviour still differs.



Seven Things That Make Web UIs Hard to Automate

Challenge

What Goes Wrong

The Technique

Asynchronous rendering

The test looks for an element before it exists

Wait for conditions, or use auto-waiting tools

Single-page app routing

The URL changes without a page load, and the test misses it

Wait for the content of the new view, not a page load

Dynamic IDs and classes

Generated attributes change on every build or session

Locate by role, label or agreed test IDs

Shadow DOM

Ordinary selectors can’t see inside web components

Use shadow-aware locators

iFrames

Embedded content sits in a separate document

Switch into the frame first

Browser differences

Layouts, form controls and timing differ by engine

Run on Chromium, WebKit and Gecko

Authentication

Sign-in, MFA and SSO slow every test down

Reuse authenticated sessions, and test sign-in separately



Locate Web Elements the Way Users See Them

The most durable web locators describe what users see. Role-based locators use the accessibility tree, so they also nudge your application towards being accessible.

TypeScript (Playwright)

await page.getByRole('button', { name: 'Place order' }).click();
await page.getByLabel('Email address').fill('[test value]');
await expect(page.getByRole('alert')).toHaveText('Order confirmed');
await page.getByRole('button', { name: 'Place order' }).click();
await page.getByLabel('Email address').fill('[test value]');
await expect(page.getByRole('alert')).toHaveText('Order confirmed');
await page.getByRole('button', { name: 'Place order' }).click();
await page.getByLabel('Email address').fill('[test value]');
await expect(page.getByRole('alert')).toHaveText('Order confirmed');
await page.getByRole('button', { name: 'Place order' }).click();
await page.getByLabel('Email address').fill('[test value]');
await expect(page.getByRole('alert')).toHaveText('Order confirmed');

Java (Selenium 4)

driver.findElement(By.cssSelector("[data-testid='place-order']")).click();
driver.findElement(By.xpath("//label[normalize-space()='Email address']/following::input[1]"))
      .sendKeys("[test value]");
driver.findElement(By.cssSelector("[data-testid='place-order']")).click();
driver.findElement(By.xpath("//label[normalize-space()='Email address']/following::input[1]"))
      .sendKeys("[test value]");
driver.findElement(By.cssSelector("[data-testid='place-order']")).click();
driver.findElement(By.xpath("//label[normalize-space()='Email address']/following::input[1]"))
      .sendKeys("[test value]");
driver.findElement(By.cssSelector("[data-testid='place-order']")).click();
driver.findElement(By.xpath("//label[normalize-space()='Email address']/following::input[1]"))
      .sendKeys("[test value]");

Where roles and labels aren’t enough, agree a stable test ID attribute with developers. It costs them seconds and saves hours of repairs.

If your locators still break when IDs and classes shift, explore the patterns in dynamic XPath in Selenium and handling dynamic elements in Selenium.



How to Handle Asynchronous Pages and Single-Page Apps

Modern pages keep working after the browser says they’ve loaded. Wait for the thing your next step depends on.

TypeScript (Playwright)

// wait for the data the view depends on, then for the view itself
const response = page.waitForResponse(r => r.url().includes('/api/claims') && r.ok());
await page.getByRole('link', { name: 'My claims' }).click();
await response;
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
// wait for the data the view depends on, then for the view itself
const response = page.waitForResponse(r => r.url().includes('/api/claims') && r.ok());
await page.getByRole('link', { name: 'My claims' }).click();
await response;
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
// wait for the data the view depends on, then for the view itself
const response = page.waitForResponse(r => r.url().includes('/api/claims') && r.ok());
await page.getByRole('link', { name: 'My claims' }).click();
await response;
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
// wait for the data the view depends on, then for the view itself
const response = page.waitForResponse(r => r.url().includes('/api/claims') && r.ok());
await page.getByRole('link', { name: 'My claims' }).click();
await response;
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();

Java (Selenium 4)

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
driver.findElement(By.linkText("My claims")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='Claims']")));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
driver.findElement(By.linkText("My claims")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='Claims']")));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
driver.findElement(By.linkText("My claims")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='Claims']")));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
driver.findElement(By.linkText("My claims")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='Claims']")));

For a closer look at implicit, explicit and fluent waits, and when each one helps, read our guide to Selenium timeouts.

Single-Page Apps in More Depth

In single-page apps built with React, Angular or Vue, clicking a link often changes the URL without loading a new page. Tests that wait for a “page load” either return immediately or wait forever. The fix is to wait for something that only exists once the new view is ready, such as a heading, a table or the data request that fills it.

Watch for loading states too. Many apps show a spinner or skeleton, then swap in real content. Wait for the spinner to disappear and the content to appear, not just for one of them.

TypeScript (Playwright)

await page.getByRole('link', { name: 'Policies' }).click();
await expect(page).toHaveURL(/\/policies$/);
await expect(page.getByRole('progressbar')).toBeHidden();
await expect(page.getByRole('heading', { name: 'Your policies' })).toBeVisible();
await page.getByRole('link', { name: 'Policies' }).click();
await expect(page).toHaveURL(/\/policies$/);
await expect(page.getByRole('progressbar')).toBeHidden();
await expect(page.getByRole('heading', { name: 'Your policies' })).toBeVisible();
await page.getByRole('link', { name: 'Policies' }).click();
await expect(page).toHaveURL(/\/policies$/);
await expect(page.getByRole('progressbar')).toBeHidden();
await expect(page.getByRole('heading', { name: 'Your policies' })).toBeVisible();
await page.getByRole('link', { name: 'Policies' }).click();
await expect(page).toHaveURL(/\/policies$/);
await expect(page.getByRole('progressbar')).toBeHidden();
await expect(page.getByRole('heading', { name: 'Your policies' })).toBeVisible();



Automating Elements Inside Shadow DOM and iFrames

Web components hide their markup inside shadow roots, and embedded tools often sit inside iFrames. Both need deliberate handling.

TypeScript (Playwright)

// open shadow roots are pierced automatically by role and CSS locators
await page.getByRole('combobox', { name: 'Country' }).click();

// iFrames need a frame locator
const payment = page.frameLocator('iframe[title="Payment"]');
await payment.getByLabel('Card number').fill('[test value]');
// open shadow roots are pierced automatically by role and CSS locators
await page.getByRole('combobox', { name: 'Country' }).click();

// iFrames need a frame locator
const payment = page.frameLocator('iframe[title="Payment"]');
await payment.getByLabel('Card number').fill('[test value]');
// open shadow roots are pierced automatically by role and CSS locators
await page.getByRole('combobox', { name: 'Country' }).click();

// iFrames need a frame locator
const payment = page.frameLocator('iframe[title="Payment"]');
await payment.getByLabel('Card number').fill('[test value]');
// open shadow roots are pierced automatically by role and CSS locators
await page.getByRole('combobox', { name: 'Country' }).click();

// iFrames need a frame locator
const payment = page.frameLocator('iframe[title="Payment"]');
await payment.getByLabel('Card number').fill('[test value]');

Java (Selenium 4)

SearchContext shadow = driver.findElement(By.cssSelector("add=ress-form")).getShadowRoot();
shadow.findElement(By.cssSelector("input[name='postcode']")).sendKeys("[test value]");

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Payment']")));
// ... interact inside the frame ...
driver.switchTo().defaultContent();
SearchContext shadow = driver.findElement(By.cssSelector("add=ress-form")).getShadowRoot();
shadow.findElement(By.cssSelector("input[name='postcode']")).sendKeys("[test value]");

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Payment']")));
// ... interact inside the frame ...
driver.switchTo().defaultContent();
SearchContext shadow = driver.findElement(By.cssSelector("add=ress-form")).getShadowRoot();
shadow.findElement(By.cssSelector("input[name='postcode']")).sendKeys("[test value]");

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Payment']")));
// ... interact inside the frame ...
driver.switchTo().defaultContent();
SearchContext shadow = driver.findElement(By.cssSelector("add=ress-form")).getShadowRoot();
shadow.findElement(By.cssSelector("input[name='postcode']")).sendKeys("[test value]");

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Payment']")));
// ... interact inside the frame ...
driver.switchTo().defaultContent();

For the traps that catch experienced testers, including XPath and slotted content, see shadow DOM testing, and for frames, handling frames in Selenium.



Handling Sign-In Without Slowing Every Test

Signing in through the UI in every test is slow and fragile. Test the sign-in journey on its own, then reuse an authenticated session for everything else.

TypeScript (Playwright)

// global setup: sign in once and save the session
await page.goto('/login');
await page.getByLabel('Email address').fill(process.env.TEST_USER!);
await page.getByLabel('Password').fill(process.env.TEST_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.context().storageState({ path: 'auth/broker.json' });

// in tests: start already signed in
test.use({ storageState: 'auth/broker.json' });
// global setup: sign in once and save the session
await page.goto('/login');
await page.getByLabel('Email address').fill(process.env.TEST_USER!);
await page.getByLabel('Password').fill(process.env.TEST_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.context().storageState({ path: 'auth/broker.json' });

// in tests: start already signed in
test.use({ storageState: 'auth/broker.json' });
// global setup: sign in once and save the session
await page.goto('/login');
await page.getByLabel('Email address').fill(process.env.TEST_USER!);
await page.getByLabel('Password').fill(process.env.TEST_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.context().storageState({ path: 'auth/broker.json' });

// in tests: start already signed in
test.use({ storageState: 'auth/broker.json' });
// global setup: sign in once and save the session
await page.goto('/login');
await page.getByLabel('Email address').fill(process.env.TEST_USER!);
await page.getByLabel('Password').fill(process.env.TEST_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.context().storageState({ path: 'auth/broker.json' });

// in tests: start already signed in
test.use({ storageState: 'auth/broker.json' });

Keep credentials in your pipeline’s secret store, never in test code, and use one saved session per role, so permission tests stay meaningful.

For the full set of sign-in checks, including lockouts and sessions, work through our login page test cases.



Forms, Uploads, Downloads, Dialogs and New Tabs

These everyday interactions trip up more web tests than anything exotic. Each has a reliable pattern.

TypeScript (Playwright)

// file upload
await page.getByLabel('Upload documents').setInputFiles(['fixtures/id.pdf', 'fixtures/proof.pdf']);

// file download
const download = page.waitForEvent('download');
await page.getByRole('button', { name: 'Download statement' }).click();
expect((await download).suggestedFilename()).toMatch(/statement.*\.pdf$/);

// browser dialog (confirm)
page.once('dialog', d => d.accept());
await page.getByRole('button', { name: 'Cancel policy' }).click();

// link that opens a new tab
const popup = page.waitForEvent('popup');
await page.getByRole('link', { name: 'View terms' }).click();
await expect((await popup).getByRole('heading', { name: 'Terms and conditions' })).toBeVisible();
// file upload
await page.getByLabel('Upload documents').setInputFiles(['fixtures/id.pdf', 'fixtures/proof.pdf']);

// file download
const download = page.waitForEvent('download');
await page.getByRole('button', { name: 'Download statement' }).click();
expect((await download).suggestedFilename()).toMatch(/statement.*\.pdf$/);

// browser dialog (confirm)
page.once('dialog', d => d.accept());
await page.getByRole('button', { name: 'Cancel policy' }).click();

// link that opens a new tab
const popup = page.waitForEvent('popup');
await page.getByRole('link', { name: 'View terms' }).click();
await expect((await popup).getByRole('heading', { name: 'Terms and conditions' })).toBeVisible();
// file upload
await page.getByLabel('Upload documents').setInputFiles(['fixtures/id.pdf', 'fixtures/proof.pdf']);

// file download
const download = page.waitForEvent('download');
await page.getByRole('button', { name: 'Download statement' }).click();
expect((await download).suggestedFilename()).toMatch(/statement.*\.pdf$/);

// browser dialog (confirm)
page.once('dialog', d => d.accept());
await page.getByRole('button', { name: 'Cancel policy' }).click();

// link that opens a new tab
const popup = page.waitForEvent('popup');
await page.getByRole('link', { name: 'View terms' }).click();
await expect((await popup).getByRole('heading', { name: 'Terms and conditions' })).toBeVisible();
// file upload
await page.getByLabel('Upload documents').setInputFiles(['fixtures/id.pdf', 'fixtures/proof.pdf']);

// file download
const download = page.waitForEvent('download');
await page.getByRole('button', { name: 'Download statement' }).click();
expect((await download).suggestedFilename()).toMatch(/statement.*\.pdf$/);

// browser dialog (confirm)
page.once('dialog', d => d.accept());
await page.getByRole('button', { name: 'Cancel policy' }).click();

// link that opens a new tab
const popup = page.waitForEvent('popup');
await page.getByRole('link', { name: 'View terms' }).click();
await expect((await popup).getByRole('heading', { name: 'Terms and conditions' })).toBeVisible();

Cookie Banners, Consent and CAPTCHAs

Consent banners cover buttons and break clicks. Either accept them once in a setup step and save the state, or set the consent cookie before the test starts. CAPTCHAs are designed to stop automation, so ask for them to be disabled, or bypassed with a test key, in test environments, rather than trying to solve them.

For why automating CAPTCHAs is the wrong goal, and what to do instead, take a look at handling CAPTCHA in Selenium testing.



Mocking the Network to Test Errors and Empty States

Mocking responses lets you test states that are hard to create for real, such as empty lists, server errors and slow responses, without touching shared environments.

TypeScript (Playwright)

await page.route('**/api/claims', route =>
  route.fulfill({ status: 500, body: JSON.stringify({ error: 'unavailable' }) }));
await page.goto('/claims');
await expect(page.getByText("We couldn’t load your claims")).toBeVisible();
await page.route('**/api/claims', route =>
  route.fulfill({ status: 500, body: JSON.stringify({ error: 'unavailable' }) }));
await page.goto('/claims');
await expect(page.getByText("We couldn’t load your claims")).toBeVisible();
await page.route('**/api/claims', route =>
  route.fulfill({ status: 500, body: JSON.stringify({ error: 'unavailable' }) }));
await page.goto('/claims');
await expect(page.getByText("We couldn’t load your claims")).toBeVisible();
await page.route('**/api/claims', route =>
  route.fulfill({ status: 500, body: JSON.stringify({ error: 'unavailable' }) }));
await page.goto('/claims');
await expect(page.getByText("We couldn’t load your claims")).toBeVisible();

Use mocks for UI states, not for proving the system works end to end. A journey that matters should also run against real services.



Covering Browsers, Viewports and Real Devices

Dimension

What to Cover

How

Engines

Chromium, WebKit (Safari) and Gecko (Firefox)

Run the same tests on each, in parallel

Viewports

Mobile, tablet and desktop widths, and the edges of each breakpoint

Set the viewport per test project

Real devices

Touch, scrolling and performance on real phones

A small real-device set before release

Locales

Dates, numbers, currencies and right-to-left text

Run the main journeys per locale

TypeScript (playwright.config.ts)

projects: [
  { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  { name: 'webkit',   use: { ...devices['Desktop Safari'] } },
  { name: 'firefox',  use: { ...devices['Desktop Firefox'] } },
  { name: 'mobile',   use: { ...devices['iPhone 13'] } },
],
projects: [
  { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  { name: 'webkit',   use: { ...devices['Desktop Safari'] } },
  { name: 'firefox',  use: { ...devices['Desktop Firefox'] } },
  { name: 'mobile',   use: { ...devices['iPhone 13'] } },
],
projects: [
  { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  { name: 'webkit',   use: { ...devices['Desktop Safari'] } },
  { name: 'firefox',  use: { ...devices['Desktop Firefox'] } },
  { name: 'mobile',   use: { ...devices['iPhone 13'] } },
],
projects: [
  { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  { name: 'webkit',   use: { ...devices['Desktop Safari'] } },
  { name: 'firefox',  use: { ...devices['Desktop Firefox'] } },
  { name: 'mobile',   use: { ...devices['iPhone 13'] } },
],

To build a browser matrix from your own traffic, and cut 180 combinations down to the 16 that matter, read our guide to browser compatibility testing.



Adding Visual and Accessibility Checks to Web UI Tests

Functional tests prove a page works. Two lightweight additions catch what they miss.

TypeScript (Playwright)

import AxeBuilder from '@axe-core/playwright';

// visual check against an approved baseline
await expect(page).toHaveScreenshot('claims-list.png', { maxDiffPixelRatio: 0.01 });

// automated accessibility scan of the current page
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
import AxeBuilder from '@axe-core/playwright';

// visual check against an approved baseline
await expect(page).toHaveScreenshot('claims-list.png', { maxDiffPixelRatio: 0.01 });

// automated accessibility scan of the current page
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
import AxeBuilder from '@axe-core/playwright';

// visual check against an approved baseline
await expect(page).toHaveScreenshot('claims-list.png', { maxDiffPixelRatio: 0.01 });

// automated accessibility scan of the current page
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
import AxeBuilder from '@axe-core/playwright';

// visual check against an approved baseline
await expect(page).toHaveScreenshot('claims-list.png', { maxDiffPixelRatio: 0.01 });

// automated accessibility scan of the current page
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);

Automated accessibility scans catch a useful share of issues, such as missing labels and contrast failures, but not all of them. Keep keyboard and screen reader checks for people.

For which accessibility checks tools can automate and which need a person, see our guide to accessibility testing.



Running Web UI Tests in Parallel Without Interference

Large suites only finish quickly when tests run in parallel. That only works if each test is isolated.

  • Use a fresh browser context per test, so cookies, storage and sessions never leak between tests.

  • Give each test its own data, such as a unique customer or order, created in setup.

  • Avoid shared accounts that one test can lock or change while another uses it.

  • Never depend on test order: Any test should pass when run alone.



Debugging Failures With Traces, Videos and Network Logs

A failure in CI is only useful if you can see what happened. Capture evidence automatically on failure, rather than rerunning and hoping to reproduce it.

TypeScript (playwright.config.ts)

use: {
  trace: 'on-first-retry',      // step-by-step trace with DOM snapshots and network
  video: 'retain-on-failure',
  screenshot: 'only-on-failure',
},
use: {
  trace: 'on-first-retry',      // step-by-step trace with DOM snapshots and network
  video: 'retain-on-failure',
  screenshot: 'only-on-failure',
},
use: {
  trace: 'on-first-retry',      // step-by-step trace with DOM snapshots and network
  video: 'retain-on-failure',
  screenshot: 'only-on-failure',
},
use: {
  trace: 'on-first-retry',      // step-by-step trace with DOM snapshots and network
  video: 'retain-on-failure',
  screenshot: 'only-on-failure',
},

A trace shows every action, the page at each step, console messages and network requests, which turns “it failed in CI” into “the save request returned a 500 at step 6”.



Checking Page Speed Inside UI Tests

UI tests can flag obvious performance regressions without replacing proper load testing. Measuring how long an important view takes to show its content, or reading Core Web Vitals in the browser, catches a page that suddenly takes eight seconds instead of two.

TypeScript (Playwright)

const start = Date.now();
await page.getByRole('link', { name: 'My claims' }).click();
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
expect(Date.now() - start).toBeLessThan(3000);   // budget for this view
const start = Date.now();
await page.getByRole('link', { name: 'My claims' }).click();
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
expect(Date.now() - start).toBeLessThan(3000);   // budget for this view
const start = Date.now();
await page.getByRole('link', { name: 'My claims' }).click();
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
expect(Date.now() - start).toBeLessThan(3000);   // budget for this view
const start = Date.now();
await page.getByRole('link', { name: 'My claims' }).click();
await expect(page.getByRole('table', { name: 'Claims' })).toBeVisible();
expect(Date.now() - start).toBeLessThan(3000);   // budget for this view



A Complete Web UI Test, Start to Finish

Here’s how the techniques above come together in one test, for a broker adding a driver to a policy.

TypeScript (Playwright)

import { test, expect } from '@playwright/test';

test.use({ storageState: 'auth/broker.json' });          // signed in as a broker

test('broker adds a named driver', async ({ page, request }) => {
  // arrange: create a policy through the API
  const policy = await (await request.post('/api/test-data/policies', {
    data: { type: 'motor', drivers: 1 } })).json();

  // act: use the UI as the broker would
  await page.goto(`/policies/${policy.id}`);
  await page.getByRole('button', { name: 'Add named driver' }).click();
  const dialog = page.getByRole('dialog', { name: 'Add driver' });
  await dialog.getByLabel('Full name').fill('[test driver]');
  await dialog.getByLabel('Date of birth').fill('[test date]');
  await dialog.getByRole('button', { name: 'Save' }).click();

  // assert: the screen and the system agree
  await expect(page.getByRole('status')).toHaveText('Driver added');
  await expect(page.getByRole('listitem', { name: /driver/i })).toHaveCount(2);
  const updated = await (await request.get(`/api/policies/${policy.id}`)).json();
  expect(updated.drivers).toHaveLength(2);

  // clean up
  await request.delete(`/api/test-data/policies/${policy.id}`);
});
import { test, expect } from '@playwright/test';

test.use({ storageState: 'auth/broker.json' });          // signed in as a broker

test('broker adds a named driver', async ({ page, request }) => {
  // arrange: create a policy through the API
  const policy = await (await request.post('/api/test-data/policies', {
    data: { type: 'motor', drivers: 1 } })).json();

  // act: use the UI as the broker would
  await page.goto(`/policies/${policy.id}`);
  await page.getByRole('button', { name: 'Add named driver' }).click();
  const dialog = page.getByRole('dialog', { name: 'Add driver' });
  await dialog.getByLabel('Full name').fill('[test driver]');
  await dialog.getByLabel('Date of birth').fill('[test date]');
  await dialog.getByRole('button', { name: 'Save' }).click();

  // assert: the screen and the system agree
  await expect(page.getByRole('status')).toHaveText('Driver added');
  await expect(page.getByRole('listitem', { name: /driver/i })).toHaveCount(2);
  const updated = await (await request.get(`/api/policies/${policy.id}`)).json();
  expect(updated.drivers).toHaveLength(2);

  // clean up
  await request.delete(`/api/test-data/policies/${policy.id}`);
});
import { test, expect } from '@playwright/test';

test.use({ storageState: 'auth/broker.json' });          // signed in as a broker

test('broker adds a named driver', async ({ page, request }) => {
  // arrange: create a policy through the API
  const policy = await (await request.post('/api/test-data/policies', {
    data: { type: 'motor', drivers: 1 } })).json();

  // act: use the UI as the broker would
  await page.goto(`/policies/${policy.id}`);
  await page.getByRole('button', { name: 'Add named driver' }).click();
  const dialog = page.getByRole('dialog', { name: 'Add driver' });
  await dialog.getByLabel('Full name').fill('[test driver]');
  await dialog.getByLabel('Date of birth').fill('[test date]');
  await dialog.getByRole('button', { name: 'Save' }).click();

  // assert: the screen and the system agree
  await expect(page.getByRole('status')).toHaveText('Driver added');
  await expect(page.getByRole('listitem', { name: /driver/i })).toHaveCount(2);
  const updated = await (await request.get(`/api/policies/${policy.id}`)).json();
  expect(updated.drivers).toHaveLength(2);

  // clean up
  await request.delete(`/api/test-data/policies/${policy.id}`);
});
import { test, expect } from '@playwright/test';

test.use({ storageState: 'auth/broker.json' });          // signed in as a broker

test('broker adds a named driver', async ({ page, request }) => {
  // arrange: create a policy through the API
  const policy = await (await request.post('/api/test-data/policies', {
    data: { type: 'motor', drivers: 1 } })).json();

  // act: use the UI as the broker would
  await page.goto(`/policies/${policy.id}`);
  await page.getByRole('button', { name: 'Add named driver' }).click();
  const dialog = page.getByRole('dialog', { name: 'Add driver' });
  await dialog.getByLabel('Full name').fill('[test driver]');
  await dialog.getByLabel('Date of birth').fill('[test date]');
  await dialog.getByRole('button', { name: 'Save' }).click();

  // assert: the screen and the system agree
  await expect(page.getByRole('status')).toHaveText('Driver added');
  await expect(page.getByRole('listitem', { name: /driver/i })).toHaveCount(2);
  const updated = await (await request.get(`/api/policies/${policy.id}`)).json();
  expect(updated.drivers).toHaveLength(2);

  // clean up
  await request.delete(`/api/test-data/policies/${policy.id}`);
});

It starts signed in, creates its own data, acts through the UI by role and label, checks both the screen and the API, and cleans up. Every test in a suite should follow the same shape.



Web UI Automation Frameworks Compared

Framework

Languages

Browsers

Strengths

Watch For

Playwright

TypeScript, JavaScript, Python, Java, .NET

Chromium, WebKit, Firefox

Auto-waiting, shadow DOM piercing, network control, test agents

Code-only, so non-engineers can’t contribute

Selenium

Java, Python, C#, JavaScript, Ruby and more

All major browsers, through WebDriver

The W3C standard, huge ecosystem, Grid for scale

More manual waiting and shadow DOM handling

Cypress

JavaScript, TypeScript

Chromium family, Firefox, experimental WebKit

Developer experience and debugging

Multi-tab and cross-origin limits

WebdriverIO

JavaScript, TypeScript

All major browsers

Flexible, WebDriver and DevTools protocols

More set-up choices to make

Plain English platforms

Plain English steps

Cloud browser grids

Readable by the whole team, lower maintenance

Check portability and how AI changes are recorded

For how the two leading open-source options compare, and where AI-native platforms fit, read Playwright vs Selenium vs AI-native testing.



Automating Browser-Based Business Systems Like Salesforce

Salesforce, Dynamics 365, ServiceNow and SAP Fiori are web applications, but harder ones. They generate dynamic IDs, nest components inside shadow DOM and iFrames, and change on the vendor’s timetable. Tests for these systems need locators based on labels and context, stable sessions per role, and runs in every vendor preview window.

For the Salesforce side in depth, including Lightning components and release cycles, see Salesforce UI test automation.



Common Web UI Automation Mistakes and How to Fix Them

Mistake

Why It Hurts

The Fix

Copying selectors straight from DevTools

Long CSS or XPath paths break with the smallest layout change

Use roles, labels or agreed test IDs

Using fixed sleeps

Slow suites, and failures on slow days

Wait for the condition the next step depends on

Signing in through the UI in every test

Minutes added to every run, and lockouts

Test sign-in once, reuse a saved session

Sharing test accounts and data

Tests interfere with each other in parallel

Create unique data per test

Testing only in Chrome

Safari and Firefox users find the bugs

Run the main journeys on all three engines

Checking only the screen

A success message can hide a failed save

Check the API or database behind the UI

Ignoring evidence on failure

Failures can’t be diagnosed without rerunning

Capture traces, video and screenshots automatically

Mocking everything

Tests pass while real services are broken

Mock only hard-to-create states

Most teams make several of these at once, and fixing just the first three usually cuts flaky failures dramatically.



A 10-Point Web UI Automation Checklist

  • Locators use roles, labels or agreed test IDs, not generated attributes

  • Tests wait for conditions, never fixed time

  • Shadow DOM and iFrames are handled deliberately

  • Sign-in is tested once, and sessions are reused per role

  • Error, empty and slow states are tested with network mocks

  • Tests run on Chromium, WebKit and Firefox

  • The main journeys run at mobile and desktop widths

  • Visual and accessibility scans run on the most important pages

  • Credentials live in the pipeline’s secret store

  • The suite runs in parallel, on every change



Web UI Test Automation With Virtuoso QA

Every technique in this guide works, and every one of them is code someone has to write, review and keep working. Waits, frame switching, shadow roots, saved sessions, browser projects and trace settings add up to a second codebase that grows with your application. For many teams, that upkeep is where web UI automation stalls.

Virtuoso QA removes that layer. Testers, analysts and developers describe the journey in plain English and Virtuoso QA works out how to reach the element, whether it sits in a shadow root, an iFrame or a page that’s still loading.

Live Authoring runs each step against your real application as it’s written, so a problem shows up in seconds, not on the next pipeline run.

The same journey runs across 2,000+ browser and OS combinations and every environment, with no browser-specific code. It can call an API and check the database in the same run, so a passing test proves the outcome, not just the screen.

When something fails, you get the failing step, a screenshot, logs and network calls. When the application changes, steps are repaired visibly and reversibly, or proposed for someone to accept, so your suite keeps pace with the product instead of falling behind it.

It’s built for the hardest web UIs too. Salesforce, Dynamics 365 and other browser-based business systems, with their dynamic IDs, nested components and vendor release calendars, are where Virtuoso QA is used most.

💡Virtuoso QA’s AI test automation turns plain English journeys into reliable web UI tests across every browser your customers use, with no waits, locators or frame code to maintain.



Related Reads

Web UI Test Automation FAQs

What is web UI test automation?

Which framework is best for web UI automation?

How do you automate shadow DOM elements?

How do you stop sign-in slowing every test?

Should web UI tests use mocks?

Why do my web UI tests pass locally but fail in CI?

Written by

Rishabh Kumar

AI Testing & Quality Engineering Contributor

Rishabh leads business development and marketing at Virtuoso QA. He writes about AI-powered test automation, end-to-end testing, self-healing tests, and quality engineering, exploring how these capabilities can improve test coverage, reduce test maintenance, and support reliable software releases.

See what your next release looks like with Virtuoso

Book a walkthrough on your applications and your workflows. Bring a requirement, a user journey, or a brittle Selenium script, and watch the loop run on something you recognise.

See what your next release looks like with Virtuoso

Book a walkthrough on your applications and your workflows. Bring a requirement, a user journey, or a brittle Selenium script, and watch the loop run on something you recognise.

See what your next release looks like with Virtuoso

Book a walkthrough on your applications and your workflows. Bring a requirement, a user journey, or a brittle Selenium script, and watch the loop run on something you recognise.

Virtuoso QA is establishing the standard of proof for software releases. Its governed QA loop turns business requirements into tests for any browser-based application: AI proposes, a deterministic engine executes, a person approves what matters, and every decision leaves evidence.

Trust Center

AICPA

SOC

WAVE STRONG PERFORMER

@ Copyright 2026 SpotQA, Creators of Virtuoso QA

Virtuoso QA is establishing the standard of proof for software releases. Its governed QA loop turns business requirements into tests for any browser-based application: AI proposes, a deterministic engine executes, a person approves what matters, and every decision leaves evidence.

Trust Center

AICPA

SOC

WAVE STRONG PERFORMER

@ Copyright 2026 SpotQA, Creators of Virtuoso QA

Virtuoso QA is establishing the standard of proof for software releases. Its governed QA loop turns business requirements into tests for any browser-based application: AI proposes, a deterministic engine executes, a person approves what matters, and every decision leaves evidence.

Trust Center

AICPA

SOC

WAVE STRONG PERFORMER

@ Copyright 2026 SpotQA, Creators of Virtuoso QA