Selenium webdriver 硒缓存问题w/Nightwatch.js集成测试
我在SeleniumWebDriver(v2.41.0)的基础上使用Nightwatch.js(v0.5.6)构建了一套小型但不断增长(希望如此)的集成测试。我总是会偶尔遇到缓存中找不到的Selenium webdriver 硒缓存问题w/Nightwatch.js集成测试,selenium-webdriver,nightwatch.js,Selenium Webdriver,Nightwatch.js,我在SeleniumWebDriver(v2.41.0)的基础上使用Nightwatch.js(v0.5.6)构建了一套小型但不断增长(希望如此)的集成测试。我总是会偶尔遇到缓存中找不到的元素错误,但我正在处理一个大型验证测试用例—一个包含超过24个单独测试以及setUp()的文件。我还没有完成这个测试,这是个问题 There was an error while executing the Selenium command - enabling the --verbose option mig
元素
错误,但我正在处理一个大型验证测试用例—一个包含超过24个单独测试以及setUp()
的文件。我还没有完成这个测试,这是个问题
There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Element not found in the cache - perhaps the page has changed since it was looked up
错误似乎总是发生在我的setUp()
函数的末尾,但我找不到阻止这种缓存发生的答案。这是我的setUp()
函数:
setUp: function(browser) {
console.log('Logging in & navigating to Eligibility Groups...');
login(browser, app.masterAdminUsername, app.masterAdminPassword)
// Navigate to Eligibility Groups
.waitForElementVisible('button[data-action="EligibilityGroups"]', 1000, function() {
browser
.click('button[data-action="EligibilityGroups"]', function() {
console.log('Link clicked. Waiting for #btnCreate to be visible');
browser
.waitForElementVisible('#btnCreate', 1000, function() {
console.log('Exiting setUp()');
});
});
})
}
最终,我明白了:
There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 3.72 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'robwilkerson.local', ip: '172.20.1.112', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Session ID: 04f47f5c-fda0-f049-9ec1-1d3a40ac44fe
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=30.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
✖ Timed out while waiting for element <#btnCreate> to be visible for 1000 milliseconds. - expected "visible" but got: not visible
执行Selenium命令时出错-启用--verbose选项可能会提供更多详细信息。
在缓存中找不到元素-可能该页在查找后已更改
命令持续时间或超时:3.72秒
有关此错误的文档,请访问:http://seleniumhq.org/exceptions/stale_element_reference.html
构建信息:版本:“2.41.0”,修订版:“3192d8a”,时间:“2014-03-27 17:17:32”
系统信息:主机:'robwilkerson.local',ip:'172.20.1.112',os.name:'Mac os X',os.arch:'x86_64',os.version:'10.9.4',java.version:'1.6.0_65'
会话ID:04f47f5c-fda0-f049-9ec1-1d3a40ac44fe
驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver
功能[{platform=MAC,acceptSslCerts=true,javascriptEnabled=true,browserName=firefox,rotatable=false,locationContextEnabled=true,version=30.0,cssSelectorsEnabled=true,databaseEnabled=true,handlesAlerts=true,browserConnectionEnabled=true,nativeEvents=false,webStorageEnabled=true,applicationCacheAbled=true,takesScreenshot=true}]
✖ 等待元素可见1000毫秒时超时。-应为“可见”,但得到:不可见
测试用例各不相同,但它似乎总是在“等待元素可见1000毫秒”时失败。更改我等待的毫秒数只会更改错误中报告的毫秒数
我能在这里做什么?我的脚本有问题吗?我读过的所有东西和尝试过的所有东西都让我一事无成。如果有人路过,我通过反复试验发现:
.click()
加载或重新加载内容时,我都需要添加.pause()
。通常,.pause(1000)
就足够了,但有时需要更长的时间。单独使用.waitForElementVisible()
很少能始终如一地工作.waitForElementVisible()
,我都会使用默认超时值30000
。对于较大的值,似乎没有任何惩罚我现在将此作为答案,但如果有人有更好的策略,我愿意改变这一点。如果有人来访,我通过反复试验发现:
.click()
加载或重新加载内容时,我都需要添加.pause()
。通常,.pause(1000)
就足够了,但有时需要更长的时间。单独使用.waitForElementVisible()
很少能始终如一地工作.waitForElementVisible()
,我都会使用默认超时值30000
。对于较大的值,似乎没有任何惩罚我现在将此标记为答案,但如果有人有更好的策略,我愿意改变这一点。使用
。wait…
函数,它们暂停执行,因此无需嵌套连续调用。您可以在waitForElementVisible
之后调用单击。使用.wait…
函数,它们暂停执行,因此无需嵌套连续调用。您可以在waitForElementVisible
之后调用单击。