1

So I created a dynamic POST Request using the features in Karate. I tested out the newly created request manually and It did return a 200. However, when running the request through Karate, I am getting a 415 Unsupported media type.

POST REQUEST:

{
  "content": [
    {
      "assetId": "273108817",
      "country" : "US",
      "sourceSystemCode" : "GE_Clarify",
      "serviceRequestCode" : "Karate-Insert: 157264280",
      "serviceRequestTypeCode" : "servicerequestcorrective",
      "serviceRequestStatusCode" : "Started",
      "requester" : "Karate,DSL",
      "problem" : "Submitted Using Karate",
      "submissionTimestamp" : null,
      "sourceUpdateDate": "2017-09-13T15:53:51.597Z",
      "completionDate" : null,
      "dueDate" : null,
      "availabilityDate" : null,
      "remotely" : "0",
      "assetAvailability" : "Up",
      "facilityCode" : "US_294629"
    }
  ]
}

Karate Syntax

Scenario: Submit a new Service Request POST:

  • def ServiceRequestPostTemplate = read('classpath:testsuite/testdata/ServiceRequestServiceTemplate.json') * replace ServiceRequestPostTemplate | token | value | | assetId | assetTblAssetId | | country | country | | sourceSystemCode | sourceSystemCode | | serviceRequestCode | 'Karate-Insert: ' + NewServiceRequestCode |

    Given path 'serviceRequests/' And request ServiceRequestPostTemplate

    • header Authorization = 'Bearer ' + Token When method post Then status 200

Error message in below attachment. Note, I checked the request manually through Swagger UI and everything worked fine. I also passed it in as a hard coded variable in Karate and it worked fine. However, something about using the 'table' feature seems to change the media type.

enter image description here

4

2 回答 2

2

您还需要使用 header 关键字添加内容类型,如下所示

给定路径“一些/路径”

并请求 { some: 'data' }

并且标头 Accept = 'application/json'

当方法发布时

然后状态 200

希望这可以帮助。

于 2017-10-20T12:17:08.913 回答
1

The moment you use replace the type is converted to string - and this is clearly mentioned in the documentation.

So you have two options: a) type-cast the result of the replace back to JSON b) set the Content-Type header manually.

Hope that helps !

于 2017-10-20T17:52:11.470 回答