Forum Discussion

mihai_lita's avatar
mihai_lita
New Contributor
6 years ago
Solved

Transfer property to aplication/x-www-urlencoded request

Hi,   I've created a test suite which contains a test case. 1. I am calling an API that returns in it's response a clientId. eg. /api/v1/getClients 2. I am retrieving that clientId and use it...
  • mihai_lita's avatar
    mihai_lita
    6 years ago

    I managed to get it working with the following solution

    JSON RESPONSE FROM WHERE I NEED DATA

    {

    "clientId" : "1234556",

    "accountNumber" : "abc123"

    }

    Groovy script I used:

     

    def response = new groovy.json.JsonSlurper().parseText(context.response)
    
    log.info "clientId is: ${response.clientId}"
    log.info "accountNumber is: ${response.accountNumber}"
    
    context.testCase.setPropertyValue('CLIENT_ID', response.clientId.toString())
    context.testCase.setPropertyValue('ACCOUNT_NUMBER',  response.accountNumber.toString())

    And the in the post request I did the following

    Content-Type : application/x-www-form-urlencoded

    Body: 

    clientid=${#TestCase#CLIENT_ID}&accnt_number=${#TestCase#ACCOUNT_NUMBER}

     

    Thank you!