Class: Appium::Core::Base::Driver

Inherits:
Selenium::WebDriver::Driver
  • Object
show all
Includes:
SearchContext, Selenium::WebDriver::DriverExtensions::HasRemoteStatus, Selenium::WebDriver::DriverExtensions::HasSessionId, Selenium::WebDriver::DriverExtensions::HasWebStorage, Selenium::WebDriver::DriverExtensions::Rotatable, Selenium::WebDriver::DriverExtensions::TakesScreenshot, Selenium::WebDriver::DriverExtensions::UploadsFiles
Defined in:
lib/appium_lib_core/common/base/driver.rb

Constant Summary

Constants included from SearchContext

SearchContext::FINDERS

Instance Method Summary collapse

Methods included from SearchContext

add_finders, #find_element, #find_elements

Constructor Details

#initialize(opts = {}) ⇒ Driver

Returns a new instance of Driver.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/appium_lib_core/common/base/driver.rb', line 16

def initialize(opts = {})
  listener = opts.delete(:listener)
  @bridge = ::Appium::Core::Base::Bridge.handshake(opts)
  if @bridge.dialect == :oss # MJSONWP
    extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen
    extend ::Selenium::WebDriver::DriverExtensions::HasLocation
    extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection
  elsif @bridge.dialect == :w3c
    # TODO: Only for Appium. Ideally, we'd like to remove the below like selenium-webdriver
    extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen
    extend ::Selenium::WebDriver::DriverExtensions::HasLocation
    extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection
  end
  super(@bridge, listener: listener)
end

Instance Method Details

#backString

Get the device window’s size.

Examples:

@driver.back # back to the previous view

Returns:

  • (String)


70
71
72
# File 'lib/appium_lib_core/common/base/driver.rb', line 70

def back
  navigate.back
end

#dialect:oss|:w3c

Get the dialect value

Returns:

  • (:oss|:w3c)


34
35
36
# File 'lib/appium_lib_core/common/base/driver.rb', line 34

def dialect
  @bridge.dialect
end

#get_timeoutsHash

For W3C. Get the timeout related settings on the server side.

Examples:

@driver.get_timeouts

Returns:

  • (Hash)


94
95
96
# File 'lib/appium_lib_core/common/base/driver.rb', line 94

def get_timeouts
  @bridge.get_timeouts
end

#logsString

Get the device window’s logs.

Examples:


@driver.logs.available_types # [:syslog, :crashlog, :performance]
@driver.logs.get :syslog # []

Returns:

  • (String)


82
83
84
# File 'lib/appium_lib_core/common/base/driver.rb', line 82

def logs
  @logs ||= Logs.new(@bridge)
end

#session_capabilitiesSelenium::WebDriver::Remote::Capabilities

Retrieve the capabilities of the specified session. It’s almost same as ‘@driver.capabilities` but you can get more details.

Examples:

@driver.session_capabilities

#=> uiautomator2
# <Selenium::WebDriver::Remote::W3C::Capabilities:0x007fa38dae1360
# @capabilities=
#     {:proxy=>nil,
#      :browser_name=>nil,
#      :browser_version=>nil,
#      :platform_name=>"android",
#      :page_load_strategy=>nil,
#      :remote_session_id=>nil,
#      :accessibility_checks=>nil,
#      :profile=>nil,
#      :rotatable=>nil,
#      :device=>nil,
#      "platform"=>"LINUX",
#      "webStorageEnabled"=>false,
#      "takesScreenshot"=>true,
#      "javascriptEnabled"=>true,
#      "databaseEnabled"=>false,
#      "networkConnectionEnabled"=>true,
#      "locationContextEnabled"=>false,
#      "warnings"=>{},
#      "desired"=>
#          {"platformName"=>"android",
#           "automationName"=>"uiautomator2",
#           "app"=>"/path/to/app/api.apk",
#           "platformVersion"=>"8.1.0",
#           "deviceName"=>"Android Emulator",
#           "appPackage"=>"io.appium.android.apis",
#           "appActivity"=>"io.appium.android.apis.ApiDemos",
#           "someCapability"=>"some_capability",
#           "unicodeKeyboard"=>true,
#           "resetKeyboard"=>true},
#      "automationName"=>"uiautomator2",
#      "app"=>"/path/to/app/api.apk",
#      "platformVersion"=>"8.1.0",
#      "deviceName"=>"emulator-5554",
#      "appPackage"=>"io.appium.android.apis",
#      "appActivity"=>"io.appium.android.apis.ApiDemos",
#      "someCapability"=>"some_capability",
#      "unicodeKeyboard"=>true,
#      "resetKeyboard"=>true,
#      "deviceUDID"=>"emulator-5554",
#      "deviceScreenSize"=>"1080x1920",
#      "deviceScreenDensity"=>420,
#      "deviceModel"=>"Android SDK built for x86",
#      "deviceManufacturer"=>"Google",
#      "pixelRatio"=>2.625,
#      "statBarHeight"=>63,
#      "viewportRect"=>{"left"=>0, "top"=>63, "width"=>1080, "height"=>1731}}>
#
#=> XCUITest
# <Selenium::WebDriver::Remote::W3C::Capabilities:0x007fb15dc01370
# @capabilities=
#     {:proxy=>nil,
#      :browser_name=>"UICatalog",
#      :browser_version=>nil,
#      :platform_name=>"ios",
#      :page_load_strategy=>nil,
#      :remote_session_id=>nil,
#      :accessibility_checks=>nil,
#      :profile=>nil,
#      :rotatable=>nil,
#      :device=>"iphone",
#      "udid"=>"DED4DBAD-8E5E-4AD6-BDC4-E75CF9AD84D8",
#      "automationName"=>"XCUITest",
#      "app"=>"/path/to/app/UICatalog.app",
#      "platformVersion"=>"10.3",
#      "deviceName"=>"iPhone Simulator",
#      "useNewWDA"=>true,
#      "useJSONSource"=>true,
#      "someCapability"=>"some_capability",
#      "sdkVersion"=>"10.3.1",
#      "CFBundleIdentifier"=>"com.example.apple-samplecode.UICatalog",
#      "pixelRatio"=>2,
#      "statBarHeight"=>23.4375,
#      "viewportRect"=>{"left"=>0, "top"=>47, "width"=>750, "height"=>1287}}>

Returns:

  • (Selenium::WebDriver::Remote::Capabilities)


183
184
185
# File 'lib/appium_lib_core/common/base/driver.rb', line 183

def session_capabilities
  @bridge.session_capabilities
end

#window_rectSelenium::WebDriver::Rectangle

Get the device window’s rect.

Examples:

size = @driver.window_rect
size.width #=> Integer
size.height #=> Integer
size.x #=> 0
size.y #=> 0

Returns:

  • (Selenium::WebDriver::Rectangle)


60
61
62
# File 'lib/appium_lib_core/common/base/driver.rb', line 60

def window_rect
  manage.window.rect
end

#window_sizeSelenium::WebDriver::Dimension

Get the device window’s size.

Examples:

size = @driver.window_size
size.width #=> Integer
size.height #=> Integer

Returns:

  • (Selenium::WebDriver::Dimension)


46
47
48
# File 'lib/appium_lib_core/common/base/driver.rb', line 46

def window_size
  manage.window.size
end