Code Monkey home page Code Monkey logo

voyagertest_casperjs's Introduction

Automated testing

This directory contains CasperJS tests that ensure the stability of the site.

Installation

Clone this repository anywhere in your project. Ideally, next to the docroot. The contents of this repository do not need to be available to a web browser.

OSX - Homebrew

Homebrew will install the phantomjs dependency automatically.

brew install casperjs --devel

From Source

cd /usr/share
sudo git clone git://github.com/n1k0/casperjs.git
cd casperjs
sudo ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs
# Download phantomjs http://phantomjs.org/download.html to /usr/share
cd /usr/share/phantomjs-1.9.2-linux-x86_64/bin
sudo ln -sf `pwd`/phantomjs /usr/local/bin/phantomjs
# Next, install Python 2.6 or greater for casperjs in the bin/ directory.
# Finally, when running `casperjs`, the output should be:
casperjs
CasperJS version 1.1.0-beta3 at /usr/share/casperjs, using phantomjs version 1.9.2

Running tests

Asuming your local environment is set up at http://localhost, all tests may be run with the following command:

./testrun

You can also run a specific test by giving it as an argument to the command. homepage.js is a sample test for http://www.msnbc.com. Here is how you could run it:

./testrun -u http://www.msnbc.com homepage.js

NOTE test is a wrapper for casperjs which sets some useful defaults when running tests. Run ./testrun -h for a list of all the available options.

Writing tests

Tests are JavaScript files which are located at the tests directory. They can be organized depending on different aspects of the site such as the homepage, the external header and footer, or the search engine.

common.js contains useful methods for all tests and it is included automatically when running tests.

Some useful resources for writing tests are:

  • Navigation steps let you wait for certain events such a page getting fully rendered before running assertions over it.
  • The casper object has commands to interact with the browser such as opening a URL or filling out a form.
  • The test object contains methods to run assertions over the current context.

Cookies

PhantomJS (the browser that CasperJS uses for navitation) stores session data in a cookie file. Future test runs will reuse the cookie if the file is present. This is the reason why the test executable creates a file called cookies.txt while running tests to store cookie information and deletes it the next time tests are run.

Tips

Taking screenshots

You can take a screenshot with casper.capture('filename');.

Alternatively, you can use casper.captureSelector('filename', 'div.some-class'); to take a screenshot of a given selector.

Find more examples at http://docs.casperjs.org/en/latest/modules/casper.html#capture.

Evaluating code

casper.evaluate() method (and its alternatives such as casper.evaluateOrDie(), casper.thenEvaluate() or test.assertEvaluate()) are highly powerful methods since they will run JavaScript code on the page just as if you were debugging with the browser's JavaScript console.

voyagertest_casperjs's People

Stargazers

Xing Xu avatar

Watchers

James Cloos avatar Xing Xu 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.