空手道API测试 - 如何使用API​​ 1中的变量(响应输出)到同一功能中的另一个API

时间:2018-01-11 17:52:59

标签: karate

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

前:

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)'我收到了错误。

1 个答案:

答案 0 :(得分: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