Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

selenium - Probable impact of implicit wait removal

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...