我正在尝试配置 Behat,但出现了一些错误。这是配置:
default:
suites:
default:
contexts:
- FeatureContext:
session: '@session'
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
sessions:
default:
symfony2: ~
导入到 config.yml。当我尝试运行 clear:cache 或 bin/behat 时,我得到:
There is no extension able to load the configuration for "default" (in /var/www/ontheway/app/config/behat.yml). Looked for namespace "default", found "framework", "security", "twig",
我执行这里描述的所有步骤: behat docs 我做错了什么?
最佳答案
我正在分享我在所有 Symfony2 项目中使用的内容。 Behat+Mink+ Selenium
Composer :
mySymfonyProject/composer.json:
"require": {
"behat/behat": "2.5.*@stable",
"behat/behat-bundle": "1.0.0",
"behat/symfony2-extension": "1.1.2",
"behat/mink": "1.5.0",
"behat/mink-extension": "~1.3",
"behat/mink-selenium2-driver": "1.1.1",
"behat/mink-goutte-driver": "1.0.9"
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "dev",
行为
mySymfonyProject/behat.yml:
default:
context:
class: FeatureContext
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://mysymfonyproject.local/app_test.php/'
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
Selenium
下载到您的项目中。是here ,确保您下载了页面中间的 2.43.1 版本。
运行它:java -jar selenium-server-standalone-2.43.1.jar
上下文特征
mySymfonyProject/src/Site/CommonBundle/Features/Context/FeatureContext.php
<?php
namespace Site\CommonBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class FeatureContext extends MinkContext implements KernelAwareInterface
{
/**
* Hold Symfony kernel object.
*
* @var object Kernel Object.
*/
protected $kernel;
/**
* Helps to use doctrine and entity manager.
*
* @param KernelInterface $kernelInterface Interface for getting Kernel.
*/
public function setKernel(KernelInterface $kernelInterface)
{
$this->kernel = $kernelInterface;
}
//And your own methods
}
测试
当你有功能文件时,你可以像这样运行它们(这会一次性运行。有关更多信息,请阅读 behat 文档):
bin/behat @SiteCommonBundle
关于symfony - 使用 Symfony2 配置 behat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27542896/