小编Mic*_* Ef的帖子

Capybara:无法使用js:true找到表单字段

我使用使用poltergeist和phantomjs作为javascript驱动程序的请求测试使用capybara编写了一些测试.

填写登录表单的以下步骤在没有js的情况下运行良好:

it "signs in" do
    visit new_user_session_path
    fill_in "Email", with: user
    fill_in "Password", with: password||"foobar"
    click_button "Login"
end
Run Code Online (Sandbox Code Playgroud)

如果我用js定义我的测试,it "signs in", js: true do我的测试失败并出现错误:

Capybara::ElementNotFound: Unable to find field "Email"
Run Code Online (Sandbox Code Playgroud)

登录表单本身是使用simple_form作为表单生成器和前端的bootstrap构建的.这些字段没有标签.搜索文本仅包含在占位符属性中.

= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
  = f.input :email, :placeholder => User.human_attribute_name(:email), :label => false, :input_html => {:class => 'input-xlarge'}
  = f.input :password, :placeholder => User.human_attribute_name(:password), :label => false, :input_html => {:class => 'input-xlarge'}
  %div
    = f.button :submit, "Login", :class => 'btn …
Run Code Online (Sandbox Code Playgroud)

rspec capybara ruby-on-rails-3 phantomjs twitter-bootstrap-rails

5
推荐指数
1
解决办法
2611
查看次数