Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a jmx file with code

I want to do distributed testing in jmeter for which we need a jmx file. I want to write a code which will create a jmx file without using jmeter libraries and populate the values. can somebody help me?

like image 362
mani deepak Avatar asked Oct 02 '22 10:10

mani deepak


1 Answers

You may know that jmx file is a xml type file and its structured as node by node. Using any XML apis jmx files can be created programmatically . My suggestion is try to create an full testplan in jmeter with all basic test elements like Samplers, Listeners, Pre and Post processors and save jmx file then build new xml files based on that jmx structure as follows

<jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9">
  <hashTree>

    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>

    <hashTree>
      <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor" enabled="true">
        <stringProp name="RegexExtractor.useHeaders">false</stringProp>
        <stringProp name="RegexExtractor.refname">REF</stringProp>
        <stringProp name="RegexExtractor.regex">(.*)</stringProp>
        <stringProp name="RegexExtractor.template">$1$</stringProp>
      </RegexExtractor>
    </hashTree>


  </hashTree>

</jmeterTestPlan>

you can use javax.xml APIs to create XML files(refer this) like above. Initially you can add basic samplers, listners ,pre & post-processors and then try for advanced. Check this for partial implementation of your idea in C#.

Good luck.

like image 86
Nithin CV Avatar answered Oct 05 '22 11:10

Nithin CV