Monkeyrunner script writing skills (Shell
Command, file operations)
Android 4.0 has been released. I am disappointed that the monkeyrunner tool has not greatly improved and the SDK does not seem to have changed much. However, I will see the trend before, the Source Code has introduced new modules such as ichampview and runtime. Unfortunately, the source code has not yet been released and the specific situation is unknown. Besides, the current monkeyrunner cannot be executed. I feel that there are too few functions listed in the SDK at present, and there are too many restrictions when writing scripts. Fortunately, the monkeyrunner script is in the python form, and the rich library files can make up for this defect.
1. ADB command execution: OS. System ()
For example, ADB root, ADB push, ADB pull, you can use OS. system (), such as OS. system ("ADB push E: \ TMP \ email_eception.log/sdcard /")
2. Directory operations: OS. chdir (), OS. getcwd ()
OS. chdir ('e: \ TMP ')
OS. getcwd ()
3. Create a folder named by time (a practical method)
First obtain the time: time. ctime (), the obtained time format is as follows: "Mon Oct 31 15:48:30 2011", because the window does not support folder names including ":", and it also causes compatibility issues with spaces, string processing function Str. replace to replace spaces with "_", delete ":", st2.replace ("","_"). replace (":","")
4. Determine whether the file exists
OS. Path. exists (), return true or false
OS. Path. exists ("D: \ shellwork \ devtool \ Setup \ music \ setup. Bat ")
From Com. android. monkeyrunner import monkeyrunner, monkeydevice, monkeyimagedevice = monkeyrunner. waitforconnection () # device. removepackage ('apidemos.apk ') device. removepackage ('com. example. android. notepad ') print ('uninstall successfully 'your monkeyrunner.sleep(15347device.installpackage('apidemos.apk') print ('installed successfully ')
1. ADB command execution: OS. System ()
For example, ADB root, ADB push, ADB pull, you can use OS. system (), such as OS. system ("ADB push E: \ TMP \ email_eception.log/sdcard /")
2. Directory operations: OS. chdir (), OS. getcwd ()
OS. chdir ('e: \ TMP ')
OS. getcwd ()
3. Create a folder named by time (a practical method)
First obtain the time: time. ctime (), the obtained time format is as follows: "Mon Oct 31 15:48:30 2011", because the window does not support folder names including ":", and it also causes compatibility issues with spaces, string processing function Str. replace to replace spaces with "_", delete ":", st2.replace ("","_"). replace (":","")
4. Determine whether the file exists
OS. Path. exists (), return true or false
OS. Path. exists ("D: \ shellwork \ devtool \ Setup \ music \ setup. Bat ")
From Com. android. monkeyrunner import monkeyrunner, monkeydevice, monkeyimagedevice = monkeyrunner. waitforconnection () # device. removepackage ('apidemos.apk ') device. removepackage ('com. example. android. notepad ') print ('uninstall successfully 'your monkeyrunner.sleep(15347device.installpackage('apidemos.apk') print ('installed successfully ')