Class: Lightpanda::Capybara::Driver
- Inherits:
-
Capybara::Driver::Base
- Object
- Capybara::Driver::Base
- Lightpanda::Capybara::Driver
- Defined in:
- lib/lightpanda/capybara/driver.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #browser ⇒ Object
- #current_url ⇒ Object
- #evaluate_script(script, *_args) ⇒ Object
- #execute_script(script, *_args) ⇒ Object
- #find_css(selector) ⇒ Object
- #find_xpath(selector) ⇒ Object
- #html ⇒ Object (also: #body)
-
#initialize(app, options = {}) ⇒ Driver
constructor
A new instance of Driver.
- #invalid_element_errors ⇒ Object
- #needs_server? ⇒ Boolean
- #quit ⇒ Object
- #reset! ⇒ Object
- #title ⇒ Object
- #visit(url) ⇒ Object
- #wait? ⇒ Boolean
Constructor Details
#initialize(app, options = {}) ⇒ Driver
10 11 12 13 14 15 16 |
# File 'lib/lightpanda/capybara/driver.rb', line 10 def initialize(app, = {}) super() @app = app = @browser = nil end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/lightpanda/capybara/driver.rb', line 8 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/lightpanda/capybara/driver.rb', line 8 def end |
Instance Method Details
#browser ⇒ Object
18 19 20 |
# File 'lib/lightpanda/capybara/driver.rb', line 18 def browser @browser ||= Lightpanda::Browser.new() end |
#current_url ⇒ Object
26 27 28 |
# File 'lib/lightpanda/capybara/driver.rb', line 26 def current_url browser.current_url end |
#evaluate_script(script, *_args) ⇒ Object
70 71 72 |
# File 'lib/lightpanda/capybara/driver.rb', line 70 def evaluate_script(script, *_args) browser.evaluate(script) end |
#execute_script(script, *_args) ⇒ Object
74 75 76 77 |
# File 'lib/lightpanda/capybara/driver.rb', line 74 def execute_script(script, *_args) browser.execute(script) nil end |
#find_css(selector) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/lightpanda/capybara/driver.rb', line 60 def find_css(selector) count = browser.evaluate("document.querySelectorAll(#{selector.inspect}).length") return [] if count.nil? || count.zero? (0...count).map do |index| Node.new(self, { selector: selector, index: index }, index) end end |
#find_xpath(selector) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lightpanda/capybara/driver.rb', line 39 def find_xpath(selector) nodes = browser.evaluate(" (function() {\n var result = document.evaluate(\n \#{selector.inspect},\n document,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null\n );\n var nodes = [];\n for (var i = 0; i < result.snapshotLength; i++) {\n nodes.push(result.snapshotItem(i));\n }\n return nodes;\n })()\n JS\n\n wrap_nodes(nodes || [])\nend\n") |
#html ⇒ Object Also known as: body
30 31 32 |
# File 'lib/lightpanda/capybara/driver.rb', line 30 def html browser.body end |
#invalid_element_errors ⇒ Object
98 99 100 |
# File 'lib/lightpanda/capybara/driver.rb', line 98 def invalid_element_errors [Lightpanda::NodeNotFoundError, Lightpanda::NoExecutionContextError] end |
#needs_server? ⇒ Boolean
90 91 92 |
# File 'lib/lightpanda/capybara/driver.rb', line 90 def needs_server? true end |
#quit ⇒ Object
85 86 87 88 |
# File 'lib/lightpanda/capybara/driver.rb', line 85 def quit @browser&.quit @browser = nil end |
#reset! ⇒ Object
79 80 81 82 83 |
# File 'lib/lightpanda/capybara/driver.rb', line 79 def reset! browser.go_to("about:blank") rescue StandardError nil end |
#title ⇒ Object
35 36 37 |
# File 'lib/lightpanda/capybara/driver.rb', line 35 def title browser.title end |
#visit(url) ⇒ Object
22 23 24 |
# File 'lib/lightpanda/capybara/driver.rb', line 22 def visit(url) browser.go_to(url) end |
#wait? ⇒ Boolean
94 95 96 |
# File 'lib/lightpanda/capybara/driver.rb', line 94 def wait? true end |