Module: Capybara::Cuprite::Browser::Input
- Included in:
- Page
- Defined in:
- lib/capybara/cuprite/browser/input.rb
Instance Method Summary collapse
- #click(node, keys = [], offset = {}) ⇒ Object
- #click_coordinates(x, y) ⇒ Object
- #double_click(node, keys = [], offset = {}) ⇒ Object
- #drag(node, other) ⇒ Object
- #drag_by(node, x, y) ⇒ Object
- #hover(node) ⇒ Object
- #right_click(node, keys = [], offset = {}) ⇒ Object
- #scroll_to(left, top) ⇒ Object
- #select(node, value) ⇒ Object
- #send_keys(node, keys) ⇒ Object
- #set(node, value) ⇒ Object
- #trigger(node, event) ⇒ Object
Instance Method Details
#click(node, keys = [], offset = {}) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/capybara/cuprite/browser/input.rb', line 4 def click(node, keys = [], offset = {}) x, y, modifiers = prepare_before_click(__method__, node, keys, offset) command("Input.dispatchMouseEvent", type: "mousePressed", modifiers: modifiers, button: "left", x: x, y: y, clickCount: 1) @wait = 0.05 # Potential wait because if network event is triggered then we have to wait until it's over. command("Input.dispatchMouseEvent", type: "mouseReleased", modifiers: modifiers, button: "left", x: x, y: y, clickCount: 1) end |
#click_coordinates(x, y) ⇒ Object
23 24 25 26 27 |
# File 'lib/capybara/cuprite/browser/input.rb', line 23 def click_coordinates(x, y) command("Input.dispatchMouseEvent", type: "mousePressed", button: "left", x: x, y: y, clickCount: 1) @wait = 0.05 # Potential wait because if network event is triggered then we have to wait until it's over. command("Input.dispatchMouseEvent", type: "mouseReleased", button: "left", x: x, y: y, clickCount: 1) end |
#double_click(node, keys = [], offset = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/capybara/cuprite/browser/input.rb', line 17 def double_click(node, keys = [], offset = {}) x, y, modifiers = prepare_before_click(__method__, node, keys, offset) command("Input.dispatchMouseEvent", type: "mousePressed", modifiers: modifiers, button: "left", x: x, y: y, clickCount: 2) command("Input.dispatchMouseEvent", type: "mouseReleased", modifiers: modifiers, button: "left", x: x, y: y, clickCount: 2) end |
#drag(node, other) ⇒ Object
40 41 42 |
# File 'lib/capybara/cuprite/browser/input.rb', line 40 def drag(node, other) raise NotImplementedError end |
#drag_by(node, x, y) ⇒ Object
44 45 46 |
# File 'lib/capybara/cuprite/browser/input.rb', line 44 def drag_by(node, x, y) raise NotImplementedError end |
#hover(node) ⇒ Object
29 30 31 32 33 |
# File 'lib/capybara/cuprite/browser/input.rb', line 29 def hover(node) evaluate_on(node: node, expr: "_cuprite.scrollIntoViewport(this)") x, y = calculate_quads(node) command("Input.dispatchMouseEvent", type: "mouseMoved", x: x, y: y) end |
#right_click(node, keys = [], offset = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/capybara/cuprite/browser/input.rb', line 11 def right_click(node, keys = [], offset = {}) x, y, modifiers = prepare_before_click(__method__, node, keys, offset) command("Input.dispatchMouseEvent", type: "mousePressed", modifiers: modifiers, button: "right", x: x, y: y, clickCount: 1) command("Input.dispatchMouseEvent", type: "mouseReleased", modifiers: modifiers, button: "right", x: x, y: y, clickCount: 1) end |
#scroll_to(left, top) ⇒ Object
57 58 59 |
# File 'lib/capybara/cuprite/browser/input.rb', line 57 def scroll_to(left, top) raise NotImplementedError end |
#select(node, value) ⇒ Object
48 49 50 |
# File 'lib/capybara/cuprite/browser/input.rb', line 48 def select(node, value) evaluate_on(node: node, expr: "_cuprite.select(this, #{value})") end |
#send_keys(node, keys) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/capybara/cuprite/browser/input.rb', line 61 def send_keys(node, keys) # value.each_char do |char| # # Check puppeteer Input.js and USKeyboardLayout.js # # also send_keys and modifiers from capybara API and unify all that. # if /\n/.match?(char) # command("Input.insertText", text: char) # # command("Input.dispatchKeyEvent", type: "keyDown", code: "Enter", key: "Enter", text: "\r") # # command("Input.dispatchKeyEvent", type: "keyUp", code: "Enter", key: "Enter") # else # command("Input.dispatchKeyEvent", type: "keyDown", text: char) # command("Input.dispatchKeyEvent", type: "keyUp", text: char) # end # end # command "send_keys", node, normalize_keys(keys) raise NotImplementedError end |
#set(node, value) ⇒ Object
35 36 37 38 |
# File 'lib/capybara/cuprite/browser/input.rb', line 35 def set(node, value) object_id = command("DOM.resolveNode", nodeId: node["nodeId"]).dig("object", "objectId") evaluate("_cuprite.set(arguments[0], arguments[1])", { "objectId" => object_id }, value) end |
#trigger(node, event) ⇒ Object
52 53 54 55 |
# File 'lib/capybara/cuprite/browser/input.rb', line 52 def trigger(node, event) = event.to_s == "click" ? { wait: 0.1 } : {} evaluate_on(node: node, expr: %(_cuprite.trigger(this, "#{event}")), **) end |