copy a file 10 times in jMeter

Advertisements

In order to copy an xml-file for my jMeter-test I created this groovy-script within a loop-controller named LC

number = (vars.get("__jm__LC__idx") as int) + 1; // get the current iteration and add 1
target = vars.get("fileName") + number;
cp(vars.get("fileName"), target);

fileName is an env-variable passed to my test as C:/MyDir/Verkehr.xml.

However when executing that test I get the following error:

Response message:javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.cp() is applicable for argument types: (String, String) values: [C:/MyDir/Verkehr.xml, C:/MyDir/Verkehr.xml41]
Possible solutions: any(), grep(), dump(), get(java.lang.String), put(java.lang.String, java.lang.Object), is(java.lang.Object)

What I want is Verkehr.xml1 (actually Verkehr1.xml but that leads too far for this question).

>Solution :

I don’t know what cp is, if it’s some custom function make sure that the class providing this function is in JMeter Classpath

If you don’t have this cp implementation – the easiest way would be going for FileUtils.copyFile() function like:

org.apache.commons.io.FileUtils.copyFile(new File(vars.get("fileName")), new File(vars.get("fileName") + number))

More information on Groovy scripting in JMeter: Apache Groovy – Why and How You Should Use It

Leave a ReplyCancel reply