Coder Social home page Coder Social logo

php-casperjs's Introduction

php-casperjs

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 !

Installation

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

1 - PhantomJS http://phantomjs.org/download.html

2 - CasperJS http://casperjs.org/installation.html

Usage

<?php

use Browser\Casper;

$casper = new Casper();

// forward options to phantomJS
// for exemple to ignore ssl errors
$casper->setOptions(array(
    'ignore-ssl-errors' => 'yes'
));

// navigate to google web page
$casper->start('http://www.google.com');

// fill the search form and submit it
$casper->fillForm(
        'form[action="/search"]',
        array(
                'q' => 'search'
        ),
        true);

// wait for 5 seconds (have a cofee)
$casper->wait(5000);

// 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
$casper->capture(
    array(
        'top' => 0,
        'left' => 0,
        'width' => 800,
        'height' => 600
    ),
    '/tmp/custom-capture.png'
);
        
// click the first result
$casper->click('h3.r a');

// switch to the first iframe
$casper->switchToChildFrame(0);

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

// get back to parent
$casper->switchToParentFrame();
        
       
// run the casper script
$casper->run();

// check the urls casper get throught
var_dump($casper->getRequestedUrls());

// need to debug? just check the casper output
var_dump($casper->getOutput());
        

php-casperjs's People

Contributors

alnutile avatar egorovpavel avatar michaelcgn avatar misterdr avatar tholu avatar untoreh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.