JMeter setProperty depending on ResponseCode or String value

I am writing a test where different users have different rights to add and remove other users to a command. The test checks if a user can add a new user to a team or remove an existing user from a team.

However, users who cannot add a new user will not receive the ID of the newly added user, so they do not have an ID to verify the deletion. For this I have added one user for which deletion can be verified by those who are not allowed to delete that user.

When I run the tests, the deletion is always checked by the same user and also who is allowed to invite new users.

I tried using BeanShell PostProcessor and BeanShell Assertion to add the correct ID depending on whether the user could 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)})}
}

      

TeamTestDelete is a property of another thread where I created a user to check for deletion for those users who were unable to invite new users. If this user returns, for example, id 100, then all my deletion tests try to remove id 100, even if they should have tried to delete id from teamAccountId.

The line ${__setProperty(teamAccountId${userId},${teamAccountId})}

itself works by the way as I used this one on its own before trying to use id in the TeamTestDelete command for users who couldn't invite another user.

Anyone who knows why he always uses the teamTestDelete ID for all users, even those who need to get a team from teamAccountId? It, like the BeanShell PostProcessor or Assertion, can never get into the "else if" for the first example or the "if" for the second example. All help would be greatly appreciated.

An example script:

  • The user has the right to invite and remove users from the team.
  • The user has the right to invite and remove users from the team.
  • UserC is not allowed to invite and remove users from the team.
  • UserD is not allowed to invite and remove users from the team.

First I create a user with id 100. Then UserA tries to invite a new user and succeed, it has ID 201. UserB tries to invite a new user and successfully, it has id 202. The user and user users both invite new users, but it fails because they have no rights.

For deletion, I want UserA to try to delete user with ID 201, I want UserB to try to delete user with ID 202, and I want UserC and UserD to try to delete user with ID 100.

The inviting users is a single thread that loops multiple times for each user, 4 times in this example, and has a counter that increments with each loop to indicate the userId. Removing users is another thread that also loops. In my example code, I sometimes have $ {userId} that refers to the userId from the counter. UserA, for example, will have userId = 1.

By looping threads and incrementing the counter each time, each user gets their own userId, which can then be used to store variables or properties for each other user.

+3


source to share


1 answer


The first problem I see in this snippet:

String teamResponse = "${teamAccountId}";

      

It looks like you are trying to use the link value teamAccountId

, but you are using the link name instead. Please replace with

String teamResponse = vars.get("teamAccountId");

      

A similar problem in



${__setProperty(teamAccountId${userId},${__property(teamTestDelete)})}

      

I would write it like

props.put("teamAccountId" + vars.get("userId"), props.get("teamTestDelete"))

      

Clearly this is also easier to read / disassemble and understand :)

+5


source







All Articles