Skip to content

Instantly share code, notes, and snippets.

@jasonyost
Created July 7, 2014 23:28
Show Gist options
  • Save jasonyost/d2a00fafc06a169f09d0 to your computer and use it in GitHub Desktop.
Save jasonyost/d2a00fafc06a169f09d0 to your computer and use it in GitHub Desktop.
Generic cucumber steps for page navigation with capybara
When(/^I (visit|am on) (.+)$/) do |word, page_name|
visit path_to(page_name)
end
Then(/^I should be on (.+)$/) do |page_name|
visit path_to(page_name)
end
Then(/^I should be redirected to (.+)$/) do |page_name|
visit path_to(page_name)
end
Then(/^I should see "(.*?)" in the page$/) do |text|
expect(page).to have_content(text)
end
Then(/^I should not see "(.*?)" in the page$/) do |text|
expect(page).not_to have_content(text)
end
Then(/^I (should|should not) see the "(.*?)" (element|selector)$/) do |operator, element, word|
case operator
when "shoud"
expect(page).to have_selector(element)
when "should not"
expect(page).not_to have_selector(element)
end
end
Then(/^I (should|should not) see "(.*?)" in "(.*?)"$/) do |operator, text, element|
case operator
when "should"
find = find(element)
expect(find).to have_content(text)
when "should not"
find = find(element)
expect(find).not_to have_content(text)
end
end
Then(/^The page (should|should not) have element "(.*?)"$/) do |operator, element|
case operator
when "should"
expect(page).to have_selector(element)
when "should not"
expect(page).not_to have_selector(element)
end
end
Then(/^I should see a "(.*?)" on the page$/) do |element|
find = find_element(element)
expect(find).to be_truthy
end
When(/^I fill in the "(.*?)" with "(.*?)"$/) do |element, text|
fill_in element, :with => text
end
When(/^I submit the form$/) do
page.evaluate_script("document.forms[0].submit();")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment