2014-04-14 4 views
0

누락 된 카피 바라 요소에 관한 기능 사양에서받은 오류 메시지에 대해 당황합니다.Capybara Conundrum, 필드를 찾을 수 없습니다.

<h1>Register a Building</h1> 
<h4 class="notice"></h4> 
<%= simple_form_for @building do |f| %> 
    <%= f.input :street_address %> 
    <%= f.input :city %> 
    <%= f.input :state, collection: Building::STATES %> 
    <%= f.input :postal_code %> 
    <%= f.input :description %> 
    <%= f.button :submit %> 
<% end %> 

내 feature_spec 필요한 필드가있는 새 건물의 등록을 테스트하고 다음과 같이 : 아래 그림과 같이

나는 나의 new.html.erb에서 간단한 양식을

scenario 'I want to submit a valid building to record' do 
building_count = Building.count 
visit new_building_path 
fill_in 'Street address', with: '5555 Summer Drive' 
fill_in 'City', with: 'Boston' 
fill_in ' State', with: 'WA' 
fill_in 'Postal code', with: '78526' 
fill_in 'Description', with: '' 
click_on 'Create Building' 
expect(page).to have_content('Building Submitted') 
expect(page).to have_content('') 
expect(Building.count).to eql(building_count + 1) 

상태 필드에 도달 할 때까지 모든 것이 정상입니다. 나는 엘레멘트를 발견하지 못하고있다. 오류는 없지만, 나는 save and open page를 할 때 분명히 거기에있다. 나는 오류 메시지의 더블/작은 따옴표를 나타났습니다하지만 따옴표 일치를 변경할 때 아무 일도 발생하지

Failure/Error: fill_in 'State', with: 'WA' 
Capybara::ElementNotFound: 
    Unable to find field "State" 

:

여기 내 오류입니다. 또한, 내 요소를 검사하고 제목이 "국가"임을 알게되었습니다. "State"가 아니라 "No State"를 찾기 위해 테스트를 변경했습니다. 이 문제를 해결하거나 해결하려면 어떻게해야합니까?

답변

1

State 필드는 텍스트 필드가 아닌 선택 상자입니다.

사용 :

select 'WA', from: 'State' 

fill_in 구체적으로 작성 가능한 같은 분야, 즉 텍스트 필드와 텍스트 영역을 찾습니다.

이것에 대해 카피 바라의 docmentation은 여기에 있습니다 : 그것을 할 것입니다 http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions

+0

그래는. 내 감독을 지적 Thx. –

관련 문제