Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

How to pass individual step status and the complete test status to test rails from API


#1

Am running a test case, which has 5 steps. After executing each step when I update the test, I want to add the result to individual steps as well as the entire test.

Below is my code.

	try {
		//Create a Map to store the result of the test case.
        Map testResultMap = new HashMap();
        
        //Create an Array List to store the status of each test step.
        List stepResults = new ArrayList();
		
		for (int i = 0; i < eachStepResults.size(); i++) {
			//Create a Map for each Step's Result
			Map curr_step = new HashMap();
			curr_step.put("status_id", Status.valueOf(eachStepResults.get(i).toString()).value);
			curr_step.put("content", "Step " + (int)(i +1));
			stepResults.add(curr_step);
		}
		testResultMap.put("status_id", testcaseFinalStatus.value);
		testResultMap.put("comment", "This test case is " +  testcaseFinalStatus);
		testResultMap.put("custom_step_results", stepResults);
		client.sendPost("add_result_for_case/" + runID + "/" + caseID, testResultMap);
	}
	
	catch (APIException ex)
	{
		log.error(ex.getMessage());
	}

But the code is updating only the test but not the steps. I cannot see any steps mentioned in the test results.

Any help on how to implement this or fix my code is greatly appreciated.

Thanks,
Hemanth Kandukuri


#2

Hello Hemanth,

Thanks for your posting! Could you please check if the name of the custom field in TestRail matches your code and is really step_results? You can review this on the Administration > Customizations page. If this doesn’t help, it would be great if you could post the rest of the code (e.g. what eachStepResults is) as well as this would make it easier to diagnose.

Cheers,
Tobias


#3

Above the screenshot of Result Fields, I changed the code to

	testResultMap.put("stepresults", stepResults);

But even then its not working.

It is only updating the test.

eachStepResults is just an array of the results of each step for a test case passed to a utility method, which updates the entire test case status as well as individual step’s statuses. I am using this only to built the hashmap of the test results, so that I can pass it to the API call.

Below is the screenshot of eachStepResults,

Please let me know if you need any further information.

Thanks,
Hemanth


#4

Hello Hemanth,

Thanks for the update! The correct field name to use is custom_stepresults in your case. The custom_ prefix is used for custom fields and the system name (stepresults) identifies the field:

testResultMap.put("custom_stepresults", stepResults);

I hope this helps!

Cheers,
Tobias


#5

Thanks Tobias, that worked for me.

Thanks a lot man. :slightly_smiling:

Hemanth Kandukuri


#6

That’s great to hear and you are welcome, Hemanth :slightly_smiling:

Cheers,
Tobias


#7

Hello Guys what is eachStepResults in the above code?


#8

Hello Yogiraj,

Thanks for your reply! Please note that this was written by another customer, and you can see their explanation via their response above along with a screenshot.

Regards,
Marco


#9

Hi Marco,
Thanks for the quick response, i’m also trying to update the individual test step result of a test case back to testrail from automation framework and was figuring out how to get the results of each step through API.
I can see that the in earlier query one of the customer is getting those results in eachStepResults but still i’m not able to get the How part(method which return each step result).

Thanks,
Yogiraj


#10

Hello Yogiraj,
eachStepResults is just a placeholder for the number of steps I have in the test case.
Basically, you have to create a List of HashMap for each map representing each step result and write their results into them. And then add these map to list and then add this list to the final result map of the test case.

i.e.


Map testResultMap = new HashMap();
List stepResults = new ArrayList();
for (int i = 0; i < eachStepResults.size(); i++) {
//Create a Map for each Step’s Result
Map curr_testcase_step = new HashMap();
curr_testcase_step.put(“status_id”, );
stepResults.add(curr_testcase_step);
}
testResultMap.put(“status_id”, )
\\Adding the step result list to main result map.
testResultMap.put(“custom_step_results”, stepResults);
client.sendPost(, testResultMap);

#11

Hi Hemanth,

Thanks for your reply, i’ll try it out on my end now.

Thanks again :slight_smile:
Yogiraj


#12

Hello Hemanth & Marco,

i’m still confused but first let me explain you my use case and what i’m trying to do here, Basically i have created a cucumber-jvm, selenium automation framework where test cases are written in Gherkin style(BDD) in feature file and i’m using scenario outline to execute same test case with multiple data set(data driven).
Now every input data from feature file represents test step in testrail.
Now consider i have a invalid login test case which gets executed for 2 invalid login credentials

  1. Invalid username & valid password
  2. valid username & invalid password
    so currently what is happening is when this test gets executed it updates the result twice in testrail since it executes the same test twice with different data.

My Requirement:

when the test case gets executed for varied input data set it should update only individual test step as pass/fail.
If all steps are passed then mark test case as passed and if one of the test step fails mark test case as failed.

Questions :
1 How to get the count of steps of a particular test case through java in framework since i’m using cucumber i get object as Scenario, how to retrieve from it?

any help on this much appreciated.!

Thanks,
Yogiraj


#13

Hi Hemanth,

I was thinking of re using your method.
I didn’t get where the Status.valueof(eachStepResults.get(i).toString()).value) come from?
Is Status is a class here?Could you please help me with the entire method.

Thanks,
Sougata