Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
784 B
1
Indexable
def tearDown(self):
        """Tear down the WebDriver instance and capture screenshots on failure or success."""
        # Check if the test has failed
        if any(error[1] for error in self._outcome.errors) or any(error[1] for error in self._outcome.failures):
            screenshot_filename = f"screenshot_{time.strftime('%Y%m%d-%H%M%S')}_failure.png"
            self.driver.save_screenshot(screenshot_filename)
            print(f"Failure screenshot {screenshot_filename} saved.")
        else:
            screenshot_filename = f"screenshot_{time.strftime('%Y%m%d-%H%M%S')}_success.png"
            self.driver.save_screenshot(screenshot_filename)
            print(f"Success screenshot {screenshot_filename} saved.")

        # Quit the WebDriver
        self.driver.quit()
Leave a Comment