I have a test in JMeter, and with GUI it runs perfectly, but when I run it using my Java code (like from here: http://blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui), I can't retrieve the params from the properties. If I print them in the beanshell log, I can see them. But, when I'm trying to use this params in thread Group as number of users it is not working.
More info:
- I have a setUp thread that counts the rows of the csv file and inserting a value to a property so that in the next thread I will use this property to set the amount of users. (this logic is happening twice during the test).
- I'm using Maven dependencies of: ApacheJMeter_http V2.11 (2.13 creates a conflict with common-pools2 and d-haven)
- eclipse (if it matters)
- The goal is that the only parameter I will pass to the test run is the test file.
- The prop statement in the test looks like this
${__P(paramName)}also tried$(__property{paramName}). - I have also created a property in the file itself instead of using in beanshell
JMeterUtils.setProperty("paramName","5");
Adding the bean shell snippet:
import org.apache.jmeter.util.JMeterUtils;
import java.io.*;
BufferedReader br = new BufferedReader(new FileReader("C:\\res\\movieResultData.csv"));
String line;
int counter = 0;
while ((line = br.readLine()) != null) {
counter++;
}
br.close();
JMeterUtils.setProperty("statsThreadNum",Integer.toString(counter-1));
My java Code:
@Test
public void ttt() throws Exception {
// JMeter Engine
StandardJMeterEngine jmeter = new StandardJMeterEngine();
// Initialize Properties, logging, locale, etc.
JMeterUtils.loadJMeterProperties("C:\\apache-jmeter-2.12\\bin\\jmeter.properties");
JMeterUtils.setJMeterHome("C:\\apache-jmeter-2.12");
//JMeterUtils.initLogging();// you can comment this line out to see extra log messages of i.e. DEBUG level
JMeterUtils.initLocale();
// Initialize JMeter SaveService
SaveService.loadProperties();
// Load existing .jmx Test Plan
FileInputStream in = new FileInputStream("C:\\apache-jmeter-2.12\\bin\\statsTests2.jmx");
HashTree testPlanTree = SaveService.loadTree(in);
in.close();
// Run JMeter Test
jmeter.configure(testPlanTree);
jmeter.run();
}