Parameterizing HTTP Body for API testing


#1

I am trying to run some API tests where I have two different JSON file payloads I want to test with.

I followed the instructions in the guide below for POST testing, but my tests keep failing with error codes 400 Bad Request.

https://docs.katalon.com/display/KD/Parameterize+a+Web+Service+object

One difference I’ve noticed between the article’s example and my API tests is that running a test request from my Object repository file will fail since my parameter’s value isn’t specified, but in the documentation’s example, their test still works.

Is there a workaround to make the documentation’s solution work or a way that I can add multiple JSON files to my test and specify which one to use during each test?

Running from the object repository like this should fail (though it doesn’t in the guide):

But when I create a test case and add in my parameter in script mode, my test again fails with an error code of 400.

Capture.PNG

Capture1.PNG


#2

Looks to me that you are trying to run your parameterized request directly from the Object Repository itself, which does not work, coz the parameters are not handled there (yet).

Maybe add a feature request for being able to test Parametrized Web Services objects directly from the Repository too.

The working example you mentioned however is being runned from a script.


#3

Thomas,
Your request could not be executed at Object Repository since it only contains parameters, not the actual value. In order to test the web service, you could create a test case, add Send Request test step for this web service and execute the test there.


#4

Sorry I did not make this clear in my original post, but I understand that I should get a 400 error when I run directly from the object repository. My issue is that when I then created a Test Case where I specified the value of my parameter the Test Case also failed with a 400 error.


#5

A shot in the dark: Are you maybe missing the quotes around your variable ${state01} in your HTTP body ?

Maybe use “${state01}” instead ?


#6

That worked, thanks!


#7

I’ve been experiencing the same issue, and have tried with the double quotes too, but it just passes the syntax as a text string.


#8

@Salema_Begum I experienced the same behavior.

But then I found in my case it happened when the variable type was String and I passed it null.
If I pass an empty string ‘’ or any string, it will work.

So, if you are in the same boat, just pass empty string for nulls.


#9

@jp12 thanks, it’s working for me now :slight_smile: