Proper test logging is a crucial part of our framework setup. As long as your plan is green then everything is good, but have you ever tried to analyse test failures on CI server with no logs or test traces? Good practice is to log every important step of your tests, so that one could read our logs and understand test logic.
In previous tutorial we went through setting up new Protractor project from scratch. If you run your test, you would noticed that Jasmine’s default test output to console is rather poor. In this post we would configure more verbose and user friendly console logging from our tests.
Our goal
If you’ve followed basic protractor project configuration, after running your tests you will see something like:
Basically what you get out of the box is dot for every it(). Well yes, not exactly the most user friendly output, not the most informative one neither. What we want to see are logs like those below:
Jasmine Spec Reporter
Since our test runner is Jasmine, we need to add new dependency to our project:
$ npm install jasmine-spec-reporter --save-dev
After that, you should see a new entry in your package.json file pointing on latest jasmine-spec-reporter library.
Setup
Next thing is reporter configuration. Open your protractor config file and add following lines into onPrepare function:
That’s all! Run your tests now and you should see some nice looking console output.
Further Configuration
Jasmine Spec Reporter comes with set of configuration switches that you can apply to your setup. Whole options list with defaults:
Lets say you want to change tick icon ( ✓ ) for something else. You can use everything what’s valid for your terminal (it depends on the OS type). Since tests success is a reason to celebrate, I’ll go with beer icon:
(Mac OS X valid)
You can check my configuration below:
…and here comes our output:
Cheers!
Summary
Jasmine Spec Reporter is simple to use and it’s an excellent way to improve our test logs. If you have any questions or want to share your own experiences, please leave a comment!