Module: Appium::Core::Android::Device

Extended by:
Forwardable
Defined in:
lib/appium_lib_core/android/device.rb,
lib/appium_lib_core/android/device/screen.rb,
lib/appium_lib_core/android/device/network.rb,
lib/appium_lib_core/android/device/emulator.rb,
lib/appium_lib_core/android/device/clipboard.rb,
lib/appium_lib_core/android/device/performance.rb,
lib/appium_lib_core/android/device/auth_finger_print.rb

Defined Under Namespace

Modules: Authentication, Clipboard, Emulator, Network, Performance, Screen

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(_mod) ⇒ Object


313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/appium_lib_core/android/device.rb', line 313

def extended(_mod)
  ::Appium::Core::Device.extend_webdriver_with_forwardable

  ::Appium::Core::Device.add_endpoint_method(:open_notifications) do
    def open_notifications
      execute :open_notifications
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:current_activity) do
    def current_activity
      execute :current_activity
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:current_package) do
    def current_package
      execute :current_package
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:get_system_bars) do
    def get_system_bars
      execute :get_system_bars
    end
  end
  # as alias to get_system_bars
  ::Appium::Core::Device.add_endpoint_method(:system_bars) do
    def system_bars
      execute :get_system_bars
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:toggle_location_services) do
    def toggle_location_services
      execute :toggle_location_services
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:start_activity) do
    def start_activity(opts)
      raise 'opts must be a hash' unless opts.is_a? Hash

      option = {}

      app_package = opts[:app_package]
      raise 'app_package is required' unless app_package

      app_activity = opts[:app_activity]
      raise 'app_activity is required' unless app_activity

      option[:appPackage] = app_package
      option[:appActivity] = app_activity

      app_wait_package  = opts.fetch(:app_wait_package, nil)
      app_wait_activity = opts.fetch(:app_wait_activity, nil)
      option[:appWaitPackage] = app_wait_package if app_wait_package
      option[:appWaitActivity] = app_wait_activity if app_wait_activity

      intent_action = opts.fetch(:intent_action, nil)
      intent_category = opts.fetch(:intent_category, nil)
      intent_flags = opts.fetch(:intent_flags, nil)
      optional_intent_arguments = opts.fetch(:optional_intent_arguments, nil)
      dont_stop_app_on_reset = opts.fetch(:dont_stop_app_on_reset, nil)

      option[:intentAction] = intent_action if intent_action
      option[:intentCategory] = intent_category if intent_category
      option[:intentFlags] = intent_flags if intent_flags
      option[:optionalIntentArguments] = optional_intent_arguments if optional_intent_arguments
      option[:dontStopAppOnReset] = dont_stop_app_on_reset if dont_stop_app_on_reset

      execute :start_activity, {}, option
    end
  end

  # Android, Override included method in bridge
  ::Appium::Core::Device.add_endpoint_method(:hide_keyboard) do
    def hide_keyboard(close_key = nil, strategy = nil)
      option = {}

      option[:key] = close_key if close_key
      option[:strategy] = strategy if strategy

      execute :hide_keyboard, {}, option
    end
  end

  # Android, Override included method in bridge
  ::Appium::Core::Device.add_endpoint_method(:background_app) do
    def background_app(duration = 0)
      execute :background_app, {}, seconds: duration
    end
  end

  # TODO: TEST ME
  ::Appium::Core::Device.add_endpoint_method(:end_coverage) do
    def end_coverage(path, intent)
      execute :end_coverage, {}, path: path, intent: intent
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:execute_cdp) do
    # SeleniumWebdriver could already define this method
    return if method_defined? :execute_cdp

    def execute_cdp(cmd, **params)
      execute :chrome_send_command, {}, { cmd: cmd, params: params }
    end
  end

  Screen.add_methods
  Performance.add_methods
  Network.add_methods
  Clipboard.add_methods
  Emulator.add_methods
  Authentication.add_methods
end

Instance Method Details

#current_activityString

Get current activity name

Examples:


@driver.current_activity # '.ApiDemos'

Returns:

  • (String)

    An activity name


# File 'lib/appium_lib_core/android/device.rb', line 38

#current_packageString

Get current package name

Examples:


@driver.current_package # 'com.example.android.apis'

Returns:

  • (String)

    A package name


# File 'lib/appium_lib_core/android/device.rb', line 47

#end_coverage(path, intent) ⇒ Object

Android only; Ends the test coverage and writes the results to the given path on device.

Parameters:

  • path (String)

    Path on the device to write too.

  • intent (String)

    Intent to broadcast when ending coverage.


# File 'lib/appium_lib_core/android/device.rb', line 142

#execute_cdp(cmd, params) ⇒ Object

Execute Chrome Devtools protocol commands chromedevtools.github.io/devtools-protocol


# File 'lib/appium_lib_core/android/device.rb', line 293

#finger_print(finger_id) ⇒ Object

Authenticate users by using their finger print scans on supported emulators.


# File 'lib/appium_lib_core/android/device.rb', line 283

#get_clipboard(content_type: :plaintext) ⇒ Object

Set the content of device's clipboard.


# File 'lib/appium_lib_core/android/device.rb', line 262

#get_display_densityInteger

Get connected device's density.

Examples:


@driver.get_display_density # 320

Returns:

  • (Integer)

    The size of density


# File 'lib/appium_lib_core/android/device.rb', line 66

#get_network_connectionObject

Get the device network connection current status See set_network_connection method for return value Same as #network_connection_type in selenium-webdriver.

Returns a key of {:airplane_mode: 1, wifi: 2, data: 4, all: 6, none: 0} in #network_connection_type Returns a number of the mode in #get_network_connection


# File 'lib/appium_lib_core/android/device.rb', line 75

#get_performance_data(package_name: , data_type: , data_read_timeout: 1000) ⇒ Object


# File 'lib/appium_lib_core/android/device.rb', line 204

#get_performance_data_typesObject

Get the information type of the system state which is supported to read such as cpu, memory, network, battery via adb commands. github.com/appium/appium-base-driver/blob/be29aec2318316d12b5c3295e924a5ba8f09b0fb/lib/mjsonwp/routes.js#L300


# File 'lib/appium_lib_core/android/device.rb', line 194

#get_system_barsString

Get system bar's information

Examples:


@driver.get_system_bars
@driver.system_bars

Returns:

  • (String)

# File 'lib/appium_lib_core/android/device.rb', line 56

#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.


# File 'lib/appium_lib_core/android/device.rb', line 127

#open_notificationsObject

Open Android notifications


# File 'lib/appium_lib_core/android/device.rb', line 30

#set_clipboard(content: , content_type: :plaintext, label: nil) ⇒ Object

Set the content of device's clipboard.


# File 'lib/appium_lib_core/android/device.rb', line 272

#set_network_connection(mode) ⇒ Object

Set the device network connection mode Same as #network_connection_type in selenium-webdriver.

Or the key matched with {:airplane_mode: 1, wifi: 2, data: 4, all: 6, none: 0}

Value (Alias)      | Data | Wifi | Airplane Mode
-------------------------------------------------
1 (Airplane Mode)  | 0    | 0    | 1
6 (All network on) | 1    | 1    | 0
4 (Data only)      | 1    | 0    | 0
2 (Wifi only)      | 0    | 1    | 0
0 (None)           | 0    | 0    | 0

Examples:


@driver.set_network_connection 1
@driver.set_network_connection :airplane_mode
@driver.network_connection_type = :airplane_mode # As selenium-webdriver

Parameters:

  • mode (String)

    Bit mask that represent the network mode


# File 'lib/appium_lib_core/android/device.rb', line 172

#start_activity(opts) ⇒ Object

Android only. Start a new activity within the current app or launch a new app and start the target activity.

Read developer.android.com/studio/command-line/adb#IntentSpec for each flags.

Examples:


start_activity app_package: 'io.appium.android.apis',
  app_activity: '.accessibility.AccessibilityNodeProviderActivity'

Parameters:

  • opts (Hash)

    Options

Options Hash (opts):

  • :app_package (String)

    The package owning the activity [required]

  • :app_activity (String)

    The target activity [required]

  • :app_wait_package (String)

    The package to start before the target package [optional]

  • :app_wait_activity (String)

    The activity to start before the target activity [optional]

  • :intent_action (String)

    The intent action to give it when start the target activity (-a) [optional]

  • :intent_category (String)

    The intent category to give it when start the target activity (-c) [optional]

  • :intent_flags (String)

    The intent flag to give it when start the target activity (-f) [optional]

  • :optional_intent_arguments (String)

    The optional intent action to give it when start the target activity [optional] You can set arbitrary arguments with space as string. e.g. '–ez your_extra_bool bool –ei your_extra_int 1'

  • :dont_stop_app_on_reset (bool)

    Do not stop the app when the reset is called in Appium create/delete session [optional]


# File 'lib/appium_lib_core/android/device.rb', line 148

#start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT', file_field_name: nil, form_fields: nil, headers: nil, force_restart: nil, video_size: nil, time_limit: '180', bit_rate: '4000000', bug_report: nil) ⇒ String

Returns Base64 encoded content of the recorded media file or an empty string if the file has been successfully uploaded to a remote location (depends on the actual options).

Examples:


@driver.start_recording_screen
@driver.start_recording_screen video_size: '1280x720', time_limit: '180', bit_rate: '5000000'

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. This option only has an effect if there is screen recording process in progress and forceRestart parameter is not set to true.

  • 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.

  • file_field_name (String) (defaults to: nil)

    The name of the form field containing the binary payload in multipart/form-data requests since Appium 1.18.0. Defaults to 'file'.

  • form_fields (Array<Hash, Array<String>>) (defaults to: nil)

    The form fields mapping in multipart/form-data requests since Appium 1.18.0. If any entry has the same key in this mapping, then it is going to be ignored.

  • headers (Hash) (defaults to: nil)

    The additional headers in multipart/form-data requests since Appium 1.18.0.

  • force_restart (Boolean) (defaults to: nil)

    Whether to try to catch and upload/return the currently running screen recording (false, the default setting on server) or ignore the result of it and start a new recording immediately (true).

  • video_size (String) (defaults to: nil)

    The format is widthxheight. The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder. For example, “1280x720”

  • time_limit (String) (defaults to: '180')

    Recording time. 180 seconds is by default. Since Appium 1.8.2 the time limit can be up to 1800 seconds (30 minutes). Appium will automatically try to merge the 3-minutes chunks recorded by the screenrecord utility, however, this requires FFMPEG utility to be installed and available in PATH on the server machine. If the utility is not present then the most recent screen recording chunk is going to be returned as the result.

  • bit_rate (String) (defaults to: '4000000')

    The video bit rate for the video, in megabits per second. 4 Mbp/s(4000000) is by default for Android API level below 27. 20 Mb/s(20000000) for API level 27 and above.

  • bug_report (Boolean) (defaults to: nil)

    Set it to true in order to display additional information on the video overlay, such as a timestamp, that is helpful in videos captured to illustrate bugs. This option is only supported since API level 27 (Android P).

Returns:

  • (String)

    Base64 encoded content of the recorded media file or an empty string if the file has been successfully uploaded to a remote location (depends on the actual options)


# File 'lib/appium_lib_core/android/device.rb', line 216

#toggle_airplane_modeObject

Toggle flight mode on or off

Examples:


@driver.toggle_airplane_mode

# File 'lib/appium_lib_core/android/device.rb', line 119

#toggle_dataObject

Switch the state of data service only for Android, and the device should be rooted


# File 'lib/appium_lib_core/android/device.rb', line 99

#toggle_location_servicesObject

Switch the state of the location service


# File 'lib/appium_lib_core/android/device.rb', line 109

#toggle_wifiObject

Switch the state of the wifi service only for Android


# File 'lib/appium_lib_core/android/device.rb', line 89