Hi there
I do define variables taken from random variables in a pre-request script as following:
pm.collectionVariables.set(“username”, Math.floor(Math.random() * 1000))
pm.collectionVariables.set(“name”,"{{$randomLastName}}");
I use the same variables in my request body:
{
“username”: “user{{username}}”,
“name”: “{{name}}”,
}
And then i test in my test script if i can find the values for {{username}} and {{name}} in the response:
pm.test(“Body matches string”, function () {
pm.expect(pm.response.text()).to.include(“user”,"{{username}}");
});
pm.test(“Body matches string”, function () {
pm.expect(pm.response.text()).to.include("{{name}}");
});
The first test succeds, but the second one fails…i do not see why as the value is correctly generated and also concluded in the response.
The console says:
Body matches string | AssertionError: expected ‘{“name":“Stehr”,“prename”:“Nathaniel”,“username”:“user239”,“organisationalUnit”:“ABC-DEF-GHI”,“telephone”:“0581234567”,“email”:"[email protected]”,“lang”:“DE”}’ to include ‘{{name}}’
Seems like the variable {{name}} is not loaded correctly?
Does anyone know of this problem?
Greetings and thanks for your help!
Benjamin