I'm using the Python unittest library to write some tests with Selenium. One of these tests involves going forward from one page to the next, checking an assertion, and then returning to the previous page as so:
def test_CheckNextPage(self):
self.nextPageLink.click()
self.assertEqual('The Next Page', self.driver.title)
self.driver.back()
If in the event that the assertion fails, the self.driver.back()
line is never reached and so all further tests are run on the wrong page, leading to them all being errors.
Is there any way to write a block of code to be run in the event of a failure after an assertion, so if it fails I can run some different code than if the assertion were to pass? (this block of course including the self.driver.back()
line).