Forum Discussion

AAB's avatar
AAB
Regular Contributor
6 years ago
Solved

ReadyAPI: How to add query parameters to an URL as a Resource

Hi,

 

Setup of my testcase is a groovy script that needs to read a URL and find a particular beId.

When found, that parameter is saved on Project Level in 'Customer Property'.

A second part of the code need to fetch that parameter from the Project Level and add it to the same URL.

What I have so far:

 

//cfr.  https://www.leveluplunch.com/groovy/examples/get-webpage-content-url-uri/
//https://community.smartbear.com/t5/SoapUI-Pro/How-to-Parse-a-JSON-Response-Using-Groovy-Examples/td-p/155770
import groovy.json.JsonSlurper

def getConceptSchemes = "https://pdc.dig.ta.belgium.be/api/pdc/concepts/schemes".toURL().getText()
//parse json string using JsonSlurper - basically converts it to a groovy list
def parsedJson = new groovy.json.JsonSlurper().parseText(getConceptSchemes)
//get data
def findAGC = parsedJson.find { it.name == 'ACTIVITY_GROUP' }
//log.info "result for specific beID: " + findAGC
log.info (findAGC.beId)
log.info (findAGC.language)

//put beid in request parameter
//cfr.  https://www.soapui.org/scripting-properties/tips-tricks.html
testRunner.testCase.testSuite.project.setPropertyValue('param_beid', findAGC.beId )
testRunner.testCase.testSuite.project.setPropertyValue('param_lang', findAGC.language )

//add the beId to the URL and put it in the REST request
//cfr; : https://kousenit.org/2011/11/02/converting-groovy-maps-to-query-strings/
def base = "https://pdc.dig.ta.belgium.be/api/pdc/concepts/schemes"
def params = [beId:findAGC.beId]
def sendToURL = base + params.collect{k,v -> '$k=$v'}.join('&')

What I get as result:

the beId in logfile and a popupwindow that only gives me the [$k=$v] in the URL in a script. (see screenshot)

 

What I want:

beId saved on PropertyLevel (=OK)

beId fetched from PropertyLevel and in URL from RESTRequest but as a Resource, it needs to be as a parameter IN the URL AS a resource. So actually I should have something like this:

https://pdc.dig.ta.belgium.be/api/pdc/concepts/schemes?beId=79ebe16a-da8b-4ce4-a388-c8b2287a2238

 

where beId = $k  and the UUID=$v

 

Does anyone have an idea how to do this please?

 

Thanks in advance.