限制硒元素搜索等待时间的正确方法 [英] Proper way to limit wait time on selenium element search
问题描述
我的守夜人/硒测试代码使用
My nightwatch/selenium test code looks for elements in the page that may not exist using code such as
browser.elementIdElement(ELEMENT,'class name', 'myclass', function(r)
{ if (r.status == 0) console.log('found match')
else console.log('did not find match')
})
如果找到该元素,则快速调用回调(<50ms),但是如果没有匹配的元素,则回调花费更长的时间(> 1000ms).我必须执行数百次,并且只有少数几个元素符合搜索条件,因此它为测试运行增加了大量时间.
If the element is found, the callback is invoked quickly (< 50ms), but if no element matches, the callback takes much longer (>1000ms). I have to do this hundreds of times and there are only a few elements that match the search criteria, so it adds a significant amount of time to a test run.
我想限制硒花在寻找元素上的时间.我尝试使用selenium timeoutsImplicitWait()函数,例如
I would like to limit the time selenium spends searching for elements. I tried using the selenium timeoutsImplicitWait() function, e.g.,
browser.timeoutsImplicitWait(250)
.elementIdElement(ELEMENT,'class name', 'myclass', function(r)
{...})
,但不影响性能.限制元素搜索时间的正确方法是什么?
but it doesn't affect performance. What is the correct method for limiting element search time?
推荐答案
以下代码用于检查可见性并即使没有匹配项也可以继续
The following code for checking the visibility and continue even if there is no match
browser.waitForElementVisible('selector',timeout,false);
或存在性:
browser.waitForElementPresent('selector',timeout,false);
根据守夜API,
默认情况下,如果未找到该元素,则测试将失败.如果您希望即使断言失败也希望测试继续进行,请将其设置为false.要全局设置此设置,可以在全局变量中定义属性
abortOnAssertionFailure
.
有关详细说明,请在此处查看: http://nightwatchjs.org/api/#waitForElementVisible
For more detailed explanation, check here: http://nightwatchjs.org/api/#waitForElementVisible
这篇关于限制硒元素搜索等待时间的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!