0

I am new to jmeter. so I need to know what is the alternative for csv data set config because if I use csv data it okay for couple of user but every time i need to change or add the data in file. it time consuming i need efficient way which i can extract the user name and password from code instead of using hot code value.

2 Answers 2

0

The alternative options would be:

0

In JMeter, you can extract user id and password without using a CSV file by using the User Parameters pre-processor element. This element allows you to define variables that can be used in your test plan.

Here are the steps to extract user id and password using the User Parameters pre-processor element:

  1. Add a User Parameters pre-processor element under the Thread Group in your test plan.

  2. Define the variables for user id and password by clicking on the "Add" button in the User Parameters pre-processor element. For example, you can define the variable names as "username" and "password" and assign them with default values.

  3. Use the defined variables in the HTTP request for login. For example, in the "Username" and "Password" fields of the HTTP request, use ${username} and ${password} respectively.

  4. To update the user id and password for each thread, you can use the __threadNum function in the User Parameters pre-processor element. For example, you can define the default values of the "username" and "password" variables as "user${__threadNum}" and "password${__threadNum}" respectively. This will generate unique usernames and passwords for each thread, based on the thread number.

Here's an example of how to extract user id and password without using a CSV file:

  1. First, add a HTTP Request sampler to the Thread Group in JMeter.

  2. In the HTTP Request sampler, enter the URL of the login page and select the method (e.g. POST).

  3. Add a HTTP Header Manager to the HTTP Request sampler and set the content type to "application/x-www-form-urlencoded".

  4. In the Body Data section of the HTTP Request sampler, enter the following parameters (replace "username" and "password" with your actual parameters):

    • username: ${__P(username)}

    • password: ${__P(password)}

  5. Add a Regular Expression Extractor to the HTTP Request sampler.

  6. In the Regular Expression Extractor, set the following values:

    • Reference Name: userID

    • Regular Expression:

    • Template: $1$

    • Match No.: 1

  7. Add another Regular Expression Extractor to the HTTP Request sampler.

  8. In the Regular Expression Extractor, set the following values:

    • Reference Name: password

    • Regular Expression:

    • Template: $1$

    • Match No.: 1

  9. Now, you can add a Loop Controller to the Thread Group and set the number of iterations to the desired number of users.

  10. Inside the Loop Controller, add a User Defined Variables configuration element.

  11. In the User Defined Variables, add the following variables (replace "user1" and "pass1" with your actual values):

    • username_1: user1

    • password_1: pass1

    • username_2: user2

    • password_2: pass2

    • ...and so on for each user.

  12. Finally, go to the HTTP Request sampler and replace the hard-coded values for username and password with the variables you just created, like this:

    • username: ${_P(username${__jm__Loop Controller__idx})}

    • password: ${_P(password${__jm__Loop Controller__idx})}

This way, each iteration of the Loop Controller will use a different set of user credentials, without the need for a CSV file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.