• 【转】在BeautiflReport中实现手动截图


    转自 https://blog.csdn.net/saint_228/article/details/90045774

    BeautifulReport(以下简称BR)是一个出色的基于unittest的Html报告生成库。
    BR默认的截图方式是通过语法糖,在assert抛异常时自动截图。
    https://github.com/TesterlifeRaymond/BeautifulReport

     但有时候我们需要手动截图,甚至在用例顺利通过时截图,之前的装饰器就不太好用了。
    所以要解决这个问题,可以手动写一个GetScreen方法,镶嵌到Html里。
    具体实现如下:

    def GetScreen(startTime,devices,action):
    	#定义截图存放目录的路径
        screenpath = os.path.join(os.getcwd(), "Screen")
    	#生成图片,此时图片还为空。action是字符串类型,存图片的说明信息
        png = screenpath +"\\"+ time.strftime('%Y%m%d_%H%M%S', time.localtime(startTime)) + "_" +  "_" + action+ ".png"
        #调用adb shell screencap方法截图,并存在手机的本地
        os.system("adb -s " + devices + " shell screencap -p /sdcard/screencap.png")
        fp = open(png, "a+", encoding="utf-8")
        fp.close()
        #将手机上的图片,转存到截图目录里。
        os.system("adb -s " + devices + " pull /sdcard/screencap.png " + png)
        #将图片发送到Html报告里,这里借用了BR生成报告的一个特性,它会将所有的print都带进报告里,这样使用预先写好的<img>标签,可以将png嵌入Html。
        print("<img src='" + png + "' width=600 />")
        return png

    然后,在unittest的test类里,如图一样,调用GetScreen()方法即可。

    最后得到的效果如下:

  • 相关阅读:
    nginx反向代理配置
    在页面完成读取EXCEL
    把List<string>转为DataTable
    临时表
    在aspx页动态加载ascx页面内容,给GridView控件绑定数据
    Content 控件
    if exists和if not exists关键字用法
    创建试图
    MyGeneration代码生成工具
    SQL Server 触发器触发器
  • 原文地址:https://www.cnblogs.com/yiruliu/p/16428151.html
Copyright © 2020-2023  润新知