Assert vs. Verify in Selenium WebDriver: What’s the Difference?
An assert usually stops a test at the first failure; a verify collects a failure and lets later checks run. Here’s how that distinction works across Selenium tools and test frameworks.
Short answer: A hard assertion usually stops the current test path when a check fails. A soft assertion (often called a “verify” in some tools) records the failure and lets later checks run. Selenium WebDriver itself does not provide a universal verify command or define assertion behavior: your test framework or assertion library does that.
This distinction matters when deciding whether a later browser action still makes sense after an earlier check fails. Use a hard assertion for a prerequisite or critical invariant. Use soft assertions for independent checks when it is useful to see several failures in one run.
1. What “assert” and “verify” mean
In older Selenium terminology and in Selenium IDE, the names describe what happens after a check fails:
- Assert: a hard check. Failure marks the test as failed and stops the current test path.
- Verify: a soft check. Failure is recorded, but later commands continue.
Selenium IDE documents its verify commands as soft assertions: “The test will continue even if the verify fails.” That behavior belongs to Selenium IDE commands. It does not establish a shared WebDriver API across Java, Python, JavaScript, or other bindings.
The Selenium project makes the boundary explicit: “WebDriver does not know a thing about testing: it does not know how to compare things, assert pass or fail, and it certainly does not know a thing about reporting or Given/When/Then grammar.” WebDriver controls the browser; test runners and assertion libraries handle comparisons, failures, and reporting.
2. Hard and soft checks compared
| Question | Hard assertion | Soft assertion / verify |
|---|---|---|
| What happens on failure? | Raises a failure immediately; the current path generally stops. | Collects or records the failure and allows execution to continue. |
| Good fit | Prerequisites and conditions required for meaningful next steps. | Independent checks that can each be evaluated even if another fails. |
| Reporting | The test runner reports the assertion failure. | Collected failures need to be reported, often after the checks finish. |
| WebDriver behavior? | No. Exact behavior comes from the chosen framework. | No universal WebDriver verify command. Selenium IDE has its own verify commands. |
“Usually stops” is deliberate: test runners, fixtures, exception handlers, and framework configuration can change what happens around a failed assertion. Name the framework when describing exact behavior.
3. Choose based on what depends on the check
Use a hard assertion for prerequisites
Stop when continuing could make the test misleading or unsafe. For example, if a checkout test cannot proceed without a loaded cart, assert that the cart is present before clicking checkout. If the prerequisite is false, later failures may only be noise caused by the same underlying problem.
Use soft assertions for independent observations
Suppose a page has separate checks for a title, a help link, and a footer label. If each can be inspected independently, collecting all three failures in one run can reduce the edit-run cycle. The soft assertion mechanism must still collect failures and fail the test at the end; merely catching or suppressing an error can accidentally produce a passing test.
A useful decision checklist
- Would the next action still be valid if this check failed? If no, use a hard assertion.
- Are the remaining checks independent and useful for diagnosis? If yes, consider soft assertions.
- Does the framework provide a documented soft assertion facility? Use that facility and its required final reporting step.
- Will a collected failure still make the test fail? Confirm the framework’s semantics.
4. Runnable Java example with TestNG
TestNG’s Assert API throws AssertionError when an assertion fails. A normal hard assertion therefore interrupts the current test method unless the failure is handled. For multiple independent assertions, TestNG provides SoftAssert; call assertAll() at the end so collected failures are reported and the test fails.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class AssertVsVerifyTest {
@Test
public void hardAndSoftChecks() {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
// Hard prerequisite: if the page title is wrong, stop this path.
org.testng.Assert.assertEquals(
driver.getTitle(), "Example Domain", "Unexpected page title"
);
// Independent observations: collect failures, then report them together.
SoftAssert verify = new SoftAssert();
verify.assertTrue(
driver.findElements(By.cssSelector("h1")).size() == 1,
"Expected exactly one h1"
);
verify.assertTrue(
driver.findElements(By.cssSelector("a")).size() >= 1,
"Expected at least one link"
);
verify.assertEquals(
driver.findElement(By.tagName("h1")).getText(),
"Example Domain",
"Unexpected heading"
);
verify.assertAll(); // Required: throws if one or more soft checks failed.
} finally {
driver.quit();
}
}
}
The example assumes Selenium, TestNG, and a compatible ChromeDriver/browser are available in the project. TestNG—not WebDriver—supplies both assertion styles. If a hard assertion fails before the soft checks, the test method exits through finally and the browser is closed. For a soft failure, execution reaches assertAll(), which reports the collected failures.
5. How the concept maps to other test frameworks
The framework supplies the assertion API and determines how failures propagate. Selenium’s testing guide points developers to assertion libraries and test runners such as JUnit, TestNG, pytest, unittest, NUnit, MSTest, RSpec, Minitest, Jest, Mocha, and Kotest. Do not assume that a method called assert or verify has the same continuation behavior in each one.
- Java: TestNG’s
Assertmethods fail withAssertionError. TestNG’s soft assertion facility collects checks untilassertAll(). - Python: pytest and unittest provide their own assertion and test-failure behavior. Check the library you use for a supported soft-check pattern; do not assume WebDriver has
verify. - JavaScript: Jest, Mocha, and their assertion libraries define how assertion errors affect a test. A thrown assertion error commonly interrupts the current function unless caught, but runner behavior and hooks matter.
- C# and other languages: use the selected framework’s documented assertion and aggregation APIs.
For the same reason, a Selenium IDE command named verifyText should not be translated mechanically into a WebDriver method. In a WebDriver test, express the comparison with the framework in use.
6. Avoid false passes and misleading continuation
- Always finalize soft assertions. In TestNG, omitting
assertAll()can leave collected failures unreported, so the test may appear to pass. - Do not continue through dependent actions. A failed login prerequisite makes later account-page assertions unhelpful; stop and report the first failure.
- Do not swallow exceptions as a substitute for verification. Catching an assertion failure without storing and reporting it hides a real failure.
- Separate independent checks from setup. If the page has not loaded or a required element is absent, later checks may produce cascading errors. Assert page readiness before gathering independent details.
- Keep diagnostics specific. Include the expected condition and useful context in each assertion message.
7. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The next line does not run after a failed “verify.” | The assertion library uses hard assertions, or the failure is an uncaught exception. | Use the framework’s documented soft assertion API; verify its aggregation and finalization requirements. |
| The test passes despite a failed soft check. | Collected errors were never raised or reported; for TestNG, assertAll() may be missing. |
Call the framework’s final aggregation method after all intended checks. |
| Several checks fail with confusing element errors. | A prerequisite such as navigation or page readiness failed, making later checks dependent. | Use a hard assertion for readiness, then soft-check only independent page conditions. |
verify is not found on the WebDriver object. |
WebDriver has no universal verify method; the term may come from Selenium IDE or another framework. | Use the test framework’s assertion API, or use Selenium IDE’s documented command where applicable. |
| Test execution stops, but the browser remains open. | Cleanup is not protected against assertion errors. | Close the driver in a guaranteed cleanup path such as Java finally or the test framework’s teardown fixture. |
8. Performance, reliability, and cost
Assertions are local checks in the test process and usually add negligible work compared with browser navigation, waits, and page rendering. Soft assertions can save time across repeated runs by exposing several independent defects at once, but they do not make each browser operation faster. They can also create noisy reports if the test continues after a shared prerequisite has failed.
For reliability, keep checks deterministic: wait for the relevant page state using your framework’s established Selenium wait pattern, assert prerequisites before dependent actions, and ensure teardown runs after failures. Avoid treating a missing element caused by a race as proof of a product defect; synchronize on the condition the test actually needs.
Assertion choice does not change Selenium licensing or create a per-assertion charge. The practical cost is test runtime and engineering time spent diagnosing failures. Use soft checks when the extra diagnostic coverage is worth continuing the test; use hard checks when continuation would generate misleading work.
9. Capture screenshots when a browser check fails
A screenshot can help diagnose a Selenium failure by preserving what the browser displayed at that point. Capture it before teardown when the test fails, and associate it with the test name and failure details. ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. It can capture a URL as PNG, JPEG, WebP, or PDF, but it does not replace assertions in your Selenium test suite.
For local evidence, use Selenium WebDriver’s screenshot support in the language binding and test framework you already use. For an independent URL capture or an agent workflow, see ScreenshotNeo and its API documentation.
10. Or skip the browser setup
If the goal is to capture a page for inspection rather than to assert browser behavior inside a test, ScreenshotNeo takes one GET request. See the API docs for response formats and options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
Cookie banners are accepted like a visitor and removed along with supported newsletter popups and chat widgets before the shot; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, with no card required.
11. Frequently asked questions
Is verify deprecated in Selenium WebDriver?
There is no universal WebDriver verify API to deprecate. The word remains in Selenium IDE command terminology and in framework-specific patterns.
Does a failed soft assertion make the test pass?
It should not. A soft assertion records failures so execution can continue, then the framework’s collection mechanism must report them and fail the test.
Can I use both types in one test?
Yes. A common pattern is a hard assertion for page readiness or another prerequisite, followed by soft assertions for independent details.
Should every assertion be soft to get more failures?
No. Continuing after a broken prerequisite often produces follow-on noise and can trigger actions in an invalid state. Choose based on dependency between checks.
Sources
- Selenium documentation: Components (WebDriver does not define testing or assertion behavior).
- Selenium IDE documentation: Commands (verify commands continue after a failed check).
- Selenium documentation: Test practices (framework and testing guidance).
- TestNG 7.9.0 API: Assert (failed assertions throw
AssertionError).


