0

The requiremnt is that a particular selenium script has to complete executing within 30 seconds. If it crosses 30 seconds, the script should fail. Not a test step, but the entire script has to run within 30 secs(not implicit or explicit wait)

2 Answers2

1

If you are using Selenium with Java and TestNG then you could go with timeOut parameter in test annotation

e.g.

@Test(timeOut = 30000)
public void testMethod(){
     // do's
}

and this is how you can configure in XML to complete the test within given time

<suite name="Time test Suite" time-out="30000" verbose="1" >
  <test name="Timeout Test" >
    <classes>
      <class name="com.howtodoinjava.test.TimeoutSuite" />
    </classes>
  </test>
</suite>

For more details refer this.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
0

setScriptTimeout

setScriptTimeout sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.

  • Defination:

    WebDriver.Timeouts setScriptTimeout(long time, java.util.concurrent.TimeUnit unit)
    
    Parameters:
     time - The timeout value.
     unit - The unit of time.
    
    Returns:
     A self reference.
    
  • Usage:

    • Java:

      driver.manage().timeouts().setScriptTimeout(1800, TimeUnit.SECONDS);
      
    • Python:

      driver.set_script_timeout(30)
      

You can find a relevant discussion in What does Selenium .set_script_timeout(n) do and how is it different from driver.set_page_load_timeout(n)?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352