Class: TrueAutomation::Driver::Capybara

Inherits:
Capybara::Selenium::Driver
  • Object
show all
Defined in:
lib/true_automation/driver/capybara.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, **options) ⇒ Capybara

Returns a new instance of Capybara.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/true_automation/driver/capybara.rb', line 23

def initialize(app, **options)
  @port = options.delete(:port) || 9515
  @driver = options.delete(:driver)
  @driver_version = options.delete(:driver_version)

  super(app, options)

  @ta_client = TrueAutomation::Client.new
  @remote = ''

  options ||= {}
  ta_url = options[:ta_url] || "http://localhost:#{@port}/"

  capabilities = options[:desired_capabilities] || {}

  if options and options[:browser] == :remote
    raise 'Remote driver URL is not specified' unless options[:url]
    capabilities[:taRemoteUrl] = options[:url]
    @remote = ' --remote'
  else
    capabilities[:browser] = options[:browser] || :chrome
  end

  @options.merge!(browser: :remote,
                  url: ta_url,
                  desired_capabilities: capabilities)
end

Instance Method Details

#browserObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/true_automation/driver/capybara.rb', line 51

def browser
  unless @browser
    @ta_client.start(port: @port,
                     remote: @remote,
                     driver: @driver,
                     driver_version: @driver_version)

    @ta_client.wait_until_start

    at_exit do
      @ta_client.stop
    end

    super
  end
  @browser
end