We have JMeter script having many test elements like test fragments, include controllers , beanshell samplers, ssh samplers, JDBC etc. When we tried running JMX script using Java code( below) include controller part of the script are getting skipped. We are running Test Fragments using include controllers by mentioning absolute as well as relative path. Please suggest us how to make test fragments inside JMX file using below Java code.
We have one JMeter script say xyz.jmx which is called from ABC.jmx jemeter script using include controller.
public class Test_INV_TI_001_XML extends BaseClass {
StandardJMeterEngine jmeter = new StandardJMeterEngine();
Summariser summer = null;
JMeterResultCollector results;
@Test()
public void INV_TI_001_XML() throws Exception {
File JmxFile1 = new File("/Path/To/JMX/File/ABC.jmx");
HashTree testPlanTree = SaveService.loadTree(JmxFile1);
JMeterTreeModel treeModel = new JMeterTreeModel();
JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
treeModel.addSubTree(testPlanTree, root);
SearchByClass<ReplaceableController> replaceableControllers =
new SearchByClass<>(ReplaceableController.class);
testPlanTree.traverse(replaceableControllers);
Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
for (ReplaceableController replaceableController : replaceableControllersRes) {
replaceableController.resolveReplacementSubTree(root);
}
HashTree clonedTree = JMeter.convertSubTree(testPlanTree,true);
jmeter.configure(clonedTree);
String summariserName = JMeterUtils.getPropDefault("summariser.name", "TestSummary");
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}
results = new JMeterResultCollector(summer);
testPlanTree.add(testPlanTree.getArray()[0], results);
jmeter.runTest();
while (jmeter.isActive())
{
System.out.println("StandardJMeterEngine is Active...");
Thread.sleep(3000);
}
if (results.isFailure())
{
TestAutomationLogger.error("TEST FAILED");
Assert.fail("Response Code: " + JMeterResultCollector.getResponseCode() + "\n" + "Response Message: " + JMeterResultCollector.getResponseMessage() + "\n" + "Response Data: " + JMeterResultCollector.getResponseData());
}
}
}
When executing ABC.jmx script using above code, xyz.jmx which is called in ABC.jmx script should also get called and gets executed successfully.