使用Symfony2配置behat [英] Configure behat with Symfony2

查看:101
本文介绍了使用Symfony2配置behat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置Behat,但是出现一些错误.这是配置:

I'm trying to configure Behat, but I have some errors. Here is config:

default:
suites:
  default:
      contexts:
          - FeatureContext:
              session:   '@session'
extensions:
  Behat\Symfony2Extension: ~
  Behat\MinkExtension:
      sessions:
      default:
      symfony2: ~

导入到config.yml.当我尝试运行clear:cache或bin/behat我得到:

Import to config.yml. And when I try run clear:cache or bin/behat I getting:

 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", 

我按照此处所述执行所有步骤: 相似的文档 我在做什么错了?

I do all steps what described here: behat docs What I am doing wrong?

推荐答案

我正在分享我在所有Symfony2项目中一直使用的内容. Behat + Mink + Selenium

I'm sharing what I have been using for all my Symfony2 projects. 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",

BEHAT

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

下载到您的项目中.可以在此处确保下载位于页面的中间.

Download into your project. It is here, make sure you download 2.43.1 version which is in the middle of the page.

运行它: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 doc):

When you have feature files you can run them like this (this runs all in one go. for more info read behat doc):

bin/behat @SiteCommonBundle

这篇关于使用Symfony2配置behat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆