Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In our Selenium automated tests, we've implicit and explicit waits. As per Jim Evan's thought https://stackoverflow.com/a/15174978/1471417, they should not be mixed. Hence planning to remove implicit wait.

For our tests, whenever we interact with an element, we've used explicit wait for it to be visible, clickable etc. with ignoring NoSuchElementException. That's why I don't think, it will throw NoSuchElementException immediately.

This makes sure removing implicit wait won't affect my tests. Apart from this, I want to know if there are any chances it can break tests. Based on your experiences, I want to understand its impact, hence requesting to share your views here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
967 views
Welcome To Ask or Share your Answers For Others

1 Answer

You saw it right. @JimEvans in this discussion clearly states that:

Part of the problem is that implicit waits are often (but may not always be!) implemented on the "remote" side of the WebDriver system. That means they're "baked in" to IEDriverServer.exe, chromedriver.exe, the WebDriver Firefox extension that gets installed into the anonymous Firefox profile, and the Java remote WebDriver server (selenium-server-standalone.jar). Explicit waits are implemented exclusively in the "local" language bindings. Things get much more complicated when using RemoteWebDriver, because you could be using both the local and remote sides of the system multiple times.

So, while interacting with an element Explicit Wait is the mandate.


Now, as per the constructors of WebDriverWait:

  • public WebDriverWait(WebDriver driver, long timeOutInSeconds): Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).
  • WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis): Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).

So, WebDriverWait() by default ignores NotFoundException and the direct known subclasses are:

  • NoAlertPresentException
  • NoSuchContextException
  • NoSuchCookieException
  • NoSuchElementException
  • NoSuchFrameException
  • NoSuchWindowException

From the source code of WebDriverWait.java:

/**
 * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in
 * the 'until' condition, and immediately propagate all others.  You can add more to the ignore
 * list by calling ignoring(exceptions to add).
 *
 * @param driver The WebDriver instance to pass to the expected conditions
 * @param timeOutInSeconds The timeout in seconds when an expectation is called
 * @param sleepInMillis The duration in milliseconds to sleep between polls.
 * @see WebDriverWait#ignoring(java.lang.Class)
 */

So, while using WebDriverWait you won't face NoSuchElementException. Incase the desired element is not returned till the WebDriverWait expires you will face timeoutException.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...