JMeter測試工具.jmx文件詳解


 

摘要:了解.jmx文件格式類型,對jmeter二次開發與拓展有很大的幫助,當然也可以利用python對其進行一些處理(生成一些測試用例,對jmx文件進行 ”增刪改查“)。

一個完整用例的.jmx文件基本結構是這樣,類似於xml結構(樹狀結構)(文章標紅處 均是 可以修改的 地方(也可以說就是一個可控變量));

python 處理xml文件的模塊,bs4 , xml.dom;

下面按結構自上而下講解各個部分再.jmx文件中的表示:

測試計划  root

<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="測試計划" 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="用戶定義的變量" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>

變量包含: testname, enabled(true啟用,false禁用)

線程組  first Child

<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="組織架構管理_業務場景測試" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循環控制器" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
 <stringProp name="LoopController.loops">1</stringProp> -- 循環一次         </elementProp>
 <stringProp name="ThreadGroup.num_threads">1</stringProp> -- 線程數1 <stringProp name="ThreadGroup.ramp_time">1</stringProp>   -- Ramp-up Time =1,啟動時間         <longProp name="ThreadGroup.start_time">1472796674000</longProp>
        <longProp name="ThreadGroup.end_time">1472796674000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>

 JDBCDataSource

<JDBCDataSource guiclass="TestBeanGUI" testclass="JDBCDataSource" testname="數據庫連接信息配置" enabled="true">
          <boolProp name="autocommit">true</boolProp>
          <stringProp name="checkQuery">Select 1</stringProp>
 <stringProp name="connectionAge">5000</stringProp>  -- 最大連接age  <stringProp name="dataSource">mysql</stringProp>  -- 資源池變量  <stringProp name="dbUrl">jdbc:mysql://localhost/db</stringProp>  --jdbc連接 <stringProp name="driver">com.mysql.jdbc.Driver</stringProp>  -- jdbc驅動(可以設置為常量)           <boolProp name="keepAlive">true</boolProp>
 <stringProp name="password">root</stringProp>  -- db密碼  <stringProp name="poolMax">10</stringProp>  -- 最大連接數           <stringProp name="timeout">10000</stringProp>
          <stringProp name="transactionIsolation">DEFAULT</stringProp>
          <stringProp name="trimInterval">60000</stringProp>
 <stringProp name="username">name</stringProp>  -- 用戶名         </JDBCDataSource>

HTTP請求默認值

   <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP請求默認值" enabled="true">
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用戶定義的變量" enabled="true">
          <collectionProp name="Arguments.arguments"/>
          </elementProp>
 <stringProp name="HTTPSampler.domain">host</stringProp>  -- host 服務器IP  <stringProp name="HTTPSampler.port">port</stringProp>  -- port端口           <stringProp name="HTTPSampler.connect_timeout">100000</stringProp>  -- 連接超時時間
          <stringProp name="HTTPSampler.response_timeout">100000</stringProp>  -- 請求超時時間
 <stringProp name="HTTPSampler.protocol">http</stringProp>  -- 協議類型(變量可填)           <stringProp name="HTTPSampler.contentEncoding">utf-8</stringProp>
          <stringProp name="HTTPSampler.path"></stringProp>
          <stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>  -- 可選擇(java\HttpCliet4)
          <stringProp name="HTTPSampler.concurrentPool">4</stringProp>
        </ConfigTestElement>

HTTP信息頭管理器(http請求頭設置,key-value對應)

        <HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息頭管理器" enabled="true">
          <collectionProp name="HeaderManager.headers">
            <elementProp name="" elementType="Header">
 <stringProp name="Header.name">Content-Type</stringProp> <stringProp name="Header.value">application/json</stringProp>             </elementProp>
          </collectionProp>
        </HeaderManager>

用戶定義的變量

  <Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="用戶定義的變量" enabled="true">
          <collectionProp name="Arguments.arguments">
            <elementProp name="accessToken" elementType="Argument">
 <stringProp name="Argument.name">accessToken</stringProp>  <stringProp name="Argument.value">${accessToken}</stringProp>               <stringProp name="Argument.metadata">=</stringProp>
 <stringProp name="Argument.desc">description</stringProp>             </elementProp>
          </collectionProp>
  </Arguments>

僅一次控制器(循環控制器)

        <OnceOnlyController guiclass="OnceOnlyControllerGui" testclass="OnceOnlyController" testname="組織管理" enabled="true"/>

查看結果樹(該部分為固定項)

         <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看結果樹" enabled="true">
            <boolProp name="ResultCollector.error_logging">false</boolProp>
            <objProp>
              <name>saveConfig</name>
              <value class="SampleSaveConfiguration">
                <time>true</time>
                <latency>true</latency>
                <timestamp>true</timestamp>
                <success>true</success>
                <label>true</label>
                <code>true</code>
                <message>true</message>
                <threadName>true</threadName>
                <dataType>true</dataType>
                <encoding>false</encoding>
                <assertions>true</assertions>
                <subresults>true</subresults>
                <responseData>false</responseData>
                <samplerData>false</samplerData>
                <xml>false</xml>
                <fieldNames>false</fieldNames>
                <responseHeaders>false</responseHeaders>
                <requestHeaders>false</requestHeaders>
                <responseDataOnError>false</responseDataOnError>
                <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
                <assertionsResultsToSave>0</assertionsResultsToSave>
                <bytes>true</bytes>
                <url>true</url>
                <hostname>true</hostname>
                <threadCounts>true</threadCounts>
                <sampleCount>true</sampleCount>
              </value>
            </objProp>
            <stringProp name="filename"></stringProp>
          </ResultCollector>
          

HTTP請求(Sampler,此處為Json寫法,因為請求類型為Application/Json)

<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="operatorLogin_操作員登錄" enabled="true">
            <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments"> <collectionProp name="Arguments.arguments"> <elementProp name="" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">false</boolProp>  <stringProp name="Argument.value">{&quot;operatorNo&quot;:&quot;${operatorNo}&quot;, &quot;password&quot;:&quot;${password}&quot;, &quot;verifyCode&quot;:&quot;${verifyCode}&quot;}</stringProp>  <stringProp name="Argument.metadata">=</stringProp> </elementProp>
              </collectionProp>
            </elementProp>
            <stringProp name="HTTPSampler.domain"></stringProp>
            <stringProp name="HTTPSampler.port"></stringProp>
            <stringProp name="HTTPSampler.connect_timeout"></stringProp>
            <stringProp name="HTTPSampler.response_timeout"></stringProp>
            <stringProp name="HTTPSampler.protocol"></stringProp>
            <stringProp name="HTTPSampler.contentEncoding"></stringProp>
 <stringProp name="HTTPSampler.path">/operatorLogin</stringProp>   -- 請求路徑             <stringProp name="HTTPSampler.method">POST</stringProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
            <boolProp name="HTTPSampler.monitor">false</boolProp>
            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
          </HTTPSamplerProxy>

響應斷言

<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="響應斷言" enabled="true">
              <collectionProp name="Asserion.test_strings">
 <stringProp name="-1610171759">&quot;errorCode&quot;:&quot;0&quot;,&quot;errorMsg&quot;:&quot;操作成功!&quot;</stringProp>               </collectionProp>
              <stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
              <boolProp name="Assertion.assume_success">false</boolProp>
              <intProp name="Assertion.test_type">2</intProp>
              <stringProp name="Assertion.scope">all</stringProp>
              <stringProp name="Scope.variable">count_1</stringProp>
            </ResponseAssertion>

Debuger Sampler(固定樣式)

  <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="Debug Sampler" enabled="true">
            <boolProp name="displayJMeterProperties">false</boolProp>
            <boolProp name="displayJMeterVariables">true</boolProp>
            <boolProp name="displaySystemProperties">false</boolProp>
          </DebugSampler>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM