Reputation: 39
Hello dear Stackoverflowers.
I'm having some seriously insanely annoying trouble with my capybara test. It seems to have a mind of its own and will sometimes decide to run with zero issue and sometimes decide to not find elements, click anything and generally just suck. I have no idea why this is.
I've been researching for days trying to find sure up my logic, find the 'best' ways of finding and clicking elements or filling in fields and haven't gotten any further. Please help, if I still had hair I would be pulling it out.
Also I'm using the Selenium Web Driver. All gems are up to date.
Thanks in advance.
It will randomly decide to not click on 'Amtrak 1234' and sometimes entirely miss the find('#atedrop4').click or will decide to click elements not even close being specified in my test. I'm very confused, and in desperate need of some help.
it 'can view the itinerary print and export', js: true do
visit '/admin/login'
fill_in 'Email', with: "[email protected]"
fill_in 'Password', with: "guest"
click_button 'Login'
click_link 'Trips'
expect(page).to have_content 'Trips'
click_link('View Trip Page', match: :first)
new_window=windows.last
page.within_window new_window do
expect(page).to have_content 'A Test To Forget'
find('.showItinerary').click
expect(page).to have_content "DAY 1, AMSTERDAM"
find(:xpath, "//a[@href='#flight1day1']").click
expect(page).to have_content "SINGAPORE AIRLINES FLIGHT 326"
click_link 'Add to Calendar'
find('.ategoogle').click
new_window=page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(new_window) do
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "boarder1"
find("#signIn").click
expect(page).to have_content "[email protected]"
page.driver.browser.close
end
find(:xpath, "//a[@href='#flight1day1']").click
find(:xpath, "//a[@href='#train1Day1']").click
click_link('Export to Calendar', match: :first)
find('.ategoogle').click
new_window=page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(new_window) do
expect(page).to have_content "[email protected]"
page.driver.browser.close
end
find(:xpath, "//a[@href='#train1Day1']").click
find(:xpath, "//a[@href='#carRentalDay1']").click
click_link('Export to Calendar', match: :first)
find('.ategoogle').click
new_window=page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(new_window) do
expect(page).to have_content "[email protected]"
page.driver.browser.close
end
find(:xpath, "//a[@href='#carRentalDay1']").click
find(:xpath, "//a[@href='#hotelDay1']").click
click_link('Export to Calendar', match: :first)
find('.ategoogle').click
new_window=page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(new_window) do
expect(page).to have_content "[email protected]"
page.driver.browser.close
end
find(:xpath, "//a[@href='#hotelDay1']").click
find(:xpath, "//a[@href='#carTransfer1Day1']").click
click_link('Export to Calendar', match: :first)
find('.ategoogle').click
new_window=page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(new_window) do
expect(page).to have_content "[email protected]"
page.driver.browser.close
end
find(:xpath, "//a[@href='#carTransfer1Day1']").click
Upvotes: 1
Views: 344
Reputation: 5462
One thing that helps is to use the save_and_open_page in your capybara tests. This way you can open up the html source of the test page and verify if your html id's and classes actually exist / are rendering the way you think they are. This has especially been the case for me when I'm doing nested forms and adding html to the page dynamically.
Upvotes: 1