Pregunta

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.

¿Fue útil?

Solución

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

Otros consejos

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

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)

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top