2015-04-07 138 views
0

我一直在试图创建一个简单的页面,包括一个选择框由country_select填充填充水豚测试用例。在我的测试情况下,我遇到的情况,我尝试从选择框选择生日的国家和月份,像这样:水豚选择选项,从:下拉

feature "registering for a new account" do 

    Capybara.javascript_driver = :poltergeist 

    scenario "a new user registers with a complete profile", :js => true do 
    page.visit '/users/sign_up' 
    select "United States", from: 'user[country]' 
    select 'January', from: 'birthMonth' 

    click 'sign up' 

    expect(response.code).to eq '200' 
    end 

end 

水豚或鬼驱人不能看到比我默认选择其他任何选项。有一次我用了一个断言,看看有什么选择我能找到

assert_selector(:css, 'option', minimum: 20) # countries + months should be way more than 20 

,我得到了如下回应:

Failure/Error: assert_selector(:css, 'option', minimum: 20) 
    Capybara::ExpectationNotMet: 
     expected to find css "option" at least 20 times, found 2 matches: "country", "month" 

我不知道我做错了。

回答

1

尝试使用此

find(:xpath, '//option[contains(text(), "United States")]').select_option 
find(:xpath, '//option[contains(text(), "January")]').select_option 

这应该工作,因为没有暧昧下拉值。

0

我的问题不是水豚,RSpec或Poltergeist故障。在控制器类中,我从数据库动态加载一年中的几个月。这个表在我的开发数据库中播种了几个月,但没有用我的测试数据库......对不起