Skip to content

Instantly share code, notes, and snippets.

@phillipkoebbe
Created January 9, 2010 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipkoebbe/272979 to your computer and use it in GitHub Desktop.
Save phillipkoebbe/272979 to your computer and use it in GitHub Desktop.
Given I am on the available_sports page
When I click the new_available_sport link
Then there should be an available_sport_form form
And the available_sport_name text_field should be empty
And the available_sport_name text_field should be focused
Then /^the ([^ ]+) ([^ ]+) (should|should not) be (enabled|visible|empty|focused)$/ do |what, type, expectation, state|
e = expectation.gsub(' ', '_')
send("element_#{e}_be_#{state}", type, what)
end
def element_should_be_focused(type, what, how = :id)
element_should_exist(type, what, how)
raise UnmetExpectation, "expected #{type} '#{what}' (using :#{how}) to be focused" unless element_is_focused?(type, what, how)
end
def element_should_exist(type, what, how = :id)
raise UnmetExpectation, "expected to find #{type} '#{what}' (using :#{how})" unless element_exists?(type, what, how)
end
def element_exists?(type, what, how = :id)
get_element(type, what, how).exists?
end
def get_element(type, what, how = :id)
type = ensure_sym(type)
browser.send(type, how, what)
end
def ensure_sym(type)
type.is_a?(Symbol) ? type : type.to_sym
end
def browser
$browser
end
def element_is_focused?(type, what, how = :id)
sleep(1)
return browser.focused_element.id == get_element(type, what, how).id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment