Module: SeleniumRecord::Actions

Included in:
Base, Scopes::LocatorScope
Defined in:
lib/selenium_record/actions.rb

Overview

Contains simple actions to play from selenium objects

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.choose_option(id, text) ⇒ Object

Chooses an option from select enhanced by javascript

Parameters:

  • id (String)

    id of the select

  • text (String)

    the option text



18
19
20
21
# 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

Instance Method Details

#accept_popupObject

Clicks accept button on popup



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

def accept_popup
  popup = browser.switch_to.alert
  popup.accept
end

#choose_menu(dropdown, menu) ⇒ Object

Chooses a menu from dropdown enhanced by javascript

Parameters:

  • dropdown (String)

    text of dropdown

  • menu (String)

    text of menu



26
27
28
29
# 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) ⇒ Object

Clear input of type ‘text’



32
33
34
35
36
# File 'lib/selenium_record/actions.rb', line 32

def clear(locator)
  el = find(locator)
  el.send_keys('')
  el.clear
end

#click(locator) ⇒ Object



51
52
53
# File 'lib/selenium_record/actions.rb', line 51

def click(locator)
  cover { find(locator).click }
end

Parameters:

  • text (String)

    text of the link to be clicked



74
75
76
77
# File 'lib/selenium_record/actions.rb', line 74

def click_link(text)
  finder = root_el || browser
  finder.find_element(link_text: text).click
end

#click_on(locator) ⇒ Object



38
39
40
# File 'lib/selenium_record/actions.rb', line 38

def click_on(locator)
  find(locator).click
end

#click_wait(locator) ⇒ Object

Clicks on element and wait until all jquery events are dispatched

Parameters:

  • how (Symbol)

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

  • what (String)


46
47
48
49
# File 'lib/selenium_record/actions.rb', line 46

def click_wait(locator)
  when_present(locator).click
  wait_js_inactive
end

#fill(locator, text) ⇒ Object



55
56
57
58
59
# 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) ⇒ Object

Parameters:

  • locator (Hash|Selenium::WebDriver::Element)


62
63
64
65
# 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) ⇒ Object

Drops the model view on the bottom to the top of the model type view list

Parameters:

  • model_type (Symbol)

    the type of the views to be affected



81
82
83
84
85
# 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) ⇒ Object

Parameters:

  • id (Symbol)

    id of select element

  • text (String)

    text of the option to be selected



89
90
91
92
93
94
95
96
97
98
# 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

#submitObject



67
68
69
70
71
# 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) ⇒ Object



4
5
6
7
# 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