allure报告实现保存失败用例截图功能


allure中可以保存日志信息和截图

日志allure能够自动识别。截图需要自己在添加allure方法。

具体实现如下:

import allure

    def save_scree_image(self):
        """
        对当前页面进行截图
        :return:
        """
        start_time = time.time()
        filename = '{}.png'.format(start_time)
        file_path = os.path.join(error_img, filename)
        self.driver.save_screenshot(file_path)
        log.info("错误页面截图成功,图表保存的路径:{}".format(file_path))
        return file_path

    def save_image_to_allure(self):
        """
        保存失败的截图到allure报告中
        :return:
        """
        file_path = self.save_scree_image()
        with open(file_path, "rb") as f:
            file = f.read()
            allure.attach(file, "失败截图", allure.attachment_type.PNG)

 

 

 

 

附:open 函数中 r 和 rb 的区别         【参考:https://www.jianshu.com/p/d9ab29cbb103

如果我们读取人工书写的数据那么就使用r,如果我们读取非人工书写的数据那么我们就是使用rb,图片就是一种非常典型的非人工书写数据。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM