Double-click the android screenshot script in python to run it.

Source: Internet
Author: User

Double-click the android screenshot script in python to run it.

Screenshots are often taken during the test. The common practice is to use the screenshot function provided by the mobile phone and copy the screenshot file. The advantage of this method is that screenshots can be taken without connecting to the data line, the disadvantage is that the generated screenshot file is named randomly, and it is troublesome to copy the screenshot file. Another method is to use mobile Assistant Software on the PC end.

Write a screenshot script in python. Double-click the script to run the screenshot. After the screenshot is completed, the screenshot file is named after the current time and saved to the screenshot folder in the current path of the script:

#!/usr/bin/env python import os import time PATH = lambda p: os.path.abspath(p) def screenshot(): path = PATH(os.getcwd() + "/screenshot") timestamp = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())) os.popen("adb wait-for-device") os.popen("adb shell screencap -p /data/local/tmp/tmp.png") if not os.path.isdir(PATH(os.getcwd() + "/screenshot")): os.makedirs(path) os.popen("adb pull /data/local/tmp/tmp.png " + PATH(path + "/" + timestamp + ".png")) os.popen("adb shell rm /data/local/tmp/tmp.png") print "success" if __name__ == "__main__": screenshot()

When you use Python to write a script and run monkeyrunner, you cannot find it in the desired path.

The '\' Escape Character in the string is not followed by an identifiable escape character. Therefore, it must be changed to result. writeToFile ('e: \ New Folder \ picture.png ', 'png') is either changed to result. writeToFile (r 'e: \ New Folder \ picture.png ', 'png ')

I started to learn python cainiao, and asked python to execute print 'hello, world'. For details, refer to "invalid syntax ".

You use python 3.2, and the statement you entered is python 2. Of course, it is incorrect.
Which version of the software do you use.

For beginners, python2 and python3 have slightly different details, with little impact. However, we recommend that you use python2 for actual projects, because python often uses third-party libraries written by others. Currently, most third-party libraries are still in the python2 version, python 3 may be incompatible.
As for how many differences exist between python2 and python3, you can buy a Python Reference Manual (version 4th). the last part of this book is described in detail.

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.