monkey指令碼執行個體(log自動儲存)_monkey實戰

來源:互聯網
上載者:User

目的:設計一個指令碼,自動執行monkey命令,並實現日誌自動儲存。

思路:readlines讀取adb devices所有裝置內容

index找到裝置名稱的分割線

唯讀取index之前的內容到一個新列表裡(可以用兩列表元素賦值,也可以用append)

通過選擇裝置號,列印相應的裝置名稱

引入os來實現互動

下面是核心代碼:

讀取裝置:

temp=os.popen('adb devices').readlines()  n=len(temp)-2  
for i in range(n):      point=temp[i+1].index('\t')            ds.append(temp[i+1][:point])      print str(i+1)+'-'+ds[i]  print ''  


迴圈執行monkey命令

fd.write(':loop\n')  fd.write('adb -s ')  fd.write(dev)  fd.write(' shell monkey -p com.x.xx --monitor-native-crashes --pct-touch 80 --pct-motion 15 --pct-nav 5 -s %random% -v --throttle 500 100000>d:\\')  fd.write(fn)  fd.write('\\%random%.log\n')  time.sleep(5)  fd.write('@goto loop') 

全部代碼如下:

#!/usr/bin/python# -*- coding: utf-8 -*-#coding=gbkimport osimport os.pathimport timeds=[]temp=os.popen('adb devices').readlines()n=len(temp)-2#print tempprint 'the number of devices is ' +str(n)for i in range(n):point=temp[i+1].index('\t')ds.append(temp[i+1][:point])print str(i+1)+'-'+ds[i]print ''nds=1if n!=1:nds=input('select device:')if nds<=n:dev=ds[nds-1]fn=raw_input('please input file name:')fd=open(fn+'.cmd','w')if not os.path.isdir('D:\\'+fn):os.mkdir('D:\\'+fn)fd.write(':loop\n')fd.write('adb -s ')fd.write(dev)fd.write(' shell monkey -p com.sky.jisuanji --monitor-native-crashes --pct-touch 80 --pct-motion 15 --pct-nav 5 -s %random% -v --throttle 500 10>d:\\')fd.write(fn)fd.write('\\%random%.log\n')time.sleep(5)fd.write('@goto loop')fd.close()


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.