Answered question

Can I evaluate a Javascript function in NeoLoad?

I recorded my application using NeoLoad. On the UI of my application there is Javascript code that is executed on the browser. 

I need to evaluate a function that is coming from the Javascript contained in the server response.

I can use a variable extractor to get the definition of that function but I do not know how to use it in NeoLoad. Is it even possible?

When you record your application with NeoLoad, all requests/responses exchanged between the browser and your server are recorded. Since NeoLoad replays a script at protocol level, none of the Javascript that was recorded is executed.

Most of the time this Javascript is only needed to render the UI and so there's no need to evaluate since NeoLoad works at the protocol level. However, if you need to evaluate a Javascript sent by your server in your script, it's still possible.


Let's say you are able to extract your function from a server response. Here it is:

function AC_AddExtension(src, ext) 
{   if (src.indexOf('?') != -1)     
  return src.replace(/\?/, ext+'?');
  return src + ext;

That function has two parameters.

You can use the NeoLoad Javascript below to evaluate that function:


//I put the content of my variable extractor inside jsfunctionDef variable
var jsfunctionDef = context.variableManager.getValue("jscontent");
//I use a NeoLoad variable to create a random string
var nlRandom = context.variableManager.getValue("StringRandomVariable_0");
//Here i evaluate my function
// Use the js function with parameters and get result
var result = AC_AddExtension(nlRandom, "hardvalue");
//We log the result in Load Generator logs.
logger.debug("JS Value="+result);


This is just an example that you can adapt to suit your needs.


For more information, see "NeoLoad Javascript API" under the Appendixes section in NeoLoad documentation.

Did you find this useful ?

No (0)

Yes (0)

0% of users found this answer useful