【问题标题】:Karate API Testing - How to use a variable (output from response) from API 1 to another API in same feature空手道 API 测试 - 如何将 API 1 中的变量(响应输出)用于相同功能的另一个 API
【发布时间】:2018-01-11 17:52:59
【问题描述】:

我有一个场景: 调用 API - 捕获响应 - 从响应中获取 ID 并调用另一个从响应 1 中获取输入 ID 的 API。

例如:

Feature: test graphql end point 

Background: 
    * url baseUrl + '/graphql'

Scenario: Create Org Call
    Given text query = 
        """
   mutation {
  test: createOrganization(
    name: "Org Name"
  )
  {
    Id
    name
  }
}
    """

And request { query: '#(query)' } 
When method post 
Then status 200 
* def res = response
* def id = res.data.test.Id
* print 'response:', response
* print 'Id:', id

Given text query = 
"""
mutation {
  createBackendHistory(orgId:  '#(id)') {
    orgId
  }
}
    """
And request { query: '#(query)' } 
When method post 
Then status 200 

如何传递值(来自调用 1 的 ID)是 createBackendHistory API

当我尝试 orgId: '#(id)' 时出现错误。

【问题讨论】:

    标签: karate


    【解决方案1】:

    由于querytext,您不能使用#() 嵌入式表达式。请参考文档:https://github.com/intuit/karate#replace

    试试这个:

    Given text query = 
    """
    mutation {
      createBackendHistory(orgId:  '<id>') {
        orgId
      }
    }
    """
    And replace query.id = id
    And request { query: '#(query)' } 
    When method post 
    Then status 200 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-15
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多