Skip to content

Instantly share code, notes, and snippets.

@reidab
Created September 27, 2011 01:01
Show Gist options
  • Save reidab/1243953 to your computer and use it in GitHub Desktop.
Save reidab/1243953 to your computer and use it in GitHub Desktop.
Useful cucumber steps to reuse
# Asserting a link based on HREF
Then /^(?:|I )should see a link to (.+?)(?: with the text "([^\"]*)")?(?: within "([^\"]*)")?$/ do |page_name, text, selector|
with_scope(selector) do
page.should have_css("a[href='#{ path_to(page_name) }']", :text => text)
end
end
Then /^(?:|I )should see a mailto link for "([^\"]*)"(?: with the text "([^\"]*)")?(?: within "([^\"]*)")?$/ do |email_address, text, selector|
with_scope(selector) do
page.should have_css("a[href='mailto:#{email_address}']", :text => text)
end
end
# Waiting for and checking element visibility changes due to javascript
When /^I wait until "([^"]*)" is visible$/ do |selector|
page.has_css?("#{selector}", :visible => true)
end
Then /^the element "([^"]*)" should be visible$/ do |selector|
page.should have_css("#{selector}", :visible => true)
end
Then /^the element "([^"]*)" should not be visible$/ do |selector|
page.should have_css("#{selector}", :visible => false)
end
# Dealing with page changes caused by JS setting window.location
When /^(?:|I )wait for javascript to redirect me to (.+)$/ do |page_name|
wait_until do
URI.parse(current_url).path == path_to(page_name)
end
end
When /^(?:|I )wait for javascript to redirect me away from (.+)$/ do |page_name|
wait_until do
URI.parse(current_url).path != path_to(page_name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment