3

Behat Api tests seem to be hitting the dev environment (dev cache folder is created, and it uses the dev database).

It creates the test database with no problems and adds the data (BeforeScenario method in FeatureContext).

My set up is as follows:

Have an app_test.php front controller.

default:
    formatters:
        pretty: true
    autoload:
        '': %paths.base%/app/features/bootstrap
    suites:
        app_suite:
            type: symfony_bundle
            bundle: AppBundle
            contexts:
                - AppBundle\Features\Context\FeatureContext:
                    parameters:
                        base_url: http://mysite.dev
            mink_session: default
            mink_javascript_session: selenium2
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            sessions:
                default:
                    symfony2: ~

This: http://www.forouzani.com/installing-behat-mink-and-selenium2-in-symfony2.html may have worked previously with behat 2, but I'm using behat 3 now so it doesn't seem to work as expected!

Thanks

7
  • Did you change "dev" to "test' in your app_test.php? Do you have any selenium tests? Looks like they're configured to go through the default front controller ("mysite.dev" is used instead of "mysite.dev/app_test.php" - unless app_test.php is the default front controller for this domain). Commented Mar 12, 2015 at 17:59
  • yes it was changed to test in app_test. the link i added had this: extensions: Behat\Symfony2Extension\Extension: mink_driver: true kernel: env: test debug: true . which didn't seem to work for me Commented Mar 12, 2015 at 18:07
  • i tried having /app_test.php in the base_url as well, but didn't seem to work :( Commented Mar 12, 2015 at 18:09
  • You should configure base_url for the MinkExtension, see github.com/Behat/MinkExtension/blob/master/doc/… Also, note that if you call session directly in your context files, you need to prepend the base url yourself to any urls you call. Commented Mar 12, 2015 at 18:14
  • it just seems to be ignoring /app_test.php, from any base_url I add (including if I use symfony2's server): 127.0.0.1:8000/app_test.php Commented Mar 12, 2015 at 18:30

1 Answer 1

7

If you still cannot do after following steps below, I'll try to give you step by step example when I have time.

Update composer.json

"require": {
    "php": ">=5.4",
    "behat/behat": "3.0.14",
    "behat/behat-bundle": "1.0.0",
    "behat/symfony2-extension": "2.0.0",
    "behat/mink": "1.6.0",
    "behat/mink-extension": "2.0.1",
    "behat/mink-browserkit-driver": "1.2.0",
    "behat/mink-goutte-driver": "1.1.0",
    "behat/mink-selenium2-driver": "1.2.0"
},

Run composer

php composer.phar update

Create behat.yml file.

default:
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            base_url: http://behat-three.local/app_test.php
            browser_name: firefox
            sessions:
                goutte: # fast, CLI, browser, no javascript support
                    goutte: ~
                selenium2: # fast, CLI, opens up a browser
                    selenium2: ~
                symfony2: # bleeding fast, CLI, no browser
                    symfony2: ~
    suites:
        test_suite:
            type: symfony_bundle
            bundle: SiteMainBundle
            mink_session: selenium2
            contexts:
                - Site\MainBundle\Features\Context\FeatureContext:
                    output_path: build/behat/output
                    screen_shot_path: build/behat/screenshot

Initiate behat to create relevant files and fodlers to work with.

php bin/behat --init --suite=test_suite

Then make sure you have app_test.php and update AppKernel line.

# your_project/web/app_test.php

$kernel = new AppKernel('test', true);

Then create config_test.yml with its own settings, something like.

# your_project/app/config/config_test.yml

imports:
    - { resource: config_dev.yml }

framework:
    test: ~
    session:
        storage_id: session.storage.mock_file
    profiler:
        collect: false

web_profiler:
    toolbar: false
    intercept_redirects: false

swiftmailer:
    disable_delivery: true

doctrine:
   dbal:
       connections:
         hello:
           driver:   pdo_sqlite
           path:     %kernel.cache_dir%/test_hello.db
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.