2014-11-20 2 views
1

를 찾을 수 없습니다 나는 다음과 같은 형식카피 바라가 필드

<%= form_for(@route, :html => {:class => "form-horizontal", :role => 'form'}) do |f| %> 
<%= render 'shared/error_messages', object: f.object %> 

<div class="form-group"> 
    <input type="text" name="route_origin_input" id="route_origin_input" placeholder="From" onFocus="geolocate(); autocompleteLocation(this,route_origin)" class="form-control" /> 
    <%= f.hidden_field :origin, class: "form-control" %> 
</div> 

<div class="form-group"> 
    <input type="text" name="route_destination_input" id="route_destination_input" placeholder="Destination" onFocus="geolocate(); autocompleteLocation(this,route_destination)" class="form-control" /> 
    <%= f.hidden_field :destination, class: "form-control" %> 
</div> 

<div class="form-group"> 
    <% options = options_from_collection_for_select(@vehicleList, 'vehicle', 'vehicle') %> 
    <%= f.select :vehicle, options, class: "form-control" %> 
</div> 

<div class="form-group"> 
    <%= f.date_field :departure_date, class: "form-control" %> 
</div> 

<%= f.submit "Post", class: "btn btn-large btn-primary", id: "route_post" %> 
<% end %> 

내가 HTML을 추가 한 두 개의 텍스트 필드에서 찾을 수없는 몇 가지 이유를 들어 다음과 같은 시험

require 'spec_helper' 

describe "Route pages" do 

subject { page } 

let(:user) { FactoryGirl.create(:user) } 
before { sign_in user } 

describe "route creation" do 
    before { 
     visit terminal_path 
    } 

    describe "with invalid information" do 

     it "should not create a route" do 
      expect { click_button "route_post" }.not_to change(Route, :count) 
     end 

     describe "error messages" do 
      before { click_button "route_post" } 
      it { should have_danger_message('Not Submitted') } 
     end 

    end 

    describe "with valid information", :js => true do 

     before do 
      fill_in 'route_origin_input', with: "Kimmage, Dublin, Ireland" 

      fill_in 'route_destination_input', with: "Kimmage, Dublin, Ireland" 

      fill_in 'route_departure_date', with: Time.now 
      select 'Car', :from => "route_vehicle" 
     end 

     it "should create a route" do 
      expect { click_button "route_post" }.to change(Route, :count).by(1) 
     end 

    end 
end 
end 

에게 있습니다 카피 바라

I 나타나는 오류는

Failure/Error: fill_in 'route_origin_input', with: "Kimmage, Dublin, Ireland" Capybara::ElementNotFound: Unable to find field "route_origin_input" # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/finders.rb:41:in block in find' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/base.rb:84:in synchronize' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/finders.rb:30:in find' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/node/actions.rb:56:in fill_in' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/session.rb:676:in block (2 levels) in <class:Session>' # /Users/jeff/.rvm/gems/ruby-2.0.0-p594/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in block (2 levels) in ' # ./spec/requests/route_pages_spec.rb:30:in `block (4 levels) in '

입니다

다른 테스트에서는 fill_in을 사용했지만 폼에서 표준 html 코드를 사용한다는 점만 볼 수 있습니다. 이 필드는 사용자가 입력 한 정보를 처리 한 다음 내 모델의 일부인 숨겨진 필드에 결과를 추가하는 데 사용되며 기본적으로 Google지도 api에서 결과를 얻습니다.

편집 : 여기

<div class="form-group"> 
    <input type="text" name="route_origin_input" id="route_origin_input" placeholder="From" onFocus="geolocate(); autocompleteLocation(this,route_origin)" class="form-control" /> 
    <input class="form-control" id="route_origin" name="route[origin]" type="hidden" /> 
</div> 
+0

try page.find (: fillable_field, 'route_origin_date'). 설정 "Kimmage, Dublin, Ireland" –

+0

... 또는 '페이지'가 필요하지 않을 수 있습니다. 그 줄에 접두어를 붙이세요. 나는 확실히 기억할 수 없다. –

+0

렌더링 된 HTML을 표시 할 수 있습니까? –

답변

1

되는 HTML에게 HTML과 확인을 찾아 SPEC. 여기에 내가 시도 할 것 몇 가지 : 당신은 route_origin_input가 아닌 다른 필드에 실패 확인

  1. 있습니까?
  2. :js => true없이 실행하면 어떻게됩니까? 아마도 양식이 렌더링 또는 리디렉션되지 못하게하는 자바 스크립트가있을 수 있습니다.
  3. save_and_open_page를 사용하거나 스크린 샷을 확인하여 진행 상황을 확인하십시오.
  4. 어떤 드라이버를 사용하고 있습니까? 다른 드라이버는 다르게 동작합니다. 다른 드라이버를 사용해보십시오.
  5. 시도 selenium-webdriver. 그것은 브라우저를 실행하고 무슨 일이 일어나고 있는지 확인할 수 있습니다. fill_in 앞에 sleep 10을 사용하십시오. 사양이 일시 중지되고 양식을 검사하거나 수동으로 입력 할 수 있습니다.
  6. 일반적으로 within '.form' do을 사용합니다. 그것은 차이를 만들 수 있습니다. within을 사용하는 방법은 Capybara docs을 참조하십시오.
+0

1. route_origin_input 또는 route_destination_input 중 하나가 실행 된 순서에 따라 오류가 발생합니다. 2. : js => true는 capybara가 입력 필드를 찾을 수있게하지만 입력은 js가 내 모델의 일부인 숨겨진 필드를 채우는 데 사용됩니다. 3,4. capybara-webkit을 사용하고 있으므로 스크린 샷이 제대로 작동하지 않을 수 있습니다. 5. 셀레늄 - webdriver를 사용하고 있었지만 js를 실행해야하므로 capybara로 이동했습니다. 6. 양식 내에서 보겠습니다. –

+0

테스트에서 내 로그인 도우미에 문제가있는 것 같습니다. 그것은 다른 시험을 위해 작동하는 것으로 보이지만 어떤 이유에서이 시험이 아닙니다. –

관련 문제