Monkeyrunner script writing skills (shell commands, file operations)-key point, Python create a folder named after time

Source: Internet
Author: User

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 ')
Related Article

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.