zoukankan      html  css  js  c++  java
  • Python实现对Android截图

     

    背景:

    测试过程中,总是需要对Android设备进行截图,然后在截图中标注问题描述;

    手动方式:

    1.使用adb scrrencap /sdcard/screen.png 命令对Android设备进行截图

    2.然后再使用adb pull /sdcard/scrren.png导入到PC端

    3.使用QQ截图进行问题描述标注

    自动化实现:


    将scrrencap.py文件copy至某个目录下,直接执行将保存截图到当前目录并自动打开展示;
    C:>screencap.py

    使用方法:

    C:>screencap.py -h
    Usage: screencap.py [-d <directory> -f <filename>]
    
    Automatic screenshots for android, After in PC display .
    
    Options:
      -h, --help            show this help message and exit
      -d DIRECTORY, --dir=DIRECTORY
                            directory of save the address
      -f FILENAME, --filename=FILENAME
                            filename of screen shots file name
     1 import os
     2 import time
     3 from optparse import OptionParser
     4 
     5 
     6 def option():
     7     # 获取脚本所在当前目录
     8     current_dir = os.path.dirname(__file__)
     9     # 根据截图时间生成默认文件名:20170722142831.png
    10     file_name = "%s.png" % time.strftime("%Y%m%d%H%M%S", time.localtime())
    11 
    12     usage = "screencap.py [-d <directory> -f <filename>]"
    13     description = "Automatic screenshots for android, After in PC display ."
    14 
    15     p = OptionParser(usage=usage, description=description)
    16 
    17     p.add_option("-d", "--dir",
    18                  dest="directory", default=current_dir,
    19                  help="directory of save the address")
    20 
    21     p.add_option("-f", "--filename",
    22                  dest="filename", default=file_name,
    23                  help="filename of screen shots file name")
    24     return p.parse_args()
    25 
    26 
    27 def screen(options):
    28     # 截图
    29     print(os.popen("adb shell screencap /sdcard/{filename}".format(filename=options.filename)).read())
    30 
    31     # 截图导出
    32     print(os.popen(r"adb pull /sdcard/{filename} {dir}".format(filename=options.filename,
    33                                                                dir=options.directory)).read())
    34     # 打开截图
    35     print(os.popen(r"start {filename}".format(filename=options.filename)).read())
    36     # 删除截图
    37     print(os.popen("adb shell rm /sdcard/{filename}".format(filename=options.filename)))
    38 
    39 
    40 if __name__ == '__main__':
    41     options, args = option()
    42     # print(options)
    43     # print(args)
    44     screen(options)
    screencap.py

      

    作者:SaoFox 
    出处:http://www.cnblogs.com/sao-fox
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
     
     
  • 相关阅读:
    电商系统服务拆分实战
    打通电商多模式支持的“任督二脉”
    win10 home安装docker快速攻略
    如何深入理解一套MQ消息中间件
    自带win10的笔记本电脑如何装win7
    《大数据日知录:架构与算法》读书笔记(多图)
    一个典型的后台软件系统的设计复盘——(三)打通任督二脉-context
    一个典型的后台软件系统的设计复盘——(二)如何id一个事物
    dubbox源码分析(一)-服务的启动与初始化
    svn老鸟转用git必须理解的概念
  • 原文地址:https://www.cnblogs.com/sao-fox/p/7235155.html
Copyright © 2011-2022 走看看