class Selenium::WebDriver::ActionBuilder
def add_input(device)
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
def add_key_input(name)
def add_key_input(name) add_input(Interactions.key(name)) end
def add_pointer_input(kind, name)
def add_pointer_input(kind, name) add_input(Interactions.pointer(kind, name: name)) end
def add_wheel_input(name)
def add_wheel_input(name) add_input(Interactions.wheel(name)) end
def clear_all_actions
def clear_all_actions @devices.each(&:clear_actions) end
def device(name: nil, type: nil)
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
def initialize(bridge, devices: [], async: false, duration: 250)
def initialize(bridge, devices: [], async: false, duration: 250) @bridge = bridge @duration = duration @async = async @devices = [] Array(devices).each { |device| add_input(device) } end
def key_inputs
def key_inputs @devices.select { |device| device.type == Interactions::KEY } end
def pause(device: nil, duration: 0)
def pause(device: nil, duration: 0) device ||= pointer_input device.create_pause(duration) self end
def pauses(device: nil, number: nil, duration: 0)
def pauses(device: nil, number: nil, duration: 0) number ||= 2 device ||= pointer_input duration ||= 0 number.times { device.create_pause(duration) } self end
def perform
def perform @bridge.send_actions @devices.filter_map(&:encode) clear_all_actions nil end
def pointer_inputs
def pointer_inputs @devices.select { |device| device.type == Interactions::POINTER } end
def release_actions
def release_actions @bridge.release_actions end
def tick(*action_devices)
def tick(*action_devices) return if @async @devices.each { |device| device.create_pause unless action_devices.include? device } end
def wheel_inputs
def wheel_inputs @devices.select { |device| device.type == Interactions::WHEEL } end