Passing multiple values between ThreadGroups - Jme

2019-09-09 08:37发布

问题:

I have ThreadGroup1 which performs login operation where it is getting Credentials from CSV file using CSV Dataset Config and saves username and password in two different variables like:

${__setProperty(USERNAMEGlobal, ${USERNAME})}
${__setProperty(PASSWORDGlobal, ${PASSWORD})}

Now in ThreadGroup2 I use these credentials using:

${__property()}

it works fine for a single user, but if I try multiple users (requests) last value overrides the previous all values and ThreadGroup2 receives only the last credentials defined.

I want all the credentials to be passed one by one to ThreadGroup2 and then the requests present in ThreadGroup2 should work according to all those credentials respectively.

How this can be done?

PS: I defined ramp-up period=1, Number of Users=3, loop=1.

回答1:

There are some options:

  • Inter-Thread Communication.
  • Put them to different properties:

    ${__setProperty(USERNAMEGlobal1, ${USERNAME1})}
    ${__setProperty(USERNAMEGlobal2, ${USERNAME2})}
    etc.
    
  • Initialize array with all usernames, stringify it and then put to property. However, it looks like a hack that will slow your plan.


回答2:

Looks like you can save all the username-password pairs into file csv-file in ThreadGroup1 and then re-use they in ThreadGroup2 via e.g. reading with CSV Data Set Config.



回答3:

I'm wondering if you really need two separate ThreadGroups?

It seems like you need only one ThreadGroup inside which you should perform your login actions and then save user/pass parameters in vars, not in props. Vars are thread local, so values of one thread won't override values of another.

You can set variable within the script: vars.put("var_name", "var_value"), and then use it like ${var_name}. Another option to set variable.