Forum Discussion

Frido's avatar
Frido
New Contributor
8 years ago
Solved

How to create a JSONPath Property Transfer including a ${Properties#property} ?

In my project I want to use the test step Property Transfer to pass along some values from a REST response with JSON data within it. The JSONPath I want makes use of a property from a Properties Step called TestData.

 

The (part of the) data looks like this:

{
	"model": {
		"key": "P394-C0-C0-C0-C0-C0-C0-F0",
		"functionalKey": "P394_Melding-Organisatie_1",
		"name": "Melding.Organisatie",
		"properties": {
			
		},
		"questionText": "Organisatie",
		"explainText": null,
		"dataType": "entity",
		"rejectedValue": null,
		"readonly": true,
		"required": true,
		"hasDomain": true,
		"multiValued": false,
		"refresh": false,
		"displayLength": -1,
		"domain": [{
			"displayValue": "Amsterdam",
			"value": "Organisatie|0f7d20b8-ea98-412e-b375-b51b5d2aa131|"
		},
		{
			"displayValue": "Stockholm",
			"value": "Organisatie|fdea2088-60f9-4064-81b2-f491bc0d5b58|"
		},
		{
			"displayValue": "Luxembourg",
			"value": "Organisatie|fdbf6753-f727-47c5-b5e2-9ed32c99bd2c|"
		},
		{
			"displayValue": "Paris",
			"value": "Organisatie|b26c12a1-794a-472c-adec-d8240cd14770|"
		}],
		"messages": [],
		"values": ["Organisatie|b26c12a1-794a-472c-adec-d8240cd14770|"],
		"validations": [{
			"blocking": true,
			"type": "Required",
			"message": null,
			"parameters": {
				
			}
		}],
		"type": "field",
		"styles": []
	}
}

The JSONPath string looks like this:

$..model.domain[?(@.displayValue=='${TestData#Gegevens_melder.Organisatie}')].value[0]

 

When I use this JSONPath within a property transfer, the value of ${TestData#Gegevens_melder.Organisatie} cannot be found properly. I have verified the JSONPath by adding a JSONPath Match assertion to the specific RestRequest step. Within this assertion the JSONPath works fine so I may conclude the path is correct.

 

How can I create such a Property Transfer?

I don't want to use the ResponseAsXml possibility because of the enormous namespace I have to declare... but using that posibility works fine when I use the XPath 

//m:displayValue[text()='${TestData#Gegevens_melder.Organisatie}']/../m:value

3 Replies

    • Frido's avatar
      Frido
      New Contributor

       

      Thank you Paul.

       

      My question is indeed comparable with Property Expansions in JSONPath expression in Property Transfer step

       

      So there is no (open source) solution but a workarround which good enough. 

      Thanks for your advise to make use of namespace wildcards. This works fine!

       

       

      //*:displayValue[text()='${TestData#Gegevens_melder.Organisatie}']/../*:value

       

       

      Regards,

      Frido

  • Frido's avatar
    Frido
    New Contributor

    Finally I created a groovy script using JsonSlurper. This one has way better performance. The Property Transfer (with XPath) lasts > 6000 msec, when the same trick is done by JsonSlurper, it takes just 20 msec!

     

    import groovy.json.JsonSlurper
    def response = testRunner.testCase.testSteps["handleEvent Melding-Type"].getAssertableContent();
    def json = new JsonSlurper().parseText(response).events.changes.changes.model[0].findAll { it != null }
    
    testRunner.testCase.setPropertyValue( "model_Melding.Organisatie_value",
    	json.find{it.name=='Melding.Organisatie'}.domain.find{it.displayValue==context.expand('${TestData#Gegevens_melder.Organisatie}')}.value )