Skip to content

UI Tests

UI tests are automated tests that simulate real user actions in a web browser to verify that the application's interface behaves correctly.

They:

  • Open a browser (Chrome, Firefox, WebKit, etc.)
  • Interact with the UI like a user would — clicking buttons, filling forms, navigating pages
  • Assert visual or functional outcomes — verifying elements appear, behave correctly, or update properly
  • Validate end-to-end workflows from the user's perspective

Why UI Testing?

Benefits

  • Tests real user workflows - Validates the entire application stack working together
  • Catches integration issues - Finds problems that unit tests miss
  • Validates UI/UX behavior - Ensures the interface works as designed
  • Cross-browser compatibility - Tests across different browsers and devices
  • Confidence for production - Provides assurance that critical features work
  • Prevents regressions - Catches unintended changes when code is updated

Challenges

  • Slower execution - Takes more time than unit or integration tests
  • Can be flaky - Environmental issues, timing problems, or network delays
  • Maintenance overhead - UI changes require test updates
  • Setup complexity - Requires browsers, drivers, and proper configuration
  • Debugging difficulty - Failures can be harder to diagnose than unit test failures
  • Resource intensive - Requires more CPU and memory to run

When to Use UI Tests

Good Use Cases

  • Critical user journeys - Login, checkout, registration flows
  • Cross-browser compatibility - Ensure it works in Chrome, Firefox, Safari
  • End-to-end workflows - Multi-step processes involving multiple pages
  • Visual regression testing - Detect unintended UI changes
  • User acceptance criteria - Validate features from user perspective
  • Integration of third-party services - Payment gateways, OAuth, etc.

When to Avoid

  • Business logic → Use unit tests instead (faster, more precise)
  • API validation → Use API/integration tests (no need for browser)
  • Edge cases and permutations → Too slow for comprehensive coverage
  • Database operations → Use integration tests
  • Utility functions → Unit tests are sufficient
  • Every possible scenario → Focus on happy paths and critical failures

Key Concepts

Test Isolation

Each test should be independent and not rely on other tests:

  • Start with a clean state (database, session, etc.)
  • Don't share data between tests
  • Tests should run in any order

Selectors

How tests identify elements on the page:

  • Best: data-testid attributes - Stable, independent of UI changes
  • Good: Semantic roles (button, link) - Accessible and meaningful
  • Okay: Text content - Can break with translations
  • Avoid: CSS classes - Change frequently with styling

Waiting Strategies

Modern frameworks auto-wait for elements, but understanding is important:

  • Wait for element to exist - Element is in the DOM
  • Wait for visibility - Element is visible to the user
  • Wait for stability - Element is not moving/animating
  • Wait for network - API calls complete

Flakiness

Tests that pass/fail inconsistently are "flaky". Common causes:

  • Timing issues - Not waiting for elements/network
  • Test dependencies - Tests affecting each other
  • External services - Third-party APIs being unreliable
  • Race conditions - Asynchronous operations completing in random order

How to reduce flakiness:

  • Use auto-waiting features
  • Avoid hardcoded waits/timeouts
  • Mock external dependencies
  • Ensure test isolation

Frameworks

Which Framework to Choose?

Choose Playwright if:

  • You want the most modern, reliable framework
  • You need cross-browser testing (Chrome, Firefox, Safari)
  • Speed and stability are priorities
  • You're starting a new project

Choose Selenium if:

  • You need the widest browser support (including older versions)
  • You have existing Selenium infrastructure
  • You need real mobile device testing (via Appium)
  • Your team knows Selenium well

Choose Cypress if:

  • You have a JavaScript/TypeScript-only team
  • You value excellent developer experience
  • You primarily test Chrome-based browsers
  • You like time-travel debugging

Getting Started with Playwright

Playwright is the recommended choice for modern UI testing. It offers the best balance of speed, reliability, and features.

Learn More About Playwright

CriteriaPlaywrightSeleniumCypress
Release Year202020042015
ArchitectureDirect browser APIs (no WebDriver)WebDriver-based (external protocol)Runs inside the browser (JS framework)
SpeedVery fastSlower due to WebDriver latencyFast, but tied to browser environment
Stability (Flakiness)Very lowMedium to highLow to medium
Auto-WaitYes, very strongPartially, often requires manual waitsYes, built-in
Supported BrowsersChromium, Firefox, WebKitAll major browsers including Edge, Safari, mobileChrome/Chromium, (Firefox experimental), no WebKit
Mobile TestingEmulators (WebKit/Chromium)Excellent, including real devices (via Appium)No
Multi-Tab/WindowWell supportedWell supportedVery limited / mostly unsupported
API testingYesNoYes
DebuggingYesNoYes
LanguagesJS/TS, Python, Java, .NETMany (Java, Python, C#, JS, …)JS/TS
Developer ExperienceVery goodMedium (depends on setup)Excellent (time travel, live reload)
Best Use CasesModern, stable web automationEnterprise, legacy, broad browser coverageJS-heavy frontend apps, great for local dev

Contact: M_Bergmann AT gmx.at