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, #status_code, #wait_until

Constructor Details

#initialize(app) ⇒ Selenium

Returns a new instance of Selenium.



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

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.



88
89
90
# File 'lib/capybara/driver/selenium_driver.rb', line 88

def app
  @app
end

#rack_serverObject (readonly)

Returns the value of attribute rack_server.



88
89
90
# File 'lib/capybara/driver/selenium_driver.rb', line 88

def rack_server
  @rack_server
end

Class Method Details

.driverObject



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

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

Instance Method Details

#bodyObject



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

def body
  browser.page_source
end

#browserObject



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

def browser
  self.class.driver
end

#cleanup!Object



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

def cleanup!
  browser.manage.delete_all_cookies
end

#current_urlObject



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

def current_url
  browser.current_url
end

#evaluate_script(script) ⇒ Object



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

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

#execute_script(script) ⇒ Object



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

def execute_script(script)
  browser.execute_script script
end

#find(selector) ⇒ Object



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

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

#sourceObject



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

def source
  browser.page_source
end

#visit(path) ⇒ Object



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

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

#wait?Boolean

Returns:

  • (Boolean)


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

def wait?; true; end

#within_frame(frame_id) ⇒ Object



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

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