Ignacio Yuste Lopez
Ignacio Yuste Lopez

Reputation: 53

Check Params in test

The question is simple. I have introduced in Params an Id and the server shall response a JSON with this Id. I have written a test:

tests["ID"] = jsonData.id === Params.Id;

but always returns ReferenceError: Params is not defined.

How can I get in a test, the variables introduced in Params?

Upvotes: 0

Views: 484

Answers (1)

MrMordoc
MrMordoc

Reputation: 13

You do not have access to the params in the javascript sandbox. My guess is it just attaches them directly to your URL. Instead, you can add the original ID as either an environmental variable or a global variable. Instead of accessing the parameter directly, set the parameter from the variable. Let's say you set the environmental variable "recordId", you could construct your params like this:

key: ID, value: {{recordId}}

Then, instead of accessing the param, you can compare the ID that is returned with the variable you have set.

tests["ID matches"] = jsonData.id === postman.getEnvironmentVariable("recordId");

Upvotes: 1

Related Questions