What's the best way for me to check in PHPUnit whether my test execution succeeded or failed?
I am trying to take a screenshot for my Selenium window, but only when my test has failed. I've tried taking a screenshot in onNotSuccessfulTest()
, but if I am always closing my window in tearDown()
(which I should be doing), then there is no session to take the screenshot with in my onNotSuccessfulTest()
function.
The solution I'm thinking of involves checking for whether the test succeeded or failed in the tearDown()
, determining whether or not to take a screenshot.
I am using PHPUnit 3.6 [reviewed for 9.5] and Facebook's php-webdriver, so as far as I know, I don't have the variable $captureScreenshotOnFailure
.
Thoughts?
You can check the return value from getStatus()
and take a screenshot under your desired conditions.
protected function tearDown() {
$status = $this->getStatus();
if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
|| $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
// take a screenshot...
}
}
See runBare()
for where the status is set based on the exception thrown from the test method. You might want to take a screenshot for skipped tests too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With