以编程方式(“在PHP内”)运行PHPUnit Selenium测试用例

如何在“ PHP内”运行测试,而不是使用“ phpunit”命令?例:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class MySeleniumTest extends PHPUnit_Extensions_SeleniumTestCase {

protected function setUp() {

$this->setBrowser("*firefox");

$this->setBrowserUrl("http://example.com/");

}

public function testMyTestCase() {

$this->open("/");

$this->click("//a[@href='/contact/']");

}

}

$test = new MySeleniumTest();

//I want to run the test and get information about the results so I can store them in the database, send an email etc.

?>

还是我必须将测试写入文件,通过system()/ exec()调用phpunit并解析输出?:(

回答:

只需使用随附的驱动程序即可。

require_once 'PHPUnit/Extensions/SeleniumTestCase/Driver.php';

//You may need to load a few other libraries. Try it.

然后,您需要像SeleniumTestCase一样进行设置:

$driver = new PHPUnit_Extensions_SeleniumTestCase_Driver;

$driver->setName($browser['name']);

$driver->setBrowser($browser['browser']);

$driver->setHost($browser['host']);

$driver->setPort($browser['port']);

$driver->setTimeout($browser['timeout']);

$driver->setHttpTimeout($browser['httpTimeout']);

然后:

$driver->open('/');

$driver->click("//a[@href='/contact/']");

以上是 以编程方式(“在PHP内”)运行PHPUnit Selenium测试用例 的全部内容, 来源链接: utcz.com/qa/406351.html

回到顶部