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(xpath) ⇒ Object



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

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

#invalid_element_errorsObject



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

def invalid_element_errors
  [::Terminus::ObsoleteElementError]
end

#needs_server?Boolean

Returns:

  • (Boolean)


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

def needs_server?
  true
end

#visit(path) ⇒ Object



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

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)


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

def wait?
  true
end

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



53
54
55
56
57
58
59
# File 'lib/capybara/driver/terminus.rb', line 53

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