class Selenium::WebDriver::Safari::Bridge

Constants

COMMAND_TIMEOUT

Public Class Methods

new(opts = {}) click to toggle source
Calls superclass method Selenium::WebDriver::Remote::Bridge.new
# File lib/selenium/webdriver/safari/bridge.rb, line 9
def initialize(opts = {})
  port = Integer(opts[:port] || PortProber.random)
  timeout = Integer(opts[:timeout] || COMMAND_TIMEOUT)

  @command_id ||= 0

  @server = Server.new(port, timeout)
  @server.start

  @browser = Browser.new
  @browser.start(prepare_connect_file)

  @server.wait_for_connection

  super(:desired_capabilities => :safari)
end

Public Instance Methods

driver_extensions() click to toggle source
# File lib/selenium/webdriver/safari/bridge.rb, line 33
def driver_extensions
  []
end
quit() click to toggle source
# File lib/selenium/webdriver/safari/bridge.rb, line 26
def quit
  super

  @server.stop
  @browser.stop
end

Private Instance Methods

camel_case(str) click to toggle source
# File lib/selenium/webdriver/safari/bridge.rb, line 75
def camel_case(str)
  parts = str.split('_')
  parts[1..-1].map { |e| e.capitalize! }

  parts.join
end
create_session(desired_capabilities) click to toggle source
# File lib/selenium/webdriver/safari/bridge.rb, line 39
def create_session(desired_capabilities)
  resp = raw_execute :newSession, {}, :desiredCapabilities => desired_capabilities
  Remote::Capabilities.json_create resp.fetch('value')
end
prepare_connect_file() click to toggle source
# File lib/selenium/webdriver/safari/bridge.rb, line 82
def prepare_connect_file
  # TODO: use tempfile?
  path = File.join(Dir.tmpdir, "safaridriver-#{Time.now.to_i}.html")

  File.open(path, 'w') do |io|
    io << "<!DOCTYPE html><script>window.location = '#{@server.uri}';</script>"
  end

  FileReaper << path
  path.gsub! "/", "\\" if Platform.windows?

  path
end
raw_execute(command, opts = {}, command_hash = nil) click to toggle source
# File lib/selenium/webdriver/safari/bridge.rb, line 44
def raw_execute(command, opts = {}, command_hash = nil)
  @command_id += 1

  params = {}
  opts.each do |key, value|
    params[camel_case(key.to_s)] = value
  end

  params.merge!(command_hash) if command_hash

  @server.send(
    :origin  => "webdriver",
    :type    => "command",
    :command => { :id => @command_id.to_s, :name => command, :parameters => params}
  )

  raw = @server.receive
  response = raw.fetch('response')

  status_code = response['status']
  if status_code != 0
    raise Error.for_code(status_code), response['value']['message']
  end

  if raw['id'] != @command_id.to_s
    raise Error::WebDriverError, "response id does not match command id"
  end

  response
end