Using PhantomJS with Behat

Firstly, to install phantomjs you need to install it’s dependency, NodeJS:-

sudo npm install -g nodejs

Then install PhantomsJS (I would recommend using npm as it installs it correctly, including updating bin path):-
sudo npm install -g phantomjs

Add to your composer “require” section

"behat/behat": "2.4.*@stable",
"behat/mink": "1.4.*@stable",
"behat/mink-extension": "*",
"behat/mink-browserkit-driver": "*",
"behat/mink-selenium2-driver": "*",

It’s smart to use profiles in your behat.yml file, as these are easily initiatized by behat (using -p parameter followed by profile name, in the behat run command)

Add this to you behat.yml

phantomjs:
extensions:
Behat\MinkExtension\Extension:
default_session: selenium2
javascript_session: selenium2
browser_name: 'phantomjs'
selenium2:
wd_host: "http://127.0.0.1:4444/wd/hub"
capabilities: { "browser": "phantomjs", "version" : "xx.xx"}

Before you run your behat tests, startup selenium and connect phantomjs to it:-

java -jar selenium-server-standalone-[version number].jar
phantomjs --webdriver=[enter a port number here]

Run behat using profile parameter:-

bin/behat -p phantomjs




No Comments


You can leave the first : )



Leave a Reply