Reputation: 47
I want to verify the content of the pop up message "Only Whole numbers" after submitting a form. Below is the code to submit the form:
fill_in 'allocationRegContrib[12].newFundValue', :with => workbook.cell(2,3)
find(:xpath, '//*[@id="allocationChangeDetails"]').click
sleep 5
expect(page).to have_content("Only Whole numbers")
Line 4 is the place where I want to check the content in the pop up . I get the error "unexpected alert open"
Then i tried in another way by adding the line 4 in the place where I accept the pop up. Below is the code:
Then (/^I accept popup for fractional part$/) do
expect(page).to have_content("Only Whole numbers")
page.driver.browser.switch_to.alert.accept
end
here too i get the same error. Please Advice
Upvotes: 0
Views: 806
Reputation: 49860
To do this in a cross driver manner with capybara you need to change your steps slightly since the step that triggers the alert needs to know it's coming
When (/^I do something and accept popup for fractional part$/) do
accept_alert "Only Whole numbers" do
# the do something code that triggers the alert box
end
end
If you're using the accept popup in more than one place you could do something along the lines of
When (/^(.+) and accept popup for fractional part$/) do |step_name|
accept_alert "Only Whole numbers" do
step(step_name)
end
end
or more generally
When (/^(.+) and accept "([^"]+)"$/) do |step_name, alert_text|
accept_alert alert_text do
step(step_name)
end
end
Upvotes: 1