好的,所以我的问题是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 => true
添加到describe
行,安装webkit驱动程序并将Capybara.javascript_driver = :webkit
添加到我的spec_helper.rb
文件中再跑一次。
这一次,我受到了#34;签约&#34;在主页上阻止之前从顶部闪烁而不是在排名页面上。
所以我认为这可能会更好地使用selenium驱动程序,所以我安装并再次尝试,但这次我的应用程序抱怨没有人注册那一轮。发生这种情况的唯一方法是,如果@entrants
为零,我已经用pry检查过,至少就数据库而言,情况绝对不是这样。
你们给予的任何帮助都将非常赞赏。我不知道如何按下我的按钮。
答案 0 :(得分:1)
我的建议:
save_and_open_page
准确地向您展示司机正在看到的内容这些作品应该告诉你模态发生了什么。