JSR223 Pre-Processor Generate a Value

44 Views Asked by At

I have a situation where I am trying to figure out how to get a value that is generated dynamically within the web application. It's used in pretty much almost every request in the workflow I have been using.

I notice that it is created based on a javascript code within a function that goes along the lines of something like

function getbrowserSecurityPrint() {
 var choices = {
   excludes: {
     'random1' = true,
     'random2' = true,
     'random3' = true,
     'random4' = true,
     'random5' = true,
     'random6' = true,
 }
};

var materials = {};
SecurityPrint2.get(options,functions(materials){
  var values = materials.map(functions(materials) {
   return materials.value; 
}};

SecurityPrintToken = SecurityPrint2.x64hash128(values.join(''), 31);
brand.d.browserSecurityPrint = '{g1}' + SecurityPrintToken;
});
if (!brand.d.ServerProxy.isDestinationLocal()){
  getbrowserSecurityPrint(); 
}
function setSecurityPrint () {
  getbrowserSecurityPrint();
}
function setbrowserSecurityPrint() {
 var element = document.getElementById("GOP");
 if (element != null) {
   document.getElementByID("GOP").value = brand.d.browserSecurityPrint;}; 

Essentially I want the value GOP, but I can't find it anywhere to correlate it since I assume it is being generated within the source code.

I tried using the JSR223 pre-processor, but I am stuck as I don't know how to use it to achieve what I want

1

There are 1 best solutions below

0
Ivan G On
  1. The value of GOP (whatever it is) you can check using your browser developer tools by running the following code in the console:

    document.getElementById("GOP")
    

    if it's not there - assume that it is null

    In case the value is there you can get it using i.e. CSS Selector Extractor

  2. With regards to "using" the JSR223 PreProcessor there are 2 options:

    • if you use javascript language you can try copying and pasting this getbrowserSecurityPrint() function however JMeter is not a browser, you won't have access to basic objects like window or navigator or the aforementioned GOP element so you will need to come up with alternative solutions
    • if you use groovy language (which is the recommended option) you will have to re-implement getbrowserSecurityPrint() function totally in Groovy. The same restrictions as for javascript apply though

Currently we cannot help you because you provided an incomplete code and for example we don't know who is `SecurityPrint2 guy. I can only suggest using JavaScript debugger and inspect the function step by step understanding what it is doing and whether it's possible and how you can replicate it in Groovy.