Мы пытаемся представить capybara в наших примерах rspec и пока не имеем большой удачи. Я не знаю, если это является частью confusion between capybara and rails integration testing, но ...Почему capybara не находит элемент формы?
Вот RSpec пример:
require 'spec_helper'
describe "planning a trip", :type => :feature do
before :each do
FactoryGirl.create(:user)
end
it "creates a new trip" do
visit '/trips/new'
save_and_open_page
within("#new_trip") do
fill_in '#trip_from_place_nongeocoded_address', :with => '730 w peachtree st, atlanta, ga'
fill_in '#trip_to_place_nongeocoded_address', :with => 'georgia state capitol, atlanta, ga'
end
click_link 'Plan it'
expect(page).to have_content 'Success'
end
end
и вот соответствующая часть HTML, из save_and_open_page водосвинку в:
<form accept-charset="UTF-8" action="/trips" class=
"simple_form form-horizontal" id="new_trip" method="post"
novalidate="novalidate">
<div class=
"control-group string required trip_from_place_nongeocoded_address">
<label class="string required control-label" for=
"trip_from_place_nongeocoded_address"><abbr title=
"required">*</abbr> From</label>
<div class="controls">
<input class="string required" id=
"trip_from_place_nongeocoded_address" name=
"trip[from_place][nongeocoded_address]" placeholder=
"Enter address" size="50" type="text">
</div>
</div>
[...etc...]
но работает на RSpec пример завершается с:
1) planning a trip creates a new trip
Failure/Error: fill_in '#trip_from_place_nongeocoded_address', :with => '730 w peachtree st, atlanta, ga'
Capybara::ElementNotFound:
Unable to find field "#trip_from_place_nongeocoded_address"
# ./spec/features/plan_a_trip_spec.rb:12:in `block (3 levels) in <top (required)>'
# ./spec/features/plan_a_trip_spec.rb:11:in `block (2 levels) in <top (required)>'
Предлагайте Ионы?
Я не уверен, почему capybara не может найти это поле, но вы должны уметь указывать capybara имя вашей метки вместо селектор к элементу DOM. 'fill_in 'From',: with => '...''. Capybara найдет поля с этим в качестве текста этикеток, который, по-видимому, вы настроили. Я предпочитаю это также потому, что он отражает то, что сделает пользователь. –
, но если у вас есть локализация? Вы принимаете стандартную локаль? – denishaskin