开发者

PHPUnit Selenium captureScreenshotOnFailure does not work?

开发者 https://www.devze.com 2022-12-30 18:20 出处:网络
I am using PHPUnit 3.4.12 to drive my selenium tests. I\'d like to be able to get a screenshot taken automati开发者_开发技巧cally when a test fails. This should be supported as explained at http://www

I am using PHPUnit 3.4.12 to drive my selenium tests. I'd like to be able to get a screenshot taken automati开发者_开发技巧cally when a test fails. This should be supported as explained at http://www.phpunit.de/manual/current/en/selenium.html#selenium.seleniumtestcase.examples.WebTest2.php

class WebTest 
{
    protected $captureScreenshotOnFailure = true;
    protected $screenshotPath = 'C:\selenium';
    protected $screnshotUrl = 'http://localhost/screenshots';

    public function testLandingPage($selenium)
    {
            $selenium->open("http://www.example.com");
            $selenium->fail("fail");
            ...
    }
}

As you can see, I am making the test to fail and in theory when it does it should take a screenshot and put it in C:\selenium, as I am running the selenium RC server on Windows.

However, when I run the test it will just give me the following:

[root@testbox selenium]$ sh run
PHPUnit 3.4.12 by Sebastian Bergmann.

F

Time: 8 seconds, Memory: 5.50Mb

There was 1 failure:

1) WebTest::testLandingPage
fail

/home/root/selenium/WebTest.php:32

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

I do not see any screenshot in C:\selenium. I can however get a screenshot with $selenium->captureScreenshot("C:/selenium/image.png");

Any ideas or suggestions most welcome.

Thanks


The error handling of this is rather poor on phpunit's part; if everything isn't perfect it will silently ignore your other options without a warning.

As Dave mentioned, if any of the variables are misspelled it will silently not work, and you might also try assigning them to the instance in your setUp.

Also, not every condition triggers a screenshot. Try $selenium->assertTextPresent("foobarbaz") instead of your $selenium->fail() for a sanity check.


you may try adding these line of codes


    try {
        $this->assertTrue($this->isTextPresent("You searched for \"Brakes\" (2 matches)"));
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->verificationErrors, $e->toString());
        $this->drivers[0]->captureEntirePageScreenshot($this->screenshotPath . DIRECTORY_SEPARATOR . rawurlencode($this->getLocation()) . '.png');
    }


I recently had this error because I was following the tutorial.

The first example in the documentation is for PHPUnit_Extensions_Selenium2TestCase. All of the others on the page are for PHPUnit_Extensions_SeleniumTestCase.

Perhaps change

extends PHPUnit_Extensions_Selenium2TestCase

to

extends PHPUnit_Extensions_SeleniumTestCase
0

精彩评论

暂无评论...
验证码 换一张
取 消