隐式等待删除的可能影响 [英] Probable impact of implicit wait removal

查看:104
本文介绍了隐式等待删除的可能影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Selenium自动化测试中,我们进行了隐式和显式的等待.按照吉姆·埃文(Jim Evan)的想法 https://stackoverflow.com/a/15174978/1471417 ,不要混为一谈.因此计划删除隐式等待.

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.

对于我们的测试,每当我们与元素交互时,我们都会使用显式等待,以使其可见,可点击等,而忽略NoSuchElementException.这就是为什么我不认为它会立即抛出NoSuchElementException的原因.

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.

推荐答案

您看对了. @JimEvans在此讨论明确指出:

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

部分问题是,隐式等待通常(但可能并不总是!)在WebDriver系统的远程"侧实现.这意味着它们被嵌入"到IEDriverServer.exe,chromedriver.exe,安装在匿名Firefox配置文件中的WebDriver Firefox扩展以及Java远程WebDriver服务器(selenium-server-standalone.jar).显式等待专门在本地"语言绑定中实现.使用RemoteWebDriver时,事情变得更加复杂,因为您可能同时使用了系统的本地端和远程端.

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.

现在,按照

  • public WebDriverWait(WebDriver driver, long timeOutInSeconds):Wait将忽略默认情况下在直到"条件下遇到(抛出)的NotFoundException实例,并立即传播所有其他实例.您可以通过调用ignoring(要添加的例外)将更多内容添加到忽略列表.
  • WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis):Wait将忽略默认情况下在直到"情况下遇到(抛出)的NotFoundException实例,并立即传播所有其他实例.您可以通过调用ignoring(要添加的例外)将更多内容添加到忽略列表.
    • 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).

    因此,WebDriverWait()默认情况下会忽略 NotFoundException 和直接已知的子类是:

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

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

    来自 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)
     */
    

    因此,在使用 WebDriverWait 时,您将不会遇到 NoSuchElementException .如果在 WebDriverWait 到期之前没有返回所需的元素,您将面临

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

    这篇关于隐式等待删除的可能影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆