Module: LapisLazuli::BrowserModule::Interaction
- Includes:
- ArgParse, Assertions
- Included in:
- LapisLazuli::Browser
- Defined in:
- lib/lapis_lazuli/browser/interaction.rb
Overview
Module with helper functions to do with DOM element interaction
Constant Summary collapse
- DEFAULT_CLICK_TYPES =
Click types
[ :method, :event, :js ]
Constants included from ArgParse
Instance Method Summary collapse
-
#click_type(elem, type) ⇒ Object
Combination of elem.click, on_click and js_click: uses the click method given as the second parameter; may be one of :method, :event, :js.
-
#click_types(elem, types = DEFAULT_CLICK_TYPES) ⇒ Object
Forces clicking by trying any of the given types of click on the given element, until one succeeds.
-
#force_click(*args) ⇒ Object
Tries the default click types on all elements passed to it.
-
#js_click(elem) ⇒ Object
Given an element, uses JavaScript to click it.
-
#on_click(elem) ⇒ Object
Given an element, fires a click event on it.
Methods included from ArgParse
#make_list_from_item, #make_list_from_nested, #parse_args
Methods included from Assertions
Instance Method Details
#click_type(elem, type) ⇒ Object
Combination of elem.click, on_click and js_click: uses the click method given as the second parameter; may be one of :method, :event, :js.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lapis_lazuli/browser/interaction.rb', line 42 def click_type(elem, type) type = type.to_sym assert DEFAULT_CLICK_TYPES.include?(type), "Not a valid click type: #{type}" case type when :method elem.click when :event on_click(elem) when :js js_click(elem) end end |
#click_types(elem, types = DEFAULT_CLICK_TYPES) ⇒ Object
Forces clicking by trying any of the given types of click on the given element, until one succeeds. If all fail, the corresponding errors are raised as an Array
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lapis_lazuli/browser/interaction.rb', line 61 def click_types(elem, types = DEFAULT_CLICK_TYPES) errors = [] types.each do |type| begin click_type(elem, type) rescue RuntimeError => err errors << err end end if errors.length > 0 world.error("Could not click #{elem} given any of these click types: #{types}: #{errors}") end end |
#force_click(*args) ⇒ Object
Tries the default click types on all elements passed to it.
79 80 81 82 83 84 85 |
# File 'lib/lapis_lazuli/browser/interaction.rb', line 79 def force_click(*args) elems = make_list_from_nested(args) elems.each do |elem| click_types(elem, DEFAULT_CLICK_TYPES) end end |
#js_click(elem) ⇒ Object
Given an element, uses JavaScript to click it.
34 35 36 |
# File 'lib/lapis_lazuli/browser/interaction.rb', line 34 def js_click(elem) self.execute_script('arguments[0].click();', elem) end |
#on_click(elem) ⇒ Object
Given an element, fires a click event on it.
27 28 29 |
# File 'lib/lapis_lazuli/browser/interaction.rb', line 27 def on_click(elem) elem.fire_event('onClick') end |