How to put Pre-request-script of postman to robot framework?

Dear Team - This is with regards to API testing with ROBOT framework. We have been passing the data file in the POST request like below
But in some case we do also have the Pre-request-script as seen below (Snap shot from postman)
Is there a way where in we can pass “both” the body and the pre-request-script from postman to our robot framework?

Hi Anshul,

Only got one of your images :frowning_face:

It’s not going to work exactly as is, you will probably need to make some changes, robot framework is not a drop-in replacement for postman

Having said that robot framework is very powerful and should be able to acheive what you need to do, and we will try to help you get there.

FYI - I don’t use postman (well I used it once for some very basic stuff), so I don’t know what this Pre-request-script does.

I’m guessing that your Pre-request-script is replacing {{query}} with some value before posting the request?

If I’m correct you can replace {{query}} with a variable (e.g. ${query}`) in robot framework, set the value of this variable and then construct the JSON body before making the POST request.

Hopefully that’s what you are after?


1 Like

Thanks Dave. You have understood very correctly and have responded in the right manner.

I will try and will surely let know.

I might be late due to some vacations ahead .

Thanks again :+1:

1 Like

Hi Dave - I got one two working by replacing the pre-request script in the body’s {query}.
While for one of that I am getting error.

The body was as below
“type”: “sbmh-adv/linkservice/savemwlink”,
“correctRequest”: {{query}}

Hi Anshul,

You haven’t given enough information for me to even have an idea why you are getting that error.

Some questions that might help find the issue

  • Does the error happen before the request is made to the server?
    • If before which line in your robot file gives this error?
  • Or is the error in the response from the server?
    • if the error in the response, compare the body created by robot framework to the one created by postman, ideally put each on in a separate text file and diff the files with a diff tool
    • Are all the HTTP request headers the same?
    • The error didn’t specify which field had an invalid format, perhaps check the server logs? Perhaps a dev can help you where to check on the server?