首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python自动化android CTS

使用python自动化android CTS
EN

Stack Overflow用户
提问于 2013-06-18 08:49:03
回答 2查看 2.3K关注 0票数 4

我试图在Ubuntu上用python & monkeyrunner自动化整个CTS的设置和执行,大部分都进行得很好。作为最后一步,我尝试执行以下python命令以在特定设备上启动CTS:

代码语言:javascript
复制
cts_tradefed_script = "./android-cts/tools/cts-tradefed"
process = subprocess.Popen([cts_tradefed_script, "run", "cts", "-s", '"' + serialno + '"', "--plan", "CTS"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

这相当于:

代码语言:javascript
复制
./android-cts/tools/cts-tradefed run cts -s "R32CB054TSZ" --plan CTS

在命令行中,我得到:

代码语言:javascript
复制
Android CTS 4.2_r4
No commands for non-interactive mode; exiting.
06-17 17:32:32 I/: Detected new device R32CB054TSZ
Saved log to /tmp/tradefed_global_log_9173619073367947049.txt
06-17 17:32:32 I/CommandScheduler: All done

CTS测试不会执行。有没有我忘了的命令,或者这是不可能用Python实现的?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-19 01:59:56

代码语言:javascript
复制
cts_tradefed_script = "./android-cts/tools/cts-tradefed"
process = subprocess.Popen([cts_tradefed_script + " " + serialno], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

编辑:脚本不是必需的。只需将所有内容作为连接字符串输入即可。

票数 1
EN

Stack Overflow用户

发布于 2018-08-21 15:47:40

非交互式的问题是您不能运行超过一个命令,所以您应该尝试在交互式模式下运行。

要在交互模式下运行,这是一种方法:

代码语言:javascript
复制
#pip install paramiko
import paramiko
import time

def run_remote_command(channel, command):
  channel.send(command)
  whole_output = ""
  while True:
    if channel.recv_ready():
      output = channel.recv(1024)
      whole_output+=output
    else:
      time.sleep(0.5)
      if not(channel.recv_ready()):
        return whole_output

server ="fill you own here"
username = "fill you own here"
password = "fill you own here"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server, 22 ,username, password)
channel =ssh.get_transport().open_session()
channel.get_pty()
channel.invoke_shell()


run_1 =run_remote_command(channel,"~/android/out/host/linux-x86/cts/android-cts/tools/cts-tradefed list devices" + "\n")
print run_1

run_2 =run_remote_command(channel,"run cts" + "\n")
print run_2

run_3 =run_remote_command(channel,"l i" + "\n")
print run_3
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17159057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档