ruby on rails - Capybara: click on element found by the icon class -
i check that, when click icon link, current_path path of 'show' action.
so, given html:
<a class="btn btn-xs" href="/admin/hotels/1"> <i class="fa fa-eye fa-lg"></i> </a>
and capybara test:
describe "get /hotels", js:true before :each @hotel = create(:hotel) visit admin.hotels_path end "eye icon links show" find(:css, 'i.fa.fa-eye.fa-lg').find(:xpath,".//..").click expect(current_path).to eq(admin.hotel_path(@hotel)) end end
i receive error message:
1) hotels index hotel creation /hotels eye icon link show failure/error: expect(current_path).to eq(admin.hotel_path(@hotel)) expected: "/admin/hotels/560bb674467261c7a4000002" got: "/admin/hotels"
i deduce find(:css, 'i.fa.fa-eye.fa-lg').find(:xpath,".//..").click
not working expect.
the execution of find(:css, 'i.fa.fa-eye.fa-lg').find(:xpath,".//..")
returning:
=> #<capybara::element tag="a">
am doing wrong?
the reason test fails :js because clicking link that. doesn't wait results of click (loading new page). because of calling current_path after still gets original path. removing :js stops using poltergeist , instead uses rack-test synchronous lacks lot of real browser behavior. in capybara 2.4 have needed check content on show page , once appeared current path, capybara 2.5 has have_current_path matcher utilize capybaras waiting behavior. there no need click on element, clicking on contents user should work fine. so
find(:css, 'i.fa.fa-eye.fa-lg').click expect(page).to have_current_path(admin.hotel_path(@hotel))
should work both , without :js
Comments
Post a Comment