DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Use Atomic Tests in Selenium

Make Selenium tests reliable and easier to debug by giving each test one purpose, independent data and browser state, focused actions, and dependable cleanup.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build each Selenium test so it prepares its own prerequisites, exercises one behavior, checks a coherent result, and leaves no state that another test needs. That is what makes a test atomic in practice: it can run independently, in any order, without relying on another test’s success. Selenium does not require exactly one assertion per test.

What makes a Selenium test atomic?

“Atomic” is a useful shorthand for a test with one clear purpose and self-contained state. Selenium’s guidance says to write each test as its own unit, independent of other tests, and to keep browser work to a discrete, short set of actions. The point is not to enforce a universal test length or assertion count; it is to make the outcome understandable and the test reliable when run alone or in a different order.

For example, do not make a test that verifies a website module depend on a separate test having created and published its content. That setup introduces timing and ordering dependencies. Instead, let the module test establish or stub the content it needs, while a separate test checks content creation and publishing. See Selenium’s test independency guidance.

Use a focused arrange–act–assert–cleanup cycle

  1. Arrange: create or select the data required for this behavior. Use a fixture, API, or other faster setup route when available.
  2. Act: perform the small sequence of browser interactions relevant to the behavior under test.
  3. Assert: use your test framework to check the result that answers the test’s purpose. Several assertions can be appropriate when they establish one coherent outcome.
  4. Clean up: remove or isolate data that could affect other tests, then end the browser session.

Keep unrelated stages of a business journey out of the same browser test. A test that creates an account, configures a product, adds it to a cart, pays, and submits feedback is slow and difficult to diagnose when it fails. Split it into independently runnable tests with distinct purposes; prepare each test’s preconditions without replaying every preceding step in the browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep tests and browser state independent

Selenium recommends that tests be able to run in any order, without depending on other tests to succeed first. In practice, each test should own its required data and browser session. Avoid shared records that can be modified by another test, and clean stale records so they cannot be mistaken for fresh test data.

  • Use distinct test data or a reliable per-test cleanup strategy to prevent collisions.
  • Create a new WebDriver instance for each test, rather than sharing a session whose cookies, navigation, or browser state can leak between tests.
  • Ensure driver teardown runs after both successful and failed tests. Selenium’s examples use a pytest fixture that yields a driver and quits it during teardown.
  • Run tests in different orders during development or CI when practical; an order-dependent failure signals that a test is not fully self-contained.

Isolation makes parallel execution easier, but it does not by itself prevent contention. Parallel workers can still collide if they share accounts, records, environments, or other limited resources. Design test data and infrastructure for concurrent use. Selenium’s recommendations are in Avoid sharing state and Test dependency.

Use Selenium only for behavior that needs a browser

Functional browser tests can be expensive. Before adding browser actions, ask whether the behavior can be verified with a lighter-weight test. If the test is about application logic rather than browser behavior, a unit or service-level test may be a better fit. When browser coverage is needed, use an API, fixture, or database operation to arrange data where appropriate, then keep Selenium focused on the user-visible behavior.

Selenium provides tools for browser interaction, but it does not prescribe a single suite design that works for every application. Its test-practices documentation frames its advice as recommendations to adapt to the project. See Selenium Test Practices and the Selenium overview.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep WebDriver and the test framework’s jobs separate

WebDriver controls the browser through the relevant browser driver. It performs actions and exposes browser state, but it does not decide whether expected and actual values match, determine pass or fail, or report test results. Your test framework—such as JUnit, NUnit, or another framework—runs tests and supplies assertions and reporting. Keep browser commands in the interaction part of the test and outcome checks in the framework’s assertion layer. Selenium’s component guide explains these roles.

Selenium IDE is a browser extension for recording and playing back interactions, while Selenium Grid distributes tests across machines and platform combinations. Grid can help scale execution; it does not remove the need for isolated test data and independent test behavior.

Common atomic-test failures and fixes

  • A later test fails when run alone. It probably relies on a previous test’s data or side effects. Create its prerequisites in its own setup and give it its own reason to exist.
  • Tests pass individually but fail in a suite. Look for shared records, stale data, reused browser sessions, and collisions between parallel workers. Isolate or clean the relevant state.
  • One test takes a long time and has many unrelated failure points. Break the journey into tests with separate purposes and arrange each test’s starting state outside the browser when feasible.
  • The browser is doing repetitive setup unrelated to the behavior. Move setup to a fixture, API, or other suitable mechanism, while retaining browser actions that are material to the behavior being tested.
  • Assertions or reporting are being attributed to WebDriver. WebDriver drives the browser; use the test framework for assertions, pass/fail decisions, and reporting.
  • “Atomic” is being interpreted as one assertion only. Selenium’s guidance emphasizes independence, isolation, short scope, and purpose; it does not set a mandatory assertion count.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If the job is capturing a website screenshot rather than testing browser behavior, ScreenshotNeo is a screenshot API and MCP server for developers. One GET request returns an image or PDF. For example, with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

See the ScreenshotNeo documentation for the API options. Cookie banners are accepted before capture and more than 60 known consent platforms, newsletter popups, and chat widgets can be removed; those steps can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server lets AI agents use screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Does an atomic Selenium test have to contain only one assertion?

No. Selenium’s guidance does not prescribe an assertion count; checks should establish one coherent outcome.

Does Selenium Grid make tests independent?

No. Grid distributes execution, while each test still needs isolated state and prerequisites.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.