Parent

Class/Module Index [+]

Quicksearch

Selenium::WebDriver::Remote::Bridge

Low level bridge to the remote server, through which the rest of the API works.

@api private


@api private

Constants

QUIT_ERRORS

Attributes

capabilities[R]
context[RW]
file_detector[RW]
http[RW]

Public Class Methods

command(name, verb, url) click to toggle source

Defines a wrapper method for a command, which ultimately calls execute.

@param name [Symbol]

name of the resulting method

@param url [String]

a URL template, which can include some arguments, much like the definitions on the server.
the :session_id parameter is implicitly handled, but the remainder will become required method arguments.

@param verb [Symbol]

the appropriate http verb, such as :get, :post, or :delete
# File lib/selenium/webdriver/remote/bridge.rb, line 28
def self.command(name, verb, url)
  COMMANDS[name] = [verb, url.freeze]
end
new(opts = {}) click to toggle source

Initializes the bridge with the given server URL.

@param url [String] url for the remote server @param http_client [Object] an HTTP client instance that implements the same protocol as Http::Default @param desired_capabilities [Capabilities] an instance of Remote::Capabilities describing the capabilities you want

# File lib/selenium/webdriver/remote/bridge.rb, line 43
def initialize(opts = {})
  opts = opts.dup

  http_client          = opts.delete(:http_client) { Http::Default.new }
  desired_capabilities = opts.delete(:desired_capabilities) { Capabilities.firefox }
  url                  = opts.delete(:url) { "http://#{Platform.localhost}:4444/wd/hub" }

  unless opts.empty?
    raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
  end

  if desired_capabilities.kind_of?(Symbol)
    unless Capabilities.respond_to?(desired_capabilities)
      raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
    end

    desired_capabilities = Capabilities.send(desired_capabilities)
  end

  uri = url.kind_of?(URI) ? url : URI.parse(url)
  uri.path += "/" unless uri.path =~ /\/$/

  http_client.server_url = uri

  @http          = http_client
  @capabilities  = create_session(desired_capabilities)
end

Public Instance Methods

acceptAlert() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 122
def acceptAlert
  execute :acceptAlert
end
addCookie(cookie) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 223
def addCookie(cookie)
  execute :addCookie, {}, :cookie => cookie
end
browser() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 71
def browser
  @browser ||= @capabilities.browser_name.gsub(" ", "_").to_sym
end
clearElement(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 327
def clearElement(element)
  execute :clearElement, :id => element
end
click() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 243
def click
  execute :click, {}, :button => 0
end
clickElement(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 239
def clickElement(element)
  execute :clickElement, :id => element
end
close() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 189
def close
  execute :close
end
contextClick() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 251
def contextClick
  execute :click, {}, :button => 2
end
create_session(desired_capabilities) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 91
def create_session(desired_capabilities)
  resp = raw_execute :newSession, {}, :desiredCapabilities => desired_capabilities
  @session_id = resp['sessionId'] || raise(Error::WebDriverError, 'no sessionId in returned payload')

  Capabilities.json_create resp['value']
end
deleteAllCookies() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 235
def deleteAllCookies
  execute :deleteAllCookies
end
deleteCookie(name) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 227
def deleteCookie(name)
  execute :deleteCookieNamed, :name => name
end
dismissAlert() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 126
def dismissAlert
  execute :dismissAlert
end
doubleClick() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 247
def doubleClick
  execute :doubleClick
end
dragElement(element, right_by, down_by) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 360
def dragElement(element, right_by, down_by)
  execute :dragElement, {:id => element}, :x => right_by, :y => down_by
end
driver_extensions() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 75
def driver_extensions
  [
    DriverExtensions::HasInputDevices,
    DriverExtensions::UploadsFiles,
    DriverExtensions::TakesScreenshot
  ]
end
elementEquals(element, other) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 364
def elementEquals(element, other)
  execute :elementEquals, :id => element.ref, :other => other.ref
end
executeAsyncScript(script, *args) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 216
def executeAsyncScript(script, *args)
  assert_javascript_enabled

  result = execute :executeAsyncScript, {}, :script => script, :args => args
  unwrap_script_result result
end
executeScript(script, *args) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 209
def executeScript(script, *args)
  assert_javascript_enabled

  result = execute :executeScript, {}, :script => script, :args => args
  unwrap_script_result result
end
find_element_by(how, what, parent = nil) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 368
def find_element_by(how, what, parent = nil)
  if parent
    id = execute :findChildElement, {:id => parent}, {:using => how, :value => what}
  else
    id = execute :findElement, {}, {:using => how, :value => what}
  end

  Element.new self, element_id_from(id)
end
find_elements_by(how, what, parent = nil) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 378
def find_elements_by(how, what, parent = nil)
  if parent
    ids = execute :findChildElements, {:id => parent}, {:using => how, :value => what}
  else
    ids = execute :findElements, {}, {:using => how, :value => what}
  end

  ids.map { |id| Element.new self, element_id_from(id) }
end
get(url) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 98
def get(url)
  execute :get, {}, :url => url
end
getActiveElement() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 355
def getActiveElement
  Element.new self, element_id_from(execute(:getActiveElement))
end
Also aliased as: switchToActiveElement
getAlert() click to toggle source

alerts

# File lib/selenium/webdriver/remote/bridge.rb, line 118
def getAlert
  execute :getAlert
end
getAlertText() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 134
def getAlertText
  execute :getAlertText
end
getAllCookies() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 231
def getAllCookies
  execute :getAllCookies
end
getCapabilities() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 102
def getCapabilities
  Capabilities.json_create execute(:getCapabilities)
end
getCurrentUrl() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 150
def getCurrentUrl
  execute :getCurrentUrl
end
getCurrentWindowHandle() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 201
def getCurrentWindowHandle
  execute :getCurrentWindowHandle
end
getElementAttribute(element, name) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 281
def getElementAttribute(element, name)
  execute :getElementAttribute, :id => element, :name => name
end
getElementLocation(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 293
def getElementLocation(element)
  data = execute :getElementLocation, :id => element

  Point.new data['x'], data['y']
end
getElementLocationOnceScrolledIntoView(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 299
def getElementLocationOnceScrolledIntoView(element)
  data = execute :getElementLocationOnceScrolledIntoView, :id => element

  Point.new data['x'], data['y']
end
getElementSize(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 305
def getElementSize(element)
  data = execute :getElementSize, :id => element

  Dimension.new data['width'], data['height']
end
getElementTagName(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 277
def getElementTagName(element)
  execute :getElementTagName, :id => element
end
getElementText(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 289
def getElementText(element)
  execute :getElementText, :id => element
end
getElementValue(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 285
def getElementValue(element)
  execute :getElementValue, :id => element
end
getElementValueOfCssProperty(element, prop) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 351
def getElementValueOfCssProperty(element, prop)
  execute :getElementValueOfCssProperty, :id => element, :property_name => prop
end
getPageSource() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 158
def getPageSource
  execute :getPageSource
end
getScreenshot() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 205
def getScreenshot
  execute :screenshot
end
getTitle() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 154
def getTitle
  execute :getTitle
end
getVisible() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 162
def getVisible
  execute :getVisible
end
getWindowHandles() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 197
def getWindowHandles
  execute :getWindowHandles
end
goBack() click to toggle source

navigation

# File lib/selenium/webdriver/remote/bridge.rb, line 142
def goBack
  execute :goBack
end
goForward() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 146
def goForward
  execute :goForward
end
isElementDisplayed(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 339
def isElementDisplayed(element)
  execute :isElementDisplayed, :id => element
end
isElementEnabled(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 331
def isElementEnabled(element)
  execute :isElementEnabled, :id => element
end
isElementSelected(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 335
def isElementSelected(element)
  execute :isElementSelected, :id => element
end
mouseDown() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 255
def mouseDown
  execute :mouseDown
end
mouseMoveTo(element, x = nil, y = nil) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 263
def mouseMoveTo(element, x = nil, y = nil)
  params = { :element => element }

  if x && y
    params.merge!(:xoffset => x, :yoffset => y)
  end

  execute :mouseMoveTo, {}, params
end
mouseUp() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 259
def mouseUp
  execute :mouseUp
end
quit() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 184
def quit
  execute :quit
rescue *QUIT_ERRORS
end
refresh() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 193
def refresh
  execute :refresh
end
sendKeysToActiveElement(key) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 273
def sendKeysToActiveElement(key)
  execute :sendKeysToActiveElement, {}, :value => key
end
sendKeysToElement(element, keys) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 311
def sendKeysToElement(element, keys)
  if @file_detector && local_file = @file_detector.call(keys)
    keys = upload(local_file)
  end

  execute :sendKeysToElement, {:id => element}, {:value => Array(keys)}
end
session_id() click to toggle source

Returns the current session ID.

# File lib/selenium/webdriver/remote/bridge.rb, line 87
def session_id
  @session_id || raise(Error::WebDriverError, "no current session exists")
end
setAlertValue(keys) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 130
def setAlertValue(keys)
  execute :setAlertValue, {}, :text => keys.to_s
end
setElementSelected(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 347
def setElementSelected(element)
  execute :setElementSelected, :id => element
end
setImplicitWaitTimeout(milliseconds) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 106
def setImplicitWaitTimeout(milliseconds)
  execute :setImplicitWaitTimeout, {}, :ms => milliseconds
end
setScriptTimeout(milliseconds) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 110
def setScriptTimeout(milliseconds)
  execute :setScriptTimeout, {}, :ms => milliseconds
end
setVisible(bool) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 166
def setVisible(bool)
  execute :setVisible, {}, bool
end
submitElement(element) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 343
def submitElement(element)
  execute :submitElement, :id => element
end
switchToActiveElement() click to toggle source
Alias for: getActiveElement
switchToDefaultContent() click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 178
def switchToDefaultContent
  execute :switchToFrame, {}, :id => nil
end
switchToFrame(id) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 174
def switchToFrame(id)
  execute :switchToFrame, {}, :id => id
end
switchToWindow(name) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 170
def switchToWindow(name)
  execute :switchToWindow, {}, :name => name
end
upload(local_file) click to toggle source
# File lib/selenium/webdriver/remote/bridge.rb, line 319
def upload(local_file)
  unless File.file?(local_file)
    raise WebDriverError::Error, "you may only upload files: #{local_file.inspect}"
  end

  execute :uploadFile, {}, :file => Zipper.zip_file(local_file)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.