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.



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

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.



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

def app
  @app
end

#rack_serverObject (readonly)

Returns the value of attribute rack_server.



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

def rack_server
  @rack_server
end

Class Method Details

.driverObject



93
94
95
96
97
98
99
100
101
# File 'lib/capybara/driver/selenium_driver.rb', line 93

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

Instance Method Details

#bodyObject



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

def body
  browser.page_source
end

#browserObject



135
136
137
# File 'lib/capybara/driver/selenium_driver.rb', line 135

def browser
  self.class.driver
end

#cleanup!Object



139
140
141
# File 'lib/capybara/driver/selenium_driver.rb', line 139

def cleanup!
  browser.manage.delete_all_cookies
end

#current_urlObject



121
122
123
# File 'lib/capybara/driver/selenium_driver.rb', line 121

def current_url
  browser.current_url
end

#evaluate_script(script) ⇒ Object



131
132
133
# File 'lib/capybara/driver/selenium_driver.rb', line 131

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

#find(selector) ⇒ Object



125
126
127
# File 'lib/capybara/driver/selenium_driver.rb', line 125

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

#sourceObject



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

def source
  browser.page_source
end

#visit(path) ⇒ Object



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

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

#wait?Boolean

Returns:

  • (Boolean)


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

def wait?; true; end