Engineering Selenium Test Generation

Selenium Test Prompt

Explicit waits, stale-element handling, drivers that actually quit — Selenium regression tests that hold the legacy fort.

Overview

Selenium suites rot predictably: Thread.sleep calls accumulate, stale element exceptions get try-catched into silence, and leaked driver sessions poison CI. This setup generates a Selenium regression contract for legacy-critical paths with the discipline that keeps WebDriver suites alive: explicit waits with expected conditions (never sleep), re-locating elements after DOM changes instead of caching them, locators that survive DOM churn, and teardown that always quits the driver. Regression strategy pins today's behavior — the job legacy suites exist to do.

How to use this resource

  1. Pin the critical paths first

    Regression strategy: the suite documents what works today, before anything changes.

  2. Enforce the wait discipline

    WebDriverWait + expected conditions everywhere — the contract treats sleep as a defect.

  3. Check the teardown

    Driver.quit in teardown, always — leaked sessions are the silent CI killer.

Why This Works

  • Explicit-wait discipline addresses Selenium's defining flake source at the source
  • Stale-element rules encode the WebDriver lesson every team learns the hard way
  • Regression strategy matches what Selenium suites are actually for in 2026: holding the fort

Best for

  • Established Selenium estates that aren't migrating this quarter
  • Legacy UIs where Playwright adoption isn't on the table yet
  • Regression suites guarding paths nobody dares touch

Not for

  • New projects — Playwright mode generates the same journey with less flake surface
  • Deciding whether to migrate frameworks — that's a team decision, not a prompt

Use cases

  • Protecting legacy admin panels with regression coverage
  • Replacing Thread.sleep with explicit waits at generation time
  • Pinning critical paths before a framework migration

FAQ

Should I generate Selenium tests for a brand-new project with this?

Not the intended use — it targets established Selenium estates guarding legacy critical paths. For new projects the resource points to Playwright mode, which generates the same journey "with less flake surface." This setup is for regression coverage on paths nobody dares touch, where a framework migration isn't on the table this quarter.

How does the generated test avoid the flaky waits Selenium is known for?

The FRAMEWORK GUIDANCE treats sleep as a defect: it mandates explicit waits via WebDriverWait plus expected conditions and forbids Thread.sleep, re-locates elements after DOM changes instead of caching WebElements, and prefers IDs and data attributes over brittle XPath positions. The generated file runs in your own environment, so you still execute and confirm the suite is green.

Why does the prompt keep tests for legacy behavior that looks wrong?

Regression strategy pins today's behavior. For untested legacy code the TEST STRATEGY writes characterization tests that "assert actual current output, even where it looks wrong, and flag the suspicious cases," because the suite's job is documenting what the system does now before anything changes — not correcting it. It also forbids weakening assertions to make tests pass.

More resources from Test Case Prompt Generator

Resources that pair well

Related tools

Tip: Save time by exploring related resources and tools that integrate with this resource.