我的一般測試設置看起來像: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