I am trying to generate jMeter JMX file using Kotlin and new jMeter functionality from v5.6.
But when I try to generate TestPlan like:
const val GUI_CLASS_VAL = "guiclass"
fun main() {
// Initialize JMeter engine
val jmeterHome = File("Apps/apache-jmeter-5.6.3")
val jmeterProperties = File(jmeterHome, "bin/jmeter.properties")
JMeterUtils.setJMeterHome(jmeterHome.path)
JMeterUtils.loadJMeterProperties(jmeterProperties.path)
JMeterUtils.initLocale()
...
// Test Plan
val testPlan = TestPlan("Test Plan")
// Test Plan HashTree
val testPlanTree = ListedHashTree()
testPlanTree.add(testPlan)
...
// Save to JMX
SaveService.saveTree(testPlanTree, FileOutputStream("test_plan.jmx"))
}
it generates something like
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3">
<hashTree>
<TestPlan testname="Test Plan">
but this file is not importable into jMeter
Problem loading XML from:'somePath/test_plan.jmx'.
Cause:
IllegalArgumentException: guiclass attribute is not found
because it should look like this:
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan">
I was trying all stuff like testPlan.addParameter(GUI_CLASS_VAL, "TestPlanGui") or testPlan.setProperty(GUI_CLASS_VAL, "TestPlanGui") but none of it worked.
Is there any way how can I force the generator to include these properties properly to all elements?
What do you mean by "JMeter doesn't generate", it's you who supposed to provide respective values for TEST_CLASS and GUI_CLASS properties
testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
Otherwise you can use "Copy Code" context menu action, it sets the proper GUI_CLASS value
More information: