Pm.test to.include a varible

Hey, how can I check the body response if it includes a variable?
I want to check if the body includes a certain string, however I want to give the variable to be checked, but haven’t been able to get the postman to work it it.
-the variable is a string, used earlier in the collection and it acts like a title, that should appear on my get request. the below script works if I put the string itself, however I want to put the variable, as I change the variable often and don’t to manually change the string.

pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include(Variable); });

Hey @theToncheff

Where are you declaring the variable?

If it is set as an environment, global or collection variable - you can use pm.variables.get('var_name') in the .include() function or use the specific variable scope to do the same thing.

1 Like

Yes, thank you! This is what I was trying to achieve.

1 Like