nowiko
nowiko

Reputation: 2567

Configure behat with Symfony2

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: ~

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?

Upvotes: 0

Views: 1685

Answers (2)

BentCoder
BentCoder

Reputation: 12740

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

SELENIUM

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

Run it: java -jar selenium-server-standalone-2.43.1.jar

CONTEXT FEATURE

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
}

TESTS

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

Upvotes: 3

Michael Sivolobov
Michael Sivolobov

Reputation: 13300

You don't need to import behat.yml in your config.yml.

Behat works independently from Symfony. And these configs cannot be messed. In the documentation from link that you provide you can find that behat.yml must be located at the project's root folder.

Upvotes: 2

Related Questions