簡體   English   中英

空手道 API 測試 - 如何在同一功能中使用從 API 1 到另一個 API 的變量(響應輸出)

[英]Karate API Testing - How to use a variable (output from response) from API 1 to another API in same feature

我有一個場景:調用 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)' 我收到錯誤。

由於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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM