Is this possible to pass dynamic elements in HTTP body in Object repository from Data Files?

KatalonObj.png

1 Like

you could replace the text with ${variale_name}, and then in the test case, if you have a parameter having the same ‘variable_name’, its value will be passed into the body.

Thanks much for the support, I have done in the same way but it’s not working! Could you please share me the screens?

Ganesh,

Sorry for my bad. We supported feature in WebElement Object and planned for doing the same with Webservice Object so I misunderstood that it was implemeted. However, the feature will be included in the release 5.4 within the next 2-3 weeks.

Great! It will be good if I get this in the planned release 5.4

This is a great news ! I can do all this using code but other member of my team do not have coding skills and it will be very nice for them to use Object parameters on Web Service Objects
Thanks !!!

1 Like

Yes, it is possible.

Dont forget to include :
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.RequestObject

create an RequestObject inside Object repository
then, add an HTTP Body request like with parameters you want (like ${name})
with object in Test case, write these lines :

//variables declarations
RequestObject request
ResponseObject reponse

//HTTP Body Request to be replace
String vsRequestBody = ‘’;

//Get the request objet in Object Repository and cast then into RequestObject
request = (RequestObject)findTestObject(‘AuthenticationServiceBinding’)

//Get request HTTP Body
vsRequestBody = request.getHttpBody();

//Replace dynamics parameters
vsRequestBody = vsRequestBody.replace(’${name}’, …your value…);

//Set the new request HTTP Body
request.setHttpBody(vsRequestBody);

//Executing the new Request object
reponse = WS.sendRequest(request);

…and that’s all

Please Katalon developpers, could you do it with parameters interfaces ?

Have a good day

bernard said:

Yes, it is possible.

Dont forget to include :
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.RequestObject

create an RequestObject inside Object repository
then, add an HTTP Body request like with parameters you want (like ${name})
with object in Test case, write these lines :

//variables declarations
RequestObject request
ResponseObject reponse

//HTTP Body Request to be replace
String vsRequestBody = ‘’;

//Get the request objet in Object Repository and cast then into RequestObject
request = (RequestObject)findTestObject(‘AuthenticationServiceBinding’)

//Get request HTTP Body
vsRequestBody = request.getHttpBody();

//Replace dynamics parameters
vsRequestBody = vsRequestBody.replace(‘${name}’, …your value…);

//Set the new request HTTP Body
request.setHttpBody(vsRequestBody);

//Executing the new Request object
reponse = WS.sendRequest(request);

…and that’s all

Please Katalon developpers, could you do it with parameters interfaces ?

Have a good day

Hi Bernard have u read the title of this post??

Code wise we can achieve!

As katalon studio claims that the tool is for non-techie users also! we need to seek in this aspect also.

Ganesh said:

Hi Bernard have u read the title of this post??

Code wise we can achieve!

As katalon studio claims that the tool is for non-techie users also! we need to seek in this aspect also.

Of course, I’ve read it…for remember : “Is this possible to pass dynamic elements in HTTP body in Object repository from Data Files??”

As Katalon does not provide functionnal issue until the next feature, i gave a technical solution with Test Case…issue that works well.

But…I will be happy to have a non-technie user solution (2 or 3 week to wait since 09 March 2018)

1 Like

bernard said:

But…I will be happy to have a non-technie user solution (2 or 3 week to wait since 09 March 2018)

That’s the true story that we really wanted we will see the same in the Future releases!

Cheers!

Trong Bui said:

you could replace the text with ${variale_name}, and then in the test case, if you have a parameter having the same ‘variable_name’, its value will be passed into the body.

Can you explain more on able solution please …by giving example.

In our application “token” is passed in the json body token " : “####9999323” . How can i replace dynamic token in the body and make request with updated body.

Please please give me solution

bernard said:

Yes, it is possible.

Dont forget to include :
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.RequestObject

create an RequestObject inside Object repository
then, add an HTTP Body request like with parameters you want (like ${name})
with object in Test case, write these lines :

//variables declarations
RequestObject request
ResponseObject reponse

//HTTP Body Request to be replace
String vsRequestBody = ‘’;

//Get the request objet in Object Repository and cast then into RequestObject
request = (RequestObject)findTestObject(‘AuthenticationServiceBinding’)

//Get request HTTP Body
vsRequestBody = request.getHttpBody();

//Replace dynamics parameters
vsRequestBody = vsRequestBody.replace(‘${name}’, …your value…);

//Set the new request HTTP Body
request.setHttpBody(vsRequestBody);

//Executing the new Request object
reponse = WS.sendRequest(request);

…and that’s all

Please Katalon developpers, could you do it with parameters interfaces ?

Have a good day

bernard said:

Yes, it is possible.

Dont forget to include :
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.RequestObject

create an RequestObject inside Object repository
then, add an HTTP Body request like with parameters you want (like ${name})
with object in Test case, write these lines :

//variables declarations
RequestObject request
ResponseObject reponse

//HTTP Body Request to be replace
String vsRequestBody = ‘’;

//Get the request objet in Object Repository and cast then into RequestObject
request = (RequestObject)findTestObject(‘AuthenticationServiceBinding’)

//Get request HTTP Body
vsRequestBody = request.getHttpBody();

//Replace dynamics parameters
vsRequestBody = vsRequestBody.replace(‘${name}’, …your value…);

//Set the new request HTTP Body
request.setHttpBody(vsRequestBody);

//Executing the new Request object
reponse = WS.sendRequest(request);

…and that’s all

Please Katalon developpers, could you do it with parameters interfaces ?

Have a good day

Your solution is not working …i implemented as it is …but not working please help

RequestObject request

//HTTP Body Request to be replace

String vsRequestBody = ‘’;

request = (RequestObject)findTestObject(‘VAM/Login’)

vsRequestBody = request.getHttpBody()

System.out.println(vsRequestBody)

vsRequestBody = vsRequestBody.replace(‘${Token}’,‘KKKKK’)

vsRequestBody = request.setHttpBody(vsRequestBody);

System.out.println(vsRequestBody)

Printing : null on the console

Hi Bernard,

I followed the same steps as you said and it is working for me. See screenshot for more details. Thanks to Bernard.

image.png

hallo Mr. Balraj,

can you explain, how it works on you? because i have the same issue. and where the body you make ? thankyou