黄瓜/水豚:测试失败随机PhantomJS [英] Cucumber/Capybara: tests fail randomly under PhantomJS
问题描述
当我在PhantomJS下运行黄瓜时,我得到
When I run cucumber scenarios under PhantomJS I get
Capybara::ElementNotFound: Unable to find css ".given_class"
随机地点的例外情况
驱动程序不等待元素外观
it looks like driver does not wait for element appearance
我使用的是:
Ruby 2.0
Cucumber 1.3.6
Capybara 2.1.0
Selenium-webdriver 2.35.1
PhantomJS 1.9.1
I'm using: Ruby 2.0 Cucumber 1.3.6 Capybara 2.1.0 Selenium-webdriver 2.35.1 PhantomJS 1.9.1
推荐答案
Capybara,特别是PhantomJS会加载一个页面,并执行检查元素。因此,一些元素可能没有加载,测试失败。默认情况下,capybara的等待时间为2,这可以增加。可能尝试:
Capybara, particularly with PhantomJS will load a page really quickly, and perform checks for elements. As such, some elements may not have loaded and tests fail. By default capybara has a wait time of 2, which you can increase. Maybe try:
Capybara.default_wait_time = 5
像他们在文档这里
>。
like they suggest in the docs here.
您还可以在步骤定义中添加Sleep(1),但这被认为是错误的形式。
You can also add a Sleep(1) in your step definition, but that is considered bad form.
如果这样做不适合您,请尝试指定该网页上应该找到该元素的位置。
If that doesn't do it for you, try specifying where on the page the element should be found.
例如:
Then /^I should see "(.*?)" on the dashboard$/ do |your_element|
within("#your") do
expect(page).to have_content(your_element)
end
end
这篇关于黄瓜/水豚:测试失败随机PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!