Páginas

SyntaxHighlighter

Mostrando postagens com marcador bsf. Mostrar todas as postagens
Mostrando postagens com marcador bsf. Mostrar todas as postagens

quarta-feira, 6 de março de 2013

How to reference the current jmeter script base path?

I use lots of javascript in my Jmeter's test plans. I usually keep the code in the "Script" text area, either in BSF or JSR223 assertions and/or processors.
Sometimes however, I'd rather keep the scripts in a separate (external) file to ease maintenance.
Differently from the "CSV Data Set Config" element, the "JSR223 Assertion" "Script File" property does not use the current running script directory as the base path, it uses the user.dir system property instead.

The problem is that I normally organize my test assets following this directory layout:

/my_project/my_test.jmx       $jmx files
/my_project/js/script.js      $script files
/my_project/data/my_test.csv  $csv files

In order to reference scripts with paths relative to the current JMX file I use the FileServer class, in conjunction with the __javaScript function, like this:

${__javaScript(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir())}/js/script.js

quinta-feira, 31 de março de 2011

JMeter - Processing and handling JSON responses using BSF post processors

In one of my Jmeter posts I talked about how to post JSON data using a HttpSampler.
Now I want to show some cool stuff we can do using Jmeter's javascript/BSF support for handling JSON responses.

Suppose we have the following JSON response:

{ success: true, data:[ 1,2,3,4,5 ]  }

This string can be easily converted to a javascript object by using the eval function like this:

eval( 'var myObj = ' + prev.getResponseDataAsString() )

After the evaluation we can use the variable "myObj" as we wish and do things like accessing the success property:

log.info(myObj.success)

Or iterate over the list in the data property:

for (  var i = 0;  i < myObj.data.length; i++ ) {
     log.info(myObj.data[i])
}

We can also put the object in the implicit vars object so it can be used in another sampler, for example:

vars.putObject('myObj', myObj)