我的一般测试设置看起来像:PHPUnit和Selenium - 如何获取测试使用的驱动程序?
class MySeleniumTest extends PHPUnit_Extensions_SeleniumTestCase{
public static $browsers = array(
array(
'name' => 'Mozilla - Firefox',
'browser' => '*firefox',
'host' => 'localhost',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Google - Chrome',
'browser' => '*googlechrome',
'host' => 'localhost',
'port' => 4444,
'timeout' => 30000,
)
);
//etc
}
,从这里单独的测试文件看起来像:
class MyTest extends MySeleniumTest{
public function setUp(){
parent::setUp();
$this->setUser(1);
}
public function testPageTitle(){
//Login and open the test page.
$this->login(8);
$this->open('/test/page');
//Check the title.
$this->assertTitle('Test Page');
}
}
从这里,当我运行MyTest.php
PHPUnit的,PHPUnit的自动运行的每个测试用例在MyTest.php
。此外,它会分别在每个指定的浏览器上运行每个测试。我想要做的就是获取有关驱动程序在该测试用例中运行特定测试用例的信息。所以像这样:
public function testPageTitle(){
//Login and open the test page.
$this->login(8);
$this->open('/test/page');
//Check the title.
$this->assertTitle('Test Page');
$driver = $this->getDriver();
print($driver['browser']); //or something.
}
但是,这是行不通的。而$this->getDrivers()
只是在测试中增加了更多的驱动程序,并且仅供设置使用。有任何想法吗?谢谢!
你应该看一下它的源代码,如果你需要确定这样的事情。试试'$ this-> drivers [0] - > getBrowser()' – 2013-03-08 17:19:32
@ColinMorelli:我正在浏览源代码。我曾看过'$ this-> drivers',但是,这段代码是不是让我成为第一个驱动程序?问题是我想获得当前测试使用的驱动程序。有关如何获得这项工作的任何建议? – 2013-03-08 17:28:13