phpunit-selenium icon indicating copy to clipboard operation
phpunit-selenium copied to clipboard

Line number on Errors not printed

Open ghost opened this issue 13 years ago • 9 comments

Running phpunit 3.6.5.

Upon test completion the line number for a given error or failure is not printed out.

This is like this with --verbose and without.

ghost avatar Dec 21 '11 23:12 ghost

Can you provide a sample output and what you expect instead? I suspect this is because the exception is rethrown.

giorgiosironi avatar Dec 22 '11 09:12 giorgiosironi

Getting...

Class::Method Current URL: www.example.com

Failed asserting that false is true.

Expecting...

Class::Method Current URL: www.example.com

Failed asserting that false is true.

/path/to/test/TestCase.php:107

ghost avatar Dec 22 '11 16:12 ghost

Having the same problem +1

stjohnjohnson avatar Mar 14 '12 21:03 stjohnjohnson

Same problem. Here's a quick temporary fix: http://stackoverflow.com/questions/9227232/selenium-dont-show-failed-number-lines

chilicheech avatar Mar 14 '12 21:03 chilicheech

Cannot replicate. This test:

public function testAssertionsErrorsAreDisplayedWithTheOriginalStackTrace()
    {
        $this->assertFalse(true);
    }

results in:

$ php run-phpunit.php --filter testAssertionsErrors Tests/SeleniumTestCaseFailuresTest.php 
#!/usr/bin/env php
PHPUnit @package_version@ by Sebastian Bergmann.

Configuration read from /home/giorgio/code/phpunit-selenium/phpunit.xml

F

Time: 4 seconds, Memory: 4.50Mb

There was 1 failure:

1) Extensions_SeleniumTestCaseFailuresTest::testAssertionsErrorsAreDisplayedWithTheOriginalStackTrace
Failed asserting that true is false.

/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/Constraint.php:145
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/Constraint.php:92
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/Assert.php:2100
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/Assert.php:866
/home/giorgio/code/phpunit-selenium/Tests/SeleniumTestCaseFailuresTest.php:84
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/TestCase.php:936
/home/giorgio/code/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php:647
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/TestCase.php:794
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/TestResult.php:649
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/TestCase.php:739
/home/giorgio/code/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php:512
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/TestSuite.php:772
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/Framework/TestSuite.php:745
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/TextUI/TestRunner.php:325
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/TextUI/Command.php:174
/home/giorgio/code/phpunit-selenium/vendor/phpunit/PHPUnit/TextUI/Command.php:128
/home/giorgio/code/phpunit-selenium/vendor/phpunit/phpunit.php:46
/home/giorgio/code/phpunit-selenium/run-phpunit.php:53

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

Generating code coverage report, this may take a moment.

which contains the line number of the failed assertion. Does this test work differently for you?

giorgiosironi avatar Mar 15 '12 12:03 giorgiosironi

The issues seems to be related to the auto capture of screenshots on failure.

This test:

class SelTest extends \PHPUnit_Extensions_SeleniumTestCase { public function setUp() { $this->setBrowserUrl('https://github.com'); }

/**
 * @test
 */
public function testError()
{
    $this->assertFalse(true);
}

}

Results in:

$ phpunit -c phpunit.xml SelTest.php PHPUnit 3.6.2 by Sebastian Bergmann.

Configuration read from /workspace/phpunit.xml

Sel

SelTest: Firefox testError F

Time: 0 seconds, Memory: 4.75Mb

There was 1 failure:

  1. SelTest::testError Failed asserting that true is false.

/workspace/SelTest.php:15

FAILURES! Tests: 1, Assertions: 1, Failures: 1.


However, this test:

class SelTest extends \PHPUnit_Extensions_SeleniumTestCase { protected $captureScreenshotOnFailure = true; protected $screenshotPath = '/tmp'; protected $screenshotUrl = 'test';

public function setUp()
{
    $this->setBrowserUrl('https://github.com');
}

/**
 * @test
 */
public function testError()
{
    $this->assertFalse(true);
}

}

Results in:

$ phpunit -c phpunit.xml SelTest.php PHPUnit 3.6.2 by Sebastian Bergmann.

Configuration read from /workspace/phpunit.xml

Sel

SelTest: Firefox testError E

Time: 26 seconds, Memory: 4.75Mb

There was 1 error:

  1. SelTest::testError Current URL: http://localhost:4444/selenium-server/core/Blank.html?start=true Screenshot: test/5a3a2580eb1b9285408f039e760637a0.png

Failed asserting that true is false.

FAILURES! Tests: 1, Assertions: 1, Errors: 1.


So, as you see, the error line numbers are only not printed when screenshot capture on failure is being used.

Btw, I'm using PHPUnit 3.6.2 and PHPUnit_Selenium 1.2.3

Hope this helps.

chilicheech avatar Mar 15 '12 21:03 chilicheech

When screenshots are off failures trigger failures. When screenshots are on failures trigger errors as opposed to failures. However, shouldn't errors also show the error line number?

chilicheech avatar Mar 15 '12 21:03 chilicheech

Ok, we have some common ground now. When screenshots have to be taken, their path has to be shown to the user; the current solution is to generate a new exception because PHPUnit does not let us modify the message of the original one.

giorgiosironi avatar Mar 16 '12 08:03 giorgiosironi

This is the problem: PHPUnit lets the line be overridden but not the trace. https://github.com/sebastianbergmann/phpunit/issues/471

giorgiosironi avatar Mar 16 '12 08:03 giorgiosironi