Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,358
Community Members
 
Community Events
165
Community Groups

Attaching evidence to a test execution API POST

Hi,

Scenario:

I am using Java + TM4J REST API to do a GET request on a test cycle, and test all the test cases that live within that cycle, before then doing a test execution POST to return the results of the tests when they are complete. As part of this, my program captures a screenshot of the browser at point of test failure and stores this locally within the project as a PNG image. All works so far..

Issue:

If you run a test execution through the GUI, you can copy and paste an image in or use the upload file to attach the image.

I cannot seem to work out however, or find any resource on how to use Java to attach an image or to paste in the image as part of the test steps or comments of that test execution. There is no API endpoints (checked with Adaptivist themselves on that) but there must be some way of getting around this problem by passing the image along with the api POST as part of the JSON body. 

 

Thankful for any help regarding this.

1 answer

1 accepted

1 vote
Answer accepted

TM4J Server API (v1) now has methods to post attachments to test executions and steps within them.

As per the API specification, in order to attach a file to a test execution (which corresponds to clicking on "Drop files here or select files" in TM4J web GUI on an open execution) use a POST call to the following resource: /testresult/{testResultId}/attachments

Mind that the testResultId part is not a test execution key, but the ID returned by the API when creating a test execution with the appropriate call.

The attachment must be passed as a multipart/form-data media type. E.g.:

POST https://jira.server.local/rest/atm/1.0/testresult/65208/attachments HTTP/1.1
Accept-Encoding: gzip,deflate
User-Agent: PostmanRuntime/7.15.0
Content-Type: multipart/form-data; boundary="----=_Part_5_1594638400.9687465465446"
MIME-Version: 1.0
Authorization: Basic PWhgKJHGKjhgkJHGKJHGUYT
Content-Length: 5766
Host: jira.server.local
Connection: Keep-Alive


------=_Part_5_1594638400.9687465465446
Content-Type: application/octet-stream; name=error.log
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="file"; filename="error.log"

<FILE CONTENT>

Is this the same when using TM4J for cloud? That is what I am currently using.

I haven't worked with TM4J Cloud API, but judging by the documentation, unfortunately no methods are implemented to work with attachments: https://docs.adaptavist.io/tm4j/cloud/api/v2/#operation/listTestCases.

It has just appeared in TM4J Server and let's hope they're working to add it in the Cloud ))

QIP Shot - Screen 01.02.20 11-34-39.png

Fingers crossed, thanks for server side info :)

@Scott Maitland, the create attachment request is finally implemented in Zephyr Cloud. Please take a look here: Create Attachment

I could not get it work, somebody can help me ?

 

Infact I realy wonder why testrun/testcase is not have a attachments ??

I use below to update test result in a cycle 

/testrun/{testRunKey}/testcase/{testCaseKey}/testresult

However this form does not have attachment.

And creating testresult id says it doesnt deal with a testrun, then how will I attach a file to test in a cycle then ????

 

In fact I tried every attachtment in this API but none of them worked for me

Zephyr Scale Server API (v1) (smartbear.com)

I can upload a file to test case, test cycle (test run), testresult that I have created but not a test instance in a cycle

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

181 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you