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

#has_shortcircuit_timeout?, #response_headers, #wait_until

Constructor Details

#initialize(app) ⇒ Selenium

Returns a new instance of Selenium.



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

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.



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

def app
  @app
end

#rack_serverObject (readonly)

Returns the value of attribute rack_server.



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

def rack_server
  @rack_server
end

Class Method Details

.driverObject



98
99
100
101
102
103
104
105
106
# File 'lib/capybara/driver/selenium_driver.rb', line 98

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

Instance Method Details

#bodyObject



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

def body
  browser.page_source
end

#browserObject



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

def browser
  self.class.driver
end

#cleanup!Object



144
145
146
# File 'lib/capybara/driver/selenium_driver.rb', line 144

def cleanup!
  browser.manage.delete_all_cookies
end

#current_urlObject



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

def current_url
  browser.current_url
end

#evaluate_script(script) ⇒ Object



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

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

#find(selector) ⇒ Object



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

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

#sourceObject



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

def source
  browser.page_source
end

#visit(path) ⇒ Object



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

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

#wait?Boolean

Returns:

  • (Boolean)


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

def wait?; true; end

#within_frame(frame_id) ⇒ Object



148
149
150
151
152
153
# File 'lib/capybara/driver/selenium_driver.rb', line 148

def within_frame(frame_id)
  old_window = browser.window_handle
  browser.switch_to.frame(frame_id)
  yield
  browser.switch_to.window old_window
end