2

Say I have this function:

    def tearDown(self):
    """ clean up by closing the browser window """
    self.driver.quit()

I want to skip closing the browser if the test failed or errored out (so I can examine what was on the screen when the test last left off). Is this possible?

Let's say I don't even care if the browser closes, because I can do

self.driver.save_screenshot('path')

I still need the "if test failed" logic to make that happen, so I won't have to dig through hundreds of screenshots to find the failed test.

I'm using nose as my test runner (http://nose.readthedocs.org/en/latest/).

2 Answers 2

2

As far as I can tell, your question is more about Nose than Selenium. You want errors and failures to do something that successes do not. I do not have any experience with Nose, but the documentation suggests that you could write your own ErrorClass plugin that will take a screenshot when the error/failure occurs.

2

I can't believe it was this simple, but this seems to work!

def tearDown(self):
    """ clean up by closing the browser window """
    if not Exception:  # leave failed test windows open
        self.driver.quit()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.