Automatic screenshots when test fail by Selenium Webdriver in Python

前端 未结 7 1186
小蘑菇
小蘑菇 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 05:01

    You can start form exploring self._outcome.errors[1] where it is possible to find information about the errors.
    i.e. below code will work only for assertion errors

     def tearDown(self):
            if self._outcome.errors[1][1] and hasattr(self._outcome.errors[1][1][1], 'actual'):
                self.driver.save_screenshot(self._testMethodName + '.png')
    

提交回复
热议问题