Catching up with Allure. Part 2: report generating

Hi, everybody! How are things? Ready for the next stage of conquering Allure framework? Okay then, let’s proceed!

In the first article, we’ve seen how we can configure Allure TestNG adapter through Maven and add it to the project. But still, we have no idea how we can build a report and what we can actually add there. I’m going to show that very soon but we need some tests for simulating a real test framework, right? So, let’s make them.

Challenge for this post:

To add several functional tests for a web-application to our project, run them and get Allure JSON files, and generate the Allure report for these test results.

Introduction

As a victim for my tests, I decided to take Amazon. It’s quite difficult to cover whole Amazon website by autotests, so I chose 3 simple scenarios:

  • search for a product and then make sure that search results are valid;
  • navigate to the “Today’s Deals” page and make sure that the first item there has a correct label;
  • find a guitar player, add his first album to the Cart and check that it was actually added.

You will also see one more test that I added just for a diversity of test results in the future report – the test which is always failed (it will be displayed as failed in the report also).

So, let’s have a look at those tests in the code. Just a short note – as you may remember, I use Selenide framework instead of pure Selenium WebDriver for writing functional UI tests, so don’t be confused, if you don’t see customary code snippets:

A couple of words about the code above. Everything is based on the 2 design patterns: PageObject and Chain-Of-Invocation. I left a lot of pages code behind but we will get back to it in the next article (also I’m going to upload the complete project to GitHub after all).

As for asserts, I put traditional TestNG assert methods in a couple of tests only: testAddingItemToCart() and testWhichAlwaysFails(). All the rest of tests use Selenide asserts which are implemented in the pages classes.

There are 2 tests with @Parameters annotation. It’s a TestNG annotation and I decided to use it because Allure can handle this case also. The values for these parameters are passed from my testng.xml:

Let’s run our tests right now! I prefer to run them from PowerShell but you can use the default Windows console app. if you get used to it. Navigate to the test project folder where your pom.xml is and run the mvn clean test commands (Maven should be added to the PATH variable, remember?):

powershell

If everything was set correctly, tests will be run and Allure JSON files will be generated under the /target/allure-results folder. And here we face the next obstacle – how to convert these files to a user-friendly and pretty report? Thet’s where Allure Command Line tool comes into play.

Configuring Allure Command Line tool

The main task of this command line tool is to generate a report from JSON files created by any Allure adapters. In order to install it on your local machine, you need to follow the steps described in the Official Guide. However, I recommend you to do manual installation instead of using Scoop, if you have a firewall on your PC. That may cause problems with running Allure Command Line tool.

Since Allure Command Line is installed and added to the PATH system variable, we can run the following command for generating a report:

Allure will generate the report in a temporary location and open it in the in the default browser (all pictures below are clickable):

As you can see, this report doesn’t have too much information about the tests and their results. That’s because we haven’t added any Allure annotations to our test code and Allure handled only the data that TestNG provided. We will customize the report in the next article and see how powerful and convenient Allure can be.

That’s it for now! I hope this post helped you to figure out how to generate an Allure report for your project. Happy automating!

Like this post?

Subscribe to updates from my blog, if you don't want to miss more interesting future posts and materials

Please check your email and confirm subscription

Pin It on Pinterest

Share This