2024年最全自动化测试中的失败截图和存log_测试失败的截图’(1),2024年最新含小米、腾讯、阿里

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

    print('nodeid:%s' % report.nodeid)
    print('description:%s' % str(item.function.__doc__))
    print(('运行结果: %s' % report.outcome))

@pytest.fixture(scope=“session”, autouse=True)
def fix_a():
print(“setup 前置操作”)
yield
print(“teardown 后置操作”)


**allure报告集成错误截图** 需要使用conftest.py文件,conftest.py需要存在在测试目录中,文件名不能变更,可以根据模块创建层级嵌套。


具体参照pytest的官方文档



@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
‘’’
hook pytest失败
:param item:
:param call:
:return:
‘’’
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# we only look at actual failing test calls, not setup/teardown
if rep.when == “call” and rep.failed:
mode = “a” if os.path.exists(“failures”) else “w”
with open(“failures”, mode) as f:
# let’s also access a fixture for the fun of it
if “tmpdir” in item.fixturenames:
extra = " (%s)" % item.funcargs[“tmpdir”]
else:
extra = “”
f.write(rep.nodeid + extra + “\n”)
# pic_info = adb_screen_shot()
with allure.step(‘添加失败截图…’):
allure.attach(driver.get_screenshot_as_png(), “失败截图”, allure.attachment_type.PNG)


好了,我们可以用在我们自己的项目里面来了。 我们可以在conftest.py里面定义:



import pytest
from selenium import webdriver
import os
import allure

_driver = None

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
‘’’
获取每个用例状态的钩子函数
:param item:
:param call:
:return:
‘’’
# 获取钩子方法的调用结果
outcome = yield
rep = outcome.get_result()
# 仅仅获取用例call 执行结果是失败的情况, 不包含 setup/teardown
if rep.when == “call” and rep.failed:
mode = “a” if os.path.exists(“failures”) else “w”
with open(“failures”, mode) as f:
# let’s also access a fixture for the fun of it
if “tmpdir” in item.fixturenames:
extra = " (%s)" % item.funcargs[“tmpdir”]
else:
extra = “”
f.write(rep.nodeid + extra + “\n”)
# 添加allure报告截图
if hasattr(_driver, “get_screenshot_as_png”):
with allure.step(‘添加失败截图…’):
allure.attach(_driver.get_screenshot_as_png(), “失败截图”, allure.attachment_type.PNG)

@pytest.fixture(scope=‘session’)
def browser():
global _driver
if _driver is None:
_driver =webdriver.Chrome()
yield _driver
print(“1111111111”)
_driver.quit()


然后写一个测试用例,如在某度上搜一个关键词。



@allure.feature(‘self study’)
class TestLesson():
@allure.story(‘user course page’)
@allure.description(‘be course’)
def test_be_ge_course(self,browser):
url = ‘http://www.baidu.com’
browser.get(url)
time.sleep(2)
browser.find_element_by_id(‘kw’).send_keys(“python”)

    with allure.step('查找元素...'):
        browser.find_element_by_id('su').click()
        time.sleep(2)

    assert browser.title == 'python'

这是一个失败的用例,所以执行错误会截图。


![](https://img-blog.csdnimg.cn/img_convert/ee5e64711a216bc70b01bb4ce9cc6236.jpeg)


这样你的报告就看起来高大上了。 截图还可以直接用allure.attach allure.attach(挺有用的) 作用:allure报告还支持显示许多不同类型的附件,可以补充测试结果;自己想输出啥就输出啥,挺好的



语法:allure.attach(body, name, attachment_type, extension)

参数列表
body:要显示的内容(附件)
name:附件名字
attachment_type:附件类型,是 allure.attachment_type 里面的其中一种
extension:附件的扩展名(比较少用)


allure.attach.file(source, name, attachment\_type, extension) source:文件路径,相当于传一个文件


其他参数和上面的一致:



TEXT = (“text/plain”, “txt”)
CSV = (“text/csv”, “csv”)
TSV = (“text/tab-separated-values”, “tsv”)
URI_LIST = (“text/uri-list”, “uri”)

HTML = (“text/html”, “html”)
XML = (“application/xml”, “xml”)
JSON = (“application/json”, “json”)
YAML = (“application/yaml”, “yaml”)
PCAP = (“application/vnd.tcpdump.pcap”, “pcap”)

PNG = (“image/png”, “png”)
JPG = (“image/jpg”, “jpg”)
SVG = (“image/svg-xml”, “svg”)
GIF = (“image/gif”, “gif”)
BMP = (“image/bmp”, “bmp”)
TIFF = (“image/tiff”, “tiff”)

MP4 = (“video/mp4”, “mp4”)
OGG = (“video/ogg”, “ogg”)
WEBM = (“video/webm”, “webm”)

PDF = (“application/pdf”, “pdf”)


根据需要,在报告里将更多的信息展现出来。 这周末啥也没干,主要就搞明白了这个。




---


#### **【下面是我整理的2023年最全的软件测试工程师学习知识架构体系图】**




---


### **一、Python编程入门到精通**


### **二、接口自动化项目实战**


### 


### **三、Web自动化项目实战**


### **四、App自动化项目实战**


### 


### **五、一线大厂简历**


### **六、测试开发DevOps体系**


### 


### **七、常用自动化测试工具**


### **八、JMeter性能测试**


### 


### **九、总结(尾部小惊喜)**


生命不息,奋斗不止。每一份努力都不会被辜负,只要坚持不懈,终究会有回报。珍惜时间,追求梦想。不忘初心,砥砺前行。你的未来,由你掌握!


生命短暂,时间宝贵,我们无法预知未来会发生什么,但我们可以掌握当下。珍惜每一天,努力奋斗,让自己变得更加强大和优秀。坚定信念,执着追求,成功终将属于你!


只有不断地挑战自己,才能不断地超越自己。坚持追求梦想,勇敢前行,你就会发现奋斗的过程是如此美好而值得。相信自己,你一定可以做到! 


**最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:**


![img](https://img-blog.csdnimg.cn/img_convert/56718321a70478f3134a82db8f36b6e7.png)
![img](https://img-blog.csdnimg.cn/img_convert/c7e8b576ddd8f96654846f0502130fd4.png)

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 14
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值