我已经为PHP编写了Selenium测试用例。我希望在执行这些测试用例时获得代码覆盖率。我的测试用例:PHPUnitSeleniumTestcase的代码覆盖率
<?php
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
protected $coverageScriptUrl = 'http://applicationname/phpunit_coverage.php';
protected function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://applicationname");
$this->setCollectCodeCoverageInformation(true);
$this->setTestId("10001");
$this->setHost("applicationname");
}
public function testMyTestCase()
{
$this->open("http://applicationame");
$this->assertEquals("title", $this->getTitle());
$this->type("id=ext-comp-1002", "testuser");
$this->fireEvent("id=ext-comp-1002", "blur");
$this->type("id=ext-comp-1003", "testpassword");
$this->fireEvent("id=ext-comp-1003", "blur");
$this->click("ext-gen45");
$this->waitForPageToLoad("200000");
}
}
?>
我已按照链接“http://www.phpunit.de/manual/current/en/selenium.html”
提到的步骤运行测试我后无法找到代码覆盖率。在phpunit_coverage.php中,它正在查找名为PHPUNIT_SELENIUM_TEST_ID的cookie。这个cookie是在Driver.php中创建的,我发现cookie可用,但它的主机名设置为“localhost”而不是我的应用程序名。
Cookie生存时间被设置为会话即意味着在测试用例执行后立即这个cookie将不再可用,当我尝试启动phpunit_coverage.php时,它无法找到cookie和信息,因此没有代码覆盖率出现。
事情我不明白:
protected $coverageScriptUrl = 'http://applicationname/phpunit_coverage.php';
- 如果cookie具有比其他应用程序不同的主机可以在此浏览器来accessable
我已经看到了这个问题,正在讨论很多论坛,但有一个具体的答案
许多论坛建议使用localhost
而不是127.0.0.1
作为服务器名称。在我的情况下,它已经是localhost。
在这方面的任何建议将有所帮助。
感谢, Ravuri
也许这个问题的答案可能会提供一些帮助:http://stackoverflow.com/questions/11270527/does-phpunit-selenium-code-coverage-work – Potherca