1

I have a suite of Selenium tests. Sometimes, for example, an 'assertIsElementPresent' will fail. In certain circumstances, this may be because someone broke something and the result of the sequence of UI clicking is an error that has resulted in the site's error page being shown.

How do I check if this has happened for every single failure, without having to implement a call to the below method everwhere?

    $isErrorPage = $selenium->isElementPresent("id=siteErrorPage");
    if ($isErrorPage){
        $html = $selenium->getHtmlSource();
        //send the $html to devs, log it, etc.
    }

The intention is simply to email the html source of the page that's being shown if the page has turned out to be an error page.

1 Answer 1

1

I looks like you would have to extend the PHPUnit_Extensions_Selenium2TestCase class, and overload onNotSuccessfulTest(). Add your code in there and make all your testcases extend your new class instead of PHPUnit_Extensions_Selenium2TestCase. Make sure to call parent::onNotSuccessfulTest() in your extended version.

I haven't tested this, but from studying the code, this should get you what you want. Looks like the stop() command is sent on session __destruct(), so the session should still be active when you go to try and get your screenshot.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.