Skip to content

Magento 2 Behat Setup

Magento-2Setting up the behat framework on a magento 2 project is slightly different to the way we would do it on a magento 1 project.

Why It Differs

The reason it differs is due to how composer works between each project, the biggest difference is that Magento 2 is heavily reliant on composer where Magento 1 is not. So we will want to use composer in the default Magento structure to get everything set up.

Magento 2 Set Up

Follow the below steps in order as they appear

  • find the composer.json file inside the project root

  • copy in dependencies and config below:

         "edmondscommerce/behat-framework": "dev-master",
         "edmondscommerce/behat-faker-context": "dev-master",
         "edmondscommerce/behat-chrome-performance-context": "dev-master",
         "edmondscommerce/behat-error-detection-context": "dev-master",
         "edmondscommerce/behat-screenshot-context": "dev-master",
         "edmondscommerce/behat-error-handling-context": "dev-master",
         "edmondscommerce/behat-html-context": "dev-master",
         "edmondscommerce/behat-javascript-context": "dev-master",
         "edmondscommerce/behat-mouse-context": "dev-master",
     },
     "config": {
         "bin-dir": "bin/"
     }
 }
* Run composer update

  • Create a new folder called feature inside the project root

Once all the above is done, just simply follow the rest of the original behat setup steps and the project will be ready

Note

Do not use anything from the magento 1 context as these will not work!

New folder structure

This will let you know where you can find everything inside of a Magento 2 Project

Feature folder:

"project-root"/features

This will contain customer context files and all feature files

Behat/Selenium Shellscripts:

"project-root"/bin

This will contain all the scripts you need for running and stopping selenium (headless) while also having scripts for running all the tests on different devices

Behat.yml and composer.json

The main versions of these files are found inside the project root

Behat Framework Context Folder:

"project-root"/vendor/edmondscommerce/

Selenium Folder:

"project-root"/vendor/edmondscommerce/

Behat/Mink config folder:

"project-root"/vendor/behat