Ewa
Ewa

Reputation: 65

How to pass url as configuration parameter in Behave Python

I am starting using behave and selenium to write automative tests. I want to create parameter called url as an configuration parameter and: - be able to set it's default value - be able to pass it as an argument from command line

I know I should be able to use userdata to achieve this, but I can't figure out how exactly. Can anybody help? :)

Upvotes: 1

Views: 3432

Answers (1)

ekostadinov
ekostadinov

Reputation: 6940

You can pass directly any variable your behave execution needs via CLI, in my project we use it on Jenkins CI (Shell step) like so:

python -m behave -D platform=desktop -D os=linux -D test.environment=$environment -D browser=remote.chrome -D jenkins.job=$JOB_NAME $TAGS -t=~ignore --no-skipped --no-capture --junit --junit-directory junit_reports

In our behave.ini:

[behave.userdata]
browser=chrome
platform=desktop   ;this should be configurable via behave @tags
os=windows
test.environment=staging

Then in Python code just access the data:

if context.config.userdata['browser'].lower() == ApplicationDriversEnum.SELENIUM_CHROME:
    driver = __create_chrome_driver(context)

Upvotes: 5

Related Questions