PHPUnit Selenium captureScreenshotOnFailure无法正常工作吗? [英] PHPUnit Selenium captureScreenshotOnFailure does not work?

查看:77
本文介绍了PHPUnit Selenium captureScreenshotOnFailure无法正常工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPUnit 3.4.12进行硒测试.我希望能够在测试失败时自动获取屏幕截图.如 http中所述,应支持此功能. ://www.phpunit.de/manual/current/zh/selenium.html#selenium.seleniumtestcase.examples.WebTest2.php

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");
            ...
    }
}

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

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.

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

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.

谢谢

推荐答案

对此的错误处理在phpunit方面相当差.如果一切都不尽如人意,它将在没有警告的情况下默默地忽略您的其他选择.

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.

如Dave所述,如果任何变量的拼写错误,它都将无声地工作,并且您也可以尝试将其分配给setUp中的实例.

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.

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

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

这篇关于PHPUnit Selenium captureScreenshotOnFailure无法正常工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆