Class: Capybara::Simulated::Driver
- Inherits:
-
Driver::Base
- Object
- Driver::Base
- Capybara::Simulated::Driver
- Defined in:
- lib/capybara/simulated/driver.rb
Constant Summary collapse
- DEFAULT_WINDOW_HANDLE =
'main'.freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #accept_modal(type, **options, &blk) ⇒ Object
- #active_element ⇒ Object
- #browser ⇒ Object
- #close_window(_handle) ⇒ Object
- #current_url ⇒ Object
- #current_window_handle ⇒ Object
- #dismiss_modal(type, **options, &blk) ⇒ Object
- #evaluate_async_script(script, *args) ⇒ Object
- #evaluate_script(script, *args) ⇒ Object
- #execute_script(script, *args) ⇒ Object
- #find_css(query, **_) ⇒ Object
- #find_xpath(query, **_) ⇒ Object
- #frame_title ⇒ Object
- #frame_url ⇒ Object
- #fullscreen_window(_handle) ⇒ Object
- #go_back ⇒ Object
- #go_forward ⇒ Object
- #html ⇒ Object
-
#initialize(app) ⇒ Driver
constructor
A new instance of Driver.
- #invalid_element_errors ⇒ Object
- #javascript_enabled? ⇒ Boolean
- #maximize_window(_handle) ⇒ Object
- #needs_server? ⇒ Boolean
- #no_such_window_error ⇒ Object
- #open_new_window ⇒ Object
- #refresh ⇒ Object
- #reset! ⇒ Object
- #resize_window_to(_h, _w, _h2) ⇒ Object
- #response_headers ⇒ Object
- #save_screenshot(path, **_options) ⇒ Object
- #send_keys(*keys) ⇒ Object
- #status_code ⇒ Object
- #switch_to_frame(_frame) ⇒ Object
- #switch_to_window(handle) ⇒ Object
- #title ⇒ Object
- #visit(path) ⇒ Object
-
#wait? ⇒ Boolean
Capybara’s synchronize loop will retry on ElementNotFound only when the driver opts into waiting.
- #window_handles ⇒ Object
- #window_size(_handle) ⇒ Object
Constructor Details
#initialize(app) ⇒ Driver
Returns a new instance of Driver.
10 11 12 |
# File 'lib/capybara/simulated/driver.rb', line 10 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/capybara/simulated/driver.rb', line 8 def app @app end |
Instance Method Details
#accept_modal(type, **options, &blk) ⇒ Object
123 124 125 126 |
# File 'lib/capybara/simulated/driver.rb', line 123 def accept_modal(type, **, &blk) push_modal_handler(type, , accept: true) wait_for_modal(type, , &blk) end |
#active_element ⇒ Object
70 71 72 73 |
# File 'lib/capybara/simulated/driver.rb', line 70 def active_element handle_id = browser.active_element Node.new(self, handle_id) if handle_id end |
#browser ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/capybara/simulated/driver.rb', line 14 def browser @browser ||= begin b = Browser.new(app) b.driver_for_results = self b end end |
#close_window(_handle) ⇒ Object
98 99 100 |
# File 'lib/capybara/simulated/driver.rb', line 98 def close_window(_handle) raise NotImplementedError, 'capybara-simulated supports a single window' end |
#current_url ⇒ Object
34 |
# File 'lib/capybara/simulated/driver.rb', line 34 def current_url = browser.current_url |
#current_window_handle ⇒ Object
93 |
# File 'lib/capybara/simulated/driver.rb', line 93 def current_window_handle = DEFAULT_WINDOW_HANDLE |
#dismiss_modal(type, **options, &blk) ⇒ Object
128 129 130 131 |
# File 'lib/capybara/simulated/driver.rb', line 128 def dismiss_modal(type, **, &blk) push_modal_handler(type, , accept: false) wait_for_modal(type, , &blk) end |
#evaluate_async_script(script, *args) ⇒ Object
56 57 58 |
# File 'lib/capybara/simulated/driver.rb', line 56 def evaluate_async_script(script, *args) browser.evaluate_async_script(script, args) end |
#evaluate_script(script, *args) ⇒ Object
52 53 54 |
# File 'lib/capybara/simulated/driver.rb', line 52 def evaluate_script(script, *args) browser.evaluate_script(script, args) end |
#execute_script(script, *args) ⇒ Object
48 49 50 |
# File 'lib/capybara/simulated/driver.rb', line 48 def execute_script(script, *args) browser.execute_script(script, args) end |
#find_css(query, **_) ⇒ Object
44 45 46 |
# File 'lib/capybara/simulated/driver.rb', line 44 def find_css(query, **_) browser.find_css(query).map {|id| Node.new(self, id) } end |
#find_xpath(query, **_) ⇒ Object
40 41 42 |
# File 'lib/capybara/simulated/driver.rb', line 40 def find_xpath(query, **_) browser.find_xpath(query).map {|id| Node.new(self, id) } end |
#frame_title ⇒ Object
115 116 117 |
# File 'lib/capybara/simulated/driver.rb', line 115 def frame_title browser.title end |
#frame_url ⇒ Object
119 120 121 |
# File 'lib/capybara/simulated/driver.rb', line 119 def frame_url browser.current_url end |
#fullscreen_window(_handle) ⇒ Object
109 |
# File 'lib/capybara/simulated/driver.rb', line 109 def fullscreen_window(_handle); end |
#go_back ⇒ Object
32 |
# File 'lib/capybara/simulated/driver.rb', line 32 def go_back = browser.go_back |
#go_forward ⇒ Object
33 |
# File 'lib/capybara/simulated/driver.rb', line 33 def go_forward = browser.go_forward |
#html ⇒ Object
35 |
# File 'lib/capybara/simulated/driver.rb', line 35 def html = browser.html |
#invalid_element_errors ⇒ Object
85 86 87 |
# File 'lib/capybara/simulated/driver.rb', line 85 def invalid_element_errors [Capybara::Simulated::StaleElementReferenceError] end |
#javascript_enabled? ⇒ Boolean
23 24 25 26 27 |
# File 'lib/capybara/simulated/driver.rb', line 23 def javascript_enabled? = true # Capybara's synchronize loop will retry on ElementNotFound only # when the driver opts into waiting. Even though our DOM updates # happen in-process, async setTimeout-style behaviours need # Capybara to give them time. |
#maximize_window(_handle) ⇒ Object
108 |
# File 'lib/capybara/simulated/driver.rb', line 108 def maximize_window(_handle); end |
#needs_server? ⇒ Boolean
22 |
# File 'lib/capybara/simulated/driver.rb', line 22 def needs_server? = false |
#no_such_window_error ⇒ Object
89 90 91 |
# File 'lib/capybara/simulated/driver.rb', line 89 def no_such_window_error Capybara::WindowError end |
#open_new_window ⇒ Object
95 96 97 |
# File 'lib/capybara/simulated/driver.rb', line 95 def open_new_window raise NotImplementedError, 'capybara-simulated supports a single window' end |
#refresh ⇒ Object
31 |
# File 'lib/capybara/simulated/driver.rb', line 31 def refresh = browser.refresh |
#reset! ⇒ Object
80 81 82 83 |
# File 'lib/capybara/simulated/driver.rb', line 80 def reset! return unless @browser @browser.reset_state! end |
#resize_window_to(_h, _w, _h2) ⇒ Object
107 |
# File 'lib/capybara/simulated/driver.rb', line 107 def resize_window_to(_h, _w, _h2); end |
#response_headers ⇒ Object
38 |
# File 'lib/capybara/simulated/driver.rb', line 38 def response_headers = browser.response_headers || {} |
#save_screenshot(path, **_options) ⇒ Object
75 76 77 78 |
# File 'lib/capybara/simulated/driver.rb', line 75 def save_screenshot(path, **) File.write(path, html) path end |
#send_keys(*keys) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/capybara/simulated/driver.rb', line 60 def send_keys(*keys) # Capybara calls session-level `send_keys` to drive global key # navigation (typically `:tab`). Even when nothing has been # focused yet, `<body>` is a valid sink so Tab handling can # advance to the first focusable descendant. handle_id = browser.active_element || browser.find_css('body').first return unless handle_id browser.send_keys(handle_id, keys) end |
#status_code ⇒ Object
37 |
# File 'lib/capybara/simulated/driver.rb', line 37 def status_code = browser.status_code |
#switch_to_frame(_frame) ⇒ Object
111 112 113 |
# File 'lib/capybara/simulated/driver.rb', line 111 def switch_to_frame(_frame) raise NotImplementedError, 'frames are not supported by capybara-simulated' end |
#switch_to_window(handle) ⇒ Object
101 102 103 104 |
# File 'lib/capybara/simulated/driver.rb', line 101 def switch_to_window(handle) return if handle == DEFAULT_WINDOW_HANDLE || handle.respond_to?(:handle) && handle.handle == DEFAULT_WINDOW_HANDLE raise Capybara::WindowError, "no such window: #{handle.inspect}" end |
#title ⇒ Object
36 |
# File 'lib/capybara/simulated/driver.rb', line 36 def title = browser.title |
#visit(path) ⇒ Object
30 |
# File 'lib/capybara/simulated/driver.rb', line 30 def visit(path) = browser.visit(path) |
#wait? ⇒ Boolean
Capybara’s synchronize loop will retry on ElementNotFound only when the driver opts into waiting. Even though our DOM updates happen in-process, async setTimeout-style behaviours need Capybara to give them time.
28 |
# File 'lib/capybara/simulated/driver.rb', line 28 def wait? = true |
#window_handles ⇒ Object
94 |
# File 'lib/capybara/simulated/driver.rb', line 94 def window_handles = [DEFAULT_WINDOW_HANDLE] |
#window_size(_handle) ⇒ Object
106 |
# File 'lib/capybara/simulated/driver.rb', line 106 def window_size(_handle) = [1024, 768] |