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)

When is the browser ready?


When we ask the browser to visit a URL, it calls us back when it's finished, but as web developers know, it's tricky to know exactly when a page load can be considered fully finished

A browser object has its own event loop that handles asynchronous events, such as loading resources, events, timeouts, and intervals. After a page is loaded and parsed, all the dependencies are loaded and parsed asynchronously—just like in real browsers—using this event loop.

Some of these dependencies may contain JavaScript files that will be loaded, parsed, and evaluated. Furthermore, the HTML document may contain some additional inline scripts that will be executed. If any of these scripts have a callback waiting for the document to be ready, these callbacks will be executed before your browser.visit() callback fires your test callback. This means that if, for instance, you have jQuery code that gets fired when the document is ready, it will run before your callback. The same can...