Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 81 lines (53 sloc) 3.543 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
UITest - jQuery Driven Automated UI Testing

DESCRIPTION

UITest is the automated UI testing framework for jQuery projects as demo'd by Menno van Slooten on April 25th at the jQuery Bay Area conference 2010. It was initially written for automated testing on the eBuddy Web Messenger (www.ebuddy.com) and later generalized to work for some/most/all jQuery projects.

INSTALLATION

Place the uitest directory in your project's root.

WRITING A TEST

Edit the uitest_tests.js file and add a basic test:

    UITest.addTestScript({
        name : 'My test',
        url : '../index.html',
        waitFor : 'pageToLoad',
        thenRun : function() {
            UITest.log('The page has loaded');
            // Your tests here
        }
    });

The waitFor property takes 5 types of arguments:

  1. "pageToLoad": The most common. It fires up the test as soon as the page is loaded and jQuery is available and ready. See this.waitForPageToLoad() in js/uitest.js.
  
  2. "#any.jquery[selector]": This starts testing as soon as the selector returns one or more elements that are visible. See this.waitForElementVisible() in js/uitest.js.
  
  3. "!#any.jquery[selector]": (Notice the exclamation mark) This starts testing as soon as the selector returns zero elements or one or more elements that are hidden. See this.waitForElementVisible() in js/uitest.js.
  
  4. A number: This starts testing after n milliseconds.
  
  5. A function: This starts testing as soon as the function returns true. See this.waitForExpressionTrue() in js/uitest.js.
    
In uitest_tests.js you will find examples of how to do basic actions and asserts. For a full list of available asserts you can open the file js/assert.js.

RUNNING A TEST

You can then run the test by opening http://your.project.url/uitest/ and choosing your test from the list on the right. Running the test "fast" (without interruptions) will probably go too fast to notice, so you might want to hit "slow" which will pause on every UITest.log() statement. Choosing "no tests" will just load the file defined by the url property of that test.

ASYNCHRONOUS ACTIONS

Any test involving asynchronous actions (Ajax requests, animations or anything having to do with setTimeout or setInterval) will have to be broken up. Study the difference between the "Ajax fail" and "Ajax success" demo tests to see how this is done.

SETUP/TEARDOWN

If something needs to run before and/or after tests are started you can use the setup and teardown options:

    UITest.addTestScript({
        name : 'My test',
        url : '../index.html',
        waitFor : 'pageToLoad',
        thenRun : function() {
            UITest.log('The page has loaded');
            // Your tests here
        },
        setup : function(testframe) {
            // Run before the tests
        },
        teardown: function(testframe) {
            // Run after the tests fail or succeed
        }
    });
    
The testframe variable passed to these functions is the frame of the page where the tests are run.

REMARKS

UITest is a very, very basic framework and not originally intended for public consumption. Prolonged exposure to the code may induce nausea and dizziness. Please help the project by:

  * Improving documentation
  * Finding, reporting and/or fixing bugs
  * Creating more helpful asserts
  * Figuring out a way to add a "record" functionality
  * Figuring out a better way to run tests in "slow motion"
  * Figuring out a way to include tests in any type of automated build process.
  

Something went wrong with that request. Please try again.