Book Image

Using Node.js for UI Testing

By : Pedro Teixeira
Book Image

Using Node.js for UI Testing

By: Pedro Teixeira

Overview of this book

<p>Automating tests for your user interfaces has always been the holy grail of programming. Now, using Zombie.js and Mocha you can create and quickly run your tests, allowing you to test even small changes. Increase your confidence in the code and minimize the number of times you have to use a real browser while you develop.</p> <p>"Using Node.js for UI Testing" is a quick and thorough guide on how to automatically test your web app, keeping it rock solid and bug-free. You will learn how to simulate complex user behaviour and verify that your application behaves correctly.</p> <p>You will create a web app in Node.js that uses complex user interactions and AJAX; by the end you will be able to fully test it from the command-line. Then you will start creating the user interface tests for this application using Mocha as a framework and Zombie.js as a headless browser.</p> <p>You will also create a complete test suite, module by module, testing simple and complex user interactions.</p>
Table of Contents (15 chapters)

Testing the user interaction


For testing these new form fields and their combined behavior, we will use the test file in test/todos.js, and augment the Todo creation form scope:

  1. First we test that these radio buttons do exist and that the alarms are turned off by default:

    it('should not present the alarm date form fields when no alarm is selected',
      login(function(browser, done) {
         browser.visit('http://localhost:3000/todos/new', function(err) {
           if (err) throw err;
    
           browser.choose('No Alarm', function(err) {
             if (err) throw err;
    
             assert.equal(browser.query('#alarm-date-time').style.display, 'none');
             done();
           });
         });
      })
    );

    Here we're verifying that we actually have two radio buttons for the alarm field, one having a false and the other having a true string value. Then we also verify that the first one is checked.

  2. We also need to verify that the animation of the new date and time form fields works; the div element that wraps the alarm date...