Lravel 5, Behat, Mink: base_url parameter is not readable from behat.yml

I am using Laravel 5 , Behat and Mink Extension for Laravel . composer.json

piece for installing components:

"require-dev": {
    "phpunit/phpunit": "~4.0",
    "behat/behat": "^3.0",
    "behat/mink": "^1.6",
    "behat/mink-extension": "^2.0",
    "laracasts/behat-laravel-extension": "^1.0"
}

      

I set the base url to behat.yml

, all file content:

default:
    extensions:
        Laracasts\Behat:
            # env_path: .env.behat
        Behat\MinkExtension:
            base_url: http://localhost/leaveTracker/public
            default_session: laravel
            laravel: ~

      

Note that I've set base_url here as:

            base_url: http://localhost/leaveTracker/public

      

Also I wrote this example function:

Feature: Viewing the list of employees
In order to operate the employees' data
As a user
I need to see the list of employees

Scenario: I have the option to add employee
    Given I am on page "/employee"
    Then the current URL should be "http://localhost/leaveTracker/public/employee"

      

And the relevant part for FeatureContext.php

:

/**
 * @Then the current URL should be :arg1
 */
public function theCurrentUrlShouldBe($arg1)
{
    PHPUnit::fail($this->getSession()->getCurrentUrl());
}

      

Here I am getting the following error, which is normal for me:

Scenario: I have the option to add employee                                      
Given I am on page "/employee"                                                 
Then the current URL should be "http://localhost/leaveTracker/public/employee" 
    Failed asserting that two strings are equal.
    --- Expected
    +++ Actual
    @@ @@
    -'http://localhost/employee'
    +'http://localhost/leaveTracker/public/employee'

      

So now my question is , why is base_url

n't it read from a behat.yml

file?

Note: I also tried to install base_url: https://test.com

, but still it acceptshttp://localhost/employee

+3


source to share


2 answers


I faced the same issue when upgrading from Behat 2.x to Behat 3.x

behat.yml: [define base_url]

extensions:
    Behat\MinkExtension:
        base_url: 'http://localhost/index.php'

      



In your context classes that propagate from the call to RawMinkContext:

$this->visitPath($url);

      

This feature combines $config['base_url']

with $url

. The call is $this->getSession()->visit($url)

viewed in normal $url

.

+4


source


Instead:

Given I am on page "/employee"

      

Try:

Given I am on "/employee"

      



I don't know about Laravel, but this is how we do it in symfony:

default:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: 'http://localhost/myproject/web/app_test.php/'

      

When you invoke the command below, you should expect to see the base URL above, so what happens in your case?

class FeatureContext extends MinkContext
{

    // In one of you methods run this
    echo $this->getSession()->getCurrentUrl();

}

      

0


source







All Articles