Behat Mink: Namespaces & Behat.yml Context Assignments

  • If namespaces are used, the php files MUST reside in the matching path for the namespace
  • For Behat... this path starts at the 'bootstrap' path specified in behat.yml

 

 

default:
  autoload:
    - "%paths.base%/bootstrap"
  suites:
    default:
      paths:
        features: '%paths.base%/../features/dev'
      contexts:
      - FeatureContext
      - Drupal\DrupalExtension\Context\DrupalContext
      - Drupal\DrupalExtension\Context\MinkContext
      - Drupal\DrupalExtension\Context\MessageContext
      - Drupal\DrupalExtension\Context\DrushContext

 

 


\features\bootstrap\FeatureContext.php

#namespace Drupal;

behat.yml

  autoload:
    - "%paths.base%/features/bootstrap"
  suites:
    default:
      paths:
        features: "%paths.base%/features/dev"
      contexts:
      - FeatureContext

 


\features\bootstrap\Drupal\FeatureContext.php

namespace Drupal;

behat.yml

  autoload:
    - "%paths.base%/features/bootstrap"
  suites:
    default:
      paths:
        features: "%paths.base%/features/dev"
      contexts:
      - Drupal\FeatureContext

 


Passing Parameters to the FeatureContext.php class

  • the contexts: block allows for 'parameters: assignments
  • no quotes needed on the key:value pairs

 

default:
    autoload: [ %paths.base%/contexts ]
    extensions:
        Behat\MinkExtension:
            base_url: http://qa.api.somesite.com
            sessions:
                default:
                    selenium2: ~
        Sanpi\Behatch\Extension: ~
    suites:
        default:
            paths:    [ %paths.base%/features ]
            filters:
            contexts:
                - FeatureContext
                - Behat\MinkExtension\Context\MinkContext
        frontend:
            paths:    [ %paths.base%/features/frontend ]
            filters:
            contexts:
                - FeatureContext:
                    parameters:
                        environment: qa
                        api_url: http://api.somesite.com
                        login: some_login
                        key: 409jfa94k4tj
                - Behat\MinkExtension\Context\MinkContext
                - behatch:browser

 

 

 

 

Tags