Using parameters from config in feature files

377 views
Skip to first unread message

Tom Rogie

unread,
Oct 23, 2015, 4:53:37 AM10/23/15
to Behat
Hello,

Is there a way to use parameters from config in the arguments of a feature/scenario step?

I have different systems i have to test against. The backend urls are http://<brand>-dev.foobar.com but when something gets done I have to test the result on http://<brand>-cds.foobar.com

I was using scenario outline before but then I have to add the brand to every scenario outline when a new one gets added... Besides I have to be able to run my tests on only one brand, not all of them together.

So I prefer to add it only to the config and so all my features/scenarios are done.

Any ideas?

Thanks,
Tom

Tom Rogie

unread,
Oct 23, 2015, 5:01:18 AM10/23/15
to Behat
So i want to have in my config.yml somewhere a profile with:
  cds_host: http://brand1-cds.foobar.com
and another with:
  cds_host: http://brand2-cds.foobar.com

in my feature files I want to use
  Given I am on "cds_host"

That would make my system more generic

tslid

unread,
Oct 23, 2015, 5:14:56 AM10/23/15
to Behat
Hello,

Behat can use parameters from the config file. Currently in my behat.yml I have something like this:

ProfileName:
  extensions:
    Behat\MinkExtension:
      files_path: %paths.base%/files
  suites:
      default:
        contexts:
          - FeatureContext:
            - testSite:
                url: "SITE_URL"
                user: "USER"
                pass: "PASS"

Then in your FeatureContext.php file you can access these variables

    public function loginDetails()
    {
        $session = $this->getSession();
        $page = $session->getPage();
        $usern = $this->params['testSite']['user'];
        $passw = $this->params['testSite']['pass'];

    }
 
I hope this makes sense and will help you.

Regards

Tom Rogie

unread,
Oct 23, 2015, 5:28:43 AM10/23/15
to Behat
Thanks tslid,

I knew about the use of config parameters in code but thats not what i need. I need the variables in the feature files:

in the config: brand_url: 'http://brand1'

in the feature:
  Given I am on "brand_url"


tslid

unread,
Oct 23, 2015, 5:45:58 AM10/23/15
to Behat
If I understand you right you want to access specific site by key which you assigned in the config file? Okay I didnt explained it very well. What I had in mind is that you will put the two sites you want to test in your behat.yml file. Lets say you have http://<brand>-dev.foobar.com and http://<brand>-cds.foobar.com
So your behat.yml will look like this :


ProfileName:
  extensions:
    Behat\MinkExtension:
      files_path: %paths.base%/files
  suites:
      default:
        contexts:
          - FeatureContext:
            - siteOne:
                url: "http://<brand>-dev.foobar.com"
              siteTwo:
                url: "http://<brand>-cds.foobar.com"

Then in your FeatureContext.php you will create the functions which you will use in the feature files. You will have two functions for the 2 different sites.

    /** Go to specific siteOne using parameters
     * @Given /^I go to siteOne$/
     */
    public function goTositeOne()

    {
        $session = $this->getSession();
        $page = $session->getPage();
        $url = $this->params['siteOne']['url'];
        $this->getSession()->visit($this->locatePath($url));

    }

    /** Go to specific siteTwo using parameters
     * @Given /^I go to siteTwo $/
     */
    public function goTositeTwo()

    {
        $session = $this->getSession();
        $page = $session->getPage();
        $url = $this->params['siteTwo']['url'];
        $this->getSession()->visit($this->locatePath($url));

    }

After this in your features you can now use:

  Given I go to siteOne
  And ...........

And of course you can use:

  Given I go to "siteTwo"
  Then ......

Tom Rogie

unread,
Oct 23, 2015, 7:15:11 AM10/23/15
to Behat
Hehe,

I'm using the drupal extension behat context and wasn't thinking on writing my own context. But it looks like there will be no other way...

Thanks,
Tom
Reply all
Reply to author
Forward
0 new messages