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

New Lines via TestRail Mini API


#1

We are doing some automated tests, and are passing results via the TestRail Mini API. For the description field, for a new test run, add_run, we are trying to write a description that has multiple lines but were unable to to figure out how to pass a new line (e.g. \n, \r, etc) as part of the string we post.


#2

Hello Tage,

Thanks for your posting. Could you explain which tools you are using for the mini API? For example, cURL or an HTTP API of a programming language?

Regards,
Tobias


#3

We are using Python 2.7. The method as follows:

def postTestRail(self, testRunName, testRunDescription):

   # Create a Test Run
   url = '%sadd_run/%s%s' % (baseUrl, self.suiteId, key)
   headers = {'Cookie' : 'Accept: application/json'}
   values ={'name':testRunName,
       'description': testRunDescription}
   data  = urllib.urlencode(values)

   req = urllib2.Request(url, data, headers)
   response = urllib2.urlopen(req)
   html = response.read()
   addRunDict = json.loads(html)
   self.testRunId = addRunDict["id"]

Everything works fine, except the ‘description’ which shows up as a single line in TestRail. The description is passed from outside the script, in our case Jenkins.

Thank you,
Tage


#4

Hello Tage,

Thanks for the additional details. I will prepare an instrumented version of the mini API with additional log statements that should show a) what is submitted to TestRail and b) how TestRail interprets this data. You are using the download version of TestRail, is this correct?

Regards,
Tobias


#5

Tobias,

We are running TestRail v2.5.1.1626. I can check with the folks that installed it if it is a ‘download version’. Rereading the open posts, I want to be clear, that we can pass \r\n or \n\n, etc as part of the string but they just appear as text in the description instead of a new line.


#6

Hello Tage,

Okay, thanks for the update. This means you see the raw ‘\r\n’ etc. characters displayed in TestRail? If so, this seems to be a client-side issue (i.e. your Python code seems to misinterpret the newline characters). Could you please try to add some debug code to view the raw HTTP request?

http://stackoverflow.com/questions/4404654/debugging-python-web-service

Also, could you post an example on how you are using the postTestRail method?

Regards,
Tobias


#7

We discovered the issue was how we were parsing our xml files to feed into TestRail.

xml files use the
code (among others) to signify a new line. Which when parsed using python’s xml.dom.minidom will generate the appropriate new line escape character to pass into TestRail. \n is just treated as a raw text when parsed from xml using this module.


#8

Hello Tage,

Thanks for the update and good to hear that the newlines are working now. Just let me know in case you have any additional questions.

Regards,
Tobias