Selenium don't show failed number lines Selenium don't show failed number lines selenium selenium

Selenium don't show failed number lines


I've had the same problem (albeit on a LAMP server), as I quite rely on these line numbers along with screenshots to figure out exactly what's going wrong in my tests. The bug, which I assume this is, is apparently reported. See https://github.com/sebastianbergmann/phpunit-selenium/issues/81 for reference.

As a temporary workaround I've forced the line number into the error message in the exception that is being thrown (because the line number can of course be found in the trace). As a side-effect, most exceptions are rethrown and I am only throwing PHPUnit_Framework_Error, but at least I get the line number in the output. As a temporary workaround until this is fixed, this works for me.

To achieve this, I extend PHPUnit_Extensions_SeleniumTestCase with my own SeleniumTestCase, and put these functions in it:

Very slightly modified version of this function for my own use: https://stackoverflow.com/a/6608751

protected function dumpStack(Exception $e) {    $stack = '';    foreach ($e->getTrace() as $trace) {        if (isset($trace['file'])        &&            isset($trace['line'])        &&            isset($trace['class'])       &&            isset($trace['function']))        {            $stack .= PHP_EOL .                $trace['file']     . ':' .                $trace['line']     . ' ' .                $trace['class']    . '::' .                $trace['function'];        }    }    return $stack;}

I override onNotSuccessfulTest from PHPUnit_Extensions_SeleniumTestCase:

protected function onNotSuccessfulTest(Exception $e) {    try {        parent::onNotSuccessfulTest($e);    }    catch (PHPUnit_Framework_IncompleteTestError $e) {        // Don't do anything with the incomplete test exception        throw $e;    }    catch (PHPUnit_Framework_SkippedTestError $e) {        // Don't do anything with the skipped test exception        throw $e;    }    catch (Exception $e_parent) {        // Include line number for specific test file in error        $error_msg = chr(10).chr(10).$this->dumpStack($e);        throw new PHPUnit_Framework_Error($e_parent->getMessage().$error_msg, $e_parent->getCode(), $e_parent->getFile(), $e_parent->getLine(), $e_parent->getTrace());     }}

I don't like this hack, so if anyone has a better solution, I'd be happy to hear it!

UPDATE:I forgot to mention this initially: You of course have to make the tests extend your own custom SeleniumTestCase, and not the PHPUnit_Extensions_SeleniumTestCase.