PHPUnit&;Selenium-如何让测试使用驱动程序?
我的常规测试设置如下所示:PHPUnit&;Selenium-如何让测试使用驱动程序?,php,selenium,phpunit,driver,Php,Selenium,Phpunit,Driver,我的常规测试设置如下所示: 类MySeleniumTest扩展了PHPUnit\u Extensions\u SeleniumTestCase{ 公共静态$browsers=array( 排列( 'name'=>'Mozilla-Firefox', '浏览器'=>'*firefox', '主机'=>'本地主机', “端口”=>4444, “超时”=>30000, ), 排列( 'name'=>'Google-Chrome', “浏览器”=>“*谷歌浏览器”, '主机'=>'本地主机', “端口”
类MySeleniumTest扩展了PHPUnit\u Extensions\u SeleniumTestCase{
公共静态$browsers=array(
排列(
'name'=>'Mozilla-Firefox',
'浏览器'=>'*firefox',
'主机'=>'本地主机',
“端口”=>4444,
“超时”=>30000,
),
排列(
'name'=>'Google-Chrome',
“浏览器”=>“*谷歌浏览器”,
'主机'=>'本地主机',
“端口”=>4444,
“超时”=>30000,
)
);
//等
}
从这里看,一个单独的测试文件如下所示:
classmytest扩展了MySeleniumTest{
公共功能设置(){
父::设置();
$this->setUser(1);
}
公共函数testPageTitle(){
//登录并打开测试页面。
$this->login(8);
$this->open('/test/page');
//检查标题。
$this->assertTitle(“测试页”);
}
}
从这里开始,当我使用PHPUnit运行MyTest.php
时,PHPUnit将自动运行MyTest.php
中的每个测试用例。此外,它分别在每个指定的浏览器上运行每个测试。我希望能够从测试用例中获取运行特定测试用例的驱动程序的信息。比如:
公共函数testPageTitle(){
//登录并打开测试页面。
$this->login(8);
$this->open('/test/page');
//检查标题。
$this->assertTitle(“测试页”);
$driver=$this->getDriver();
打印($driver['browser']);//之类的东西。
}
然而,这是行不通的。而
$this->getDrivers()
只是将更多的驱动程序添加到测试中,并且只假设安装程序使用这些驱动程序。有什么想法吗?谢谢 即使$this->drivers
是一个数组,但其中始终只有一个元素。你可以检查一下。所以
$this->drivers[0]
包含有关当前运行的浏览器的信息,您可以使用$this->drivers[0]->getBrowser()
输出浏览器名称
例如:
require_once 'MySeleniumTest.php';
class MyTest extends MySeleniumTest{
public function setUp(){
parent::setUp();
$this->setBrowserUrl('http://www.google.com/');
}
public function testPageTitle(){
$this->open('http://google.com');
echo "{$this->drivers[0]->getBrowser()}\n";
}
}
产出:
PHPUnit 3.7.18 by Sebastian Bergmann.
.*firefox
.*googlechrome
Time: 7 seconds, Memory: 3.50Mb
OK (2 tests, 0 assertions)
如果您需要确定这样的事情,您应该查看它的来源。请尝试
$this->drivers[0]->getBrowser()
@ColinMorelli:我正在查看源代码。我已经看过了$this->drivers
,但是,这段代码不就是让我成为第一个驱动程序吗?问题是我想得到测试当前正在使用的驱动程序。有什么建议可以让它工作吗?哦!我还以为里面有司机名单呢。伟大的