Monkey script instance (log Auto Save) _monkey combat

Source: Internet
Author: User

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 ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.