Module: Capybara::Rc::Extensions
- Includes:
- SeleniumRcLocators
- Defined in:
- lib/capybara/rc/extensions.rb
Overview
Contributes methods to the adapter that are not part of Selenium-RC, but which are useful in a test suite in transition.
Expects a ‘session` accessor to be provided where it is mixed in.
Instance Method Summary collapse
-
#capybara_find_by_locator(locator) ⇒ Capybara::Node::Element
Parses the locator and finds the corresponding Capybara element.
-
#capybara_has_locator?(locator) ⇒ Boolean
Parses the locator and queries the session to see if it is present.
-
#capybara_has_no_locator?(locator) ⇒ Boolean
Parses the locator and queries the session to see if it is not present.
Methods included from SeleniumRcLocators
#parse_selenium_rc_locator, #parse_selenium_rc_select_option_locator, #parse_selenium_rc_string_pattern, #parse_selenium_rc_window_locator
Instance Method Details
#capybara_find_by_locator(locator) ⇒ Capybara::Node::Element
Parses the locator and finds the corresponding Capybara element. Raises Capybara::ElementNotFound when the element can’t be found, or a StandardError if the locator is not supported.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/capybara/rc/extensions.rb', line 20 def (locator) parsed = parse_selenium_rc_locator(locator) css_selector = locator_to_css_selector(parsed) return session.find(css_selector) if css_selector xpath_expression = locator_to_xpath_expression(parsed) return session.find(:xpath, xpath_expression) if xpath_expression fail "Don't know how to find a #{parsed[:type].inspect} Selenium locator with Capybara" end |
#capybara_has_locator?(locator) ⇒ Boolean
Parses the locator and queries the session to see if it is present.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capybara/rc/extensions.rb', line 36 def (locator) parsed = parse_selenium_rc_locator(locator) css_selector = locator_to_css_selector(parsed) return session.has_css?(css_selector) if css_selector xpath_expression = locator_to_xpath_expression(parsed) return session.has_xpath?(xpath_expression) if xpath_expression fail "Don't know how to find a #{parsed[:type].inspect} Selenium locator with Capybara" end |
#capybara_has_no_locator?(locator) ⇒ Boolean
Parses the locator and queries the session to see if it is not present. This saves time over ‘!adapter.is_visible(locator)` because Capybara [pauses]( github.com/jnicklas/capybara#asynchronous-javascript-ajax-and-friends) to wait for an element to show up after you find it. If you want to check that it isn’t there, this pause is a waste of time. As a side effect of this Capybara behavior, this method will also wait for an element to disappear.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/capybara/rc/extensions.rb', line 56 def (locator) parsed = parse_selenium_rc_locator(locator) css_selector = locator_to_css_selector(parsed) return session.has_no_css?(css_selector) if css_selector xpath_expression = locator_to_xpath_expression(parsed) return session.has_no_xpath?(xpath_expression) if xpath_expression fail "Don't know how to find a #{parsed[:type].inspect} Selenium locator with Capybara" end |