simple PHP wrapper for CasperJS
Clone or download
alwex Merge pull request #40 from stexaz/master
Enrich php-casperjs with headers, cookies and status and fix slimerjs tests on CI
Latest commit 5a0f2fb Apr 4, 2017


Travis branch Packagist Version License


php-casperjs is a simple PHP wrapper for the fine library CasperJS designed to automate user testing against web pages.

It is easy to integrate into PHPUnit test case.

Making webcrawler has never been so easy!


Before using php-casperjs, you need to install both library:

1 - PhantomJS

2 - CasperJS

npm install phantomjs
npm install casperjs


composer require phpcasperjs/phpcasperjs



use Browser\Casper;

$casper = new Casper();

// forward options to phantomJS
// for example to ignore ssl errors
    'ignore-ssl-errors' => 'yes'

// navigate to google web page

// fill the search form and submit it with input's name
                'q' => 'search'

// or with javascript selectors:
                'input#email-id' => 'user-email',
                'input#password-id'   =>  'user-password'

// wait for 5 seconds (have a coffee)

// wait for text if needed for 3 seconds
$casper->waitForText('Yahoo', 3000);

// or wait for selector
$casper->waitForSelector('.gbqfb', 3000);

// make a screenshot of the google logo
$casper->captureSelector('#hplogo', '/tmp/logo.png');

// or take a screenshot of a custom area
        'top' => 0,
        'left' => 0,
        'width' => 800,
        'height' => 600

// click the first result
$casper->click('h3.r a');

// switch to the first iframe

// make some stuff inside the iframe
$casper->fillForm('#myForm', array(
    'search' => 'my search',

// go back to parent

// run the casper script

// check the urls casper get through

// need to debug? just check the casper output

If you want to see your crawler in action, set the engine to slimerjs

$casper = new Casper();
$casper->setOptions(['engine' => 'slimerjs']);