Use Python to write an Android screenshots script and double-click to run it _python

Source: Internet
Author: User

The process of testing often requires intercepting the screen, the usual approach is to use the phone's own screen-cutting function, and then the screen file copied out, the advantage of this method is not required to connect the data line can be screenshots, the disadvantage is that the resulting screenshot file name is randomly named, copy out also more trouble. Another way is to use the PC-side phone helper software.

Here use Python to write a screenshot of the script, double-click the run script is OK, screen after the success of the screenshot file has the current time name, and save the script in the current path of 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 ( )) 
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 "Succe SS " 

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.