Páginas

SyntaxHighlighter

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