Forum Discussion

AAB's avatar
AAB
Regular Contributor
5 years ago

ReadyAPI use groovyscript to fetch the token from the environment

Hello,   I'm already using Token Authentication for my testcases. It's setup on environment level. For one of my testcases I need to go to the URL where an overview of all elements that I need is ...
  • AAB's avatar
    AAB
    5 years ago

    So....Ok, did it a little bit differently. I've added an extra TestSuite where I'm fetching the overview of the schemes. I've saved that into a parameter on project level.

     

    def response = context.expand( '${REST Request#Response}' ) log.info response testRunner.testCase.testSuite.project.setPropertyValue("SchemeS", response )

     

    In the testcase itself I deleted the pointing to the URL and called upon the parameter on project level.

    import be.environment.Of.myClient.testing.readyapi.java.lib.JsonParser
    
    //get the overview schemes on project level
    def getConceptSchemes = testRunner.testCase.testSuite.project.getPropertyValue('SchemeS')
    //parse json string using JsonSlurper - basically converts it to a groovy list
    JsonParser jsonParser = new JsonParser(getConceptSchemes)
    
    //search for beId country
    def beidCountrycode=  jsonParser.getJsonArray("['clientData'][?(@.name=='COUNTRY')]['beId']")
    //put beId on TesSuite level
    testRunner.testCase.testSuite.setPropertyValue('param_beid', beidCountrycode.get(0) )
    log.info beidCountrycode

     

    Then I put the AdminV2.0 Token on Projectlevel in the authManager and selected this profile for the project itself. ReadyAPI then asks me if it needs to inherent to the children cases. I said yes.