Tuning Allure to save time for a QA engineer

Telegram and not only.

Allure is a popular tool for generating test reports. But no matter how pleasant the Allure interface is, no one likes to watch it for half an hour while the launch is in progress. There are always a lot of tasks for a QA engineer, so it would be convenient to attach a notification mechanism to our favorite tool in order to return to it when the time comes. This idea has visited me for a long time, and now it’s time to do it.

To receive instant notifications about the status of tests, there is a project Allure Notifications. This plugin allows you to automatically send test launch notifications to your chosen Telegram/Slack/Skype/Email channel. As I understood from communication with QA colleagues, few people have heard about this tool, and those who have heard have not tried it. Let’s fix this.

What does it look like?

This is what a Telegram message looks like. Taken from https://github.com/qa-guru/allure-notifications

What do we need?

  • get a short summary for each test run;

  • do not wait for the end of the wound;

  • in a convenient messenger – so that you can send it to the team;

  • with the usual diagram – to look and everything is clear;

  • with a link for detailed information;

  • to work from CI.

Like we have?

  • a separate chat for the bot and QA, where notifications are received, then forwarded to the team if necessary;

  • Telegram bot (separate for each project);

  • reports come both regularly and on triggers in the repository;

  • if the tests have fallen – we go to Allure to understand, if not – rejoice and rest Let’s go do other things.

How to use it?

For those who like to read instructions:

Everything happens in 3 stages:

1. Execution of tests;

2. Report generation (should contain summary.json);

3. Directly generating notification content and sending it

If the first two steps are not very interesting to you, then you can immediately skip them and go to the third, but for a general understanding, I recommend that you familiarize yourself with all the steps.

The first stage is the execution of tests

(Obviously) executing tests

pytest --alluredir=allure-results

We are using Python3 + pytest. It doesn’t matter how you do it on the project, since the main thing here is that the output should be artifacts like these:

We use the allure-pytest plugin for this. In the command above, the –alluredir argument points to the folder where all these files should be placed.

The second stage is report generation

The next step is to generate a report. Here you will need the Allure Command Line Tool.

allure generate allure-results -o allure-report

What does it mean “take artifacts from allure-results and generate a report from them in allure-report“.

At this step, it is important for us to get summary.jsonsince it will be used to generate the diagram and text of the notification

The structure of the report in the allure-report folder and the summary.js we are interested in

The structure of the report in the allure-report folder and the summary.json we are interested in

This is how the file looks like:

{
"reportName" : "Allure Report",
"testRuns" : [ много чего ],
"statistic" : {
        	"failed" : 182,
        	"broken" : 70,
        	"skipped" : 118,
        	"passed" : 439,
        	"unknown" : 42,
        	"total" : 851
        	},
 "time»: что-то
}
The third stage is generating a report and sending a notification.
wget https://github.com/qa-guru/allure-notifications/releases/download/4.2.1/allure-notifications-4.2.1.jar
java "-DconfigFile=config.json" -jar allure-notifications-4.2.1.jar

Everything is simple – download and run .jarreceived notification.

Something like that. As a result, we will receive a notification in Telegram as in the example above.

Want! How to setup?

It’s simple – you need a bot that will send us a message to TG, and do a little magic over the config. Go:

First of all, let’s create a bot using BotFather and get its token. If you know how to do it – feel free to skip it, no – expand the spoiler.

How to make a bot
  1. Write https://telegram.me/BotFather

  2. He will ask you for the name and nickname for the bot

  3. Upon completion, it will send a token of the form:

    123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11

  4. Ready

So, we have a bot and we know its token. In order to get a report from him using allure-notifications just paste the token into the config. Here is an example config.json

{
  "base": {
	"project": "Your project",
	"environment": "stage",
	"comment": "some comment",
	"reportLink": "your.alure.host.ru/project/id вашего проекта/launches",
	"language": "en",
	"allureFolder": "allure-report",
	"enableChart": true
  },
  "telegram": {
	"token": "ТУТ_ТОКЕН_БОТА",
	"chat": "ТУТ_ID_ЧАТА",
	"replyTo": ""
  }
}

Next, you need to add a bot to the chat where you want to receive notifications and make it an admin.

Inside allure-notifications is used api.telegram.org – API Telegram. According to the API we need chat_idto send a message there on behalf of the bot. It is very easy to find out – after adding the bot, create a link and follow it:

https://api.telegram.org/botHERE_SUBSTITUTE THE TOKEN/getUpdates

Note that the token must be preceded by the word bot. Then write any message to the chat with the bot and refresh the page. You will see a response in the format json. From there we only need to take the value of the field result > message > chat > ​​id.

Example:

{
  "ok": true,
  "result": [
	{
  	"update_id": ********,
  	"message": {
    	"message_id": 310,
    	"from": {
      	"id": *******,
      	"is_bot": false,
      	"first_name": "Данила",
      	"last_name": "Шкердин",
      	"username": "dashkerdin",
      	"language_code": "ru"
  	},
  	"chat": {
    	"id": -8*9*63*0*,
    	"title": "ALLURE MONITOR",
    	"type": "group",
        "all_members_are_administrators": true
  	},
  	"date": *************,
      "text": "1"
  	}
	}
  ]
}

To check, you can pull the request through cURL:

curl -X POST \
 	-H 'Content-Type: application/json' \
 	-d '{"chat_id": "ТУТ_ВАШ_ЧАТ_АЙДИ", "text": "Тестовое сообщение", "disable_notification": true}' \
 	https://api.telegram.org/botСЮДА_ПОДСТАВЬТЕ ТОКЕН/sendMessage
A few words about proxies

You can add proxy configuration to config.json. Personally, this was important to me, since messages are sent from the corporate network to an external API. To do this, you need to open access to the proxy for api.telegram.org.

Now let’s substitute id chat to our config and you can test:

pytest --alluredir=allure-results
 
allure generate allure-results -o allure-report
 
wget https://github.com/qa-guru/allure-notifications/releases/download/4.2.1/allure-notifications-4.2.1.jar
java "-DconfigFile=config.json" -jar allure-notifications-4.2.1.jar

Hurray, everything worked out!

conclusions

So, I told you how to set up notifications about the execution of autotests using allure-notifications to the usual Telegram. Notifications to email / slack / skype are configured in the same way – you can see more details in original repository.

PS

Thank you for your time, I hope my experience is useful to you. If you have any questions, comments, or want to share your Allure tuning stories, write in the comments!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *