Guys, I have a problem. I have a request “Create a teacher”. In this request, in the request body, I use Dynamic variables:
{
"username": "{{$randomUserName}}",
"firstName": "{{$randomFirstName}}",
"lastName": "{{$randomLastName}}",
"email": "{{$randomEmail}}",
"password": "{{$randomPassword}}",
"role": "teacher"
}
In the Tests tab, I write a script to set these randomly generated username and password as collection variables:
const requestData = JSON.parse(request.data);
pm.collectionVariables.set("teacherUsername1", requestData.username);
pm.collectionVariables.set("teacherPassword1", requestData.password);
Here, I am addressing the request body since there is no password in the response.
Next, I use these variables teacherUsername1
and teacherPassword1
in my next request “Create a teacher token”:
{
"username": "{{teacherUsername1}}",
"password": "{{teacherPassword1}}"
}
Now the problem: when I run each request manually in order, everything works how it is supposed to work: username and password are randomly generated and saved as variables, and in the getting a token request, Postman uses these variables.
However!!! when I do a Collection run, I can see in the logs that the info in the request and response bodies of my “Create a teacher” request doesn’t match:
this a request body:
{
"username": "Kameron.Roberts",
"firstName": "Gabriel",
"lastName": "Huel",
"email": "Tremayne58@gmail.com",
"password": "ucrTJRCkozxHpzk",
"role": "teacher"
}
This is a response body:
{
"id": 2286,
"username": "Freddy42",
"email": "Wade14@yahoo.com",
"firstName": "Darrin",
"lastName": "Kozey",
"role": 2
}
The question is WHY? And how to solve this?