Class: Selenium::WebDriver::ActionBuilder
- Inherits:
-
Object
- Object
- Selenium::WebDriver::ActionBuilder
- Includes:
- KeyActions, PointerActions, WheelActions
- Defined in:
- lib/selenium/webdriver/common/action_builder.rb
Instance Attribute Summary collapse
-
#devices ⇒ Object
readonly
Returns the value of attribute devices.
Attributes included from WheelActions
Attributes included from PointerActions
Instance Method Summary collapse
-
#add_key_input(name) ⇒ Interactions::KeyInput
Adds a KeyInput device.
-
#add_pointer_input(kind, name) ⇒ Interactions::PointerInput
Adds a PointerInput device of the given kind.
-
#add_wheel_input(name) ⇒ Interactions::WheelInput
Adds a WheelInput device.
-
#clear_all_actions ⇒ Object
Clears all actions from the builder.
-
#device(name: nil, type: nil) ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the input device for the given name or type.
-
#initialize(bridge, devices: [], async: false, duration: 250) ⇒ ActionBuilder
constructor
Initialize a W3C Action Builder.
-
#key_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current KeyInput device.
-
#pause(device: nil, duration: 0) ⇒ ActionBuilder
Creates a pause for the given device of the given duration.
-
#pauses(device: nil, number: nil, duration: 0) ⇒ ActionBuilder
Creates multiple pauses for the given device of the given duration.
-
#perform ⇒ Object
Executes the actions added to the builder.
-
#pointer_inputs ⇒ Array
Retrieves the current PointerInput devices.
-
#release_actions ⇒ Object
Releases all action states from the browser.
-
#wheel_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current WheelInput device.
Methods included from WheelActions
#scroll_by, #scroll_from, #scroll_to
Methods included from PointerActions
#click, #click_and_hold, #context_click, #double_click, #drag_and_drop, #drag_and_drop_by, #move_by, #move_to, #move_to_location, #pointer_down, #pointer_up, #release
Methods included from KeyActions
#key_down, #key_up, #send_keys
Constructor Details
#initialize(bridge, devices: [], async: false, duration: 250) ⇒ ActionBuilder
Initialize a W3C Action Builder. Differs from previous by requiring a bridge and allowing asynchronous actions. The W3C implementation allows asynchronous actions per device. e.g. A key can be pressed at the same time that the mouse is moving. Keep in mind that pauses must be added for other devices in order to line up the actions correctly when using asynchronous.
45 46 47 48 49 50 51 52 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 45 def initialize(bridge, devices: [], async: false, duration: 250) @bridge = bridge @duration = duration @async = async @devices = [] Array(devices).each { |device| add_input(device) } end |
Instance Attribute Details
#devices ⇒ Object (readonly)
Returns the value of attribute devices.
27 28 29 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 27 def devices @devices end |
Instance Method Details
#add_key_input(name) ⇒ Interactions::KeyInput
Adds a KeyInput device
84 85 86 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 84 def add_key_input(name) add_input(Interactions.key(name)) end |
#add_pointer_input(kind, name) ⇒ Interactions::PointerInput
Adds a PointerInput device of the given kind
68 69 70 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 68 def add_pointer_input(kind, name) add_input(Interactions.pointer(kind, name: name)) end |
#add_wheel_input(name) ⇒ Interactions::WheelInput
Adds a WheelInput device
100 101 102 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 100 def add_wheel_input(name) add_input(Interactions.wheel(name)) end |
#clear_all_actions ⇒ Object
Clears all actions from the builder.
211 212 213 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 211 def clear_all_actions @devices.each(&:clear_actions) end |
#device(name: nil, type: nil) ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the input device for the given name or type
112 113 114 115 116 117 118 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 112 def device(name: nil, type: nil) input = @devices.find { |device| (device.name == name.to_s || name.nil?) && (device.type == type || type.nil?) } raise(ArgumentError, "Can not find device: #{name}") if name && input.nil? input end |
#key_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current KeyInput device
136 137 138 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 136 def key_inputs @devices.select { |device| device.type == Interactions::KEY } end |
#pause(device: nil, duration: 0) ⇒ ActionBuilder
Creates a pause for the given device of the given duration. If no duration is given, the pause will only wait for all actions to complete in that tick.
166 167 168 169 170 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 166 def pause(device: nil, duration: 0) device ||= pointer_input device.create_pause(duration) self end |
#pauses(device: nil, number: nil, duration: 0) ⇒ ActionBuilder
Creates multiple pauses for the given device of the given duration.
188 189 190 191 192 193 194 195 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 188 def pauses(device: nil, number: nil, duration: 0) number ||= 2 device ||= pointer_input duration ||= 0 number.times { device.create_pause(duration) } self end |
#perform ⇒ Object
Executes the actions added to the builder.
201 202 203 204 205 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 201 def perform @bridge.send_actions @devices.filter_map(&:encode) clear_all_actions nil end |
#pointer_inputs ⇒ Array
Retrieves the current PointerInput devices
126 127 128 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 126 def pointer_inputs @devices.select { |device| device.type == Interactions::POINTER } end |
#release_actions ⇒ Object
Releases all action states from the browser.
219 220 221 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 219 def release_actions @bridge.release_actions end |
#wheel_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current WheelInput device
146 147 148 |
# File 'lib/selenium/webdriver/common/action_builder.rb', line 146 def wheel_inputs @devices.select { |device| device.type == Interactions::WHEEL } end |