Integrating Automated Test Cases with TestRail

TestRail is a comprehensive tool to manage, track, and organize test cases. It caters the need to maintain test suites, test cases, and test results. Here, SpecFlow is used to run the test cases.

  1. Open your TestRail account and create a new project.create new project
  2. Define a test suite within the project containing automated test cases. You may have multiple suites depending upon requirement. While creating a test suite you can add description to explain about the purpose of test suite.Test suite description
  3. The created test suite will not contain any sections or test cases.test suite section

A test case is a single test that is executed by testers on a regular basis. Sections can be used to manage related test cases into groups.

  1. Create test cases in TestRail representing the automated test case.automated test cases
  2. This completes the creation of 1 test suite containing 1 test case.Test suite complete
  3. You can run a single test case multiple times. However, the result might differ each time. Using TestRail you can combine the test cases within a test run and provide a combined result.test passed
  4. Enable API for your TestRail project. This can be done by going to the Administration page through Dashboard.Admin Page
  5. Click ‘Manage site settings’ and go to ‘API’ tab and select ‘Enable API’ checkbox.Enable API

Note: You can create a dedicated user to have the automated test cases integrate with TestRail.

  1. Download the API and extract it to the folder where your solution is located.
  2. Add the API to your solution by inserting TestRail.csproj file into your solution using File->Add->Existing Project.
  3. Change your .Net framework to version 4.5.
  4. Build the Gurock project and add reference to Gurock.TestRail assembly.
  5. Add reference to the Newtonsoft JSON library.
  6. Create automated test case in SpecFlow by adding the following statements in your binding.

using Gurock.TestRail;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

  1. Add the following method to the binding.

[AfterScenario]

public static void AfterScenario(){

Gurock.TestRail.APIClient client = new Gurock.TestRail.APIClient(“https://yoursite.testrail.com/”);

client.User = “user@domain.com”; //user e-mail

client.Password = “SpecFlow”; //user password

Dictionary<string, object> testResult = new Dictionary<string, object>();

if(null != ScenarioContext.Current.TestError){

testResult[“status_id”] = “5”; //failed;

testResult[“comment”] = ScenarioContext.Current.TestError.ToString();}

else

{testResult[“status_id”] = “1”; //passed}

client.SendPost(“add_result/1”, testResult); //hardcoded test id.}

  1. Run the test and check TestRail getting passed.Test Passed

   You may also like – How to Manage Test Cases with Test Rail?

SHARE THIS

Get A Free Quote

Leave a Reply

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.