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)

Chapter 7. Debugging

This chapter shows how you can use the browser object to inspect some internal states of your application.

Topics covered in this chapter include:

  • Enabling the debugging output

  • Dumping the browser state

By default, Zombie does not output the internal events to the console, but you can run Zombie with the DEBUG environment variable set to true. If you have a UNIX shell command line, you can prefix the launching of your test suite with DEBUG=true, shown as follows:

$ DEBUG=true node_modules/.bin/mocha test/todos

If you are running Windows, you can set and unset the DEBUG environment variable shown as follows:

$ SET DEBUG=true
$ SET DEBUG=

By enabling this environment variable, Zombie will output every HTTP request that it makes, along with the received HTTP status code:

…
Zombie: GET http://localhost:3000/js/todos.js => 200
Zombie: 303 => http://localhost:3000/todos
Zombie: GET http://localhost:3000/todos => 200
Zombie: GET http://localhost:3000/js/jquery-1.8.2.js =&gt...