Module: SeleniumRecord::Preconditions

Included in:
Base
Defined in:
lib/selenium_record/preconditions.rb

Overview

Selenium helpers for doing an action after a precondition takes place

Instance Method Summary collapse

Instance Method Details

#when_clickable(locator) ⇒ Selenium::WebDriver::Element

Returns once the element is clickable.

Parameters:

  • locator (Hash)

    contains unique value where the key is the locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)

Returns:

  • (Selenium::WebDriver::Element)

    once the element is clickable

Raises:

  • (Selenium::WebDriver::Error::TimeOutError)

    whether the element stays no clickable after time out period



22
23
24
25
26
# File 'lib/selenium_record/preconditions.rb', line 22

def when_clickable(locator)
  element = wait_clickable(locator)
  yield if block_given?
  element
end

#when_hidden(locator) ⇒ Selenium::WebDriver::Element

Returns once the element is hidden.

Parameters:

  • locator (Hash)

    contains unique value where the key is the locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)

Returns:

  • (Selenium::WebDriver::Element)

    once the element is hidden

Raises:

  • (Selenium::WebDriver::Error::TimeOutError)

    whether the element stays visible after time out period



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/selenium_record/preconditions.rb', line 38

def when_hidden(locator)
  self.class.wait_for do
    begin
      element = root_el.find_element(locator)
      element unless element.displayed?
    rescue => error
      raise if error.is_a? Selenium::WebDriver::Error::TimeOutError
      true
    end
  end
end

#when_modal_present(title, &block) ⇒ Object



28
29
30
# File 'lib/selenium_record/preconditions.rb', line 28

def when_modal_present(title, &block)
  when_present(:xpath, modal_header_xpath(title), &block)
end

#when_present(locator) ⇒ Object

Returns the first element matching the given arguments once this element is displayed in the DOM

Parameters:

  • how (Symbol)

    (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)

  • what (String)


10
11
12
13
14
# File 'lib/selenium_record/preconditions.rb', line 10

def when_present(locator)
  element = wait_displayed(locator)
  yield if block_given?
  element
end