Question

I'm having some problems with Behat and Mink. The driver used is Goutte. I'm trying to test my Symfony 2.1 application.

My behat.yml:

default:
extensions:
    Behat\Symfony2Extension\Extension:
        mink_driver: true
    Behat\MinkExtension\Extension:
        base_url: 'http://localhost/project/web/app_dev.php'
        goutte: ~

My test.feature:

Feature: Test
   In order to log-in
   As a user
   I need to be able to use the login-form

   Scenario: Logging in
       Given I am on "/login"
       When I fill in "username" with "admin"
       And I fill in "password" with "password"
       And I press "_submit"
       Then show last response
       Then I should see "Hello"

When I try to execute the tests (on Windows 7):

bin\behat @MyTestBundle

The tests stop at

And I press "_submit"

With this error:

Current URI must be an absolute URL ("/app_dev.php").

I've already tried almost all possible base_url paths and I didn't managed to get it work.

Do You have any idea's how to fix this problem?

The form I try to submit:

<form action="/app_dev.php/login_check" class="form-horizontal" method="post">
    <fieldset>
        <div class="control-group">
            <label class="control-label" for="username">Nazwa użytkownika:</label>

            <div class="controls"><input type="text" id="username" name="_username" value=""/></div>
        </div>

        <div class="control-group">
            <label for="password" class="control-label">Hasło:</label>

            <div class="controls"><input type="password" id="password" name="_password"/></div>
        </div>

        <div class="control-group">
            <div class="controls">
                <label for="remember_me" class="checkbox">
                    <input type="checkbox" id="remember_me" name="_remember_me" value="on"/>Nie wylogowuj mnie
                </label>
            </div>

        </div>
        <div class="form-actions">
            <input type="submit" class="btn-primary" id="_submit" name="_submit"
                   value="Zaloguj"/>
            <a href="/app_dev.php/register/" class="btn btn-success">Rejestracja</a>
        </div>
    </fieldset>
</form>
Était-ce utile?

La solution 2

I've found a solution to my problem today.

Indeed the problem Was in the path function. The path function should be replaced with the twig url function.

What's interesting: changing the function to url in the form action attribute won't help. In my base layout i had:

<base href="{{ path('_default')}}"/>

This one line of code caused the problem, it should be:

<base href="{{ url('_default')}}"/>

After this change the test works as expected.

Autres conseils

In your twig template, when you create the login_check url, you have to create an absolute url (the third argument of path, being true to create an absolute url) :

{{ path('route', {}, true) }}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top