【发布时间】:2013-02-24 07:50:15
【问题描述】:
我的一般测试设置如下所示:
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');
}
}
从这里开始,当我使用 PHPUnit 运行 MyTest.php 时,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() -
@ColinMorelli:我正在查看源代码。我看过
$this->drivers,但是,这段代码不是让我成为第一个驱动程序吗?问题是我想获取测试当前正在使用的驱动程序。关于如何让它发挥作用的任何建议?
标签: php selenium phpunit driver