Class: Appium::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/appium_lib/driver.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, global_driver = false) ⇒ Driver

Creates a new driver. The driver is defined as global scope by default. We can avoid defining global driver.

Examples:


require 'rubygems'
require 'appium_lib'

# platformName takes a string or a symbol.
# Start iOS driver with global scope
opts = {
         caps: {
           platformName: :ios,
           app: '/path/to/MyiOS.app'
         },
         appium_lib: {
           server_url: 'http://127.0.0.1:4723'
           wait_timeout: 30
         }
       }
appium_driver = Appium::Driver.new(opts, true)
appium_driver.start_driver

# Start Android driver with global scope
opts = {
         caps: {
           platformName: :android,
           app: '/path/to/my.apk'
         },
         appium_lib: {
           wait_timeout: 30,
           wait_interval: 1
         }
       }
appium_driver = Appium::Driver.new(opts, true)
appium_driver.start_driver

# Start iOS driver without global scope
opts = {
         caps: {
           platformName: :ios,
           app: '/path/to/MyiOS.app'
         },
         appium_lib: {
           wait_timeout: 30
         }
       }
appium_driver = Appium::Driver.new(opts, false)
appium_driver.start_driver

# Start iOS driver without global scope
opts = {
         caps: {
           platformName: :ios,
           app: '/path/to/MyiOS.app'
         },
         appium_lib: {
           wait_timeout: 30
         },
         global_driver: false
       }
appium_driver = Appium::Driver.new(opts)
appium_driver.start_driver

Parameters:

  • opts (Object) (defaults to: {})

    A hash containing various options.

  • global_driver (Bool) (defaults to: false)

    A bool require global driver before initialize.

Raises:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/appium_lib/driver.rb', line 153

def initialize(opts = {}, global_driver = false)
  # Capybara can't put `global_driver` as the 2nd argument.
  global_driver = opts.delete :global_driver if global_driver.nil?

  $driver&.driver_quit if global_driver

  raise ArgumentError, 'opts must be a hash' unless opts.is_a? Hash

  @core = ::Appium::Core.for(opts)
  extend ::Appium::Core::Device

  opts = Appium.symbolize_keys opts
  appium_lib_opts = opts[:appium_lib] || {}

  @caps = @core.caps
  @custom_url = @core.custom_url
  @default_wait = @core.default_wait || 0
  @appium_port = @core.port
  @appium_wait_timeout = @core.wait_timeout
  @appium_wait_interval = @core.wait_interval
  @listener = @core.listener
  @appium_device = @core.device
  @automation_name = @core.automation_name

  # Arrange the app capability. This must be after @core = ::Appium::Core.for(opts)
  set_app_path(opts)

  # enable debug patch
  @appium_debug = appium_lib_opts.fetch :debug, !!defined?(Pry) # rubocop:disable Style/DoubleNegation
  set_sauce_related_values(appium_lib_opts)

  # Extend Common methods
  extend Appium::Common
  extend Appium::Device

  # Extend each driver's methods
  extend_for(device: @core.device, automation_name: @core.automation_name)

  # for command

  if @appium_debug
    Appium::Logger.debug opts unless opts.empty?
    Appium::Logger.debug "Debug is: #{@appium_debug}"
    Appium::Logger.debug "Device is: #{@core.device}"
  end

  # Save global reference to last created Appium driver for top level methods.
  $driver = self if global_driver

  self # rubocop:disable Lint/Void # return newly created driver
end

Instance Attribute Details

#appium_debugObject (readonly)

Boolean debug mode for the Appium Ruby bindings



79
80
81
# File 'lib/appium_lib/driver.rb', line 79

def appium_debug
  @appium_debug
end

#appium_deviceObject (readonly)

Returns the value of attribute appium_device.



69
70
71
# File 'lib/appium_lib/driver.rb', line 69

def appium_device
  @appium_device
end

#appium_portObject (readonly)

Returns the value of attribute appium_port.



68
69
70
# File 'lib/appium_lib/driver.rb', line 68

def appium_port
  @appium_port
end

#appium_server_statusObject (readonly)

Appium’s server version



77
78
79
# File 'lib/appium_lib/driver.rb', line 77

def appium_server_status
  @appium_server_status
end

#appium_wait_intervalObject (readonly)

Returns the value of attribute appium_wait_interval.



74
75
76
# File 'lib/appium_lib/driver.rb', line 74

def appium_wait_interval
  @appium_wait_interval
end

#appium_wait_timeoutObject (readonly)

Returns the value of attribute appium_wait_timeout.



73
74
75
# File 'lib/appium_lib/driver.rb', line 73

def appium_wait_timeout
  @appium_wait_timeout
end

#automation_nameObject (readonly)

Returns the value of attribute automation_name.



70
71
72
# File 'lib/appium_lib/driver.rb', line 70

def automation_name
  @automation_name
end

#capsObject (readonly)



65
66
67
# File 'lib/appium_lib/driver.rb', line 65

def caps
  @caps
end

#coreObject (readonly)

Instance of Appium::Core::Driver



84
85
86
# File 'lib/appium_lib/driver.rb', line 84

def core
  @core
end

#custom_urlObject (readonly)

Returns the value of attribute custom_url.



66
67
68
# File 'lib/appium_lib/driver.rb', line 66

def custom_url
  @custom_url
end

#default_waitObject (readonly)

Returns the value of attribute default_wait.



67
68
69
# File 'lib/appium_lib/driver.rb', line 67

def default_wait
  @default_wait
end

#driverDriver (readonly)

Returns the driver

Returns:



82
83
84
# File 'lib/appium_lib/driver.rb', line 82

def driver
  @driver
end

#global_webdriver_http_sleepObject

The amount to sleep in seconds before every webdriver http call.



49
50
51
# File 'lib/appium_lib/driver.rb', line 49

def global_webdriver_http_sleep
  @global_webdriver_http_sleep
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



72
73
74
# File 'lib/appium_lib/driver.rb', line 72

def http_client
  @http_client
end

#listenerObject (readonly)

Returns the value of attribute listener.



71
72
73
# File 'lib/appium_lib/driver.rb', line 71

def listener
  @listener
end

#sauceObject (readonly)

SauceLab’s settings



52
53
54
# File 'lib/appium_lib/driver.rb', line 52

def sauce
  @sauce
end

#sauce_access_keyObject (readonly)

Access Key for use on Sauce Labs. Set ‘false` to disable Sauce, even when SAUCE_ACCESS_KEY is in ENV. same as @sauce.access_key



58
59
60
# File 'lib/appium_lib/driver.rb', line 58

def sauce_access_key
  @sauce_access_key
end

#sauce_endpointObject (readonly)

Override the Sauce Appium endpoint to allow e.g. TestObject tests same as @sauce.endpoint



61
62
63
# File 'lib/appium_lib/driver.rb', line 61

def sauce_endpoint
  @sauce_endpoint
end

#sauce_usernameObject (readonly)

Username for use on Sauce Labs. Set ‘false` to disable Sauce, even when SAUCE_USERNAME is in ENV. same as @sauce.username



55
56
57
# File 'lib/appium_lib/driver.rb', line 55

def sauce_username
  @sauce_username
end

Class Method Details

.absolute_app_path(opts) ⇒ String

Deprecated

Converts app_path to an absolute path.

opts is the full options hash (caps and appium_lib). If server_url is set then the app path is used as is.

if app isn’t set then an error is raised.

Returns:

  • (String)

    APP_PATH as an absolute path

Raises:



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/appium_lib/driver.rb', line 386

def self.absolute_app_path(opts)
  raise ArgumentError, 'opts must be a hash' unless opts.is_a? Hash

  # FIXME: 'caps' and 'app' will be correct
  caps            = opts[:caps] || opts['caps'] || {}
  app_path        = caps[:app] || caps['app']
  raise ArgumentError, 'absolute_app_path invoked and app is not set!' if app_path.nil? || app_path.empty?
  # Sauce storage API. http://saucelabs.com/docs/rest#storage
  return app_path if app_path.start_with? 'sauce-storage:'
  return app_path if app_path =~ URI::DEFAULT_PARSER.make_regexp # public URL for Sauce

  ::Appium::Logger.warn('[Deprecation] Converting the path to absolute path will be removed. ' \
                        'Please specify the full path which can be accessible from the appium server')

  absolute_app_path = File.expand_path app_path
  if File.exist? absolute_app_path
    absolute_app_path
  else
    ::Appium::Logger.info("Use #{app_path}")
    app_path
  end
end

Instance Method Details

#actionSelenium::WebDriver::PointerActions

Examples:


element = find_element(:id, "some id")
action.click(element).perform # The `click` is a part of `PointerActions`

Returns:

  • (Selenium::WebDriver::PointerActions)


331
332
333
# File 'lib/appium_lib/driver.rb', line 331

def action
  @driver&.action
end

#appium_client_versionHash

Returns the client’s version info

Examples:


{
    "version" => "9.1.1"
}

Returns:

  • (Hash)


374
375
376
# File 'lib/appium_lib/driver.rb', line 374

def appium_client_version
  { version: ::Appium::VERSION }
end

#appium_server_versionHash Also known as: remote_status

Returns the server’s version info

Examples:

{
  "build" => {
      "version" => "0.18.1",
      "revision" => "d242ebcfd92046a974347ccc3a28f0e898595198"
  }
}

Returns:

  • (Hash)


346
347
348
349
350
351
352
353
# File 'lib/appium_lib/driver.rb', line 346

def appium_server_version
  @core.appium_server_version
rescue Selenium::WebDriver::Error::WebDriverError => ex
  raise ::Appium::Core::Error::ServerError unless ex.message.include?('content-type=""')

  # server (TestObject for instance) does not respond to status call
  {}
end

#automation_name_is_espresso?Boolean

Return true if automationName is ‘Espresso’

Returns:

  • (Boolean)


311
312
313
# File 'lib/appium_lib/driver.rb', line 311

def automation_name_is_espresso?
  !@core.automation_name.nil? && @core.automation_name == :espresso
end

#automation_name_is_uiautomator2?Boolean

Return true if automationName is ‘uiautomator2’

Returns:

  • (Boolean)


305
306
307
# File 'lib/appium_lib/driver.rb', line 305

def automation_name_is_uiautomator2?
  !@core.automation_name.nil? && @core.automation_name == :uiautomator2
end

#automation_name_is_xcuitest?Boolean

Return true if automationName is ‘XCUITest’

Returns:

  • (Boolean)


317
318
319
# File 'lib/appium_lib/driver.rb', line 317

def automation_name_is_xcuitest?
  !@core.automation_name.nil? && @core.automation_name == :xcuitest
end

#current_urlObject



698
699
700
701
702
# File 'lib/appium_lib/driver.rb', line 698

def current_url
  raise NoDriverInstanceError if @driver.nil?

  @driver.current_url
end

#device_is_android?Boolean

Returns:

  • (Boolean)


291
292
293
# File 'lib/appium_lib/driver.rb', line 291

def device_is_android?
  @core.device == :android
end

#device_is_ios?Boolean

Returns:

  • (Boolean)


295
296
297
# File 'lib/appium_lib/driver.rb', line 295

def device_is_ios?
  @core.device == :ios
end

#device_is_windows?Boolean

Returns:

  • (Boolean)


299
300
301
# File 'lib/appium_lib/driver.rb', line 299

def device_is_windows?
  @core.device == :windows
end

#driver_attributesObject

Returns a hash of the driver attributes



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/appium_lib/driver.rb', line 273

def driver_attributes
  {
    caps:                @core.caps,
    automation_name:     @core.automation_name,
    custom_url:          @core.custom_url,
    default_wait:        @default_wait,
    sauce_username:      @sauce.username,
    sauce_access_key:    @sauce.access_key,
    sauce_endpoint:      @sauce.endpoint,
    port:                @core.port,
    device:              @core.device,
    debug:               @appium_debug,
    listener:            @listener,
    wait_timeout:        @core.wait_timeout,
    wait_interval:       @core.wait_interval
  }
end

#driver_quitvoid Also known as: quit_driver

This method returns an undefined value.

Quits the driver



454
455
456
457
458
459
# File 'lib/appium_lib/driver.rb', line 454

def driver_quit
  @driver&.quit
  @driver = nil
rescue Selenium::WebDriver::Error::WebDriverError
  nil
end

#element_screenshot(element, png_save_path) ⇒ File

Takes a png screenshot of particular element’s area

Examples:


el = find_element :accessibility_id, zzz
element_screenshot el, '/tmp/hi.png'

Parameters:

  • element (String)

    Element take a screenshot

  • png_save_path (String)

    the full path to save the png

Returns:

  • (File)


447
448
449
450
# File 'lib/appium_lib/driver.rb', line 447

def element_screenshot(element, png_save_path)
  @driver&.take_element_screenshot element, png_save_path
  nil
end

#execute_async_script(script, *args) ⇒ Object

Wrap calling selenium webdrier APIs via ruby_core

Get the window handles of open browser windows



627
628
629
630
631
# File 'lib/appium_lib/driver.rb', line 627

def execute_async_script(script, *args)
  raise NoDriverInstanceError if @driver.nil?

  @driver.execute_async_script script, *args
end

#execute_driver(script: '', type: 'webdriverio', timeout_ms: nil) ⇒ Appium::Core::Base::Device::ExecuteDriver::Result

Run a set of script against the current session, allowing execution of many commands in one Appium request. Supports WebdriverIO API so far. Please read command API for more details about acceptable scripts and the output.

Examples:

script = <<~SCRIPT
  const status = await driver.status();
  console.warn('warning message');
  return [status];
SCRIPT
r = @@driver.execute_driver(script: script, type: 'webdriverio', timeout: 10_000)
r        #=> An instance of Appium::Core::Base::Device::ExecuteDriver::Result
r.result #=> The `result` key part as the result of the script
r.logs   #=> The `logs` key part as `{'log' => [], 'warn' => [], 'error' => []}`

Parameters:

  • script (String) (defaults to: '')

    The string consisting of the script itself

  • type (String) (defaults to: 'webdriverio')

    The name of the script type. Defaults to ‘webdriverio’. Depends on server implementation which type is supported.

  • timeout_ms (Integer) (defaults to: nil)

    The number of ‘ms` Appium should wait for the script to finish before killing it due to timeout.

Returns:

  • (Appium::Core::Base::Device::ExecuteDriver::Result)

    The script result parsed by Appium::Core::Base::Device::ExecuteDriver::Result.

Raises:

  • (::Selenium::WebDriver::Error::UnknownError)

    If something error happens in the script. It has the original message.



661
662
663
664
665
# File 'lib/appium_lib/driver.rb', line 661

def execute_driver(script: '', type: 'webdriverio', timeout_ms: nil)
  raise NoDriverInstanceError if @driver.nil?

  @driver.execute_driver(script: script, type: type, timeout_ms: timeout_ms)
end

#execute_script(script, *args) ⇒ Object

The same as @driver.execute_script

Parameters:

  • script (String)

    The script to execute

  • args (*args)

    The args to pass to the script

Returns:

  • (Object)

Raises:



617
618
619
620
621
# File 'lib/appium_lib/driver.rb', line 617

def execute_script(script, *args)
  raise NoDriverInstanceError if @driver.nil?

  @driver.execute_script script, *args
end

#exists(pre_check = 0, post_check = @default_wait) { ... } ⇒ Boolean

Returns existence of element.

Example:

exists { button(‘sign in’) } ? puts(‘true’) : puts(‘false’)

Parameters:

  • pre_check (Integer) (defaults to: 0)

    The amount in seconds to set the wait to before checking existence

  • post_check (Integer) (defaults to: @default_wait)

    The amount in seconds to set the wait to after checking existence

Yields:

  • The block to call

Returns:

  • (Boolean)


593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
# File 'lib/appium_lib/driver.rb', line 593

def exists(pre_check = 0, post_check = @default_wait)
  # do not uset set_wait here.
  # it will cause problems with other methods reading the default_wait of 0
  # which then gets converted to a 1 second wait.
  @driver&.manage&.timeouts&.implicit_wait = pre_check
  # the element exists unless an error is raised.
  exists = true

  begin
    yield # search for element
  rescue StandardError
    exists = false # error means it's not there
  end

  # restore wait
  @driver&.manage&.timeouts&.implicit_wait = post_check if post_check != pre_check

  exists
end

#find_element(*args) ⇒ Element

Calls @driver.find_element

If you call ‘Appium.promote_appium_methods`, you can call `find_element` directly.

Examples:


@driver = Appium::Driver.new(opts, false)
@driver.start_driver
@driver.find_element :accessibility_id, zzz

Parameters:

  • args (*args)

    The args to use

Returns:

  • (Element)

Raises:



759
760
761
762
763
# File 'lib/appium_lib/driver.rb', line 759

def find_element(*args)
  raise NoDriverInstanceError if @driver.nil?

  @driver.find_element(*args)
end

#find_element_by_image(png_img_path) ⇒ ::Appium::Core::ImageElement

Return ImageElement if current view has a partial image

Examples:


@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

Returns:

  • (::Appium::Core::ImageElement)

Raises:

  • (::Appium::Core::Error::NoSuchElementError|::Appium::Core::Error::CoreError)

    No such element



776
777
778
779
780
# File 'lib/appium_lib/driver.rb', line 776

def find_element_by_image(png_img_path)
  raise NoDriverInstanceError if @driver.nil?

  @driver.find_element_by_image(png_img_path)
end

#find_elements(*args) ⇒ Array<Element>

Calls @driver.find_elements_with_appium

If you call ‘Appium.promote_appium_methods`, you can call `find_elements` directly.

If you call ‘Appium.promote_appium_methods`, you can call `find_elements` directly.

Examples:


@driver = Appium::Driver.new(opts, false)
@driver.start_driver
@driver.find_elements :predicate, yyy

@driver = Appium::Driver.new(opts, false)
@driver.start_driver
@driver.find_elements :predicate, yyy

Parameters:

  • args (*args)

    The args to use

Returns:

  • (Array<Element>)

    Array is empty when no elements are found.

Raises:



741
742
743
744
745
# File 'lib/appium_lib/driver.rb', line 741

def find_elements(*args)
  raise NoDriverInstanceError if @driver.nil?

  @driver.find_elements(*args)
end

#find_elements_by_image(png_img_paths) ⇒ [::Appium::Core::ImageElement], ::Appium::Core::Error::CoreError

Return ImageElement if current view has partial images

Examples:


@driver.find_elements_by_image ['./test/functional/data/test_element_image.png']

Parameters:

  • png_img_paths ([String])

    Paths to a partial image you’d like to find

Returns:

  • ([::Appium::Core::ImageElement])
  • (::Appium::Core::Error::CoreError)

Raises:



793
794
795
796
797
# File 'lib/appium_lib/driver.rb', line 793

def find_elements_by_image(png_img_paths)
  raise NoDriverInstanceError if @driver.nil?

  @driver.find_elements_by_image(png_img_paths)
end

#get(url) ⇒ Object



692
693
694
695
696
# File 'lib/appium_lib/driver.rb', line 692

def get(url)
  raise NoDriverInstanceError if @driver.nil?

  @driver.get(url)
end

#log_event(vendor:, event:) ⇒ nil

Logs a custom event. The event is available via Core::Events#get.

Examples:


log_event vendor: 'appium', event: 'funEvent'

log_event = { vendor: 'appium', event: 'anotherEvent' }
log_events #=> {...., 'appium:funEvent' => [1572957315, 1572960305],
           #          'appium:anotherEvent' => 1572959315}

Parameters:

  • vendor (String)

    The vendor prefix for the event

  • event (String)

    The name of event

Returns:

  • (nil)

Raises:

Since:

  • Appium 1.16.0



833
834
835
836
837
# File 'lib/appium_lib/driver.rb', line 833

def log_event(vendor:, event:)
  raise NoDriverInstanceError if @driver.nil?

  @driver.logs.event vendor: vendor, event: event
end

#log_event=(log_event) ⇒ Object



839
840
841
842
843
844
845
846
# File 'lib/appium_lib/driver.rb', line 839

def log_event=(log_event)
  raise if @driver.nil?
  unless log_event.is_a?(Hash)
    raise ::Appium::Core::Error::ArgumentError('log_event should be Hash like { vendor: "appium", event: "funEvent"}')
  end

  @driver.logs.event vendor: log_event[:vendor], event: log_event[:event]
end

#log_events(type = nil) ⇒ Hash

Returns events with filtering with ‘type’. Defaults to all available events.

Examples:


log_events #=> {}
log_events #=> {'commands' => [{'cmd' => 123455, ....}], 'startTime' => 1572954894127, }

Parameters:

  • type (String) (defaults to: nil)

    The type of events to get

Returns:

  • (Hash)

Raises:

Since:

  • Appium 1.16.0



859
860
861
862
863
# File 'lib/appium_lib/driver.rb', line 859

def log_events(type = nil)
  raise NoDriverInstanceError if @driver.nil?

  @driver.logs.events(type)
end

#manageObject



686
687
688
689
690
# File 'lib/appium_lib/driver.rb', line 686

def manage
  raise NoDriverInstanceError if @driver.nil?

  @driver.manage
end


680
681
682
683
684
# File 'lib/appium_lib/driver.rb', line 680

def navigate
  raise NoDriverInstanceError if @driver.nil?

  @driver.navigate
end

#no_waitObject

Set implicit wait to zero.



562
563
564
# File 'lib/appium_lib/driver.rb', line 562

def no_wait
  @driver&.manage&.timeouts&.implicit_wait = 0
end

#platform_versionArray<Integer>

Return the platform version as an array of integers

Returns:

  • (Array<Integer>)


358
359
360
361
362
363
# File 'lib/appium_lib/driver.rb', line 358

def platform_version
  return [] if @driver.nil?

  p_version = @driver.capabilities['platformVersion']
  p_version.split('.').map(&:to_i)
end

#restartDriver

Restarts the driver

Returns:



420
421
422
423
# File 'lib/appium_lib/driver.rb', line 420

def restart
  driver_quit
  start_driver
end

#screenshot(png_save_path) ⇒ File

Takes a png screenshot and saves to the target path.

Examples:


screenshot '/tmp/hi.png'

Parameters:

  • png_save_path (String)

    the full path to save the png

Returns:

  • (File)


433
434
435
# File 'lib/appium_lib/driver.rb', line 433

def screenshot(png_save_path)
  @driver&.save_screenshot png_save_path
end

#server_urlString

Get the server url

Returns:

  • (String)

    the server url



411
412
413
414
415
416
# File 'lib/appium_lib/driver.rb', line 411

def server_url
  return @core.custom_url if @core.custom_url
  return @sauce.server_url if @sauce.sauce_server_url?

  "http://127.0.0.1:#{@core.port}/wd/hub"
end

#set_implicit_wait(wait) ⇒ Object

To ignore error for Espresso Driver



551
552
553
554
555
556
557
558
559
# File 'lib/appium_lib/driver.rb', line 551

def set_implicit_wait(wait)
  @driver.manage.timeouts.implicit_wait = wait
rescue Selenium::WebDriver::Error::UnknownError => e
  unless e.message.include?('The operation requested is not yet implemented by Espresso driver')
    raise ::Appium::Core::Error::ServerError
  end

  {}
end

#set_location(opts = {}) ⇒ Selenium::WebDriver::Location

Note:

This method does not work on real devices.

Calls @driver.set_location

Parameters:

  • opts (Hash) (defaults to: {})

    consisting of:

Options Hash (opts):

  • :latitude (Float)

    the latitude in degrees (required)

  • :longitude (Float)

    the longitude in degees (required)

  • :altitude (Float)

    the altitude, defaulting to 75

Returns:

  • (Selenium::WebDriver::Location)

    the location constructed by the selenium webdriver

Raises:



808
809
810
811
812
813
814
815
# File 'lib/appium_lib/driver.rb', line 808

def set_location(opts = {})
  raise NoDriverInstanceError if @driver.nil?

  latitude = opts.fetch(:latitude)
  longitude = opts.fetch(:longitude)
  altitude = opts.fetch(:altitude, 75)
  @driver.set_location(latitude, longitude, altitude)
end

#set_wait(timeout = nil) ⇒ void

This method returns an undefined value.

Set implicit wait. Default to @default_wait.

Examples:


set_wait 2
set_wait # @default_wait

Parameters:

  • timeout (Integer) (defaults to: nil)

    the timeout in seconds



576
577
578
579
# File 'lib/appium_lib/driver.rb', line 576

def set_wait(timeout = nil)
  timeout = @default_wait if timeout.nil?
  @driver&.manage&.timeouts&.implicit_wait = timeout
end

#start_driver(http_client_ops = { http_client: ::Appium::Http::Default.new, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Selenium::WebDriver

Creates a new global driver and quits the old one if it exists. You can customise http_client as the following

Read www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Device to understand more what the driver can call instance methods.

Examples:


require 'rubygems'
require 'appium_lib'

# platformName takes a string or a symbol.
# Start iOS driver
opts = {
         caps: {
           platformName: :ios,
           app: '/path/to/MyiOS.app'
         },
         appium_lib: {
           wait_timeout: 30
         }
       }
appium_driver = Appium::Driver.new(opts) #=> return an Appium::Driver instance
appium_driver.start_driver #=> return an Appium::Core::Base::Driver

Parameters:

  • http_client_ops (Hash) (defaults to: { http_client: ::Appium::Http::Default.new, open_timeout: 999_999, read_timeout: 999_999 })

    a customizable set of options

Options Hash (http_client_ops):

  • :http_client (Hash)

    Custom HTTP Client

  • :open_timeout (Hash)

    Custom open timeout for http client.

  • :read_timeout (Hash)

    Custom read timeout for http client.

Returns:

  • (Selenium::WebDriver)

    the new global driver



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/appium_lib/driver.rb', line 524

def start_driver(http_client_ops =
                     { http_client: ::Appium::Http::Default.new, open_timeout: 999_999, read_timeout: 999_999 })

  # TODO: do not kill the previous session in the future version.
  if $driver.nil?
    driver_quit
  else
    $driver.driver_quit
  end

  # If automationName is set only in server side, then the following automation_name should be nil before
  # starting driver.
  automation_name = @core.automation_name

  @driver = @core.start_driver(server_url: server_url, http_client_ops: http_client_ops)
  @http_client = @core.http_client

  # if automation_name was nil before start_driver, then re-extend driver specific methods
  # to be able to extend correctly.
  extend_for(device: @core.device, automation_name: @core.automation_name) if automation_name.nil?

  @appium_server_status = appium_server_version

  @driver
end

#switch_toTargetLocator

Returns:

  • (TargetLocator)

Raises:

See Also:

  • TargetLocator


712
713
714
715
716
# File 'lib/appium_lib/driver.rb', line 712

def switch_to
  raise NoDriverInstanceError if @driver.nil?

  @driver.switch_to
end

#titleObject



704
705
706
707
708
# File 'lib/appium_lib/driver.rb', line 704

def title
  raise NoDriverInstanceError if @driver.nil?

  @driver.title
end

#window_handleObject

Get the current window handle



674
675
676
677
678
# File 'lib/appium_lib/driver.rb', line 674

def window_handle
  raise NoDriverInstanceError if @driver.nil?

  @driver.window_handle
end

#window_handlesObject



667
668
669
670
671
# File 'lib/appium_lib/driver.rb', line 667

def window_handles
  raise NoDriverInstanceError if @driver.nil?

  @driver.window_handles
end

#window_rectSelenium::WebDriver::Rectangle

Get the device window’s rect.

Examples:


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

Returns:

  • (Selenium::WebDriver::Rectangle)

Raises:



489
490
491
492
493
# File 'lib/appium_lib/driver.rb', line 489

def window_rect
  raise NoDriverInstanceError if @driver.nil?

  @driver.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)

Raises:



471
472
473
474
475
476
# File 'lib/appium_lib/driver.rb', line 471

def window_size
  # maybe exception is expected as no driver created
  raise NoDriverInstanceError if @driver.nil?

  @driver.window_size
end

#xvoid

This method returns an undefined value.

Quit the driver and Pry. quit and exit are reserved by Pry.



868
869
870
871
# File 'lib/appium_lib/driver.rb', line 868

def x
  driver_quit
  exit # exit pry
end