Module: Capybara::Cuprite::Page
- Extended by:
- Forwardable
- Defined in:
- lib/capybara/cuprite/page.rb
Constant Summary collapse
- MODAL_WAIT =
ENV.fetch("CUPRITE_MODAL_WAIT", 0.05).to_f
- TRIGGER_CLICK_WAIT =
ENV.fetch("CUPRITE_TRIGGER_CLICK_WAIT", 0.1).to_f
Instance Method Summary collapse
- #accept_confirm ⇒ Object
- #accept_prompt(modal_response) ⇒ Object
- #before_click(node, name, keys = [], offset = {}) ⇒ Object
- #dismiss_confirm ⇒ Object
- #dismiss_prompt ⇒ Object
- #find_modal(options) ⇒ Object
- #hover(node) ⇒ Object
- #initialize(*args) ⇒ Object
- #reset_modals ⇒ Object
- #select(node, value) ⇒ Object
- #send_keys(node, keys) ⇒ Object
- #set(node, value) ⇒ Object
- #switch_to_frame(handle) ⇒ Object
- #title ⇒ Object
- #trigger(node, event) ⇒ Object
Instance Method Details
#accept_confirm ⇒ Object
53 54 55 |
# File 'lib/capybara/cuprite/page.rb', line 53 def accept_confirm @accept_modal << true end |
#accept_prompt(modal_response) ⇒ Object
61 62 63 64 |
# File 'lib/capybara/cuprite/page.rb', line 61 def accept_prompt(modal_response) @accept_modal << true @modal_response = modal_response end |
#before_click(node, name, keys = [], offset = {}) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/capybara/cuprite/page.rb', line 96 def before_click(node, name, keys = [], offset = {}) evaluate_on(node: node, expression: "_cuprite.scrollIntoViewport(this)") x, y = find_position(node, offset[:x], offset[:y]) evaluate_on(node: node, expression: "_cuprite.mouseEventTest(this, '#{name}', #{x}, #{y})") true rescue Ferrum::JavaScriptError => e raise MouseEventFailed.new(e.) if e.class_name == "MouseEventFailed" end |
#dismiss_confirm ⇒ Object
57 58 59 |
# File 'lib/capybara/cuprite/page.rb', line 57 def dismiss_confirm @accept_modal << false end |
#dismiss_prompt ⇒ Object
66 67 68 |
# File 'lib/capybara/cuprite/page.rb', line 66 def dismiss_prompt @accept_modal << false end |
#find_modal(options) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/capybara/cuprite/page.rb', line 70 def find_modal() start = Ferrum.monotonic_time timeout = .fetch(:wait, browser.timeout) expect_text = [:text] expect_regexp = expect_text.is_a?(Regexp) ? expect_text : Regexp.escape(expect_text.to_s) not_found_msg = "Unable to find modal dialog" not_found_msg += " with #{expect_text}" if expect_text begin modal_text = @modal_messages.shift raise Capybara::ModalNotFound if modal_text.nil? || (expect_text && !modal_text.match(expect_regexp)) rescue Capybara::ModalNotFound => e raise e, not_found_msg if Ferrum.timeout?(start, timeout) sleep(MODAL_WAIT) retry end modal_text end |
#hover(node) ⇒ Object
38 39 40 41 42 |
# File 'lib/capybara/cuprite/page.rb', line 38 def hover(node) evaluate_on(node: node, expression: "_cuprite.scrollIntoViewport(this)") x, y = find_position(node) command("Input.dispatchMouseEvent", type: "mouseMoved", x: x, y: y) end |
#initialize(*args) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/capybara/cuprite/page.rb', line 16 def initialize(*args) @frame_stack = [] @accept_modal = [] @modal_messages = [] super end |
#reset_modals ⇒ Object
90 91 92 93 94 |
# File 'lib/capybara/cuprite/page.rb', line 90 def reset_modals @accept_modal = [] @modal_response = nil @modal_messages = [] end |
#select(node, value) ⇒ Object
28 29 30 |
# File 'lib/capybara/cuprite/page.rb', line 28 def select(node, value) evaluate_on(node: node, expression: "_cuprite.select(this, #{value})") end |
#send_keys(node, keys) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/capybara/cuprite/page.rb', line 44 def send_keys(node, keys) if !evaluate_on(node: node, expression: %(_cuprite.containsSelection(this))) before_click(node, "click") node.click(mode: :left, keys: keys) end keyboard.type(keys) end |
#set(node, value) ⇒ Object
23 24 25 26 |
# File 'lib/capybara/cuprite/page.rb', line 23 def set(node, value) object_id = command("DOM.resolveNode", nodeId: node.node_id).dig("object", "objectId") evaluate("_cuprite.set(arguments[0], arguments[1])", { "objectId" => object_id }, value) end |
#switch_to_frame(handle) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/capybara/cuprite/page.rb', line 105 def switch_to_frame(handle) case handle when :parent @frame_stack.pop when :top @frame_stack = [] else @frame_stack << handle inject_extensions end end |
#title ⇒ Object
117 118 119 |
# File 'lib/capybara/cuprite/page.rb', line 117 def title active_frame.current_title end |
#trigger(node, event) ⇒ Object
32 33 34 35 36 |
# File 'lib/capybara/cuprite/page.rb', line 32 def trigger(node, event) = {} .merge!(wait: TRIGGER_CLICK_WAIT) if event.to_s == "click" && TRIGGER_CLICK_WAIT > 0 evaluate_on(node: node, expression: %(_cuprite.trigger(this, "#{event}")), **) end |