Monday, May 4, 2015

Using PhantomJS with PHPUnit

I found it pretty hard to get PHPUnit working with PhantomJS so thought I'd put together a quick tutorial.

Step 1: Make sure you have the following dependencies in your composer.json and run composer update:
"require-dev": { 
      "facebook/webdriver": "dev-master",  
       "phpunit/phpunit": "4.0.*", 
       "phpunit/phpunit-selenium": ">=1.2" 
}
Step 2: Download PhantomJS and Selenium Server and put them in a new directory 'bin' in your tests folder. (Might not be the most optimum place to stash them but it works for now)

Step 3: Add the following code to your tests folder as TestScaffold.php. It will start the Selenium server if it's not already running and boot up PhantomJS for each test.
Step 4: Write a test that extends the scaffold

No comments:

Post a Comment