0
votes

I have JMeter script having many test elements like test fragments, include controllers , beanshell samplers, ssh samplers, SFTP samplers, JDBC etc. When I tried running JMX script using Java code( below) some of the test elements are getting skipped.One of the major problem is it is skipping Test fragments with out going inside another JMX script.We are running Test Fragments using include controllers which we tried all the combinations of paths.Please help to run test fragments inside JMX file using below Java code.

I tried all the paths inside JMX scripts, I added all JMeter Jars in maven repository etc.

public class Test_SM_RS_001_XML extends BaseClass {
public void Test121() throws Exception {
        StandardJMeterEngine jmeter = new StandardJMeterEngine();
    Summariser summer = null;
    JMeterResultCollector results;

        File JmxFile1 = new File(/path/to/JMX/File/test121.jmx");
        HashTree testPlanTree = SaveService.loadTree(JmxFile1);
        testPlanTree.getTree(JmxFile1);
        jmeter.configure(testPlanTree);
        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());
        }
}
}

I expect to run Test fragments inside JMX file ,but it is not considering and Skipping.

1

1 Answers

0
votes

Your test code is lacking essential bit: resolving of Module and Include controllers which need to be traversed and added to the "main" HashTree

So you need to replace this line:

 testPlanTree.getTree(JmxFile1);

with these:

JMeterTreeModel treeModel = new JMeterTreeModel(new Object());
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);

and this one:

jmeter.configure(testPlanTree);

with this one:

jmeter.configure(clonedTree);

More information: Five Ways To Launch a JMeter Test without Using the JMeter GUI