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

Defined Under Namespace

Modules: Clipboard, Emulator, Network, Performance, Screen

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(_mod) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/appium_lib_core/android/device.rb', line 245

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

  ::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
      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
      app_wait_package  = opts.fetch(:app_wait_package, '')
      app_wait_activity = opts.fetch(:app_wait_activity, '')

      unknown_opts = opts.keys - i(app_package app_activity app_wait_package app_wait_activity)
      raise "Unknown options #{unknown_opts}" unless unknown_opts.empty?

      execute :start_activity, {}, appPackage: app_package,
                                   appActivity: app_activity,
                                   appWaitPackage: app_wait_package,
                                   appWaitActivity: app_wait_activity
    end
  end

  # Android, Override
  ::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 || :tapOutside # default to pressKey

      execute :hide_keyboard, {}, option
    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

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

Instance Method Details

#current_activityString

Get current activity name

Examples:


@driver.current_activity # '.ApiDemos'


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


#current_packageString

Get current package name

Examples:


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


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


#end_coverage(path, intent) ⇒ Object

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



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


#get_clipboard(content_type: :plaintext) ⇒ Object

Set the content of device’s clipboard.



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


#get_display_densityInteger

Get connected device’s density.

Examples:


@driver.get_display_density # 320


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


#get_network_connectionObject

Get the device network connection current status See set_network_connection method for return value



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


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



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


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


#get_system_barsString

Get system bar’s information

Examples:


@driver.get_system_bars


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


#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


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


#open_notificationsObject

Open Android notifications



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


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


#set_network_connection(mode) ⇒ Object

Set the device network connection mode

Examples:


@driver.set_network_connection 1
@driver.network_connection_type = 1


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


#start_activity(opts) ⇒ Object

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

Examples:


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

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]



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


#start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_restart: nil, video_size: nil, time_limit: '180', bit_rate: '4000000') ⇒ Object

Examples:


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


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


#toggle_airplane_modeObject

Toggle flight mode on or off

Examples:


@driver.toggle_airplane_mode


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


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


#toggle_location_servicesObject

Switch the state of the location service



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


#toggle_wifiObject

Switch the state of the wifi service only for Android



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