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.
1 2 |
$ git clone git@github.com:Shashikant86/BehatDemo.git $ cd BehatDemo |
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
1 |
$ brew update && brew install phantomjs |
You can now check if PhantomJS installed using
1 |
$ phantomjs -v |
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
1 |
$ phantomjs --webdriver=8643 |
Now that, we need to add another profile to run scenarios with phantomjs profile. Let’s edit ‘behat.yml’ and add phantomJS profile.
1 |
$ vim behat.yml |
Add following code
1 2 3 4 5 6 7 8 9 |
phantomjs: context: class: 'FeatureContext' extensions: Behat\MinkExtension\Extension: base_url: 'http://saucelabs.com/' goutte: ~ selenium2: wd_host: "http://localhost:8643/wd/hub" |
Now we can run our existing features with ‘phantomjs’ profile
1 |
$ ./bin/behat -p phantomjs |
You will see all the scenarios passes and used PhantomJS as a browser under Selenium
Source-Code
The source code is available on the github. You can try it by your own
1 2 3 4 5 |
$ git clone git@github.com:Shashikant86/BehatDemo.git $ cd BehatDemo $curl http://getcomposer.org/installer | php $php composer.phar install $ .bin/behat -p phantomjs |
In this way, you can run BDD, Behat scenarios using Behat, Mink, Selenium and PhantomJS.
Watch Video: