[英]Capybara integration test object creation
I have a basic integration test that is using Capybara, the problem is that if I do not create the required objects firstly the integration test fails. 我有一个使用Capybara的基本集成测试,问题是如果我不首先创建所需的对象,则集成测试将失败。 Am I required to create all objects as the first step in an integration test using Capybara? 作为使用Capybara进行集成测试的第一步,我是否需要创建所有对象? I am using Rails 4.2.4
with Capybara 2.4.3
我在Capybara 2.4.3
使用Rails 4.2.4
Fail 失败
scenario 'if media content contains more than 10 items display pagination links' do
sign_in
# Object creation
11.times do
FactoryGirl.create(:media_content)
end
within '.pagination' do
expect(page).to have_content '1'
end
end
Success 成功
scenario 'if media content contains more than 10 items display pagination links' do
# Object creation
11.times do
FactoryGirl.create(:media_content)
end
sign_in
within '.pagination' do
expect(page).to have_content '1'
end
end
If the objects creation affects the page that you are visit
-ing in your capybara test then yes, you need to create the objects before you test for elements on that page because upon visiting the page, its content is already grabbed by the test browser. 如果对象的创建影响了您正在visit
的页面-在水豚测试中,那么是的,您需要在测试该页面上的元素之前创建对象,因为访问该页面时,其内容已被测试浏览器捕获。
I assume that you have a visit "some_login_page"
and perhaps a redirect upon successful login in your sign_in
method, so when finishing the sign_in
, the test browser already visited (ie grabbed) the page on which you are trying to test content later. 我假设您visit "some_login_page"
并且可能在登录成功后使用sign_in
方法进行了重定向,因此,在完成sign_in
,测试浏览器已经访问(即抓取了)您稍后要在其上测试内容的页面。
The only exception that comes to my mind is if you used a delayed AJAX request to grab the newly created elements from the server to the page dynamically - in that case creating the objects after page visit
might work ok. 我想到的唯一例外是,如果您使用了延迟的AJAX请求来将新创建的元素从服务器动态地捕获到页面,则在这种情况下, 在页面visit
之后创建对象可能就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.