ruby-on-rails-4 – Capybara无法点击模态中的表单按钮,不同的水
好的,所以我的问题是Capybara无法单击一个表单的提交按钮(用简单的表单生成),它位于一个模态(Bootstrap v2.3)中.请注意,以下代码是非常杂乱的学习者代码.我试图让它经过测试,以便我能够重构它.
模态代码: <div class="modal hide" id="updateModal"> <button type="button" class="close" data-dismiss="modal">×</button> <div class="modal-header" <h3>Update your score</h3> </div> <div class="modal-body"> <%= simple_form_for @update do |f| %> <%= render 'shared/error_messages',object: f.object %> <%= f.input :newread,:label => "Amount Read",:placeholder => 'pages/screens/minutes #',:input_html => { :maxlength => 5 } %> <%= f.input :medium,:label=> "Medium Read",:collection => ["book","manga","game","fgame","net","lyric","subs","news","sent","nico" ],:prompt => "Select medium read" %> <% lang_list = Update::user_langs(current_user,ApplicationHelper::curr_round) %> <%= f.input :lang,:label => "Language",:collection => lang_list,:prompt => "Select your language" %> <%= f.input :repeat,:label => "Repeat number",:collection =>0..50,:priority => '0' %> <%= f.input :dr,:inline_label => 'Double Rowed?',:hint => 'Only to be used with Japanese books',:label => false %> </div> <div class="modal-footer"> <%= submit_tag 'Cancel',:class => "btn btn-danger",'data-dismiss' => "modal" %> <%= f.button :submit,'Submit Update',:class => "btn btn-primary"%> </div> <% end %> </div> 圆控制器索引功能: def index @entrants = Round.includes(:user).where(:round_id => "#{ApplicationHelper::curr_round}") if @entrants == nil redirect_to root_url,:flash => { :error => "There are currently no users registered for this round." } end list = Round.where(:round_id => ApplicationHelper::curr_round).select(:tier).uniq lang_list = Update.where(:round_id => ApplicationHelper::curr_round).select(:lang).uniq @tier = list.map(&:tier) @tier = @tier.sort{ |a,b| Tier::TIER_VALUES[a.to_sym] <=> Tier::TIER_VALUES[b.to_sym]} @lang = lang_list.map(&:lang) if signed_in? @update = current_user.updates.build end end Update_page_spec: describe "Update Pages" do before do sign_in #omniauth fake signin end subject { page } describe "a registered user submitting an update",:js => true do before do user = User.find_by_uid(123545) user_round = user.rounds.create!(round_id: ApplicationHelper::curr_round,lang1: 'jp',lang2: 'en',lang3:'zh',tier: 'Bronze',book: 10,manga: 10,fgame: 10,game: 10,net: 10,news: 10,lyric: 10,subs: 10,nico: 10,sent:10,pcount: 1010) visit round_path(ApplicationHelper.curr_round) end it "should update successfully" do click_link("Update") fill_in('update[newread]',:with => '10') select "book",:from => "Medium Read" select "Japanese",:from => "Language" click_button "Submit Update" save_and_open_page page.should have_selector('alert-success',:text => "Update successfully submitted") end end end 所以我这样做,当我检查save_and_open_page看到了什么,它的页面没有任何变化.没有按钮被按下的证据.所以我认为生成js的模态可能是个问题所以我添加:js =>如果对于describe行,请安装webkit驱动程序并将Capybara.javascript_driver =:webkit添加到我的spec_helper.rb文件并再次运行. 这次我在主页上阻止了从顶部开始的“登录”闪光,而不是在排名页面上. 所以我想也许这可能会更好用selenium驱动程序,所以我安装并再次尝试,但这次我的应用程序抱怨没有人注册该轮.发生这种情况的唯一方法是,如果@entrants为零,我已经检查过pry,至少就数据库而言,这绝对不是这种情况. 你们给予的任何帮助都将非常感激.我不知道如何按下我的按钮. 解决方法
我的建议:
>尽可能多地清理代码.这将有助于澄清正在发生的事情,以及可能导致意外行为的原因. 这些作品应该告诉你模态发生了什么. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |