Skip to main content
SeleniumDecoded
Back to Challenges

The 30-Second Negative Check

intermediate C# 10 min

Asserting that an error is not shown takes 30 seconds every time. Diagnose the wait configuration and fix it.

The Scenario

The suite has an implicit wait of 30 seconds “so nothing flakes”. A colleague notices that every test asserting the absence of an error banner takes exactly 30 seconds longer than it should, and the whole suite is 20 minutes slower than it was a year ago.

Your Task

Explain why the negative check is slow and fix the configuration so both positive and negative checks are fast and reliable.

What Good Looks Like

  • Implicit wait set to zero.
  • Explicit waits on the conditions each step needs.
  • The negative check runs after a positive signal that the action completed, so it is both fast and meaningful.

Your task

Asserting that an error is not shown takes 30 seconds every time. Diagnose the wait configuration and fix it.

Problem Code
[SetUp]
public void SetUp()
{
    driver = new ChromeDriver();
    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
    wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
}

[Test]
public void ValidCouponShowsNoError()
{
    driver.Navigate().GoToUrl("https://app.example.com/checkout");
    driver.FindElement(By.Name("promoCode")).SendKeys("SAVE10");
    driver.FindElement(By.Id("apply")).Click();

    wait.Until(d => d.FindElement(By.CssSelector("[data-testid='order-total']")).Text == "$89.00");

    // This line takes 30 seconds even though the page is done
    Assert.That(driver.FindElements(By.CssSelector(".alert-error")), Is.Empty);
}

Need Help?

Solution

Try to solve the challenge yourself before revealing the solution.

Lessons that cover this