Running Behat Scenarios with PahntomJS

Behat

Behat is a Behavior Driven Development tool for the PHP application. Behat and Mink uses many drivers like Selenium, Sahi, Zombie and goutte to launch scenarios.

In this post, we will see how to run Behat scenarios using an awesome tool called ‘PhantomJS‘. We will use a existing Demo project on GitHub.

PhantomJS

PhantomJS is a headless browser with full support of JavaScript. PhantomJS can be used for the various purpose like

  • Headless Website Testing
  • Page Automation
  • Network Monitoring

Installation

On Mac OSX, you can install it with HomeBrew

You can now check if PhantomJS installed using

Now you are good to go with PahntomJS and Behat

Behat, Selenium and PhantomJS

In order to use PhantomJS with Behat-Mink and Selenium. We need to launch it on port 8643

PhantomJS-WebDriver

Now that, we need to add another profile to run scenarios with phantomjs profile. Let’s edit ‘behat.yml’ and add phantomJS profile.

Add following code

Now we can run our existing features with ‘phantomjs’ profile

You will see all the scenarios passes and used PhantomJS as a browser under Selenium

BehatPhantomjs

Source-Code

The source code is available on the github. You can try it by your own

In this way, you can run BDD, Behat scenarios using Behat, Mink, Selenium and PhantomJS.

 

Watch Video: