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

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

Constant Summary collapse

DEFAULT_MATCH_THRESHOLD =
0.5

Constants included from SearchContext

SearchContext::FINDERS

Instance Method Summary collapse

Methods included from TakeScreenshot

#element_screenshot_as, #save_element_screenshot, #save_screenshot, #save_viewport_screenshot, #screenshot_as

Methods included from SearchContext

add_finders, #find_element, #find_elements

Constructor Details

#initialize(opts = {}) ⇒ Driver

Returns a new instance of Driver.



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

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

#activate_app(app_id) ⇒ Hash

Activate(Launch) the specified app.

Examples:


@driver.activate_app("io.appium.bundle") #=> {}

Returns:

  • (Hash)


503
504
505
# File 'lib/appium_lib_core/common/base/driver.rb', line 503

def activate_app(app_id)
  @bridge.activate_app(app_id)
end

#app_installed?(app_id) ⇒ Boolean

Check whether the specified app is installed on the device

Examples:


@driver.app_installed?("io.appium.bundle")

Returns:

  • (Boolean)


492
493
494
# File 'lib/appium_lib_core/common/base/driver.rb', line 492

def app_installed?(app_id)
  @bridge.app_installed?(app_id)
end

#app_state(app_id) ⇒ AppState::STATUS

Get the status of an existing application on the device. State:

:not_installed : The current application state cannot be determined/is unknown
:not_running : The application is not running
:running_in_background_suspended : The application is running in the background and is suspended
:running_in_background : The application is running in the background and is not suspended
:running_in_foreground : The application is running in the foreground

For more details: developer.apple.com/documentation/xctest/xcuiapplicationstate

Examples:


@driver.app_state("io.appium.bundle") #=> :not_running

Parameters:

  • app_id (String)

    A target app’s bundle id

Returns:

  • (AppState::STATUS)

    A number of the state



540
541
542
# File 'lib/appium_lib_core/common/base/driver.rb', line 540

def app_state(app_id)
  @bridge.app_state(app_id)
end

#app_strings(language = nil) ⇒ Hash

Return the hash of all localization strings.

Examples:


@driver.app_strings #=> "TransitionsTitle"=>"Transitions", "WebTitle"=>"Web"

Returns:

  • (Hash)


418
419
420
# File 'lib/appium_lib_core/common/base/driver.rb', line 418

def app_strings(language = nil)
  @bridge.app_strings(language)
end

#available_contextsArray<String>

Returns All usable contexts, as an array of strings.

Examples:


@driver.available_contexts

Returns:

  • (Array<String>)

    All usable contexts, as an array of strings.



214
215
216
# File 'lib/appium_lib_core/common/base/driver.rb', line 214

def available_contexts
  @bridge.available_contexts
end

#backString

Get the device window’s size.

Examples:

@driver.back # back to the previous view

Returns:

  • (String)


640
641
642
# File 'lib/appium_lib_core/common/base/driver.rb', line 640

def back
  navigate.back
end

#background_app(duration = 0) ⇒ String

Backgrounds the app for a set number of seconds. This is a blocking application

Examples:


@driver.background_app
@driver.background_app(5)
@driver.background_app(-1) #=> the app never come back. https://github.com/appium/appium/issues/7741

Parameters:

  • duration (Integer) (defaults to: 0)

    How many seconds to background the app for.

Returns:

  • (String)


433
434
435
# File 'lib/appium_lib_core/common/base/driver.rb', line 433

def background_app(duration = 0)
  @bridge.background_app(duration)
end

#close_appObject

Close an app on device

Examples:


@driver.close_app


397
398
399
# File 'lib/appium_lib_core/common/base/driver.rb', line 397

def close_app
  @bridge.close_app
end

#compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) ⇒ Object



785
786
787
# File 'lib/appium_lib_core/common/base/driver.rb', line 785

def compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil)
  @bridge.compare_images(mode: mode, first_image: first_image, second_image: second_image, options: options)
end

#current_contextString

Returns The context currently being used.

Examples:


@driver.current_context

Returns:

  • (String)

    The context currently being used.



204
205
206
# File 'lib/appium_lib_core/common/base/driver.rb', line 204

def current_context
  @bridge.current_context
end

#device_locked?Boolean

Check current device status is weather locked or not

Examples:


@driver.device_locked?

Returns:

  • (Boolean)


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

def device_locked?
  @bridge.device_locked?
end

#device_time(format = nil) ⇒ String

Get the time on the device

Examples:


@driver.device_time #=> "2018-06-12T11:13:31+02:00"
@driver.device_time "YYYY-MM-DD" #=> "2018-06-12"

Parameters:

  • format (String) (defaults to: nil)

    The set of format specifiers. Read momentjs.com/docs/ to get the full list of supported datetime format specifiers. The default format is ‘YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601

Returns:

  • (String)

    Formatted datetime string or the raw command output if formatting fails



595
596
597
# File 'lib/appium_lib_core/common/base/driver.rb', line 595

def device_time(format = nil)
  @bridge.device_time(format)
end

#dialect:oss|:w3c

Get the dialect value

Returns:

  • (:oss|:w3c)


36
37
38
# File 'lib/appium_lib_core/common/base/driver.rb', line 36

def dialect
  @bridge.dialect
end

#find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) ⇒ ::Appium::Core::ImageElement

Return ImageElement if current view has a partial image

Examples:


e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'

Parameters:

  • png_img_path (String)

    A path to a partial image you’d like to find

  • match_threshold (Flood) (defaults to: DEFAULT_MATCH_THRESHOLD)

    At what normalized threshold to reject

  • visualize (Bool) (defaults to: false)

    Makes the endpoint to return an image, which contains the visualized result of the corresponding picture matching operation. This option is disabled by default.

Returns:

Raises:



803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/appium_lib_core/common/base/driver.rb', line 803

def find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false)
  full_image = @bridge.screenshot
  partial_image = Base64.encode64 File.read(png_img_path)

  element = begin
    @bridge.find_element_by_image(full_image: full_image,
                                  partial_image: partial_image,
                                  match_threshold: match_threshold,
                                  visualize: visualize)
  rescue Selenium::WebDriver::Error::TimeOutError
    raise ::Appium::Core::Error::NoSuchElementError
  rescue ::Selenium::WebDriver::Error::WebDriverError => e
    raise ::Appium::Core::Error::NoSuchElementError if e.message.include?('Cannot find any occurrences')
    raise ::Appium::Core::Error::CoreError, e.message
  end
  raise ::Appium::Core::Error::NoSuchElementError if element.nil?

  element
end

#find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) ⇒ [::Appium::Core::ImageElement], ::Appium::Core::Error::CoreError

Return ImageElement if current view has partial images

Examples:


e = @@driver.find_elements_by_image ['./test/functional/data/test_element_image.png']
e == [] # if the `e` is empty

Parameters:

  • png_img_paths ([String])

    Paths to a partial image you’d like to find

  • match_threshold (Flood) (defaults to: DEFAULT_MATCH_THRESHOLD)

    At what normalized threshold to reject

  • visualize (Bool) (defaults to: false)

    Makes the endpoint to return an image, which contains the visualized result of the corresponding picture matching operation. This option is disabled by default.

Returns:



838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
# File 'lib/appium_lib_core/common/base/driver.rb', line 838

def find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false)
  full_image = @bridge.screenshot

  partial_images = png_img_paths.map do |png_img_path|
    Base64.encode64 File.read(png_img_path)
  end

  begin
    @bridge.find_elements_by_image(full_image: full_image,
                                   partial_images: partial_images,
                                   match_threshold: match_threshold,
                                   visualize: visualize)
  rescue Selenium::WebDriver::Error::TimeOutError
    []
  rescue ::Selenium::WebDriver::Error::WebDriverError => e
    return [] if e.message.include?('Cannot find any occurrences')
    raise ::Appium::Core::Error::CoreError, e.message
  end
end

#find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil) ⇒ Object



774
775
776
777
778
779
# File 'lib/appium_lib_core/common/base/driver.rb', line 774

def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
  @bridge.find_image_occurrence(full_image: full_image,
                                partial_image: partial_image,
                                visualize: visualize,
                                threshold: threshold)
end

#get_images_similarity(first_image:, second_image:, visualize: false) ⇒ Object



781
782
783
# File 'lib/appium_lib_core/common/base/driver.rb', line 781

def get_images_similarity(first_image:, second_image:, visualize: false)
  @bridge.get_images_similarity(first_image: first_image, second_image: second_image, visualize: visualize)
end

#get_settingsObject

Get appium Settings for current test session

Examples:


@driver.pull_folder '/data/local/tmp' #=> Get the folder at that path


108
109
110
# File 'lib/appium_lib_core/common/base/driver.rb', line 108

def get_settings
  @bridge.get_settings
end

#get_timeoutsHash

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

Examples:

@driver.get_timeouts

Returns:

  • (Hash)


664
665
666
# File 'lib/appium_lib_core/common/base/driver.rb', line 664

def get_timeouts
  @bridge.get_timeouts
end

#hide_keyboard(close_key = nil, strategy = nil) ⇒ Object

Hide the onscreen keyboard

Examples:


@driver.hide_keyboard # Close a keyboard with the 'Done' button
@driver.hide_keyboard('Finished') # Close a keyboard with the 'Finished' button
@driver.hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard

Parameters:

  • close_key (String) (defaults to: nil)

    The name of the key which closes the keyboard. Defaults to ‘Done’ for iOS(except for XCUITest).

  • strategy (Symbol) (defaults to: nil)

    The symbol of the strategy which closes the keyboard. XCUITest ignore this argument. Default for iOS is ‘:pressKey`. Default for Android is `:tapOutside`.



88
89
90
# File 'lib/appium_lib_core/common/base/driver.rb', line 88

def hide_keyboard(close_key = nil, strategy = nil)
  @bridge.hide_keyboard close_key, strategy
end

#ime_activate(ime_name) ⇒ Object

Android only. Make an engine that is available active.

Examples:


ime_activate engine: 'com.android.inputmethod.latin/.LatinIME'

Parameters:

  • ime_name (String)

    The IME owning the activity [required]



130
131
132
# File 'lib/appium_lib_core/common/base/driver.rb', line 130

def ime_activate(ime_name)
  @bridge.ime_activate(ime_name)
end

#ime_activatedObject

Examples:


ime_activated #=> True if IME is activated


161
162
163
# File 'lib/appium_lib_core/common/base/driver.rb', line 161

def ime_activated
  @bridge.ime_activated
end

#ime_active_engineObject

Android only. Get the name of the active IME engine.

Examples:


ime_active_engine #=> Get the current active IME such as 'com.android.inputmethod.latin/.LatinIME'


150
151
152
# File 'lib/appium_lib_core/common/base/driver.rb', line 150

def ime_active_engine
  @bridge.ime_active_engine
end

#ime_available_enginesObject

Android only. List all available input engines on the machine.

Examples:


ime_available_engines #=> Get the list of IME installed in the target device


140
141
142
# File 'lib/appium_lib_core/common/base/driver.rb', line 140

def ime_available_engines
  @bridge.ime_available_engines
end

#ime_deactivateObject

Android only. De-activates the currently-active IME engine.

Examples:


ime_deactivate #=> Deactivate current IME engine


171
172
173
# File 'lib/appium_lib_core/common/base/driver.rb', line 171

def ime_deactivate
  @bridge.ime_deactivate
end

#install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) ⇒ Object

Install the given app onto the device

Examples:


@driver.install_app("/path/to/test.apk")
@driver.install_app("/path/to/test.apk", replace: true, timeout: 20000, allow_test_packages: true,
                    use_sdcard: false, grant_permissions: false)

Parameters:

  • path (String)

    The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these.

  • replace: (Boolean) (defaults to: nil)

    Only for Android. Whether to reinstall/upgrade the package if it is already present on the device under test. ‘true` by default

  • timeout: (Integer) (defaults to: nil)

    Only for Android. How much time to wait for the installation to complete. 60000ms by default.

  • allow_test_packages: (Boolean) (defaults to: nil)

    Only for Android. Whether to allow installation of packages marked as test in the manifest. ‘false` by default

  • use_sdcard: (Boolean) (defaults to: nil)

    Only for Android. Whether to use the SD card to install the app. ‘false` by default

  • grant_permissions: (Boolean) (defaults to: nil)

    Only for Android. whether to automatically grant application permissions on Android 6+ after the installation completes. ‘false` by default



457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/appium_lib_core/common/base/driver.rb', line 457

def install_app(path,
                replace: nil,
                timeout: nil,
                allow_test_packages: nil,
                use_sdcard: nil,
                grant_permissions: nil)
  @bridge.install_app(path,
                      replace: replace,
                      timeout: timeout,
                      allow_test_packages: allow_test_packages,
                      use_sdcard: use_sdcard,
                      grant_permissions: grant_permissions)
end

#is_keyboard_shownBoolean

Get whether keyboard is displayed or not.

Examples:

@driver.is_keyboard_shown # false

Returns:

  • (Boolean)

    Return true if keyboard is shown. Return false if keyboard is hidden.



98
99
100
# File 'lib/appium_lib_core/common/base/driver.rb', line 98

def is_keyboard_shown # rubocop:disable Naming/PredicateName
  @bridge.is_keyboard_shown
end

#keyevent(key, metastate = nil) ⇒ Object

Send keyevent on the device.(Only for Selendroid) developer.android.com/reference/android/view/KeyEvent.html

Examples:


@driver.keyevent 82

Parameters:

  • key (integer)

    The key to press.

  • metastate (String) (defaults to: nil)

    The state the metakeys should be in when pressing the key.



333
334
335
# File 'lib/appium_lib_core/common/base/driver.rb', line 333

def keyevent(key, metastate = nil)
  @bridge.keyevent(key, metastate)
end

#launch_appObject

Start the simulator and application configured with desired capabilities

Examples:


@driver.launch_app


387
388
389
# File 'lib/appium_lib_core/common/base/driver.rb', line 387

def launch_app
  @bridge.launch_app
end

#lock(duration = nil) ⇒ String

Lock the device

Examples:


@driver.lock    #=> Lock the device
@driver.lock(5) #=> Lock the device in 5 sec and unlock the device after 5 sec.
                #   Block other commands during locking the device.

Returns:

  • (String)


51
52
53
# File 'lib/appium_lib_core/common/base/driver.rb', line 51

def lock(duration = nil)
  @bridge.lock(duration)
end

#logsString

Get the device window’s logs.

Examples:


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

Returns:

  • (String)


652
653
654
# File 'lib/appium_lib_core/common/base/driver.rb', line 652

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

#long_press_keycode(key, metastate: [], flags: []) ⇒ Object

Examples:


@driver.long_press_keycode 66
@driver.long_press_keycode 66, flags: [0x20, 0x2000]
@driver.long_press_keycode 66, metastate: [1], flags: [32, 8192]

Parameters:



377
378
379
# File 'lib/appium_lib_core/common/base/driver.rb', line 377

def long_press_keycode(key, metastate: [], flags: [])
  @bridge.long_press_keycode(key, metastate: metastate, flags: flags)
end

#match_images_features(first_image:, second_image:, detector_name: 'ORB', match_func: 'BruteForce', good_matches_factor: nil, visualize: false) ⇒ Object

Image Comparison



760
761
762
763
764
765
766
767
768
769
770
771
772
# File 'lib/appium_lib_core/common/base/driver.rb', line 760

def match_images_features(first_image:,
                          second_image:,
                          detector_name: 'ORB',
                          match_func: 'BruteForce',
                          good_matches_factor: nil,
                          visualize: false)
  @bridge.match_images_features(first_image: first_image,
                                second_image: second_image,
                                detector_name: detector_name,
                                match_func: match_func,
                                good_matches_factor: good_matches_factor,
                                visualize: visualize)
end

#multi_touch(actions) ⇒ Object



604
605
606
# File 'lib/appium_lib_core/common/base/driver.rb', line 604

def multi_touch(actions)
  @bridge.multi_touch(actions)
end

#press_keycode(key, metastate: [], flags: []) ⇒ Object

Examples:


@driver.press_keycode 66
@driver.press_keycode 66, flags: [0x02]
@driver.press_keycode 66, metastate: [1], flags: [32]

Parameters:



355
356
357
# File 'lib/appium_lib_core/common/base/driver.rb', line 355

def press_keycode(key, metastate: [], flags: [])
  @bridge.press_keycode(key, metastate: metastate, flags: flags)
end

#pull_file(path) ⇒ Base64-decoded

Pull a file from the simulator/device. On iOS the server should have ifuse libraries installed and configured properly for this feature to work on real devices. On Android the application under test should be built with debuggable flag enabled in order to get access to its container on the internal file system.

Examples:


@driver.pull_file '/local/data/some/path'     #=> Get the file at that path
@driver.pull_file 'Shenanigans.app/some/file' #=> Get 'some/file' from the install location of Shenanigans.app

Parameters:

  • path (String)

    Either an absolute path OR, for iOS devices, a path relative to the app, as described. If the path starts with application id prefix, then the file will be pulled from the root of the corresponding application container. Otherwise the root folder is considered as / on Android and on iOS it is a media folder root (real devices only).

Returns:

  • (Base64-decoded)

    Base64 decoded data

See Also:



294
295
296
# File 'lib/appium_lib_core/common/base/driver.rb', line 294

def pull_file(path)
  @bridge.pull_file(path)
end

#pull_folder(path) ⇒ Base64-decoded

Pull a folder content from the simulator/device. On iOS the server should have ifuse libraries installed and configured properly for this feature to work on real devices. On Android the application under test should be built with debuggable flag enabled in order to get access to its container on the internal file system.

Examples:


@driver.pull_folder '/data/local/tmp' #=> Get the folder at that path

Parameters:

  • path (String)

    Absolute path to the folder. If the path starts with @applicationId/ prefix, then the folder will be pulled from the root of the corresponding application container. Otherwise the root folder is considered as / on Android and on iOS it is a media folder root (real devices only).

Returns:

  • (Base64-decoded)

    Base64 decoded data which is zip archived

See Also:



320
321
322
# File 'lib/appium_lib_core/common/base/driver.rb', line 320

def pull_folder(path)
  @bridge.pull_folder(path)
end

#push_file(path, filedata) ⇒ Object

Place a file in a specific location on the device. On iOS, the server should have ifuse libraries installed and configured properly for this feature to work on real devices. On Android, the application under test should be built with debuggable flag enabled in order to get access to its container on the internal file system.

Examples:


@driver.push_file "/file/to/path", "data"

Parameters:

  • path (String)

    Either an absolute path OR, for iOS devices, a path relative to the app, as described. If the path starts with application id prefix, then the file will be pushed to the root of the corresponding application container.

  • filedata (String)

    Raw file data to be sent to the device. Converted to base64 in the method.

See Also:



268
269
270
# File 'lib/appium_lib_core/common/base/driver.rb', line 268

def push_file(path, filedata)
  @bridge.push_file(path, filedata)
end

#remove_app(app_id, keep_data: nil, timeout: nil) ⇒ Object

Examples:


@driver.remove_app("io.appium.bundle")
@driver.remove_app("io.appium.bundle", keep_data: false, timeout, 10000)

Parameters:

  • app_id (Strong)

    BundleId for iOS or package name for Android

  • keep_data: (Boolean) (defaults to: nil)

    Only for Android. Whether to keep application data and caches after it is uninstalled. ‘false` by default

  • timeout: (Integer) (defaults to: nil)

    Only for Android. How much time to wait for the uninstall to complete. 20000ms by default.



481
482
483
# File 'lib/appium_lib_core/common/base/driver.rb', line 481

def remove_app(app_id, keep_data: nil, timeout: nil)
  @bridge.remove_app(app_id, keep_data: keep_data, timeout: timeout)
end

#replace_value(element, *value) ⇒ Object

Replace the value to element directly

Examples:


replace_value element, 'hello'


245
246
247
# File 'lib/appium_lib_core/common/base/driver.rb', line 245

def replace_value(element, *value)
  @bridge.replace_value(element, *value)
end

#resetObject

Reset the device, relaunching the application.

Examples:


@driver.reset


407
408
409
# File 'lib/appium_lib_core/common/base/driver.rb', line 407

def reset
  @bridge.reset
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)


753
754
755
# File 'lib/appium_lib_core/common/base/driver.rb', line 753

def session_capabilities
  @bridge.session_capabilities
end

#set_context(context = null) ⇒ Object

Change the context to the given context.

Examples:


@driver.set_context "NATIVE_APP"

Parameters:

  • context (String) (defaults to: null)

    The context to change to



225
226
227
# File 'lib/appium_lib_core/common/base/driver.rb', line 225

def set_context(context = null)
  @bridge.set_context(context)
end

#set_immediate_value(element, *value) ⇒ Object

Set the value to element directly

Examples:


set_immediate_value element, 'hello'


235
236
237
# File 'lib/appium_lib_core/common/base/driver.rb', line 235

def set_immediate_value(element, *value)
  @bridge.set_immediate_value(element, *value)
end

#shakeObject

Cause the device to shake

Examples:


@driver.shake


579
580
581
# File 'lib/appium_lib_core/common/base/driver.rb', line 579

def shake
  @bridge.shake
end

#stop_and_save_recording_screen(file_path) ⇒ Object

Examples:


@driver.stop_and_save_recording_screen 'example.mp4'

Parameters:

  • file_path (String)

    The path to save video decoded from base64 from Appium server.



569
570
571
# File 'lib/appium_lib_core/common/base/driver.rb', line 569

def stop_and_save_recording_screen(file_path)
  @bridge.stop_and_save_recording_screen(file_path)
end

#stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') ⇒ Object

Examples:


@driver.stop_recording_screen
@driver.stop_recording_screen remote_path: 'https://example.com', user: 'example', pass: 'pass', method: 'POST'

Parameters:

  • remote_path: (String) (defaults to: nil)

    The path to the remote location, where the resulting video should be uploaded. The following protocols are supported: http/https, ftp. Null or empty string value (the default setting) means the content of resulting file should be encoded as Base64 and passed as the endpoint response value. An exception will be thrown if the generated media file is too big to fit into the available process memory.

  • user: (String) (defaults to: nil)

    The name of the user for the remote authentication.

  • pass: (String) (defaults to: nil)

    The password for the remote authentication.

  • method: (String) (defaults to: 'PUT')

    The http multipart upload method name. The ‘PUT’ one is used by default.



559
560
561
# File 'lib/appium_lib_core/common/base/driver.rb', line 559

def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT')
  @bridge.stop_recording_screen(remote_path: remote_path, user: user, pass: pass, method: method)
end

#switch_to_default_contextObject

Change to the default context. This is equivalent to ‘set_context nil`.

Examples:


@driver.switch_to_default_context


194
195
196
# File 'lib/appium_lib_core/common/base/driver.rb', line 194

def switch_to_default_context
  @bridge.switch_to_default_context
end

#terminate_app(app_id, timeout: nil) ⇒ Boolean

Terminate the specified app.

Examples:


@driver.terminate_app("io.appium.bundle") # true
@driver.terminate_app("io.appium.bundle", timeout: 500)

Parameters:

  • app_id (Strong)

    BundleId for iOS or package name for Android

  • timeout: (Integer) (defaults to: nil)

    Only for Android. How much time to wait for the application termination to complete. 500ms by default.

Returns:

  • (Boolean)


519
520
521
# File 'lib/appium_lib_core/common/base/driver.rb', line 519

def terminate_app(app_id, timeout: nil)
  @bridge.terminate_app(app_id, timeout: timeout)
end

#touch_actions(actions) ⇒ Object

touch actions



600
601
602
# File 'lib/appium_lib_core/common/base/driver.rb', line 600

def touch_actions(actions)
  @bridge.touch_actions(actions)
end

#unlockObject

Unlock the device

Examples:


@driver.unlock


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

def unlock
  @bridge.unlock
end

#update_settings(settings) ⇒ Object

Update Appium Settings for current test session

Examples:


@driver.update_settings('allowInvisibleElements': true)

Parameters:

  • settings (Hash)

    Settings to update, keys are settings, values to value to set each setting to



119
120
121
# File 'lib/appium_lib_core/common/base/driver.rb', line 119

def update_settings(settings)
  @bridge.update_settings(settings)
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)


630
631
632
# File 'lib/appium_lib_core/common/base/driver.rb', line 630

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)


616
617
618
# File 'lib/appium_lib_core/common/base/driver.rb', line 616

def window_size
  manage.window.size
end

#within_context(context) ⇒ Object

Perform a block within the given context, then switch back to the starting context.

Examples:


result = @driver.within_context('NATIVE_APP') do
  @driver.find_element :tag, "button"
end # The result of `find_element :tag, "button"`

Parameters:

  • context (String)

    The context to switch to for the duration of the block.



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

def within_context(context)
  block_given? ? @bridge.within_context(context, &Proc.new) : @bridge.within_context(context)
end