Skip to content

Behat phantomJs install

nader77 edited this page Dec 25, 2014 · 14 revisions

Install phantomJs on local machine.

  • (linux)
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
sudo apt-get install phantomjs
  • (mac - with brew)
brew update && brew install phantomjs

Use phantomJs.

  • Activate phantomJs from the terminal in a new tab (This should be kept running with the behat testing).
phantomjs --webdriver=8643
  • If the phantomJs won't run on linux, please apply the following commands:
export PHANTOM_JS="phantomjs-1.9.7-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS.tar.bz2 /usr/local/share/
sudo tar xvjf /usr/local/share/$PHANTOM_JS.tar.bz2
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs

##Install behat settings.

  • We need to activate Behat. cd to the behat directory.

  • Copy the behat.yml example file

cp behat.local.yml.example behat.local.yml
  • If you never activated behat before, you need download composer with the following commands:
sudo apt-get install curl
curl http://getcomposer.org/installer | php
  • Add the following dependencies to your composer.json
{
  "require": {
    "drupal/drupal-extension": "v0.1.5",
    "behat/behat": "2.5.*@stable",
    "behat/mink": "1.5.*@stable",
    "behat/mink-extension": "*",
    "behat/mink-browserkit-driver": "*",
    "behat/mink-selenium2-driver": "*"
  },
  "config": {
    "bin-dir": "bin/"
  }
}
  • Add phantomJs to your behat.yml
phantomjs:
  context:
      class:  'FeatureContext'
  extensions:
    Behat\MinkExtension\Extension:
      goutte: ~
      selenium2:
        wd_host: "http://localhost:8643/wd/hub"
  • Install the composer.phar
php composer.phar install

Run behat with PhantomJs

We need to run in 2 parallel terminals, One for behat and one for phantomJs.

  • If your phantomJs is not running still, Open a new terminal tab and run this command:
phantomjs --webdriver=8643
  • Run behat with phantomJS using this command:
bin/behat -p phantomjs

If you get this error: Drupal\Exception\BootstrapException]
Unable to determine Drupal core version. Supported versions are 6, 7, and 8.

Check the path of the drupal installation in your new behat.yml.local file.

Testing with PhantomJs

The test must have a @javascript tag in order to activate the javascript capability. you can see a log running on the GhostDriver in the terminal window.

Clone this wiki locally