2016-08-02 44 views
1

我正在使用Gatling工具加載測試我的服務。 我有以下從我的服務器(只是一個例子)迴應:Gatling - 檢索json的一部分並檢查相等性

{ 
    "result: { 
    "288249": { 
     "allowEdit": 1, 
     "cells": [ 
     { 
      "rollupId": "288249", 
      "description": "Gatling description: 93" 
     }, 
     { 
      "rollupId": "288249", 
      "description": "Gatling description: 83" 
     } 
     ] 
    } 
    } 
} 

我需要的是循環認爲所有$ .result.288249.cells [*]描述字段,並驗證有一個值,這就是生活。等於我在其中一個會話對象中擁有的內容。 它應類似於下面的僞代碼:

.check(
    jsonPath("$.result.*.cells[*].description").contains("${mySessionValue}) 
) 

的是,有方法,我可以以類似的方式使用?

提前致謝!

回答

-1

可以循環直通如下

$.each($.result, function(index,obj){ 
     $.each(obj['cells'], function(innerInd, innerObj){ 
      if(${mySessionValue} == innerObj['description']) 
      { 
       console.log('Found') 
       return 
      } 
     }) 
    }) 
+0

你的回答不是我期待看到的。我需要一個Gatling專家,它可以顯示應該如何完成 –

3

我想,我已經找到了解決辦法

.check(
     jsonPath("$.result.*.cells[?(@.description == '${mySessionValue}')]") 
     .find 
     .exists 
    ) 

這應該做的工作。

+0

您甚至不需要'find'和'exists',因爲那些是這些檢查步驟的默認值。 –

+0

很酷。謝謝,你已經創建了非常強大的工具;) –

+0

感謝您的友好的話:) –