Search code examples
karatejira-xray

Importing cucumber json result from karate feature file to Xray


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();


Solution

  • 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' }