我已经想了3个小时了,似乎不明白为什么这不起作用。我的硒服务器启动良好。
当我使用硒运行behat时,我的终端上不断出现以下错误
Fatal error: Call to a member function open() on null (Behat'Testwork'Call'Exception'FatalThrowableError)
我不知道这个错误信息是什么意思。如果有人能帮我弄清楚这一点,我将不胜感激。
下面是我的功能上下文代码,问题发生在
use Behat'Behat'Tester'Exception'PendingException;
use Behat'Behat'Context'Context;
use Behat'Behat'Context'SnippetAcceptingContext;
use Behat'Gherkin'Node'PyStringNode;
use Behat'Gherkin'Node'TableNode;
use Behat'MinkExtension'Context'MinkContext;
use Behat'Mink'Driver'Selenium2Driver;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
public $session;
public function __construct()
{
$driver = new 'Behat'Mink'Driver'Selenium2Driver('firefox');
$this->session = new 'Behat'Mink'Session($driver);
}
}
执行以下操作:
class FeatureContext extends MinkContext
{
public function __construct()
{
// Don't do anything with session or driver here
}
/**
* @Then /^I need selenium driver for this step$/
*/
public function iNeedSeleniumDriverForThisStep()
{
$driver = $this->getSession()->getDriver();
if (!$driver instanceof Selenium2Driver) {
throw new UnsupportedDriverActionException('Selenium2Driver not installed.');
return;
}
// ......
// ......
// Do whatever you want
}
}
示例behat.yml
default:
context:
class: FeatureContext
extensions:
Behat'Symfony2Extension'Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat'MinkExtension'Extension:
base_url: 'http://symfony.local/app_test.php/'
files_path: %behat.paths.base%/build/dummy/
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
同时在此网站中搜索Selenium2Driver
和selenium
关键字:http://www.inanzzz.com/index.php/posts/behat