我有一个使用rspec 3.4.0
capybara 2.6.2
和capybara-webkit 1.8.0
的rails项目。
我正在为我的网站上的流程编写功能测试,如下所示:
scenario "Buyer creates a seller profile", :js => true do
click_link("SELL ON MYSITE",match: :first)
expect(page).to have_text("Reach thousands of customers in your area")
click_link("Create an Activity",match: :first)
expect(current_path).to eql (new_seller_profile_path)
fill_in "seller_profile[business_name]", :with => "Test company"
fill_in "seller_profile[business_email]", :with => "test@email.com"
fill_in "seller_profile[business_phone_number]", :with => "07771330510"
fill_in "seller_profile[business_description]", :with => "This is a test company"
find('label[for="social"]').click
find("#facebook-placeholder").click
fill_in "seller_profile[business_facebook_url]", :with => "https://www.facebook.com/test"
click_button("CREATE AN ACTIVITY")
------这个按钮在页面改变后打开一个模态--------
fill_in "seller_profile[requested_postcode]", :with => "EH21 8PB"
click_button("Submit")
save_and_open_screenshot
------这就是出错的地方-------
click_link("Continue")
expect(page).to have_text("Choose the type of activity that you want to create")
end
click_link继续失败,错误:
Failure/Error: click_link("Continue")
Capybara::ElementNotFound:
Unable to find link "Continue"
链接确实存在 - 当您单击提交按钮时,会执行一些javascript来更改模式的内容以显示一些新文本和一个新按钮。但是由于某些原因,click_link不会等待或查看模态,它会立即失败。
添加了save_and_open_screenshot调用,我们可以看到这种情况,因为模态javascript尚未执行,因为我们仍然可以看到提交按钮:
有趣的是,鼠标似乎不在“提交”按钮上,因为它应该只是点击它?
如何让click_link等到“继续”按钮出现?!
这是在按下“提交”时执行的javascript。添加到改变它的模态:
$('#gate .modal-body .intro').text('Congratulations, we are available in your location, please continue to create your activity.');
$('#gate .modal-footer').append('<a class="btn btn-lg btn-primary" href="/events/new/">Continue</a>');
答案 0 :(得分:0)
fill_in "seller_profile[requested_postcode]", :with => "EH21 8PB"
sleep 2
click_button("Submit")
sleep 2
click_link("Continue")