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.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/true_automation/driver/capybara.rb', line 69

def initialize(app, **options)
  options = fetch_options(options)
  if options[:browser].to_s != 'remote'
    default_options = Selenium::WebDriver::Options.send(options[:browser] || :chrome)
  end
  options[:capabilities] ||= default_options
  @port = options.delete(:port) || find_available_port('localhost')
  @driver = options.delete(:driver)
  @driver_version = options.delete(:driver_version)

  if options && options[:ta_debug]
    @ta_debug = ' --ta-debug'
    options.delete(:ta_debug)
  end

  if options[:ta_service]
    @ta_service = options.delete(:ta_service)
  end

  super(app, **options)

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

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

  capabilities = options[:capabilities] || {}

  if options && options[:browser] == :remote
    raise 'Remote driver URL is not specified' unless options[:url]
    input_caps = opts_to_json(options[:capabilities]) || {}
    browser = opts_browser(options[:capabilities] || Selenium::WebDriver::Options.chrome)
    capabilities = options_class(browser).new(**input_caps)
    capabilities.add_preference(:taRemoteUrl, options[:url])
    @remote = ' --remote'
  end

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

Instance Method Details

#browserObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/true_automation/driver/capybara.rb', line 112

def browser
  unless @browser
    @ta_client.start(port: @port,
                     remote: @remote,
                     ta_debug: @ta_debug,
                     driver: @driver,
                     ta_service_path: @ta_service&.executable_path,
                     driver_version: @driver_version,
                     ta_recorder: @ta_recorder)

    @ta_client.wait_until_start

    at_exit do
      @ta_client.stop
    end
    super
  end
  @browser
end

#quitObject



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

def quit
  super
  @ta_client.stop
end

#specialize_driver(*args) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/true_automation/driver/capybara.rb', line 137

def specialize_driver(*args)
  if ::Capybara::Selenium::Driver.respond_to?(:register_specialization)
    browser_type = browser.browser
    # Original method uses self.class, and all classes use Capybara::Selenium::Driver.
    # Thereby no specializations in the list for TA driver class and error occured.
    ::Capybara::Selenium::Driver.specializations.select { |k, _v| k === browser_type }.each_value do |specialization| # rubocop:disable Style/CaseEquality
      extend specialization
    end
  else
    super
  end
end