I am writing a test where different users have different rights to add and delete other users to a team. The test checks if the user can add a new user to the team or delete an existing user from the team.
However the users who can't add a new user won't get the id of the newly added user returned, so they don't have an id to test the delete on. For that purpose I added one user on which the delete can be tested by those who aren't allowed to delete that user.
When I run the tests the delete is always tried on the same user, also for those who are allowed to invite new users.
I tried with both BeanShell PostProcessor and BeanShell Assertion to add the proper id depending on if they user should have been able to invite a new user or not.
String teamResponse = "${teamAccountId}";
if (teamResponse == null)
{
${__setProperty(teamAccountId${userId},${__property(teamTestDelete)})}
}
else if (teamResponse.length() > 0)
{
${__setProperty(teamAccountId${userId},${teamAccountId})}
}
OR
if (ResponseCode.equals("201") == true)
{
${__setProperty(teamAccountId${userId},${teamAccountId})}
}
else
{
${__setProperty(teamAccountId${userId},${__property(teamTestDelete)})}
}
The teamTestDelete is a property from another thread where I have created the user to test delete on for those users who were unable to invite new users. If this user returns for example id 100, then all my delete tests try to delete id 100, even if they should have tried to delete the id from teamAccountId.
The line ${__setProperty(teamAccountId${userId},${teamAccountId})}
itself works by the way, as I have used this one on its own before attempting to use the id in teamTestDelete for the users who couldn't invite another user.
Anyone here who knows why it is always using the teamTestDelete id for all users, even for those who should get the one from teamAccountId? It's like the BeanShell PostProcessor or Assertion can never get in the "else if" for the first example or in the "if" for the second example. All help would be greatly appreciated.
Example scenario:
First I create a user with ID 100. Then UserA tries to invite a new user and succeeds, it has ID 201. UserB tries to invite a new user and succeeds, it has ID 202. UserC and UserD both try to invite new users, but fail as they don't have the rights.
For the delete I want UserA to try deleting the user with ID 201, I want UserB to try deleting the user with ID 202 and I want UserC and UserD to try deleting the user with ID 100.
The inviting users is a single thread that loops a number of times for each user, 4 times in this example, and has a counter that increases with each loop to specify the userId. The deleting users is another thread, which loops too. In my example code I sometimes have ${userId}, which refers to the userId from the counter. UserA for example will then have userId = 1.
By looping the threads and increasing the counter each time, every user gets their own userId, which can then be used to save variables or properties for each different user.
The first problem I see is with this snippet:
String teamResponse = "${teamAccountId}";
It looks like you're trying to use the value of reference teamAccountId
but are using the reference-name instead. Please replace with
String teamResponse = vars.get(“teamAccountId”);
Similar problem in
${__setProperty(teamAccountId${userId},${__property(teamTestDelete)})}
I would write this as
props.put("teamAccountId" + vars.get("userId"), props.get("teamTestDelete"))
Clearly, this is also easier to read/parse and understand :)