Class: Teaspoon::Driver::BrowserStack

Inherits:
Base
  • Object
show all
Defined in:
lib/teaspoon/driver/browserstack.rb

Constant Summary collapse

MAX_PARALLEL =
10

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ BrowserStack

Returns a new instance of BrowserStack.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/teaspoon/driver/browserstack.rb', line 18

def initialize(options = nil)
  options ||= {}
  case options
  when Hash then @options = options.symbolize_keys
  when String then @options = JSON.parse(options).symbolize_keys
  else raise Teaspoon::DriverOptionsError.new(types: "hash or json string")
  end

  unless @options[:capabilities] && @options[:capabilities].is_a?(Array)
    raise Teaspoon::DriverOptionsError.new(types: "capabilities array." \
                                           "Options must have a key 'capabilities' of type array")
  end
  @options[:capabilities].each(&:symbolize_keys!)
rescue JSON::ParserError
  raise Teaspoon::DriverOptionsError.new(types: "hash or json string")
end

Instance Method Details

#run_specs(runner, url) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/teaspoon/driver/browserstack.rb', line 35

def run_specs(runner, url)
  parallelize do
    driver = Thread.current[:driver]
    driver.navigate.to(url)
    ::Selenium::WebDriver::Wait.new(driver_options).until do
      done = driver.execute_script("return window.Teaspoon && window.Teaspoon.finished")
      driver.execute_script("return window.Teaspoon && window.Teaspoon.getMessages() || []").each do |line|
        runner.process("#{line}\n")
      end
      done
    end
  end
end