Class: Selenium::WebDriver::ActionBuilder
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/action_builder.rb |
Class Method Summary
-
.new(bridge, devices: [], async: false, duration: 250) ⇒ ActionBuilder
constructor
Initialize a W3C Action Builder.
Instance Attribute Summary
- #devices readonly
WheelActions
- Included
#default_scroll_duration | By default this is set to 250ms in the |
#default_scroll_duration= |
PointerActions
- Included
#default_move_duration | By default this is set to 250ms in the |
#default_move_duration= |
Instance Method Summary
-
#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
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.
-
#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
Executes the actions added to the builder.
-
#pointer_inputs ⇒ Array
Retrieves the current PointerInput devices.
-
#release_actions
Releases all action states from the browser.
-
#wheel_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current WheelInput device.
-
#add_input(device)
private
Adds an InputDevice.
-
#tick(*action_devices)
private
Adds pauses for all devices but the given devices.
WheelActions
- Included
#scroll_by | Scrolls by provided amounts with the origin in the top left corner of the viewport. |
#scroll_from | Scrolls by provided amount based on a provided origin. |
#scroll_to | If the element is outside the viewport, scrolls the bottom of the element to the bottom of the viewport. |
#scroll, #wheel_input |
PointerActions
- Included
#click | Clicks in the middle of the given element. |
#click_and_hold | Clicks (without releasing) in the middle of the given element. |
#context_click | Performs a context-click at middle of the given element. |
#double_click | Performs a double-click at middle of the given element. |
#drag_and_drop | A convenience method that performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse. |
#drag_and_drop_by | A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse. |
#move_by | Moves the pointer from its current position by the given offset. |
#move_to | Moves the pointer to the in-view center point of the given element. |
#move_to_location | Moves the pointer to a given location in the viewport. |
#pointer_down | Presses (without releasing) at the current location of the PointerInput device. |
#pointer_up | Releases the pressed mouse button at the current mouse location of the PointerInput device. |
#release | Releases the depressed left mouse button at the current mouse location. |
#button_action, #pointer_input |
KeyActions
- Included
#key_down | Performs a key press. |
#key_up | Performs a key release. |
#send_keys | Sends keys to the active element. |
#key_input, #key_action |
Constructor Details
.new(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.
Instance Attribute Details
#devices (readonly)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 27
attr_reader :devices
Instance Method Details
#add_input(device) (private)
Adds an InputDevice
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 237
def add_input(device) device = Interactions.send(device) if device.is_a?(Symbol) && Interactions.respond_to?(device) raise TypeError, "#{device.inspect} is not a valid InputDevice" unless device.is_a?(Interactions::InputDevice) unless @async max_device = @devices.max { |a, b| a.actions.length <=> b.actions.length } pauses(device: device, number: max_device.actions.length) if max_device end @devices << device device end
#add_key_input(name) ⇒ Interactions::KeyInput
Adds a KeyInput device
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 80
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
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 64
def add_pointer_input(kind, name) add_input(Interactions.pointer(kind, name: name)) end
#add_wheel_input(name) ⇒ Interactions::WheelInput
Adds a WheelInput device
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 96
def add_wheel_input(name) add_input(Interactions.wheel(name)) end
#clear_all_actions
Clears all actions from the builder.
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 207
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
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 108
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
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 132
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.
#pauses(device: nil, number: nil, duration: 0) ⇒ ActionBuilder
Creates multiple pauses for the given device of the given duration.
#perform
Executes the actions added to the builder.
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 197
def perform @bridge.send_actions @devices.filter_map(&:encode) clear_all_actions nil end
#pointer_inputs ⇒ Array
Retrieves the current PointerInput devices
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 122
def pointer_inputs @devices.select { |device| device.type == Interactions::POINTER } end
#release_actions
Releases all action states from the browser.
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 215
def release_actions @bridge.release_actions end
#tick(*action_devices) (private)
Adds pauses for all devices but the given devices
#wheel_inputs ⇒ Selenium::WebDriver::Interactions::InputDevice
Retrieves the current WheelInput device
# File 'rb/lib/selenium/webdriver/common/action_builder.rb', line 142
def wheel_inputs @devices.select { |device| device.type == Interactions::WHEEL } end