Class: Selenium::WebDriver::W3CActionBuilder
- Inherits:
-
Object
- Object
- Selenium::WebDriver::W3CActionBuilder
- Includes:
- KeyActions, PointerActions
- Defined in:
- lib/selenium/webdriver/common/w3c_action_builder.rb
Constant Summary
Constants included from PointerActions
PointerActions::DEFAULT_MOVE_DURATION
Instance Attribute Summary collapse
-
#devices ⇒ Object
readonly
Returns the value of attribute devices.
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.
-
#clear_all_actions ⇒ Object
Clears all actions from the builder.
-
#get_device(name) ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the input device for the given name.
-
#initialize(bridge, mouse, keyboard, async = false) ⇒ W3CActionBuilder
constructor
Initialize a W3C Action Builder.
-
#key_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current KeyInput device.
-
#pause(device, duration = nil) ⇒ W3CActionBuilder
Creates a pause for the given device of the given duration.
-
#pauses(device, number, duration = nil) ⇒ W3CActionBuilder
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.
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, mouse, keyboard, async = false) ⇒ W3CActionBuilder
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.
41 42 43 44 45 46 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 41 def initialize(bridge, mouse, keyboard, async = false) # For backwards compatibility, automatically include mouse & keyboard @bridge = bridge @devices = [mouse, keyboard] @async = async end |
Instance Attribute Details
#devices ⇒ Object (readonly)
Returns the value of attribute devices.
25 26 27 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 25 def devices @devices end |
Instance Method Details
#add_key_input(name) ⇒ Interactions::KeyInput
Adds a KeyInput device
80 81 82 83 84 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 80 def add_key_input(name) new_input = Interactions.key(name) add_input(new_input) new_input end |
#add_pointer_input(kind, name) ⇒ Interactions::PointerInput
Adds a PointerInput device of the given kind
62 63 64 65 66 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 62 def add_pointer_input(kind, name) new_input = Interactions.pointer(kind, name: name) add_input(new_input) new_input end |
#clear_all_actions ⇒ Object
Clears all actions from the builder.
173 174 175 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 173 def clear_all_actions @devices.each(&:clear_actions) end |
#get_device(name) ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the input device for the given name
93 94 95 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 93 def get_device(name) @devices.find { |device| device.name == name.to_s } end |
#key_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current KeyInput device
113 114 115 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 113 def key_inputs @devices.select { |device| device.type == Interactions::KEY } end |
#pause(device, duration = nil) ⇒ W3CActionBuilder
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.
133 134 135 136 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 133 def pause(device, duration = nil) device.create_pause(duration) self end |
#pauses(device, number, duration = nil) ⇒ W3CActionBuilder
Creates multiple pauses for the given device of the given duration.
154 155 156 157 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 154 def pauses(device, number, duration = nil) number.times { device.create_pause(duration) } self end |
#perform ⇒ Object
Executes the actions added to the builder.
163 164 165 166 167 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 163 def perform @bridge.send_actions @devices.map(&:encode).compact clear_all_actions nil end |
#pointer_inputs ⇒ Array
Retrieves the current PointerInput devices
103 104 105 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 103 def pointer_inputs @devices.select { |device| device.type == Interactions::POINTER } end |
#release_actions ⇒ Object
Releases all action states from the browser.
181 182 183 |
# File 'lib/selenium/webdriver/common/w3c_action_builder.rb', line 181 def release_actions @bridge.release_actions end |