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

Python: testrail.APIError: Unable to add result to "custom_step_results"


#1

Hello,
I want to update the results for individual steps under"custom_step_results". I have written a python code below:

if value['custom_parentsteps'] != None:
    print("Test ID: %s" %(value['id']))
    print("Case ID: %s"%(value['case_id']))
    data={"custom_step_results": [{"status_id": 2}]}

client.send_post('add_result/%s'%(value['id']),data)

Here value[‘id’] is Test ID.

I am getting following error. Could someone please take a look.

testrail.APIError: TestRail API returned HTTP 400 ("One of Status ID, Assigned To or Comment is required")


#2

Anyone please reply to my query please ?


#3

Hi there,

Thank you for your post. TestRail is mentioning that the ‘status_id’ or other required fields are missing, and this likely means that you have not correctly submitted the POST arguments with your request. Based on the example you referenced, it does not look like you have included all of these.


#4

Hi, Thanks for the reply.
Do you mean I need to include all these fields:

"custom_step_results": [
		{
			"content": "Step 1",
			"expected": "Expected Result 1",
			"actual": "Actual Result 1",
			"status_id": 1
		},

Mentioned in http://docs.gurock.com/testrail-api2/reference-results ??
Basically I want to add test results to individual steps value['custom_parentsteps'] , not overall test result. Could you please let me know.


#5

Hi,

Thank you for the follow up. You should be including all of those variables in your call.


#6

Hello, Thanks for the reply. I tried with all variables, but still it is not working. Could you give me an example of setting results for individual steps using python APIs? http://docs.gurock.com/testrail-faq/config-steps

Also according to http://docs.gurock.com/testrail-faq/config-steps , ‘actual result’ is an optional field, but you suggested to include “all” variables.

Here is my whole code:

#!/usr/bin/python

from testrail import *
from pprint import pprint
import json

client = APIClient('https://testrail.xxx.net/')
client.user = 'xxxx'
client.password = 'xxxxx'


#Each user has its id. This function returns respective user id
def get_user_id():
    user_id=client.send_get('get_user_by_email&email=xxx@xxx.com')
    #print user_id['id']
    return user_id['id']


#Get the test cases for the test run . You need to specify Test run id.
tests=client.send_get('get_tests/22047')
pprint(tests)

AssignedUser=get_user_id()

for value in tests:
    if value['custom_parentsteps'] != None:
        print("Test ID: %s" %(value['id']))
        print("Case ID: %s"%(value['case_id']))
        print("%s"%(value['custom_parentsteps']))
        data={"custom_step_results": [{"status_id": 2,'content': 'Build and install any sample app on the device.', 'expected': 'App installs successfully.'}]}

       client.send_post('add_result/%s'%(value['id']),data)

Sill I am getting following error:

Traceback (most recent call last):
  File "add_results_steps_testrail.py", line 38, in <module>
    client.send_post('add_result/%s'%(value['id']),data)
  File "/Users/nzunjarwad/my_scripts/testrail.py", line 51, in send_post
    return self.__send_request('POST', uri, data)
  File "/Users/nzunjarwad/my_scripts/testrail.py", line 79, in __send_request
    (e.code, error))
testrail.APIError: TestRail API returned HTTP 400 ("One of Status ID, Assigned To or Comment is required")

#7

Hello,

Thanks for your reply! We wouldn’t be able to provide any code/language-specific assistance as part of our support, but we’re happy to help with any general questions you have regarding the TestRail API methods and their syntax. From the error provided, it looks as though you’re not sending over one of the required fields (Status ID, Assigned To, or Comment). Please note that at least one of these fields also needs to be added for the overall test in addition to the fields/statuses that are added to the steps. You can see an example JSON request below:

{
	"comment": "Comment here",
	"custom_step_results": [
		{
			"actual": "Actual Result 1",
			"status_id": 1
		},
		{
			"content": "Step 2",
			"expected": "Expected Result 2",
			"actual": "Actual Result 2",
			"status_id": 2
		}
	]
}

Hope this helps!

Regards,
Marco


#8

Hello, Sorry i was not able to explain but my suggestion is to attend a free demo class by 12+ years experience on Python they are giving some free demo class so you can attend Here! Python