Module: Honeydew::DeviceCommands

Included in:
DeviceActions
Defined in:
lib/honeydew/device_commands.rb

Instance Method Summary collapse

Instance Method Details

#adb(command) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/honeydew/device_commands.rb', line 87

def adb(command)
  adb_command = "adb -s #{serial} #{command}"
  log "executing '#{adb_command}'"
  `#{adb_command} 2>/dev/null`.tap do
    if $?.exitstatus != 0
      raise "ADB command '#{command}' failed"
    end
  end
end

#clear_app_data(package_name) ⇒ Object



75
76
77
# File 'lib/honeydew/device_commands.rb', line 75

def clear_app_data(package_name)
  adb "shell pm clear #{package_name}"
end

#clear_directory(directory) ⇒ Object



11
12
13
14
# File 'lib/honeydew/device_commands.rb', line 11

def clear_directory(directory)
  all_files_in_directory_path = [directory.chomp('/'), '/*'].join
  adb "shell rm -r #{all_files_in_directory_path}"
end

#device_endpoint(action) ⇒ Object



16
17
18
# File 'lib/honeydew/device_commands.rb', line 16

def device_endpoint action
  URI.join("http://localhost:#{port}", action)
end

#dump_window_hierarchy(local_path) ⇒ Object



20
21
22
23
# File 'lib/honeydew/device_commands.rb', line 20

def dump_window_hierarchy(local_path)
  path_in_device = perform_action('dump_window_hierarchy')['description']
  adb "pull #{path_in_device} #{local_path}"
end

#forwarding_portObject



63
64
65
# File 'lib/honeydew/device_commands.rb', line 63

def forwarding_port
  adb "forward tcp:#{port} tcp:7120"
end

#honeydew_server_fileObject



48
49
50
# File 'lib/honeydew/device_commands.rb', line 48

def honeydew_server_file
  File.absolute_path(File.join(File.dirname(__FILE__), "../../server/target/#{honeydew_server_package}"))
end

#honeydew_server_packageObject



44
45
46
# File 'lib/honeydew/device_commands.rb', line 44

def honeydew_server_package
  "honeydew-server-#{Honeydew::VERSION}.jar"
end

#install_app(apk_location) ⇒ Object



71
72
73
# File 'lib/honeydew/device_commands.rb', line 71

def install_app(apk_location)
  adb "install #{apk_location}"
end

#is_app_installed?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/honeydew/device_commands.rb', line 7

def is_app_installed?(package_name)
  has_app_installed?(package_name)
end

#launch_settingsObject



83
84
85
# File 'lib/honeydew/device_commands.rb', line 83

def launch_settings
  adb 'shell am start -n com.android.settings/com.android.settings.Settings'
end

#rebootObject



79
80
81
# File 'lib/honeydew/device_commands.rb', line 79

def reboot
  adb 'reboot'
end

#start_automation_serverObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/honeydew/device_commands.rb', line 52

def start_automation_server
  log "starting honeydew-server on the device"
  Thread.new do
    adb "push #{honeydew_server_file} /data/local/tmp"
    adb "shell uiautomator runtest #{honeydew_server_package} -c com.amplify.honeydew_server.TestRunner"
  end
  at_exit do
    terminate_honeydew_server
  end
end

#start_honeydew_serverObject



31
32
33
34
35
# File 'lib/honeydew/device_commands.rb', line 31

def start_honeydew_server
  forwarding_port
  terminate_honeydew_server
  start_automation_server
end

#take_screenshot(local_path) ⇒ Object



25
26
27
28
29
# File 'lib/honeydew/device_commands.rb', line 25

def take_screenshot(local_path)
  path_in_device = '/data/local/tmp/honeydew.png'
  adb "shell /system/bin/screencap -p #{path_in_device}"
  adb "pull #{path_in_device} #{local_path}"
end

#terminate_honeydew_serverObject



37
38
39
40
41
42
# File 'lib/honeydew/device_commands.rb', line 37

def terminate_honeydew_server
  log "terminating honeydew-server"
  Net::HTTP.post_form device_endpoint('/terminate'), {}
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError
  # Swallow
end

#uninstall_app(package_name) ⇒ Object



67
68
69
# File 'lib/honeydew/device_commands.rb', line 67

def uninstall_app(package_name)
  adb "uninstall #{package_name}"
end