Forum Discussion

armygrad's avatar
armygrad
Contributor
2 years ago

Set access_token Global variable from a jason response

Hi

 

Im trying to set a global variable token from a json response below is my response

 

{
"access_token": "94g4hCtN78",
"token_type": "Bearer",
"expires_in": 86400
}

 

Many Thanks

4 Replies

  • Hi armygrad,

    try to use json.tokenData.access_token to get the token string and put it in Property variable:
    testSuite.setPropertyValue("myToken", json.tokenData.access_token);  //in a defined Property myToken

     

    khelfrich23

    • armygrad's avatar
      armygrad
      Contributor

      Thanks for replying would be from a property transfer test step?

  • jkrolczy's avatar
    jkrolczy
    Regular Contributor

    By different ways to extract the token value from your response.
    If you can isolate that value into a variable, then you could use the following code example.

    Use Groovy script step here.

     

    ** Note: tokenID is my custom project properties

     

    def tokenid = extractedValue2
    log.info(" Token value: "+tokenid);

    testRunner.testCase.testSuite.project.setPropertyValue( "tokenID", tokenid );

     

    Global variable syntax shown below.

     

    Very useful webpage:

    https://www.softwaretestinghelp.com/soapui-tutorial-7-properties-in-soapui-groovy-script/

     

    These script lines are used to set the value to the local and global property.

     

    testRunner.testCase.setPropertyValue( " LocalPropertyName ", someValue )

     

    testRunner.testCase.testSuite.setPropertyValue( " LocalPropertyName ", someValue )

     

    testRunner.testCase.testSuite.project.setPropertyValue( " LocalPropertyName ", someValue )
    com.eviware.soapui.SoapUI.globalProperties.setPropertyValue
    ( " GlobalPropertyName ", someValue )