Nathan Merrill
Nathan Merrill

Reputation: 8386

How to wait X minutes between tests in TestNG

I am testing a website that has a page that will update 4-5 minutes after I have done a certain action.

Here's what I've thought of:

  1. Thread.sleep()/Continuously refreshing page waiting for update. This means my tests automatically get an additional 5 minutes added on.
  2. I have a set of tests that are ordered by DependsOnMethod in a lengthy list. I could depend the first test on the test that performs the action, and have the second test depend on the last test to run. This option is not as bad...but it means putting the methods in a class that is completely irrelevant (and dependencies that don't make logical sense)

Are there any other options?

Note: I am using TestNG with WebDriver

Upvotes: 0

Views: 3023

Answers (1)

Petr Mensik
Petr Mensik

Reputation: 27496

Best solution would be to use implicit or explicit waits but it depends how the page update looks like. But if it's for instance some element with counter, you should try something like.

WebElement myDynamicElement = (new WebDriverWait(driver, 5 * 60)) //time in seconds
    .until(ExpectedConditions.textToBePresentInElement(By.id("id"), 
    "Text after update"));

Upvotes: 1

Related Questions