Ruby on rails 尝试填充文本\u字段\u标记时出现水豚错误
在我的应用程序中,用户可以搜索zipcode,该zipcode返回相应的街道名称和城市。zipcode写在Ruby on rails 尝试填充文本\u字段\u标记时出现水豚错误,ruby-on-rails,rspec,capybara,Ruby On Rails,Rspec,Capybara,在我的应用程序中,用户可以搜索zipcode,该zipcode返回相应的街道名称和城市。zipcode写在中,而街道名称和城市则放在div中 it 'submits the zipcode and house number', js: true do fill_in 'zipcode', with: '1111AA' fill_in 'house_number', with: 1 click_button('Search') within('#street_n
中,而街道名称和城市则放在div中
it 'submits the zipcode and house number', js: true do
fill_in 'zipcode', with: '1111AA'
fill_in 'house_number', with: 1
click_button('Search')
within('#street_name') do
page.should have_content 'Street X'
end
within('#city') do
page.should have_content 'Town X'
end
end
现在我改变了它,街道名称也将被呈现为
,但是我的规范现在失败了
下面的代码是一个工作测试,其中streetname和city将被放入div中
it 'submits the zipcode and house number', js: true do
fill_in 'zipcode', with: '1111AA'
fill_in 'house_number', with: 1
click_button('Search')
within('#street_name') do
page.should have_content 'Street X'
end
within('#city') do
page.should have_content 'Town X'
end
end
我的部门:
<div id="street_name"><%= street_name %></div>
<div id="city"><%= city %></div>
我的文本字段标记:
<%= text_field_tag 'street_name', street_name, placeholder: 'Straatnaam', id: 'street_name' %>
<%= text_field_tag 'city', city, placeholder: 'Woonplaats', id: 'city' %>
我应该如何编写规范,以便它检查streetname和city是否位于
而不是div?我确信您可以找到文本字段,并使用以下代码对其值进行断言:
find_字段(“street_name”).value.应等于'street X'
但是,请确保id在整个布局中是唯一的,否则您可能会遇到一些严重的模糊性故障
我希望这有帮助 似乎您有几个具有asme id的dom元素,这很糟糕。我必须说,我目前使用的是divs,而不是文本字段标记,不是同时使用这两个标记。我编写了textfieldtags,因为这就是我想要实现它们的方式。当我使用它们(从而删除div)时,测试失败。