Capybara 和 Ajax 测试不工作
我用ajax提交表单。当表单提交出现错误时,表单会使用 ajax、jquery 再次呈现。
我正在尝试使用 Capybara 和 Rspec 测试此行为,如下所示:
描述“板创建失败”,:type => :request do
it "should not create a birthday board" do
Capybara.default_wait_time = 5
lambda do
visit root_path
fill_in "Name", :with => ""
select('1967', :from => "board_birthday_1i" )
select('October', :from => "board_birthday_2i" )
select('30', :from => "board_birthday_3i" )
click_button("Start the surprise")
page.should have_selector('div#error_explanation')
page.find_field('Name').value
end.should_not change(Board, :count)
end
end
结果如下:
Failure/Error: page.should have_selector('div#error_explanation')
expected following output to contain a <div#error_explanation/> tag:
但是我实际上页面上有一个 error_explanation div。
为什么这个测试会失败?
先感谢您。
I submit a form with ajax. When there are errors on the form submission the form is rendered again using ajax, jquery.
I am trying to test this behavior with Capybara and Rspec as follows:
describe "board creation failure", :type => :request do
it "should not create a birthday board" do
Capybara.default_wait_time = 5
lambda do
visit root_path
fill_in "Name", :with => ""
select('1967', :from => "board_birthday_1i" )
select('October', :from => "board_birthday_2i" )
select('30', :from => "board_birthday_3i" )
click_button("Start the surprise")
page.should have_selector('div#error_explanation')
page.find_field('Name').value
end.should_not change(Board, :count)
end
end
The results are as follows:
Failure/Error: page.should have_selector('div#error_explanation')
expected following output to contain a <div#error_explanation/> tag:
However I do in fact have an error_explanation div on the page.
Why does this test fail?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过等待几秒钟直到回复到达。
在行前添加
sleep(3)
并再次测试。
这可能会有所帮助。
Have you tried by waiting few seconds until the response arrive.
Add
sleep(3)
beforeline and test again.
This might help.