Robot Framework Integration with TestRail & TestRail CLI – Devstringx

Back to Blog
robot framework integration with TestRail

Robot Framework Integration with TestRail & TestRail CLI – Devstringx

In this blog, we share 02 different-2 methods of robot framework integration:-” should be In this blog you will learn the two ways to integrate the TestRail with RobotFramework:
  • TestRail CLI
  • TestRail API
In this blog, you will learn-
  • Execute Robot Framework tests using Selenium and Chrome driver
  • How to install TestRail CLI?
  • How to Configure TestRail instance?
  • Commands to save results in JUnit XML format and import generated results into TestRail.
  • See the executed test cases result in TestRail.

1) Robot Framework Integration With TestRail Using TestRail CLI

Let’s start the process of Robot Framework Integration With TestRail CLI

Prerequisites

  1. Download and install Python 3.10.4 and above.
  2. Download the Chrome driver version matching your current Chrome browser.
  3. Download and set up the IDE you are using for creating Robot Framework test cases.
  4. Create a sample project in the downloaded IDE. (Note: Here I am using PyCharm IDE)

Install TestRail CLI

  1. Open the command prompt.
  2. Type the command “pip install trcli”.
  3. Press the enter button.

Steps to Configure Your TestRail Instance:

  • Open the TestRail.
  • Click on Administration>Site Settings, click on the API tab and check the Enable API

Image of site setting

  • To map your automated test cases code in your TestRail you need to create a custom test case field. To create the custom test case field, follow the following steps:-
  1. Click on Administration
  2. Click on Customizations
  3. Click on Add Field
  4. Give Label Name “Automation ID
  5. Give System Name “automation_id
  6. Select Type as “String”
Upload Test Automation Results Using TestRail CLI
  1. Create a yml file and save it with “trcli-config,yml” name.
  2. You can configure the user credentials by using the following details in your trcli-config,yml file.
  • host: https://<instance name>.testrail.io
  • project: Project Name
  • username: [email protected] #Right your TestRail credentials here
  • password: test@123
  • title: TestRail Integration
Create a Sample Test Case
*** Settings ***
Library           OperatingSystem
Library           Selenium2Library
Library           String
Resource          ../Resources/resource.robot
Resource          ../Resources/common.robot
Test Teardown     Close All Browsers

*** Variables ***
${driver}   webdriver.gecko.driver
${path}   C:\\Users\\ddev0\\Downloads\\driver\\chromedriver
${url}    https://accounts.google.com/
${browser}   chrome

*** Test Cases ***
Test Open Gmail
#Note: Your test case will go here, its just a sample case
[Tags]    testrailid=2
Set Environment Variable    ${driver}   ${path}
Open Browser   ${url}   ${browser}
Input Text    ID=identifierId   [email protected]   #useremailaddress

Execute the Sample Test Case

After executing the below command in PyCharm to run the test case of RobotFramework, the results will save in JUNIT XML format. A new folder with the name “reports” will be created in your project working directory if your robot command was executed successfully.

  1. robot -itestrailid=2 -d reports -x junit-report.xml”.\TestCases\TestBrowser.robot”

If the above command will execute successfully then 2 reports will automatically generate in the robot framework project folder:

  • report.html

image of testbrowser report

  • junit-report.xml

Image of xml Version

2. Type the command “trcli -y -c “trcli-config.yml” parse_junit -f “reports/junit-report.xml” in PyCharm IDE to create the TestRun and upload the results into it.

Image of Command

After executing the above command, you will get the following information on your IDE screen.

image after project done

 

Visualizing the Results On TestRail

Now go to TestRail and you will observe test results report will be created in TestRail CLI automatically. Notice that it added a unique Automation ID by combining the classname and name attributes on each test on the JUnit report. This Automation ID is used to map the tests on your automation code base to the test cases on TestRail. This means that each time you run the TestRail CLI, it first attempts to match an existing test case on TestRail and only creates a new one in case there is no test case with that Automation ID.

image of test user login

In the overview, the section you will observe the Test Run with the given name (“Test Integration New”) was created into TestRail.

image of test run & test suite

By Clicking on generated Test Run you can see the detailed result.

Image of new test integration

2) Robot Framework Integration With TestRail Using TestRail API

Now we are going to share another process of Robot Framework Integration With TestRail CLI

What Is TestRail?

TestRail is a test case and test management programming device that can coordinate with Jira. In easy language, TestRail is the application used to compose the experiments in the proper arrangement. It’s the combination of sophisticated project management capabilities with features and is mostly used by the QA and Development teams to manage functional, exploratory, and automated tests. TestRail tool plays a so crucial role to organize your QA department and tracking software testing efforts.

Benefits of  Robot Framework Integration with TestRail
  1. Web-Based
  2. Integration with Jira
  3. Versatility
  4. User-Friendly
  5. Easy use of multiple testing Methods

3 Ways to Save Test Case Execution Results into the TestRail by Using

  a) Testrail Binding
  b) Testrail Listener
  c) Testrail API with the help of references

Here, In our blog, we are using a TestRail listener to do so.

Prerequisites

  • Enable TestRail API for your project: Navigate to TestRail > Administration > Site Settings > API menu and enable API.
  • Install the Robot Framework TestRail library using the below command
   pip install robot framework-testrail
  • Remove TestRail from the path in URLs
       <python folder path>/Lib/site-packages/TestRailListener.py         testrail_url

       <python folder path>Lib/site-packages/TestRailAPIClient.py       self._url
  • Create a TestRun into TestRail by including all those tests which you want to run and save the results

Read Also :- Read PDF File Using Python in Robot Framework

Link Test Cases

To submit test results from Robot Framework Integration with TestRail, you need to link a test case from Robot Framework to the one in TestRail. In order to do that, Create a tag named restrained in each test case of the robot framework to store the related TestRail test case ID. This tag should store numbers only. For example, if you have a test case with ID C1929, the variable should be filled with 1929.

  So the tag will be testrailid=1929

  Example:

*** Test Cases ***

Open Gmail

    [Tags]  testrailid=1929

    Open Browser https://www.gmail.com chrome

    [Teardown]    Close Browser
Run Tests Using Listener
pybot --listener TestRailListener.py:testrail_server_name:tester_user_name:tester_user_password:run_id:https:update  robot_suite.robot
FAQs
  • What is TestRail?

An online tool for managing test cases is called TestRail. Software testing efforts are managed, tracked, and organized using it by testers, developers, and team leads.

  • How to integrate Jira in TestRail?

You may sync requirements and tests between Jira and your TestRail installation in real-time using the TestRail-Jira connection. With individual to-do lists, filters, and email notifications, you can start test runs, create test plans, submit rich results, generate insightful reports, and work more efficiently.

  • How to Integrate Selenium with TestRail?

Step-by-step instructions for configuring and running test cases

  1. In TestRail, create test cases.
  2. Use UI script to add a button that says “Start Tests.”
  3. Create a trial run.
  4. Use C# and Selenium to set up and conduct UI test automation.
  5. Jenkins integration: parse the output and update TestRail.
  • Which tool is better than JMeter?

A popular tool for load testing is called Loadrunner from Micro Focus. It is among the best JMeter alternatives since it provides a simple interface for monitoring and analysis, complete with colorful charts and graphs.

  • What is better than TestRail?

PractiTest, Micro Focus ALM Quality Center, Zephyr E, and Case are among the products on our list of TestRail alternatives and rivals that reviewers deemed to be the best overall.

To read more blogs on ROBOT Framework from us here at Devstringx, then we have a lot to choose from you.

Share this post

Back to Blog