class Teaspoon::Driver::Selenium

Public Class Methods

new(options = nil) click to toggle source
# File lib/teaspoon/driver/selenium.rb, line 14
def initialize(options = nil)
  options ||= {}
  case options
  when Hash then @options = options
  when String then @options = JSON.parse(options)
  else raise Teaspoon::DriverOptionsError.new(types: "hash or json string")
  end
rescue JSON::ParserError
  raise Teaspoon::DriverOptionsError.new(types: "hash or json string")
end

Public Instance Methods

run_specs(runner, url) click to toggle source
# File lib/teaspoon/driver/selenium.rb, line 25
def run_specs(runner, url)
  driver = ::Selenium::WebDriver.for(
    driver_options[:client_driver],
    **driver_options[:selenium_options].to_hash.to_options
  )
  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
ensure
  driver.quit if driver
end

Protected Instance Methods

driver_options() click to toggle source
# File lib/teaspoon/driver/selenium.rb, line 45
def driver_options
  @driver_options ||= HashWithIndifferentAccess.new(
    client_driver: :firefox,
    timeout: Teaspoon.configuration.driver_timeout.to_i,
    interval: 0.01,
    message: "Timed out",
    selenium_options: {}
  ).merge(@options)
end