A practical guide to building a reusable Behat Extension

asgorobets

Most of you familiar with basic Behat concepts and practices had written some glue code on every project here and there to achieve some testing needs. Some of us have written additional steps for testing Drupal, others implemented steps or hooks that allow easier debugging or taking screenshots on failures. We are doing this all the time on every single project and ogranize it in our FeatureContext file, probably move the code around or post a blog post so people can use the snippet, but is this the right thing to do?

We'll discuss ways to extend Behat using it's native extension mecanisms, Behat extensions. There are reasons to do that, first, we can reuse the code on multiple projects, and second, we can release it for greater PHP/Drupal community to get feedback and improve on it.

We'll be covering the minimal things you need to consider when developing an extension, including:

  • Extension initialization and discovery
  • Extension configuration from behat.yml file and it's defautls
  • Extension points and ways to tweak the testing process on example of TokensExtension
  • Providing new contexts and code organization for ability to implement other custom steps on top of a base API on example of SoapExtension
  • Testing behat extensions with Behat itself

After this session you will know how to start building your Behat extension, ways to extend Behat and best practices to make it useful for developers to build custom steps on top

 

Session Track

PHP

Experience Level

Advanced

Drupal Version