Use Python to write Android screenshot scripts double click to run

Source: Internet
Author: User
The process of testing often need to intercept the screen, the usual practice is to use the phone's own screenshot function, and then copy the screenshot file, the advantage of this method is no need to connect the data line can be screenshots, the disadvantage is that the resulting screenshot file naming is randomly named, copying out is also more troublesome. Another way is to use the PC-side of the phone helper class software.

Here, using Python to write a screenshot of the script, double-click to run the script is OK, the screenshot will be successful after the screenshot file is the current time named, and saved in the current path of the script to the screenshot folder:

#!/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 ()
  • 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.