如果我的 webdriver 测试失败(任何异常或断言错误),我想自动捕获屏幕截图.我正在使用 Python unittest 和 Selenium Webdriver.有没有人可以解决这个问题?
I want to automatic capturing screenshots if my webdriver tests failed (any exception or assertion error). I am using Python unittest and Selenium Webdriver. Does anyone have any solution to this problem?
在 Firefox 中做一些 webdriver 的东西...保存任何异常的截图到一个过时的图像文件:
do some webdriver stuff in Firefox... save screenshot on any exception to a dated image file:
from datetime import datetime
from selenium import webdriver
browser = webdriver.Firefox()
try:
# do some webdriver stuff here
except Exception as e:
print e
now = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
browser.get_screenshot_as_file('screenshot-%s.png' % now)
这篇关于Python 中 Selenium Webdriver 测试失败时的自动截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!