Automatically merge launches on reportportal


644
644 points
automatically merge launches on reportportal
automatically merge launches on reportportal

Automatically merge launches on reportportal

Reportportal it’sa great tool and provides a lot of nice features for automation engineers , on this article I will cover how to automatically merge launches on reportportal.

What is reportportal ?

Report Portal is a service, it provides great capabilities for speeding up results analysis and reporting by means of built-in analytical features.

Report Portal is the great addition to the Continuous Integration and Continuous Testing process.

It seamlessly integrates with mainstream platforms such as Jenkins, Jira, BDD process, majority of Functional and Unit testing frameworks.

Real-time integration allows to manage and track execution status directly from Report Portal.

Test cases execution results are stored following the same structure you have it in your suites and test plan. The test cases are shown with all related data in one place, right where you need it: logs, screenshots, binary data. The execution pipeline of certain test case is also available for you, so one can see previous execution result in one click.

What technologies are used?

Considering high load rate and performance requirements, we use a cutting edge technologies:

  • NoSQL MongoDB – super fast write to DB, clustering.
  • REST Web Service – lightweight requests, industry standard.
  • Mobile responsive UI – check it at any mobile device with default browser.
Reportportal key features:
  • Manage all your automation results and reports in one place
  • Make automation results analysis actionable & collaborative
  • Establish fast traceability with defect management
  • Accelerate routine results analysis
  • Visualize metrics and analytics
  • Make smarter decisions together
  • Follow up your test automation on any device

 

One of the great technical features that reportportal provides it’s a REST API , that gives you a full hand of cards and you can play a good game here.  I will tell you why is that. Imagine one scenario: You run all your tests in multithreading , and for each test session you have 50 threads, so for reportportal that means 50 launches , which is correct but that might affect some of the reports.

For example the last execution pie chart will show only for the last completed launch , that  means will not cover all the other 49 launches in your reports.

Advertisements

Using reportportal powerful rest api I decided to automatically merge my launches at the end of the test session.

Create a report portal helper module
require 'rest-client'
require 'json'
require 'pry'
module MainModule
  module RP
    URL = 'http://reportportal.url:80/api/v1'
    TOKEN = MainModule.config.rp['uuid']
    class << self
      # Get list of all launches by project
      # @param project [String]
      # @return [Hash]
      def launches(project = 
        MainModule.brand)
        r = RestClient.get "#{URL}/#{project}/launch?access_token=#{TOKEN}"
        JSON.parse(r.body)
      end

      # Merge launches into one
      def merge_todays(project = MainModule.brand)

        ls = launches['content'].find_all do |l|
          (['to_merge', Time.now.strftime('%Y-%m-%d')] - l['tags']).empty?
        end
        ids = ls.map { |l| l['id'] }
        start_time = ls.map { |l| l['start_time'] }.max
        description_joined = ls.map { |l| l['description'] }.join("\n==============================\n")
        params = {
            description: description_joined,
            extendSuitesDescription: true,
            launches: ids,
            mode: 'DEFAULT',
            name: project,
            start_time: start_time,
            tags: ['regression', Time.now.strftime('%Y-%m-%d'), 'merged']

        }
        RestClient.post "#{URL}/#{project}/launch/merge",
                        params.to_json,
                        {content_type: :json, accept: :json, authorization: "Bearer #{TOKEN}"}
      end



    end
  end
end
On the root directory create a report_portal.yml file
---
uuid: secret_key
endpoint: http://reportportal.url/api/v1
project: reportportalprojectname
launch: reportportalprojectname
tags:
- regression
- to_merge
- "2017-06-09"

And here the question will come : Where do we place the default report_portal.yml file? Well inside the init.rb we dynamically tell reportportal witch file to use:

init_dir = File.expand_path('../../init', __FILE__)

FileUtils.cp_r 'config/report_portal.yml', 'report_portal.yml' if not(File.exist?('report_portal.yml'))
rp_data = YAML.load_file("#{init_dir}/#{MainModule.brand}/report_portal.yml").to_yaml
parsed = rp_data % {date: Time.now.strftime('%Y-%m-%d')}
require 'fileutils'
FileUtils.chmod(0777, 'report_portal.yml')
File.open('report_portal.yml', 'w') { |f| f.write parsed }

So the file is placed in : /init/folder/report_portal.yml. Why ? in my case the framework has 7 project embedded in it , so each project has it’s own reportportal yml file.

Create the rake task
require_relative 'features/support/config'
require_relative 'features/support/logger'

namespace :rp do
  require_relative 'features/support/helpers/rp_helper'

  desc 'Merge today\'s launches in report portal for specific project'
  task :merge_todays, [:project] do |t, args|
    raise 'Specify project name: `rake merge_todays[project_name]`' if args[:project].nil?
    MainModule::RP.merge_todays args[:project]
  end
end

Basically now you are good to go , running the following command will merge your today’s launches for a specific reportportal project.

rake merge_todays[project_name]

Im using the merge command inside my pipeline script:

def merge(){

    currentBuild.description="Testing Image"
    def dockerContainerName="test1000-${env.BUILD_NUMBER}"

     sh """
      chmod ugo+rx ./bin/run_rake_merge_launches.sh;
       """

    sh """
    ./bin/run_rake_merge_launches.sh ${dockerContainerName} ${"docker.endpoint/ruby-autotest:${env.BUILD_NUMBER}"} rp:merge_todays[project_name];
    """
}

And here is the code for the sh script:

#!/bin/sh
# run_test.sh <container_name> <image_id> <features>
(
    CONTAINER_NAME=$1
    IMAGE_ID=$2
    RAKE_CMD=$3
    echo "cont: " $CONTAINER_NAME;
    echo "image: " $IMAGE_ID;
    echo "rake: " $RAKE_CMD;
    docker run --cap-add sys_admin  -v /dev/shm:/dev/shm -i  -e BROWSER -e TEST_ENV -e TEST_BRAND --name $CONTAINER_NAME $IMAGE_ID rake $RAKE_CMD;
    exit_code=$(docker inspect -f "{{ .State.ExitCode }}" $CONTAINER_NAME)
    docker cp $CONTAINER_NAME:/code/output .;
    docker rm $CONTAINER_NAME
    echo "exit:" $exit_code
    exit $exit_code
)

Having a reliable test reports tool is a very important step part of continuous integration that every company should target for . Such tools can give you a very good idea about the quality of your project , your framework reliability and any non technical person can read this kind of statistics.

It helps you and your team to monitor your tests  and gives you a clue how to improve your webdriver tests performance.

Happy Testing!


Like it? Share with your friends!

644
644 points
Test engineer

0 Comments

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.