Chapter 01Lesson 03~100 minutes

Browser Automation and Test Engineering Foundations: Configuration, Design Patterns, and Trade-Offs

Design a browser-automation portfolio deliberately: use Selenium where browser behavior matters, keep setup and low-level checks below the UI when possible, and make each trade-off observable.

Test designTrade-offsIsolationPortabilityMaintainability

Learning objectives

  • Choose browser automation based on test intent rather than tool enthusiasm.
  • Compare end-to-end breadth with smaller focused tests.
  • Separate UI assertions from API/setup shortcuts without hiding user-visible risk.
  • Relate locator/DOM coupling to maintenance cost and diagnostic quality.
  • Separate Selenium configuration from runner, AUT, browser policy, proxy/TLS, and CI configuration.
  • Create a decision record that makes runtime, coverage, privacy, and reliability trade-offs explicit.

1. Start with risk, not with Selenium

The question “Can Selenium automate this?” is too weak. A better question is “Which failure are we trying to detect, and does a real browser add evidence that a cheaper layer cannot?” If the risk is a tax-calculation rule, a unit/service test is usually the strongest first line. If the risk is that a browser cannot complete checkout because of DOM, JavaScript, cookie, navigation, or compatibility behavior, Selenium is appropriate.

This does not mean UI tests are unimportant. It means their higher cost should buy browser-specific confidence.

2. Browser realism versus execution cost

The following table organizes the key choices and evidence for Browser realism versus execution cost. Use it together with the surrounding prose so the rows serve as a comparison aid rather than standalone rules.

Choice Benefit Cost/risk Observable evidence
Real browser E2E High user-path realism. Startup, rendering, timing, environment, data, and network failure layers. Capabilities, URL/DOM, screenshots/logs, assertion results.
API/component Fast, focused contract verification. Misses browser rendering/interaction problems. HTTP/status/payload/component outputs.
Unit Very fast and precise diagnostics. No integrated browser/service evidence. Function/class result and stack trace.

Use the smallest layer that can detect the intended failure, then add a browser test where browser integration is itself the risk. This generally produces a small number of meaningful journeys rather than thousands of browser-level duplicates.

3. Broad journeys versus focused browser scenarios

A single 25-step end-to-end journey feels realistic, but it creates a long causal chain: if step 17 fails, the test may never reach the behavior you actually wanted to verify at step 23. Focused browser scenarios shorten diagnosis and make test data easier to isolate. Broad journeys still have value as smoke/canary coverage when the product risk truly spans the whole path.

Design test: if a scenario fails, can a maintainer identify which product behavior was violated without replaying half the application? If not, the journey may be too broad.

4. UI setup versus lower-layer setup

Selenium’s own test-practice guidance recommends generating application state outside the browser when appropriate. Repeating UI login/data-creation steps before every test adds time and failure opportunities that are unrelated to the behavior under test. A common production pattern is: create synthetic data through a trusted test API/fixture → start a fresh browser → verify the user-visible behavior → delete/reset data through the fixture layer.

That shortcut is valid only when it does not bypass the thing you are trying to test. If the test intent is “login works,” logging in through an API defeats the purpose. If the test intent is “an authenticated user can edit a profile,” API-based setup may make the browser test smaller and clearer.

5. Isolation: fresh browser and independent data

The Selenium project encourages tests not to share state and recommends a fresh WebDriver instance per test. A fresh browser profile removes many cookie/cache/local-storage interactions, but it does not reset the AUT database. Browser isolation and application-data isolation are separate controls.

Isolation boundaries

The following diagram visualizes the relationships described in Isolation: fresh browser and independent data. Read the nodes in sequence and use the arrows to connect the conceptual state changes to the explanation around the diagram.

flowchart TB
T1[Test A] --> B1[Fresh browser/session A]
T2[Test B] --> B2[Fresh browser/session B]
B1 --> A[AUT]
B2 --> A
D1[Unique synthetic data A] --> A
D2[Unique synthetic data B] --> A
E1[Evidence directory A] --> T1
E2[Evidence directory B] --> T2

This model becomes essential when the course reaches parallel execution. Reusing one driver, one user account, or one download folder across concurrent tests converts hidden shared state into nondeterminism.

6. Maintainability versus implementation-detail checks

Browser tests should describe stable user-facing or test-owned identities. A selector tied to a durable id, accessible role/name, or test-owned attribute survives visual refactoring better than an absolute DOM path. Assertions should likewise target intended behavior: visible status, navigation destination, enabled/disabled state, or meaningful content—not incidental wrapper classes unless those classes are the requirement.

Chapter 04 will cover locator mechanics. The foundation rule is simpler: couple to product intent, not to accidental markup.

7. Configuration boundaries

The following table organizes the key choices and evidence for Configuration boundaries. Use it together with the surrounding prose so the rows serve as a comparison aid rather than standalone rules.

Concern Lives primarily in Example
Browser capability Selenium/browser options Browser name, page-load strategy, window preferences.
Test lifecycle Runner/framework Per-test setup/teardown, discovery, reports.
Application behavior AUT/config/services Feature flags, seeded records, server endpoints.
Enterprise browser policy OS/browser management Managed extensions, certificate policy.
Proxy/TLS/identity Network/browser/IdP infrastructure Proxy route, CA trust, SSO.
Job scheduling/artifacts CI platform Matrix, workspace, secret store, artifact retention.

Putting every knob into “Selenium config” hides ownership. When a test fails behind a corporate proxy, browser policy and network configuration may be the failing layer even though the exception appears in the Selenium process.

8. Headed versus headless execution

Headless mode can reduce desktop requirements and is common in CI, but it is still a browser mode with version-specific behavior. Do not assume “headless is identical” or “headed is always more realistic.” Record which mode you used, preserve the same viewport/window assumptions, and reproduce suspicious failures in the mode where they occur before changing the test.

9. Worked decision table

The following table organizes the key choices and evidence for Worked decision table. Use it together with the surrounding prose so the rows serve as a comparison aid rather than standalone rules.

Product risk Primary layer Browser supplement? Reason
Price rounding rule Unit/service One journey at most Mathematical rule is faster and clearer below UI.
Login form redirects and establishes browser session Browser Yes, central Browser cookies/navigation/form interaction are the behavior.
API rejects malformed request API Only for user-visible validation mapping HTTP contract does not require rendering.
Responsive navigation remains usable Browser Yes Viewport/layout/interaction are browser concerns.
1000 concurrent requests meet latency SLO Load tool No as load generator Selenium is not a performance-load substitute.

10. Design lab: classify a small release surface

Imagine a synthetic account-settings feature with these risks: username validation, API authorization, profile form rendering, save-button disabled state, persistence, responsive layout, email delivery, and 500-user load. For each risk, write:

  1. the failure you need to detect;
  2. the smallest layer that can detect it;
  3. whether a browser adds unique evidence;
  4. required synthetic data and cleanup;
  5. the assertion/evidence you would preserve;
  6. expected runtime/capacity cost.

A reasonable outcome might keep validation rules and authorization mostly below the UI, use Selenium for the form/browser session/responsive behavior, use a fake mail service for delivery integration, and use a dedicated load tool for concurrency.

11. Production operating principles

  • Keep browser tests independent; do not encode test ordering as hidden setup.
  • Prefer new WebDriver sessions per test or per safely isolated fixture scope.
  • Use lower-layer setup when it shortens the test without bypassing the behavior under test.
  • Record browser/version/mode when comparing failures or performance.
  • Do not trade away assertions or isolation merely to make a suite “faster.”
  • Keep screenshots/logs privacy-aware and tied to a specific test/session.

Knowledge check

When is API-based setup inappropriate for a Selenium test?

Why does a fresh browser not guarantee full test isolation?

What is the main benefit of a focused browser scenario over one giant journey?

Is headless mode automatically equivalent to headed mode?

Which tool should generate sustained application load?

Next lesson

Turn red tests into evidence, not noise

Lesson 4 introduces a diagnostic sequence, an intentionally broken timing example, evidence capture, failure classification, and production-safe correction patterns.

Official references and version notes

Version and compatibility note

Version-sensitive statements were rechecked against current Selenium primary documentation on 2026-08-27. Mandatory examples pin the Python Selenium binding to 4.47.0, require Python 3.10+, use an installed supported local browser with Selenium Manager as the default driver-management path, and do not require Selenium Grid, a paid browser cloud, enterprise identity, or a production website. Record the browser and driver versions returned by the actual session because those remain environment-specific.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.