Class: Capybara::Driver::Selenium

Inherits:
Base
  • Object
show all
Defined in:
lib/capybara/driver/selenium_driver.rb

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#response_headers

Constructor Details

#initialize(app) ⇒ Selenium

Returns a new instance of Selenium.



91
92
93
94
95
# File 'lib/capybara/driver/selenium_driver.rb', line 91

def initialize(app)
  @app = app
  @rack_server = Capybara::Server.new(@app)
  @rack_server.boot if Capybara.run_server
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



79
80
81
# File 'lib/capybara/driver/selenium_driver.rb', line 79

def app
  @app
end

#rack_serverObject (readonly)

Returns the value of attribute rack_server.



79
80
81
# File 'lib/capybara/driver/selenium_driver.rb', line 79

def rack_server
  @rack_server
end

Class Method Details

.driverObject



81
82
83
84
85
86
87
88
89
# File 'lib/capybara/driver/selenium_driver.rb', line 81

def self.driver
  unless @driver
    @driver = Selenium::WebDriver.for :firefox
    at_exit do
      @driver.quit
    end
  end
  @driver
end

Instance Method Details

#bodyObject



105
106
107
# File 'lib/capybara/driver/selenium_driver.rb', line 105

def body
  browser.page_source
end

#browserObject



123
124
125
# File 'lib/capybara/driver/selenium_driver.rb', line 123

def browser
  self.class.driver
end

#cleanup!Object



127
128
129
# File 'lib/capybara/driver/selenium_driver.rb', line 127

def cleanup!
  browser.manage.delete_all_cookies
end

#current_urlObject



109
110
111
# File 'lib/capybara/driver/selenium_driver.rb', line 109

def current_url
  browser.current_url
end

#evaluate_script(script) ⇒ Object



119
120
121
# File 'lib/capybara/driver/selenium_driver.rb', line 119

def evaluate_script(script)
  browser.execute_script "return #{script}"
end

#find(selector) ⇒ Object



113
114
115
# File 'lib/capybara/driver/selenium_driver.rb', line 113

def find(selector)
  browser.find_elements(:xpath, selector).map { |node| Node.new(self, node) }
end

#sourceObject



101
102
103
# File 'lib/capybara/driver/selenium_driver.rb', line 101

def source
  browser.page_source
end

#visit(path) ⇒ Object



97
98
99
# File 'lib/capybara/driver/selenium_driver.rb', line 97

def visit(path)
  browser.navigate.to(url(path))
end

#wait?Boolean

Returns:

  • (Boolean)


117
# File 'lib/capybara/driver/selenium_driver.rb', line 117

def wait?; true; end