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)

Acting on radio buttons


To test the usage of radio buttons, we need to add some to a form in our app. We will introduce a radio button in the to-do item creation form to indicate if an alarm should be scheduled. Depending on the selected value, a field should appear, allowing us to set the to-do item's alarm date and time.

  1. First, we need to change the to-do item creation template in templates/todos/new.html to:

    <h1>New To-Do</h1>
    <form id="new-todo-form" action="/todos" method="POST">
    
      <p>
        <label for="what">What</label>
        <textarea name="what" id="what" required></textarea>
      </p>
    
      <p>
        
        <label class="radio" for="alarm-false">
          <input type="radio" name="alarm" value="false" id="alarm-false" checked="checked" /> No Alarm
        </label>
    
        <label class="radio" for="alarm-true">
          <input type="radio" name="alarm" value="true" id="alarm-true" /> Use Alarm
        </label>
    
      &lt...