I'm trying to add something to my teardown method so that in the event of an exception it takes a screenshot before closing the browser instance.
So far I have: -
def tearDown(self):
if sys.exc_info()[0]:
test_method_name = self._testMethodName
screenshot_name = common_functions.create_unique_id() + test_method_name + ".png"
common_functions.take_screenshot(self.driver, screenshot_name)
self.driver.close()
As it is the screenshot is never taken and if I change the if statement to if sys.exc_info():
then it always takes a screenshot regardless of whether an exception is raised.
When I query what is returned by sys.exc_info
I get None, None, None
. I was hoping that the first element should contain the exception name at least.