Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

copy a file 10 times in jMeter

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading