我已经编写了基于PHP的Selenium测试用例。我想在执行这些测试用例时获得代码覆盖率。我的测试用例:
<?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 具有不同于应用程序的主机,是否可以访问该 cookie?
我在许多论坛中看到了这个问题的讨论,但没有一个给出了具体的答案。
许多论坛建议将服务器名称从 127.0.0.1
更改为 localhost
。在我的情况下,它已经是 localhost。
如果有任何建议,请告诉我。谢谢, Ravuri