2

I am trying to call "POST /rest/raven/1.0/import/execution/cucumber/multipart" for Import Execution Results - REST

As this endpoint allows you to send two JSON files, I am written the below karate test

@UploadResultMultiPartURL Scenario: To export execution result to xray Test plan Given path 'import/execution/cucumber/multipart' And header Authorization = 'Bearer ' + accessToken And multipart file info = { read('classpath:data/testplanwithkey.json'), filename: 'testplanwithkey.json', contentType: 'application/json' } And multipart file result = { read('classpath:JiraReports/cucumber.json'), filename: 'cucumber.json', contentType: 'application/json' } When method post And print response

How ever I am karate response
15:50:50.334 [print] { "error": "Unexpected field (result)" }

I have attached my karate result file for the reference. Please let me where I am going wrong.

enter image description here

Also I have tried the same with rest api and I am to upload result with that but not sure where I am going wrong with karate: ResponseBody responseBody = given() .multiPart("results", new File(CUCUMBER_RESULT_FILE)) .mul .multiPart("info", "info.json", jiraExecutionJson.getBytes()) .header("Authorization", "Bearer " + jiraTokenGenerator.getXrayToken()) .post(JIRA_IMPORT_EXECUTION_MULTIPART_URL) .getBody();

abdul khan
  • 173
  • 5

2 Answers2

1

the problem seems to be in your karate specification where you have a multipart named "result" and it should be named "results".

And multipart file results = ....

Just for reference, you can see here a python code implementing a similar request.

Sérgio
  • 1,777
  • 2
  • 10
  • 12
  • Thanks, for the answer, probably I moved I step ahead now but I am still getting a error while running the karate test:{"error":"Error parsing results file!"} 11:47:40.571 [main] INFO com.intuit.karate - [print] { "error": "Error parsing results file!" } Also I tried the to execute the same steps with the same files manually via postman tool and were are able to execute the test but getting issue with karate test – abdul khan Jan 04 '22 at 11:26
  • which error are you getting exactly @abdulkhan? – Sérgio Jan 04 '22 at 11:28
  • {"error":"Error parsing results file!"} 11:47:40.571 [main] INFO com.intuit.karate - [print] { "error": "Error parsing results file!" } – abdul khan Jan 04 '22 at 11:29
1

I finally managed to resolved this issue by using value: alternative to read in rare cases where something like a JSON or XML file is being uploaded and you want to create it dynamically. So earlier I was trying to read the json with And multipart file info = { read('classpath:data/testplanwithkey.json'), filename: 'testplanwithkey.json' } And this worked for me

 And def value = read('classpath:data/testplanwithkey.json')
And multipart file info = { value: '#(value)', filename: 'testplanwithkey.json' }
abdul khan
  • 173
  • 5