JMeter, streams with dynamic incremental value

I created a JMeter functional test, which essentially:

  • creates a user;
  • logs in with the user;
  • deletes the user.

Now I need to be able to stream this and dynamically generate a username with a default prefix and a numeric incremented suffix (i.e. TestUser_1, TestUser_2, ... etc.).

I used a counter and everything worked fine until I really typed in the number of threads / loops. When I did this, I had a conflict with the counter. Some threads tried to read the counter, but the counter was already incremented by another thread. This led to an attempt to delete the thread that was just created, and then tried to log in with the thread that was just deleted.

The project is configured as follows:

Test plan
    Thread group
        Counter
        User Defined Variables
        Samplers

I was hoping to solve this problem using a counter to add a number to user variables when a thread executes, but the counter cannot be accessed in user-defined variables.

Any ideas on how I can solve this problem?

Thanks in advance.

0
source share
2 answers

I have successfully used the following scheme with any number of users tested:

1. Generate using a beanshell-script (in BeanShell Sampler for example) a csv file with the -ser test, for example:

testUserName001,testPwd001
testUserName002,testPwd002
. . .
testUserName00N,testPwd00N

, .
" N ", , setUp Thread Group , , jmx- script... .

beanshell- .


2. TEST APPLICATION, .
, .

    Thread Group
    Number of Threads = 1   
    Loop Count = 1
        . . .
        While Controller
        Condition = ${__javaScript("${newUserName}"!="",)}  // this will repeat until EOF
            CSV Data Set Config
            Filename = ${__property(user.dir)}${__BeanShell(File.separator,)}${__P(users-list,)}    // path to generated users-list
            Variable Names = newUserName,newUserPwd    // these are test-users details read from file into pointed variables
            Delimiter = '
            Recycle on EOF? = False
            Stop thread on EOF? = True
            Sharing Mode = Current thread group

            [CREATE TEST USERS LOGIC HERE]  // here are actions to create separate user in application
                . . .


3. . , , 1, N .

    Thread Group
    Number of Threads = ${__P(usersCount,)}    // set number of users you need to test
    Ramp-Up Period = ${__P(rampUpPeriod,)}  
    Loop Count = X
        . . .
        While Controller
        Condition = ${__javaScript("${newUserName}"!="",)}  // this will repeat until EOF
            CSV Data Set Config
            Filename = ${__property(user.dir)}${__BeanShell(File.separator,)}${__P(users-list,)}    // path to generated users-list
            Variable Names = newUserName,newUserPwd    // these are test-users details read from file into pointed variables
            Delimiter = '
            Recycle on EOF? = False
            Stop thread on EOF? = True
            Sharing Mode = Current thread group

            [TEST LOGIC HERE]  // here are test actions
                . . .


" + + CSV":

3,1. CSV Data Set Config :
,, . - - " EOF? = True",
,, . ( , , ) - - " = "; ,, . - " = newUserName, newUserPwd" - ;
3.2. CSV Data Set Config - - ( EOF).
3.3. - , ramp-up = 0.


script : multiuser.jmx.


Beanshell script :
 -
 - ( "TestUser_" )
 - (, 0 - TestUser_1, 00 - TestUser_01, 000- TestUser_001 ..), orexclude )
 - .

import java.text.*;
import java.io.*;
import java.util.*;

String [] params = Parameters.split(",");

int count = Integer.valueOf(params[0]);
String testName = params[1];
String nameFormat = params[2];
String usersList = params[3];

StringBuilder contents = new StringBuilder();

try {
    DecimalFormat formatter = new DecimalFormat(nameFormat);
    FileOutputStream fos = new FileOutputStream(System.getProperty("user.dir") + File.separator + usersList);

    for (int i = 1; i <= count; i++) {
        String s = formatter.format(i);
        String testUser = testName + s;
        contents.append(testUser).append(",").append(testUser);

        if (i < count) {
            contents.append("\n");
        }
    }

    byte [] buffer = contents.toString().getBytes();    

    fos.write(buffer);
    fos.close();
}
catch (Exception ex) {
    IsSuccess = false;
    log.error(ex.getMessage());
    System.err.println(ex.getMessage());
}
catch (Throwable thex) {
    System.err.println(thex.getMessage());
}


:

enter image description here

, .
, .

+4

" " "". , JMeter. 3.2. "BeanShell Sampler", .

, "Counter" INDEX Counter

RUN_FOLDER TESTS_FOLDER INDEX "BeanShell Sampler", Beanshell

"Debug Sampler" , "View Results Tree". , RUN_FOLDER INDEX (5 ). enter image description here

+1

All Articles