当我在 PhantomJS 下运行 cucumber 场景时,我得到
Capybara::ElementNotFound: Unable to find css ".given_class"
随机位置的异常
看起来驱动程序不会等待元素出现
我正在使用: 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.default_wait_time = 5
就像他们在文档中建议的那样 here .
您还可以在步骤定义中添加 Sleep(1),但这被认为是不好的形式。
如果这不适合您,请尝试指定应在页面上的位置找到该元素。
例如:
Then /^I should see "(.*?)" on the dashboard$/ do |your_element|
within("#your") do
expect(page).to have_content(your_element)
end
end
关于exception - cucumber / capybara : tests fail randomly under PhantomJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18693683/