Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 desk6 min

How to Prioritize TestNG Tests with Selenium

TestNG priority schedules tests; dependencies express prerequisites, groups select a subset, and parallel modes target elapsed time. Here’s how to use each without making Selenium tests order-dependent.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use TestNG’s priority to schedule otherwise independent tests in a deliberate order: lower numbers run first. Use dependencies only for genuine prerequisites, groups to choose which tests run, and parallel execution to reduce elapsed time. These controls solve different problems; none is a built-in risk-ranking system. With Selenium, keep tests independently runnable whenever possible.

Choose the TestNG mechanism that matches your goal

Goal TestNG mechanism What it controls Main caution
Schedule independent methods in a deliberate order @Test(priority = ...) Execution ordering; lower values are scheduled first. It does not measure business risk or make tests depend on one another.
Express a genuine prerequisite dependsOnMethods or dependsOnGroups Requires the prerequisite to run successfully for a hard dependency. If the prerequisite fails, the dependent test is skipped.
Run a selected subset Groups, suite XML, or command-line selection Which tests are included or excluded from a run. Your team defines and maintains categories such as smoke or regression.
Reduce elapsed suite time Parallel modes and thread count How work is distributed across threads. Parallelism needs safe isolation of browser sessions, test data, and application state.

These distinctions follow the mechanisms documented in the TestNG documentation. Decide whether you need order, a prerequisite, subset selection, or throughput before changing annotations.

Schedule independent tests with priority

Assign a lower number to a test you want TestNG to schedule earlier. Priority is a runner-ordering hint, not a ranking by importance, failure likelihood, or user impact.

import org.testng.annotations.Test;

public class CheckoutTests {
    @Test(priority = 1, groups = "smoke")
    public void guestCanOpenCheckout() {
        // Start a browser session and establish this test's own preconditions.
    }

    @Test(priority = 2, groups = "regression")
    public void savedAddressCanBeEdited() {
        // This test should create or load its own required data.
    }

    @Test(priority = 3, groups = "regression")
    public void orderHistoryShowsCompletedOrder() {
        // This test should not rely on another test having placed an order.
    }
}

Keep priority values and their purpose easy to understand. If the only reason one method must run first is that it creates state for another, priority is not the right expression of that relationship. Make the later test establish its own preconditions where feasible, or model an actual prerequisite explicitly.

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

Use dependencies only for real prerequisites

A dependency states that a method or group must precede another. A hard dependency makes the dependent method contingent on the prerequisite’s success; if the prerequisite fails, TestNG skips the dependent method. That can be appropriate where the second operation cannot meaningfully be attempted without the first, but it can also conceal how much of a suite is independently testable.

import org.testng.annotations.Test;

public class AccountFlowTests {
    @Test(groups = "account-setup")
    public void createAccount() {
        // Create the account required by the dependent scenario.
    }

    @Test(dependsOnMethods = "createAccount")
    public void verifyAccountCanSignIn() {
        // Runs only after createAccount succeeds.
    }
}

For a prerequisite represented by a group, use dependsOnGroups; for a method, use dependsOnMethods. TestNG also supports alwaysRun = true to make a dependency soft: the method can run after its dependency even when that dependency failed. Use that only when order matters but success of the earlier method does not.

Selenium’s official guidance is direct: “Your tests should be able to run in any order, and not rely on other tests to complete in order to be successful.” See the Selenium test dependency guidance. For a multi-step business journey, consider whether it is one end-to-end scenario or whether each check can create and clean up its own data, rather than making many tests depend on shared browser or application state.

Run a fast subset before a broader suite

Groups let a team label tests for selection, but the names and membership are local policy. For example, define a small confidence set as smoke and a broader set as regression; agree what qualifies and keep the definitions current.

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

Select groups in suite XML

<suite name="Fast checks">
  <test name="Smoke">
    <groups>
      <run>
        <include name="smoke"/>
      </run>
    </groups>
    <classes>
      <class name="example.CheckoutTests"/>
      <class name="example.AccountFlowTests"/>
    </classes>
  </test>
</suite>

Use the class names and package structure from your project. XML can include or exclude groups, and TestNG also documents command-line group selection with -groups and exclusion with -excludegroups; method selection is available with -methods. Consult the TestNG documentation for invocation details matching the way your project launches TestNG.

Do not rely on XML order as a correctness guarantee

In the documented suite configuration context, TestNG runs methods in XML order by default. Setting preserve-order to false makes listed classes and methods run in an unpredictable order. Neither is a substitute for independent test setup or an explicit dependency when a genuine prerequisite exists.

Use parallel execution for throughput, not importance

TestNG documents parallel modes at several scopes: methods, tests, classes, and instances, with a thread-count setting. These modes change how execution work is distributed; they do not decide which tests are more important.

  • parallel="methods": methods run in separate threads; dependent methods still respect their dependency ordering.
  • parallel="tests": methods inside one <test> tag share a thread, while separate <test> tags can run on separate threads.
  • parallel="classes" and parallel="instances": work is grouped by class or instance, respectively.

Choose a scope based on how safely your tests can isolate WebDriver sessions, test data, and application state. A higher thread count is not automatically faster or safer: shared mutable state and shared accounts can create interference. Start with a scope your test design can support, then verify that independent sessions and data remain isolated. The official TestNG documentation describes the modes and configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Define risk-based ordering as team policy

TestNG provides scheduling and selection controls, not a universal risk formula. A project may choose to run tests earlier based on business impact, changed areas, historical failures, or runtime, but that ranking is a team heuristic rather than a TestNG feature. Write down the rule so that a priority or group name means something stable to maintainers. Do not present a locally chosen score as an official TestNG criticality measure.

Troubleshoot common prioritization problems

  • A lower-priority test does not make another test wait for its success: priority controls scheduling, not prerequisites. Use a dependency only if the later test genuinely cannot proceed otherwise.
  • A method is skipped after another method fails: inspect its dependsOnMethods or dependsOnGroups configuration. A hard dependency skips the dependent method when the prerequisite fails.
  • The wrong subset runs: check the group names on @Test, the include/exclude names in XML, or the group and method selection passed to the TestNG command line. Group labels are exact project conventions.
  • Tests fail intermittently when run together or in parallel: look for shared browser drivers, accounts, mutable test data, and application state. Isolate setup and cleanup; reduce parallel scope while diagnosing interference.
  • Tests pass only in a particular suite order: remove hidden state dependence by making each test establish its own preconditions. Use a real dependency only where the scenario necessarily requires a prior successful operation.

Or skip the browser setup

If your goal is to capture a page image or PDF as part of a developer workflow, ScreenshotNeo offers a one-call screenshot API rather than requiring Selenium browser setup. It accepts cookie banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses indicate the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. Plans include 1,000 screenshots per month free with no card, with paid plans starting at $5 for 3,000; see ScreenshotNeo.

For a runnable cURL request, replace the target URL as needed and add your API key. See the ScreenshotNeo API documentation for options.

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

Python equivalent:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

Node.js equivalent:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Sign up for ScreenshotNeo to get 1,000 screenshots a month free, with no card required.

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

Frequently Asked Questions

Which official references cover TestNG groups and parallel execution?

The TestNG documentation and its table of contents are available at testng.org/documentation.html and testng.org/book-toc.html.

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.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair 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.