Automatic screenshots when test fail by Selenium Webdriver in Python

前端 未结 7 1221
小蘑菇
小蘑菇 2020-12-13 04:42

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 hav

7条回答
  •  盖世英雄少女心
    2020-12-13 04:54

    For me help this solution:

    def teardown_method(self, method):
        """Driver elimination"""
        if sys.exc_info():
            allure.attach('screenshot', self.driver.get_screenshot_as_png(), type=AttachmentType.PNG)
        self.driver.quit()
        pass
    

提交回复
热议问题