Skip to main content

Protractor Tutorial: Jasmine test logging

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!

Popular posts from this blog

Test Automation: Good, Bad and Ugly

The modern approach to software quality and software development life cycle requires that business guys, developers and testers understand that the long manual test phase, although often still necessary, must be reduced to a minimum and replaced by test automation. Working in continuous delivery and continuous integration environment requires us to create automated tests that run on demand, checking our application integration and it’s core functionality correctness. However, there are still many problems with designing and writing automated tests, resulting in their costly maintenance or abandonment in favour of a return to manual processes.
In this article I will focus on describing common good practices of test automation. This post is more than an overview than complete reference guide. Broader aspects, such as the Page Object pattern or Page Factory will be described in detail in a separate article on this blog. Although most practices apply for every types of automated tests, thi…

REST-Assured framework overview

In modern software development, REST services becomes most popular choice for implementing distributed and scalable web application. They are light and easy to maintain, which results in faster and more effective implementation and system integration.
I recommend you also my other posts about REST-Assured and building microservice’s test automation frameworks: REST-Assured: going deeperBuilding microservices testing framework
With the increase popularity of RESTful services, there is a need for fast and lightweight tool for REST webservices testing automation. One of the most popular choice is Rest-Assured framework from Jayway. It introduces simplicity of testing web services from dynamic languages like groovy or ruby to java. In this post we will get our hands dirty and write automatic test in Rest-Assured framework.
In order to create complete implementation of automated tests in Rest-Assured framework, we need to write our code against some example API. We’ll use standalone Wiremock m…

REST-Assured: going deeper

In my previous post I described the basic REST-Assured usage – the lightweight framework for testing RESTful services. Despite the fact that described range of functionalities would be enough in most cases,REST-Assured has a lot more to offer. In this post I would like to bring some more advanced examples of the framework usage.



I recommend you also my other posts about REST-Assured and building microservice’s test automation frameworks:

REST-Assured – framework overviewBuilding microservices testing framework
Object Mapping Sending request’s body as string is easy and straightforward, but it can be inconvenient in the case of more complex operations on request / response properties. Proven solution for this is a good-known serialization of request/response body to objects. REST-Assured supports object mapping to (and from) JSON and XML. For JSON you need either to have Jackson or Gson in your classpath and for XML you need JAXB. Here is an example of request object serialization using J…