Class: Capybara::Driver::Terminus

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capybara/driver/terminus.rb

Constant Summary collapse

NULL_APP =
lambda do |env|
  [200, {'Content-Type' => 'text/html'}, ['']]
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ Terminus

Returns a new instance of Terminus.



8
9
10
11
12
13
14
15
16
# File 'lib/capybara/driver/terminus.rb', line 8

def initialize(app = nil, options = {})
  @app         = Terminus::Proxy[app || NULL_APP]
  @options     = options
  @rack_server = Capybara::Server.new(@app)

  @rack_server.boot
  sleep(0.1) until Terminus.server_running?(@rack_server)
  Terminus.register_local_port(@rack_server.port)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/capybara/driver/terminus.rb', line 2

def options
  @options
end

Instance Method Details

#find_css(css) ⇒ Object



18
19
20
# File 'lib/capybara/driver/terminus.rb', line 18

def find_css(css)
  browser.find_css(css, self)
end

#find_xpath(xpath) ⇒ Object Also known as: find



22
23
24
# File 'lib/capybara/driver/terminus.rb', line 22

def find_xpath(xpath)
  browser.find_xpath(xpath, self)
end

#invalid_element_errorsObject



27
28
29
# File 'lib/capybara/driver/terminus.rb', line 27

def invalid_element_errors
  [::Terminus::ObsoleteElementError]
end

#needs_server?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/capybara/driver/terminus.rb', line 31

def needs_server?
  true
end

#visit(path) ⇒ Object



35
36
37
38
39
# File 'lib/capybara/driver/terminus.rb', line 35

def visit(path)
  h, s = Capybara.app_host, @rack_server
  path = "#{h || "http://#{s.host}:#{s.port}"}#{path}" unless path =~ /^https?:\/\//
  browser.visit(path)
end

#wait?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/capybara/driver/terminus.rb', line 41

def wait?
  true
end

#within_window(name) ⇒ Object Also known as: within_frame



61
62
63
64
65
66
67
68
# File 'lib/capybara/driver/terminus.rb', line 61

def within_window(name)
  name = name['id'] unless String === name
  current_browser = browser
  Terminus.browser = browser.id + '/' + name
  result = yield
  Terminus.browser = current_browser
  result
end