Behat "base_url" from command line
Asked Answered
M

4

10

I would like to know if it's possible to set the base_url via the command line. Example

bin/behat --base_url=http://google.fr

I would like to avoid creating a new profile and passing it via the command line each time I have to test a new url, for flexibility purpose.

Is there any trick here to do this ?

Thank you.

Miscarriage answered 6/11, 2013 at 14:49 Comment(3)
It is a bit puzzling why you don't mind passing the base_url on the command line, but passing the profile (which is less characters) is not ok. :)Steamship
aderuwe, I had the same question as original poster because we spin up new servers at will for testing branches. The URL is different for each instance. Storing these urls in behat.yml is not ideal.Grous
Totally forgot to validate the answer. @Grous you can use my solutionMiscarriage
M
12

I found the solution by myself.

Just pass the base_url in the BEHAT_PARAM environment variable.

export BEHAT_PARAMS="context[parameters][base_url]=http://google.fr"

Then run behat

bin/behat
Miscarriage answered 7/11, 2013 at 9:55 Comment(1)
Does not work at least with Behat 3.2 and ends up in ConfigurationLoadingException: Environment variable BEHAT_PARAMS` should contain a valid JSON` Solution is to use: export BEHAT_PARAMS='{"extensions" : {"Behat\\MinkExtension" : {"base_url" : "http://google.fr/"}}}' see: behat.org/en/latest/user_guide/…Vortumnus
G
12

Alternatively if you are using Mink you could define a profile in behat.yml

# behat.yml
default:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://local.mysite.com
            goutte: ~
            selenium2: ~

dev:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://dev.mysite.com

And then you can run your tests against local.mysite.com by default with

$ behat

Or against dev.mysite.com with

$ behat --profile=dev
Gladisgladney answered 8/11, 2013 at 16:35 Comment(0)
S
5

In Behat 3, this parameter seems to have become JSON, so it works like:

export BEHAT_PARAMS='{"extensions":{"Behat\\MinkExtension":{"base_url":"https://google.com/"}}}'

Important these params are not overrides, they are defaults, and get over-written by behat.yml. So you must UNSET the base_url in behat.yml for this CLI setting to work.

extensions:
  Behat\MinkExtension:
    # YOU MUST EDIT THIS YOURSELF!
    # Either set this here, or set the base_url via BEHAT_PARAMS
    # base_url: 'https://my.livesite.com/'

(Refs: feature-request, clue)

Shortbread answered 17/5, 2015 at 15:54 Comment(0)
B
4

The shorter way of achieving the same as per your answer would be just to pass the environment variables before the command itself:

BEHAT_PARAMS="context[parameters][base_url]=http://google.fr" bin/behat
Beggar answered 28/10, 2014 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.