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
Another method would be to add the following to your tearDown method:
if sys.exc_info()[0]:
test_method_name = self._testMethodName
self.driver.save_screenshot("Screenshots/%s.png" % test_method_name)
This would be assuming a test class like this:
class SeleniumTest(unittest2.TestCase):
...
def tearDown(self):
if sys.exc_info()[0]:
test_method_name = self._testMethodName
self.driver.save_screenshot("Screenshots/%s.png" % test_method_name)
super(SeleniumTest, self).tearDown()
def test_1(self):
...
def test_2(self):
...