黄瓜/水豚:测试失败随机PhantomJS [英] Cucumber/Capybara: tests fail randomly under PhantomJS

查看:207
本文介绍了黄瓜/水豚:测试失败随机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屋!

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