ADB错误代码

Ian*_*oud 22 android

我们有一个Android设备,作为测试的一部分,我需要在目标设备上执行控制台测试应用程序.如果测试应用程序检测到错误,则返回-1.

我可以使用adb shell在目标上远程运行测试应用程序,但我找不到返回返回代码的方法.我需要这个,所以我可以把它构建成一个自动测试套件.

我可以尝试使用控制台输出来获取一些失败的文本,但这有点肮脏.有谁知道更优雅的解决方案?

Pau*_*aka 9

这是获取退出代码的解决方法:adb shell'{your command here}>/dev/null 2>&1; echo $?'

这是Ruby中adb的包装:

def adb(opt)
  input = "#{adb_command} #{opt[:command]} #{opt[:params]}"
  puts "Executing #{input}...\n"
  output = nil
  exit_code = 0

  def wait_for(secs)
    if secs
      begin
        Timeout::timeout(secs) { yield }
      rescue
        print 'execution expired'
      end
    else
      yield
    end
  end

  wait_for(opt[:timeout]) do
    case opt[:command]
    when :install, :push, :uninstall
      output, exit_code = `#{input}`, $?.to_i
    when :shell
      input = "#{adb_command} shell \"#{opt[:params]}; echo \\$?\""
      output = `#{input}`.split("\n")
      exit_code = output.pop.to_i
      output = output.join("\n")
    else
      raise 'Error: param command to adb not defined!'
    end
  end

  return if opt[:ignore_fail] and output =~ /#{opt[:ignore_fail]}/
  raise output unless exit_code == 0
end
Run Code Online (Sandbox Code Playgroud)