Passing multiple values between ThreadGroups - Jmeter - testing

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.

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.

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.

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.

Related

get request for search in JMeter

I am performing a search request in jmeter. So my test plan flow is home then login then product catalogue and then search. I tried to make a post request for search but it failing all the time. I used a CSV file so each time the query is changed. But then I used a get request and used the query variable in the search path like this search?query=${search_input}and then it passed but when i checked the html it is not the correct page. In the html response I also see this
{{noSearchResults.query}}'. But if i put the url on the browser it works fine. Can you please help me with this?
Double check that your ${search_input} variable has the anticipated value using Debug Sampler and View Results Tree listener combination
It might be the case that your ${search_input} variable contains special characters which need to be URL-encoded so you might need to wrap the variable into __urlencode() function like:
search?query=${__urlencode(${search_input})}
JMeter automatically treats responses with status code below 400 as successful, if you need to add an extra layer of check for presence of the results or absence of {{noSearchResults.query}} - use Response Assertion

Update secret parameter in Jenkins Job

I have a lot of free-style jobs in my Jenkins instance. I create them with Jenkins API (generate XML-file with configuration and post them by "http://my-jenkins-instance:8080/createItem?name=JobName").
There is one problem - I can not generate value in secret fields. For example, I want such a config:
Inject passwords to the build as environment variables -> Job passwords.
And I need to set 123 to Password field.
I can not do this through XML because it appears decoded in XML. Something like this: {AQAAABAAAANwHq0hsSF6...}
I want to set the value to this parameter
So my questions are:
Can I get the decoded value of a plain password through some API? So I could send 123 and get {AQAAABAAAANwHq0hsSF6...} back.
If not, can I set secret value some other way? I can only think of using Selenium but it is too slow (comparing to API).
I have found the solution.
I can set the value as a plain text: <value>123</value>, create or update a job. Then I need to disable and enable the job.

Jmeter: variable scope - How to use different random value for the same request

I'm willing to use 2 variables for random values with the same request.
I defined both in User Parameters as follows: var1=${__Random(1,100)}; var2=${__Random(1000,2000)} (Also I checked: Update once per iteration)
I have the requests:
Request1: GET user/${var1}
Request2: GET user/${var2}
During run-time, when it gets to request2 var2 equals var1!
How do I fix that?
Well, User Parameters is a PreProcessor so you should put it as a child of your HTTP Request in order to get correct behavior. You can use Debug Sampler and View Results Tree listener combination to validate variables values (see How to Debug your Apache JMeter Script article for more details)
I would recommend discarding this User Parameters and injecting the __Random() function directly into your HTTP Request sampler Path like
/user/${__Random(1,100,var1)}
/user/${__Random(1000,2000,var2)}
This is a simpler way to generate random numbers and get them stored into JMeter Variables.

Jmeter - use csv for setting http header

I want to set header for each request.
header is -
"token:value"
For every request this header value will be different and I have a csv file having all tokens listed there. Now, like we use csv for POST data values, I want to use this csv file to set header for each request.
CSV file -
"token1,token2,token3"
How to do this in jmeter ?
To achieve your goal, you should do following for each request:
Add HTTP Header Manager:
2 . Add CSV Data Set Config configured like this:
the idea is pretty good, if the referer field is widely used.
I'm not sure that you can use CSV data sets, because it reads ONE line for each user/ thread.
In a situation similar to yours, I had to use a __CSVread function, that allows to manually control if and when to read the next line.
Refer to: "CSVRead">http://jmeter.apache.org/usermanual/functions.html#_CSVRead"
If request the same but header changes, then you obviously need CSV Data Set Config element. Example of usage you can find in %JMETER_HOME%/bin/examples. If requests are different then I'm not sure it makes sens to use CSV file.

multiple user logins in jmeter

I am using jmeter to test a php application. I need to create a different thread with a unique session for each user. Because in my application you can only have one login per user at a time so putting 100 times the same user I will not get to any conclusion.
I have created 40 users user0,user1....user39 with the same password is there a way to automatically create simultaneous threads for each of them?
Thanks
I just implemented this using jmeter for an app that uses Spring Security (It would be very similar to PHP). This is fairly straightforward, basically:
1) Create a new CSV file using a text editor
Ex: CSVSample_user.csv
username1, password1
username2, password2
2) In jmeter, create a CSV Data Set Config element
Thread Group>add>Config Element>CSV Data Set Config
=> Assign variable names (see image)
3) Create an HTTP Request element
Thread Group>add>Sampler>HTTP Request
=> Create a POST with parameters, have the variable you created
put the values for the parameter. (See bottom image).
NOTE: There are other elements you need, such as cookie manager, etc. Also number of threads needs to be set to the number of login users.
You can use a CSV Data Set Config. This control will allow you to use an external source of variables.
Add -> Config Element -> CSV Data Set Config
You must set the variable names, something like:
Variable Names (comma-delimited): USERNAME,PASSWORD
Then you can use the variables in your HTTP Requests parameters like:
${USERNAME} and ${PASSWORD}
I realize this question is over a year old, but I just came across the same issue and thought I'd add my solution for anyone else who stumbles upon this issue.
If you have a sequence of usernames and passwords that are simply differentiated by numbers at the end of their values, you can use the __threadNum variable to log them in. So for the value of username you might say user${__threadNum}.
This solution is simpler than including a csv but only works where you have a list such as the one you suggested in your question.
keep csv file and testplan (i.e jmx) in a same folder and recheck the variable name in CSV datasetconfig and http request for any typing error.