Behat “base_url” from command line

大兔子大兔子 提交于 2019-12-04 18:19:33

问题


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.


回答1:


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



回答2:


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



回答3:


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)




回答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


来源:https://stackoverflow.com/questions/19815144/behat-base-url-from-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!