PHPUnit Selenium captureScreenshotOnFailure 不起作用?

发布于 2024-09-01 18:29:19 字数 1227 浏览 7 评论 0原文

我正在使用 PHPUnit 3.4.12 来驱动我的硒测试。我希望能够在测试失败时自动截取屏幕截图。这应该得到支持,如 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");
            ...
    }
}

如您所见,我正在使测试失败,理论上当它失败时它应该截取屏幕截图并将其放在 C:\selenium 中,因为我在 Windows 上运行 selenium RC 服务器。

但是,当我运行测试时,它只会给出以下内容:

[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.

我在 C:\selenium 中没有看到任何屏幕截图。不过,我可以使用 $selenium->captureScreenshot("C:/selenium/image.png"); 获取屏幕截图

欢迎任何想法或建议。

谢谢

I am using PHPUnit 3.4.12 to drive my selenium tests. I'd like to be able to get a screenshot taken automatically 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

分分钟 2024-09-08 18:29:19

phpunit 的错误处理相当差;如果一切都不完美,它会默默地忽略您的其他选项,而不发出警告。

正如 Dave 提到的,如果任何变量拼写错误,它将默默地不起作用,您也可以尝试将它们分配给设置中的实例。

此外,并非所有条件都会触发屏幕截图。尝试使用 $selenium->assertTextPresent("foobarbaz") 而不是 $selenium->fail() 进行健全性检查。

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.

一个人的旅程 2024-09-08 18:29:19

你可以尝试添加这行代码

    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');
    }

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');
    }

少女的英雄梦 2024-09-08 18:29:19

我最近遇到了这个错误,因为我正在遵循教程。

文档中的第一个示例适用于 PHPUnit_Extensions_Selenium2TestCase。页面上的所有其他内容均适用于 PHPUnit_Extensions_SeleniumTestCase。

或许

extends PHPUnit_Extensions_Selenium2TestCase

改成

extends PHPUnit_Extensions_SeleniumTestCase

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文