Module: Adb
Defined Under Namespace
Classes: Device
Instance Method Summary collapse
- #android_5_or_greater? ⇒ Boolean
- #android_6? ⇒ Boolean
- #android_6_or_greater? ⇒ Boolean
- #android_7? ⇒ Boolean
- #app_version(package_name) ⇒ Object
- #asus? ⇒ Boolean
- #brand ⇒ Object
- #connected_device_udid ⇒ Object
- #density ⇒ Object
- #emulator? ⇒ Boolean
- #execute_command(command, timeout_in_seconds = 10) ⇒ Object
- #htc? ⇒ Boolean
- #lenovo? ⇒ Boolean
- #model ⇒ Object
- #package_exists?(package_name) ⇒ Boolean
- #portrait? ⇒ Boolean
- #real_device? ⇒ Boolean
- #remove_package(name) ⇒ Object
- #restart_adb ⇒ Object
- #samsung? ⇒ Boolean
Instance Method Details
#android_5_or_greater? ⇒ Boolean
21 22 23 |
# File 'lib/adb_driver/adb.rb', line 21 def android_5_or_greater? android_version[0].to_i >= 5 end |
#android_6? ⇒ Boolean
29 30 31 |
# File 'lib/adb_driver/adb.rb', line 29 def android_6? android_version.start_with?('6') end |
#android_6_or_greater? ⇒ Boolean
25 26 27 |
# File 'lib/adb_driver/adb.rb', line 25 def android_6_or_greater? android_version[0].to_i >= 6 end |
#android_7? ⇒ Boolean
33 34 35 |
# File 'lib/adb_driver/adb.rb', line 33 def android_7? android_version.start_with?('7') end |
#app_version(package_name) ⇒ Object
11 12 13 14 15 |
# File 'lib/adb_driver/adb.rb', line 11 def app_version(package_name) output = execute_command("shell dumpsys package #{package_name}") version_line = output.lines.grep(/versionName/).first.strip version_line[/=(.*)/, 1] end |
#asus? ⇒ Boolean
55 56 57 |
# File 'lib/adb_driver/adb.rb', line 55 def asus? brand == 'asus' end |
#brand ⇒ Object
67 68 69 |
# File 'lib/adb_driver/adb.rb', line 67 def brand execute_command('shell getprop ro.product.brand').strip end |
#connected_device_udid ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/adb_driver/adb.rb', line 90 def connected_device_udid case when devices.none? then fail('No devices detected') when devices.one? then devices.first.udid when devices.count > 1 && emulators.none? then fail('Several devices detected. Set ANDROID_SERIAL to pick one') when devices.count > 1 && emulators.one? then emulators.first.udid when devices.count > 1 && emulators.count > 1 then fail('Several emulators detected. Close all but one') end end |
#density ⇒ Object
63 64 65 |
# File 'lib/adb_driver/adb.rb', line 63 def density @density ||= execute_command('shell getprop ro.sf.lcd_density').to_i end |
#emulator? ⇒ Boolean
43 44 45 |
# File 'lib/adb_driver/adb.rb', line 43 def emulator? !real_device? end |
#execute_command(command, timeout_in_seconds = 10) ⇒ Object
7 8 9 |
# File 'lib/adb_driver/adb.rb', line 7 def execute_command(command, timeout_in_seconds = 10) timeout(timeout_in_seconds) { `adb #{command}` } end |
#htc? ⇒ Boolean
51 52 53 |
# File 'lib/adb_driver/adb.rb', line 51 def htc? brand == 'htc' end |
#lenovo? ⇒ Boolean
59 60 61 |
# File 'lib/adb_driver/adb.rb', line 59 def lenovo? brand == 'Lenovo' end |
#model ⇒ Object
71 72 73 |
# File 'lib/adb_driver/adb.rb', line 71 def model execute_command('shell getprop ro.product.model').strip end |
#package_exists?(package_name) ⇒ Boolean
17 18 19 |
# File 'lib/adb_driver/adb.rb', line 17 def package_exists?(package_name) execute_command('shell pm list packages').lines.grep(/#{package_name}\s*$/).one? end |
#portrait? ⇒ Boolean
85 86 87 88 |
# File 'lib/adb_driver/adb.rb', line 85 def portrait? @orientation_enum ||= `adb shell dumpsys input`.lines.find { |l| l =~ /SurfaceOrientation/ }.strip[-1].to_i @orientation_enum.even? end |
#real_device? ⇒ Boolean
37 38 39 40 41 |
# File 'lib/adb_driver/adb.rb', line 37 def real_device? output = execute_command('devices -l') output = output.lines.grep(/#{ENV['ANDROID_SERIAL']}/).first output.include?('usb') end |
#remove_package(name) ⇒ Object
75 76 77 78 79 |
# File 'lib/adb_driver/adb.rb', line 75 def remove_package(name) return unless package_exists?(name) `adb uninstall #{name}` fail "#{name} package wasn't removed" if package_exists?(name) end |
#restart_adb ⇒ Object
81 82 83 |
# File 'lib/adb_driver/adb.rb', line 81 def restart_adb `adb kill-server; adb start-server` end |
#samsung? ⇒ Boolean
47 48 49 |
# File 'lib/adb_driver/adb.rb', line 47 def samsung? brand == 'samsung' end |