Using Zombie.js Driver with Behat’s MinkExtension[Updated]

Zombie.js

Zombie.js is a headless browser which uses Node.js, NPM, a C++ compiler and Python. We can use Zombie.js with Behat’s MinkExtesion to make your BDD scenarios much faster. We have seen that we can also use Selenium, WebDriver, Sahi etc etc with MinkExtension.

Here are few Benefits you can achieve using Zombie.js

  • You don’t need browser so your tests become so fast.
  • You don’t need to launch Server before running tests, Zombie will automatically do it for you, saving your time and efforts.
  • Robust automated tests.
  • Easy to setup on Linux and Mac OSX servers.

Being honest, it was pain in everywhere until I got Zombie working in my local machine. I managed to get it working on Linux (Ubuntu) by taking help from Behat community, but faced many issues while getting it work on my Mac OSX. Finally, I have everything setup!!

Installation

On Ubuntu

On Mac OSX

You need to have Xcode and HomeBrew installed.

 My terminal window looks like this after installation:

Node NPM
Node NPM

 

 NODE_PATH ENV Variable

 Next, you need to add NODE_PATH envirnomental variable to your .bashrc Or .bash_profile. It’s time consuming to find out right ‘node_module’ where ‘zombie’ is installed. You have to do it in a right way other wise you will end up with error 

It’s so annoying error so it’s fucking important to add right NODE_PATH to your .bashrc / .bash_profile

On Mac OSX

Now insert following code, We are going to add ‘npm’ in the PATH and NODE_PATH

 On Ubuntu

 

Create Behat-Mink-Zombie Project

Now, Let’s create sample project which uses Mink-Extension with Zombie driver. Let’s call this Project as ‘Behat-Mink-Zombie’

  • Create composer.json

 

  • Create a simple ‘behat.yml’ config file

  • Install Behat and other dependencies using composer.

  • Initialize Behat

  • Create a Simple Feature File in ‘features’ directory

Now write a features with some user actions.

  • Extend Auto-Generated ‘FeatureContext.php’ to Mink Extension.

Delete all the unwanted code, It should look like this:

  • Run ‘behat’ and watch your tests passing by using headless Zombie Driver.

Behat-Zombie

 

Great! You should be laughing at this point.

GitHub

Source Code is also available on GitHub on “Behat-Zombie” repository. You can clone the repository and try it yourself by executing following commands in sequence. [I assume, you have Node, npm and Zombie installed ]

Conclusion

You can make your BDD scenarios more robust, faster and maintainable by using headless browsers like Zombies with BDD tools like Behat. Zombie.js is easy to setup on Linux and Mac OSX as part of Continuous Integration. Enjoy Mink-Extension with Zombie driver.