Search code examples
jmetercorrelationjsr223

Jmeter - Calling javascript using JSR223 Post processor


I capture 6 elements using a regular expression. say

Variable : UserDetails
Regular Expression : loadHeadWorkFlow\('(.+?)','(.+?)','(.+?)','(.+?)','(.+?)','(.+?)','/I
Template : $1$$2$$3$$4$$5$$6$

Now I could access these values via UserDetails_g1, UserDetails_g2.....UserDetails_g6

Next, these 6 values need to be encrypted using a javascript file. The file contains the logic.

How should my code be using JSR223 post processor?

The steps that I followed:

1.

load('Encryption.js');

   var result = encrypt("${UserDetails_g1}","password");
   log.info("encrypted value is "+result);
   vars.put("LoginDataString",result);

   var result1 = encrypt("${UserDetails_g2}","password1");
   vars.put("UserId",result1);

   var result2 = encrypt("${UserDetails_g3}","password2");
   vars.put("RoleId",result2);

First value is encrypted correctly. But the other values aren't correct. If I add individual post processors for every variable. All the encrypted values show correctly.

Is there a way where I could use a single post processor to perform all the 6 encryptions. Thanks in advance

Regards, Ajith


Solution

  • Use vars instead of ${} syntax

     var result = encrypt(vars.get("UserDetails_g1"),"password");
     log.info("encrypted value is "+result);
     vars.put("LoginDataString",result);
    
     var result1 = encrypt(vars.get("UserDetails_g2"),"password1");
     vars.put("UserId",result1);
    
     var result2 = encrypt(vars.get("UserDetails_g3"),"password2");
     vars.put("RoleId",result2);