Objective: To design a script that automatically executes the monkey command and realizes the automatic log save.
Train of thought: ReadLines read all device contents of ADB devices
Index to find the split line of the device name
Read only the content before index to a new list (you can assign a value with a two-column element, or you can use append)
Print the appropriate device name by selecting the device number
Introducing the OS to enable interaction
Here is the core code:
Read device:
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][:p oint])
print str (i+1) + '-' +ds[i]
print '
Loop Execute Monkey Command
Fd.write (': loop\n ')
fd.write (' adb-s ')
fd.write (Dev)
fd.write (' Shell monkey-p com.x.xx- Monitor-native-crashes--pct-touch--pct-motion--pct-nav 5-s%random%-v--throttle ')
100000>d:\\ ITE (FN)
fd.write (' \\%random%.log\n ')
time.sleep (5)
All the code is as follows:
#!/usr/bin/python
#-*-coding:utf-8-*-
#coding =gbk
import os
import os.path
import time
ds =[]
temp=os.popen (' adb devices '). ReadLines ()
N=len (temp)-2
#print temp
print ' Number of devices Is ' +str (n) to
I in range (n):
point=temp[i+1].index (' \ t ')
ds.append (temp[i+1][:p oint])
print STR (i+1) + '-' +ds[i]
print '
nds=1
if 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 15- -pct-nav 5-s%random%-v--throttle 10>d:\\ ')
fd.write (FN)
fd.write (' \\%random%.log\n ')
Time.sleep (5)
fd.write (' @goto loop ')
Fd.close ()