Forum Discussion

AAB's avatar
AAB
Regular Contributor
6 years ago

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 o...
  • AAB's avatar
    AAB
    6 years ago

    richie  OK, I found the solution on my own!  :-) 

     

    Setup a Project in ReadyAPI with 

    * 1 TestSuite

    * 1 TestCase

    * 2 teststeps: 1 Groovy and 1 REST Request

     

    copy this code in the groovy (it seems like a lot but it's not.  I've just added a lot of comments for later or someone else)

     

    //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
    /*=========================================================================================================*/
    //declare your parameters on Project level. In this case I have declared 2 parameters: beId and language. 
    //don't fill in anything.
    /*==========================================================================================================*/
    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 (findAGC.beId)
    log.info (findAGC.language)
    
    //fill in beid-value in PropertyValue  'param_beid'
    //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 )
    

    In your 'Rest Request' not necessary to add a parameter. Except if you want it to be added to the parameters of the URL.

    Go to the tab 'Projects', select the webservice that is linked to your Project, go to its Endpoint and add this in the resource of the URL:

    beId=${#Project#param_beid}

    beId = the parameter that should be looked for by the URL

    Project = Soapcall, don't change this!

    param_beid = the parameter that I defined on Project level for my parameter.

     

    If you run the Groovy test step and the request test step you will see the response.

     

    EDIT:

    This is a possibility for if the file doesn't use rootnames or space declarations!