module SeleniumRecord::Actions

Contains simple actions to play from selenium objects

Public Class Methods

choose_option(id, text) click to toggle source

Chooses an option from select enhanced by javascript @param id [String] id of the select @param text [String] the option text

# File lib/selenium_record/actions.rb, line 18
def choose_option(id, text)
  click_wait xpath: select_xpath(id)
  click_wait xpath: select_option_xpath(id, text)
end

Public Instance Methods

accept_popup() click to toggle source

Clicks accept button on popup

# File lib/selenium_record/actions.rb, line 10
def accept_popup
  popup = browser.switch_to.alert
  popup.accept
end
choose_menu(dropdown, menu) click to toggle source

Chooses a menu from dropdown enhanced by javascript @param dropdown [String] text of dropdown @param menu [String] text of menu

# File lib/selenium_record/actions.rb, line 26
def choose_menu(dropdown, menu)
  click_wait xpath: dropdown_xpath(trans dropdown)
  click_wait xpath: dropdown_menu_xpath(trans menu)
end
clear(locator) click to toggle source

Clear input of type ‘text’

# File lib/selenium_record/actions.rb, line 32
def clear(locator)
  el = find(locator)
  el.send_keys('')
  el.clear
end
click(locator) click to toggle source
# File lib/selenium_record/actions.rb, line 51
def click(locator)
  cover { find(locator).click }
end
click_on(locator) click to toggle source
# File lib/selenium_record/actions.rb, line 38
def click_on(locator)
  find(locator).click
end
click_wait(locator) click to toggle source

Clicks on element and wait until all jquery events are dispatched @param how [Symbol] (:class, :class_name, :css, :id, :link_text, :link,

:partial_link_text, :name, :tag_name, :xpath)

@param what [String]

# File lib/selenium_record/actions.rb, line 46
def click_wait(locator)
  when_present(locator).click
  wait_js_inactive
end
fill(locator, text) click to toggle source
# File lib/selenium_record/actions.rb, line 55
def fill(locator, text)
  return unless text
  clear(locator)
  find(locator).send_keys(text || '')
end
focus(locator) click to toggle source

@param locator [Hash|Selenium::WebDriver::Element]

# File lib/selenium_record/actions.rb, line 62
def focus(locator)
  element = (locator.is_a?(Hash) && find(locator)) || locator
  browser.action.move_to(element).perform
end
pop_last(model_type) click to toggle source

Drops the model view on the bottom to the top of the model type view list @param model_type [Symbol] the type of the views to be affected

# File lib/selenium_record/actions.rb, line 81
def pop_last(model_type)
  elements = send("#{model_type}_elements")
  browser.action
    .drag_and_drop(elements.last, elements.first).perform
end
select_from_chosen(id, text) click to toggle source

@param id [Symbol] id of select element @param text [String] text of the option to be selected

# File lib/selenium_record/actions.rb, line 89
    def select_from_chosen(id, text)
      browser.execute_script <<-script
        var optValue = $("##{id} option:contains('#{text}')").val();
        var value = [optValue];
        if ($('##{id}').val()) {
          $.merge(value, $('##{id}').val());
        }
        $('##{id}').val(value).trigger('chosen:updated');
      script
    end
submit() click to toggle source
# File lib/selenium_record/actions.rb, line 67
def submit
  click(xpath: ".//button[@type='submit']")
  wait_page_load
  load_dom
end
textarea_content(locator, content) click to toggle source
# File lib/selenium_record/actions.rb, line 4
def textarea_content(locator, content)
  find(locator).clear  # gain focus on textarea
  find(locator).send_keys content
end

Private Instance Methods

choose_option(id, text) click to toggle source

Chooses an option from select enhanced by javascript @param id [String] id of the select @param text [String] the option text

# File lib/selenium_record/actions.rb, line 18
def choose_option(id, text)
  click_wait xpath: select_xpath(id)
  click_wait xpath: select_option_xpath(id, text)
end