电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

基于Python組裝jmx并調(diào)用JMeter實(shí)現(xiàn)壓力測(cè)試

瀏覽:4日期:2022-07-06 14:16:18

JMeter可以通過(guò)os命令調(diào)用Python腳本,Python同樣可以通過(guò)系統(tǒng)命令調(diào)用JMeter執(zhí)行壓測(cè)

Python調(diào)用JMeter

首先要安裝JMeter,官方下載地址

解壓并配置配置環(huán)境路徑或建立軟連,使得在命令輸入jmeter便可以執(zhí)行,如

unzip apache-jmeter-5.3.zipmv apache-jmeter-5.3 /usr/loca/jmeterln -s /usr/local/jmeter/bin/jmeter /usr/bin/jmeterln -s /usr/local/jmeter/bin/jmeter-server /usr/bin/jmeter-server

打開(kāi)JMeter并設(shè)計(jì)一個(gè)測(cè)試計(jì)劃保存為testplan.jmx

使用Python調(diào)用JMeter壓測(cè)并生成報(bào)告

Python中可以使用os.system()或supprocess.Popen()調(diào)用系統(tǒng)命令,前者實(shí)時(shí)顯示在屏幕上,后者可以獲取到屏幕輸出信息。使用Python調(diào)用JMeter運(yùn)行及生成報(bào)告的命令如下。

import subprocessjmx_file = ’testplan.jmx’ # jmx文件路徑result_file = ’result.jtl’ # log_file = ’run.log’report_dir = ’report’run_cmd = f’jmeter -n -t {jmx_file} -l {result_file} -j {log_file}’ # 無(wú)界面運(yùn)行JMeter壓測(cè)命令report_cmd = f’jmeter -g {result_file} -o {report_dir}’ # 生成HTML報(bào)告命令# 不需要獲取屏幕輸出是,可以使用os.system()# os.system(run_cmd)# os.system(report_cmd)# 需要獲取屏幕輸出是,可以使用subprocess.Popen()p1 = subprocess.Popen(run_cmd, shell=True, stdout=subprocess.PIPE)print(p1.stdout.read().decode(’utf-8’))p2 = subprocess.Popen(report_cmd, shell=True, stdout=subprocess.PIPE)print(p2.stdout.read().decode(’utf-8’))

組裝jmx

每一測(cè)試計(jì)劃為一個(gè)jmx文件,jmx實(shí)際上是xml格式的,包含一些JMeter自定義的格式規(guī)范。常用的組件有:

: 測(cè)試計(jì)劃 : 線程組 : CSV數(shù)據(jù)文件 : HTTP請(qǐng)求 : HTTP請(qǐng)求頭管理器 : Cookies管理器 : DNS緩存管理器 : 監(jiān)聽(tīng)器(包括查看結(jié)果樹(shù)、聚合報(bào)告等) : 響應(yīng)斷言 <io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample></io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample>: 三方Dubbo請(qǐng)求插件

Dubbo插件jmeter-plugins-dubbo下載鏈接

jmx中,如果一個(gè)組件有子組件,格式為

<ThreadGroup 組件基本屬性> ...線程組配置</ThreadGroup><hashTree> ...內(nèi)部子組件</hashTree>···如果不包含子組件,則后面接一個(gè)<hashTree/> 單標(biāo)簽直接結(jié)束,例如:```xml<CSVDataSet> ... CSV數(shù)據(jù)組件配置</CSVDataSet><hashTree/>

詳細(xì)的格式可以自己使用JMeter創(chuàng)建一個(gè)測(cè)試計(jì)劃,使用文本文件打開(kāi)jmx文件查看。

使用Python組裝jmx文件的方式有兩種,一種是固定模板的數(shù)據(jù)渲染,一種類似JMeter的逐個(gè)組件添加,第一種比較簡(jiǎn)單。通過(guò)分析jmx文件中的變量,我們使用jinja2模板語(yǔ)法,將其中的變量進(jìn)行參數(shù)化,對(duì)需要判斷和循環(huán)的變量設(shè)置if和for循環(huán)。

Jinja2中文文檔

假設(shè)我們的測(cè)試計(jì)劃結(jié)構(gòu)為:

測(cè)試計(jì)劃 DNS緩存管理器 Cookies管理器 CSV文件(多個(gè)) ... 聚合報(bào)告 線程組(多個(gè)) CSV文件(多個(gè)) HTTP請(qǐng)求(或Dubbo請(qǐng)求) HTTP請(qǐng)求頭管理器 CSV文件(多個(gè)) 響應(yīng)斷言 察看結(jié)果樹(shù)

將jmx中的關(guān)鍵數(shù)據(jù)抽取并組合,我使用的完整數(shù)據(jù)格式如下:

data.yaml

test_plan_name: 測(cè)試計(jì)劃comments: 測(cè)試計(jì)劃描述hosts: - name: las.secoo.com address: 112.126.120.128cookies: clear_each_iteration: ’true’csv_files: - {’name’: ’數(shù)據(jù)文件1’, ’path’: ’data.csv’, ’varnames’: ’a,b’, ’delimiter’: ’,’} - {’name’: ’數(shù)據(jù)文件2’, ’path’: ’data.csv’, ’varnames’: ’c,d’, ’delimiter’: ’,’}thread_groups: - thread_group_name: 線程組1 comments: 線程組1描述 enabled: ’true’ num_threads: 50 loops: -1 ramp_time: 0 scheduler: ’true’ duration: 30 delay: ’’ http_samples: - request_name: HTTP-GET enabled: ’true’ csv_files: - {’name’: ’數(shù)據(jù)文件4’, ’path’: ’data.csv’, ’varnames’: ’a,b’, ’delimiter’: ’,’} request: protocol: https domain: httpbin.org port: ’’ encoding: ’’ path: /get method: GET connect_timeout: ’’ response_timeout: ’’ params: {’a’: 1, ’b’: 2} headers: {’token’: ’aaaaaa’, ’x-text’: ’bbbbb’} follow_redirects: ’false’ auto_redirects: ’false’ use_keepalive: ’false’ validate: - test_field: response_data # response_data響應(yīng)文本 response_code響應(yīng)代碼response_message響應(yīng)信息response_headers # 請(qǐng)求頭request_headers sample_label URL樣本 response_data_as_document文檔(文本) 請(qǐng)求數(shù)據(jù)request_data test_type: 2 # 2 包括 1匹配 8 相等 16字符串 否+4 或者+32 strings: [’a’, ’b’] - request_name: HTTP-POST enabled: ’true’ request: protocol: https domain: httpbin.org port: ’’ encoding: ’’ path: /post method: POST data: {’c’: 3, ’d’: 4} follow_redirects: ’false’ auto_redirects: ’false’ use_keepalive: ’false’ connect_timeout: ’’ response_timeout: ’’ - request_name: HTTP-JSON enabled: ’true’ request: protocol: https domain: httpbin.org port: ’’ encoding: ’’ path: /post method: POST connect_timeout: ’’ response_timeout: ’’ raw_data: ’{'e': 5, 'f': 6}’ follow_redirects: ’false’ auto_redirects: ’false’ use_keepalive: ’false’ - thread_group_name: 線程組2 comments: 線程組2描述 enabled: ’false’ num_threads: 50 loops: -1 ramp_time: 0 scheduler: ’true’ duration: 30 delay: ’’ csv_files: - {’name’: ’數(shù)據(jù)文件3’, ’path’: ’data.csv’, ’varnames’: ’a,b’,’delimiter’: ’t’} dubbo_samples: - request_name: 查詢運(yùn)費(fèi)接口-dubbo enabled: ’true’ registry: type: zookeeper group: ’’ address: ’zk-mall1.secoolocal.com:5181?backup=zk-mall2.secoolocal.com:5181,zk-mall3.secoolocal.com:5181’ dubbo: timeout: 100 retires: 0 group: ’’ connections: 100 load_balance: random cluster: failfast service: ’com.secoo.business.config.rpc.service.BusinessConfigStoreService’ method: queryFreight headers: Content-Type: ’application/json’ params: - type: java.util.List value: ${freight_wareHouseId_sendAreaId} - type: java.lang.String value: 110100 - type: java.util.List value: ${freight_wareHouseId_sendAreaId} validate: - test_field: response_data # response_data響應(yīng)文本 response_code響應(yīng)代碼response_message響應(yīng)信息response_headers test_type: 16 # 2 包括 1匹配 8 相等 16字符串 否+4 或者+32 strings: [’'code': 0’]

對(duì)應(yīng)的模板文件tpl.xml代碼如下:

<?xml version='1.0' encoding='UTF-8'?><jmeterTestPlan version='1.2' properties='5.0' jmeter='5.3'> <hashTree> <TestPlan guiclass='TestPlanGui' testclass='TestPlan' testname='{{test_plan_name}}' enabled='true'> <stringProp name='TestPlan.comments'>{{comments}}</stringProp> <boolProp name='TestPlan.functional_mode'>false</boolProp> <boolProp name='TestPlan.tearDown_on_shutdown'>true</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> <hashTree>{% if hosts %} <DNSCacheManager guiclass='DNSCachePanel' testclass='DNSCacheManager' testname='DNS緩存管理器' enabled='true'> <collectionProp name='DNSCacheManager.servers'/> <collectionProp name='DNSCacheManager.hosts'>{% for host in hosts %} <elementProp name='las.secoo.com' elementType='StaticHost'> <stringProp name='StaticHost.Name'>{{host.name}}</stringProp> <stringProp name='StaticHost.Address'>{{host.address}}</stringProp> </elementProp>{% endfor %} </collectionProp> <boolProp name='DNSCacheManager.clearEachIteration'>false</boolProp> <boolProp name='DNSCacheManager.isCustomResolver'>true</boolProp> </DNSCacheManager> <hashTree/>{% endif %} {% if cookies %} <CookieManager guiclass='CookiePanel' testclass='CookieManager' testname='HTTP Cookie管理器' enabled='true'> <collectionProp name='CookieManager.cookies'/> <boolProp name='CookieManager.clearEachIteration'>{{cookies.clear_each_iteration}}</boolProp> </CookieManager> <hashTree/>{% endif %} {% if csv_files %}{% for csv_file in csv_files %} <CSVDataSet guiclass='TestBeanGUI' testclass='CSVDataSet' testname='{{csv_file.name}}' enabled='true'> <stringProp name='filename'>dat/{{csv_file.path}}</stringProp> <stringProp name='fileEncoding'>UTF-8</stringProp> <stringProp name='variableNames'>{{csv_file.varnames}}</stringProp> <boolProp name='ignoreFirstLine'>true</boolProp> <stringProp name='delimiter'>{{csv_file.delimiter}}</stringProp> <boolProp name='quotedData'>false</boolProp> <boolProp name='recycle'>true</boolProp> <boolProp name='stopThread'>false</boolProp> <stringProp name='shareMode'>shareMode.group</stringProp> </CSVDataSet> <hashTree/>{% endfor %}{% endif %} <ResultCollector guiclass='StatVisualizer' testclass='ResultCollector' testname='聚合報(bào)告' 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>true</fieldNames> <responseHeaders>false</responseHeaders> <requestHeaders>false</requestHeaders> <responseDataOnError>true</responseDataOnError> <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage> <assertionsResultsToSave>0</assertionsResultsToSave> <bytes>true</bytes> <sentBytes>true</sentBytes> <threadCounts>true</threadCounts> <idleTime>true</idleTime> </value> </objProp> <stringProp name='filename'></stringProp> </ResultCollector> <hashTree/>{% for thread_group in thread_groups %} <ThreadGroup guiclass='ThreadGroupGui' testclass='ThreadGroup' testname='{{thread_group.thread_group_name}}' enabled='{{thread_group.enabled}}'> <stringProp name='TestPlan.comments'>{{thread_group.comments}}</stringProp> <stringProp name='ThreadGroup.on_sample_error'>continue</stringProp> <elementProp name='ThreadGroup.main_controller' elementType='LoopController' guiclass='LoopControlPanel' testclass='LoopController' testname='循環(huán)控制器' enabled='true'> <boolProp name='LoopController.continue_forever'>false</boolProp> <intProp name='LoopController.loops'>{{thread_group.loops}}</intProp> </elementProp> <stringProp name='ThreadGroup.num_threads'>{{thread_group.num_threads}}</stringProp> <stringProp name='ThreadGroup.ramp_time'>{{thread_group.ramp_time}}</stringProp> <boolProp name='ThreadGroup.scheduler'>{{thread_group.scheduler}}</boolProp> <stringProp name='ThreadGroup.duration'>{{thread_group.duration}}</stringProp> <stringProp name='ThreadGroup.delay'>{{thread_group.delay}}</stringProp> <boolProp name='ThreadGroup.same_user_on_next_iteration'>false</boolProp> </ThreadGroup> <hashTree>{% if thread_group.csv_files %}{% for csv_file in thread_group.csv_files %} <CSVDataSet guiclass='TestBeanGUI' testclass='CSVDataSet' testname='{{csv_file.name}}' enabled='true'> <stringProp name='filename'>dat/{{csv_file.path}}</stringProp> <stringProp name='fileEncoding'>UTF-8</stringProp> <stringProp name='variableNames'>{{csv_file.varnames}}</stringProp> <boolProp name='ignoreFirstLine'>true</boolProp> <stringProp name='delimiter'>{{csv_file.delimiter}}</stringProp> <boolProp name='quotedData'>false</boolProp> <boolProp name='recycle'>true</boolProp> <boolProp name='stopThread'>false</boolProp> <stringProp name='shareMode'>shareMode.group</stringProp> </CSVDataSet> <hashTree/>{% endfor %}{% endif %} {% if thread_group.http_samples %}{% for http_sample in thread_group.http_samples %} <HTTPSamplerProxy guiclass='HttpTestSampleGui' testclass='HTTPSamplerProxy' testname='{{http_sample.request_name}}' enabled='{{http_sample.enabled}}'> <elementProp name='HTTPsampler.Arguments' elementType='Arguments' guiclass='HTTPArgumentsPanel' testclass='Arguments' testname='用戶定義的變量' enabled='true'> <collectionProp name='Arguments.arguments'>{% if http_sample.request.params %}{% for name, value in http_sample.request.params.items() %} <elementProp name='{{name}}' elementType='HTTPArgument'><boolProp name='HTTPArgument.always_encode'>false</boolProp><stringProp name='Argument.value'>{{value}}</stringProp><stringProp name='Argument.metadata'>=</stringProp><boolProp name='HTTPArgument.use_equals'>true</boolProp><stringProp name='Argument.name'>{{name}}</stringProp> </elementProp>{% endfor %}{% endif %} {% if http_sample.request.data %}{% for name, value in http_sample.request.data.items() %} <elementProp name='{{name}}' elementType='HTTPArgument'><boolProp name='HTTPArgument.always_encode'>false</boolProp><stringProp name='Argument.value'>{{value}}</stringProp><stringProp name='Argument.metadata'>=</stringProp><boolProp name='HTTPArgument.use_equals'>true</boolProp><stringProp name='Argument.name'>{{name}}</stringProp> </elementProp>{% endfor %}{% endif %} {% if http_sample.request.raw_data %} <elementProp name='' elementType='HTTPArgument'><boolProp name='HTTPArgument.always_encode'>false</boolProp><stringProp name='Argument.value'>{{http_sample.request.raw_data}}</stringProp><stringProp name='Argument.metadata'>=</stringProp> </elementProp>{% endif %} </collectionProp> </elementProp> <stringProp name='HTTPSampler.domain'>{{http_sample.request.domain}}</stringProp> <stringProp name='HTTPSampler.port'>{{http_sample.request.port}}</stringProp> <stringProp name='HTTPSampler.protocol'>{{http_sample.request.protocol}}</stringProp> <stringProp name='HTTPSampler.contentEncoding'>{{http_sample.request.encoding}}</stringProp> <stringProp name='HTTPSampler.path'>{{http_sample.request.path}}</stringProp> <stringProp name='HTTPSampler.method'>{{http_sample.request.method}}</stringProp> <boolProp name='HTTPSampler.follow_redirects'>{{http_sample.request.follow_redirects}}</boolProp> <boolProp name='HTTPSampler.auto_redirects'>{{http_sample.request.auto_redirects}}</boolProp> <boolProp name='HTTPSampler.use_keepalive'>{{http_sample.request.use_keepalive}}</boolProp> <boolProp name='HTTPSampler.DO_MULTIPART_POST'>false</boolProp> <stringProp name='HTTPSampler.embedded_url_re'></stringProp> <stringProp name='HTTPSampler.connect_timeout'>{{http_sample.request.connect_timeout}}</stringProp> <stringProp name='HTTPSampler.response_timeout'>{{http_sample.request.response_timeout}}</stringProp> </HTTPSamplerProxy> <hashTree>{% if http_sample.request.headers %} <HeaderManager guiclass='HeaderPanel' testclass='HeaderManager' testname='HTTP信息頭管理器' enabled='true'> <collectionProp name='HeaderManager.headers'>{% for name, value in http_sample.request.headers.items() %} <elementProp name='' elementType='Header'><stringProp name='Header.name'>{{name}}</stringProp><stringProp name='Header.value'>{{value}}</stringProp> </elementProp>{% endfor %} </collectionProp> </HeaderManager> <hashTree/>{% endif %} {% if http_sample.csv_files %}{% for csv_file in http_sample.csv_files %} <CSVDataSet guiclass='TestBeanGUI' testclass='CSVDataSet' testname='CSV 數(shù)據(jù)文件設(shè)置' enabled='true'> <stringProp name='delimiter'>{{csv_file.delimiter}}</stringProp> <stringProp name='fileEncoding'>UTF_8</stringProp> <stringProp name='filename'>dat/{{csv_file.path}}</stringProp> <boolProp name='ignoreFirstLine'>true</boolProp> <boolProp name='quotedData'>false</boolProp> <boolProp name='recycle'>true</boolProp> <stringProp name='shareMode'>shareMode.group</stringProp> <boolProp name='stopThread'>false</boolProp> <stringProp name='variableNames'>{{csv_file.varnames}}</stringProp> </CSVDataSet> <hashTree/>{% endfor %}{% endif %} {% if http_sample.validate %}{% for assertion in http_sample.validate %} <ResponseAssertion guiclass='AssertionGui' testclass='ResponseAssertion' testname='響應(yīng)斷言' enabled='true'> <collectionProp name='Asserion.test_strings'>{% if assertion.strings %}{% for string in assertion.strings %} <stringProp name='97'>{{string}}</stringProp>{% endfor %}{% endif %} </collectionProp> <stringProp name='Assertion.custom_message'></stringProp> <stringProp name='Assertion.test_field'>Assertion.{{assertion.test_field}}</stringProp> <boolProp name='Assertion.assume_success'>false</boolProp> <intProp name='Assertion.test_type'>{{assertion.test_type}}</intProp> </ResponseAssertion> <hashTree/>{% endfor %}{% endif %} <ResultCollector guiclass='ViewResultsFullVisualizer' testclass='ResultCollector' testname='察看結(jié)果樹(shù)' 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>true</fieldNames><responseHeaders>false</responseHeaders><requestHeaders>false</requestHeaders><responseDataOnError>false</responseDataOnError><saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage><assertionsResultsToSave>0</assertionsResultsToSave><bytes>true</bytes><sentBytes>true</sentBytes><url>true</url><threadCounts>true</threadCounts><idleTime>true</idleTime><connectTime>true</connectTime> </value> </objProp> <stringProp name='filename'></stringProp> </ResultCollector> <hashTree/> </hashTree>{% endfor %}{% endif %} {% if thread_group.dubbo_samples %} {% for dubbo_sample in thread_group.dubbo_samples %} <io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample guiclass='io.github.ningyu.jmeter.plugin.dubbo.gui.DubboSampleGui' testclass='io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample' testname='{{dubbo_sample.request_name}}' enabled='{{dubbo_sample.enabled}}'> <stringProp name='FIELD_DUBBO_REGISTRY_PROTOCOL'>{{dubbo_sample.registry.type}}</stringProp> <stringProp name='FIELD_DUBBO_REGISTRY_GROUP'>{{dubbo_sample.registry.group}}</stringProp> <stringProp name='FIELD_DUBBO_RPC_PROTOCOL'>dubbo://</stringProp> <stringProp name='FIELD_DUBBO_ADDRESS'>{{dubbo_sample.registry.address}}</stringProp> <stringProp name='FIELD_DUBBO_TIMEOUT'>{{dubbo_sample.dubbo.timeout}}</stringProp> <stringProp name='FIELD_DUBBO_VERSION'></stringProp> <stringProp name='FIELD_DUBBO_RETRIES'>{{dubbo_sample.dubbo.retries}}</stringProp> <stringProp name='FIELD_DUBBO_GROUP'>{{dubbo_sample.dubbo.group}}</stringProp> <stringProp name='FIELD_DUBBO_CONNECTIONS'>{{dubbo_sample.dubbo.connections}}</stringProp> <stringProp name='FIELD_DUBBO_LOADBALANCE'>{{dubbo_sample.dubbo.load_balance}}</stringProp> <stringProp name='FIELD_DUBBO_ASYNC'>sync</stringProp> <stringProp name='FIELD_DUBBO_CLUSTER'>{{dubbo_sample.dubbo.cluster}}</stringProp> <stringProp name='FIELD_DUBBO_INTERFACE'>{{dubbo_sample.dubbo.service}}</stringProp> <stringProp name='FIELD_DUBBO_METHOD'>{{dubbo_sample.dubbo.method}}</stringProp> <intProp name='FIELD_DUBBO_METHOD_ARGS_SIZE'>1</intProp>{% for param in dubbo_sample.dubbo.params %} <stringProp name='FIELD_DUBBO_METHOD_ARGS_PARAM_TYPE1'>{{param.type}}</stringProp> <stringProp name='FIELD_DUBBO_METHOD_ARGS_PARAM_VALUE1'>{{param.value}}</stringProp>{% endfor %} <intProp name='FIELD_DUBBO_ATTACHMENT_ARGS_SIZE'>0</intProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_PROTOCOL'></stringProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_GROUP'></stringProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_NAMESPACE'></stringProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_USER_NAME'></stringProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_PASSWORD'></stringProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_ADDRESS'></stringProp> <stringProp name='FIELD_DUBBO_CONFIG_CENTER_TIMEOUT'></stringProp> <stringProp name='FIELD_DUBBO_REGISTRY_USER_NAME'></stringProp> <stringProp name='FIELD_DUBBO_REGISTRY_PASSWORD'></stringProp> <stringProp name='FIELD_DUBBO_REGISTRY_TIMEOUT'></stringProp> </io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample> <hashTree>{% if dubbo_sample.dubbo.headers %} <HeaderManager guiclass='HeaderPanel' testclass='HeaderManager' testname='HTTP信息頭管理器' enabled='true'> <collectionProp name='HeaderManager.headers'>{% for name, value in dubbo_sample.dubbo.headers.items() %} <elementProp name='' elementType='Header'><stringProp name='Header.name'>{{name}}</stringProp><stringProp name='Header.value'>{{value}}</stringProp> </elementProp>{% endfor %} </collectionProp> </HeaderManager> <hashTree/>{% endif %} {% if dubbo_sample.validate %} {% for assertion in dubbo_sample.validate %} <ResponseAssertion guiclass='AssertionGui' testclass='ResponseAssertion' testname='響應(yīng)斷言' enabled='true'> <collectionProp name='Asserion.test_strings'>{% if assertion.strings %}{% for string in assertion.strings %} <stringProp name='97'>{{string}}</stringProp>{% endfor %}{% endif %} </collectionProp> <stringProp name='Assertion.custom_message'></stringProp> <stringProp name='Assertion.test_field'>Assertion.{{assertion.test_field}}</stringProp> <boolProp name='Assertion.assume_success'>false</boolProp> <intProp name='Assertion.test_type'>{{assertion.test_type}}</intProp> </ResponseAssertion>{% endfor %} {% endif %} <hashTree/>{% endfor %}{% endif %} {% endfor %} </hashTree> </hashTree> </hashTree></jmeterTestPlan>

組裝出類似data.yaml格式的數(shù)據(jù),并使用jinja2渲染模板即可得到完整的jmx文件

pip install pyyaml jinja2

import yamlimport jinja2# 組裝或讀取數(shù)據(jù)with open(’data.yaml’, encoding=’utf-8’) as f: data = yaml.safe_load(f) # 讀取模板with open(’tpl.xml’, encoding=’utf-8’) as f: tpl = f.read()# 渲染模板生成jmxjmx = jinja2.Template(tpl).render(data)with open(jmx_file, ’w’, encoding=’utf-8’) as f: f.write(jmx)

后計(jì)

在實(shí)際項(xiàng)目中,還涉及數(shù)據(jù)文件的拷貝,節(jié)點(diǎn)環(huán)境的部署,腳本的分發(fā),報(bào)告的下載等等,可以使用paramiko或者fabric或ansible完成,壓測(cè)節(jié)點(diǎn)數(shù)據(jù)分發(fā)的服務(wù)管理。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 膜结构停车棚-自行车棚-膜结构汽车棚加工安装厂家幸福膜结构 | 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 超声骨密度仪-动脉硬化检测仪器-人体成分分析仪厂家/品牌/价格_南京科力悦 | 自动气象站_农业气象站_超声波气象站_防爆气象站-山东万象环境科技有限公司 | 东莞办公家具厂家直销-美鑫【免费3D效果图】全国办公桌/会议桌定制 | 卫生纸复卷机|抽纸机|卫生纸加工设备|做卫生纸机器|小型卫生纸加工需要什么设备|卫生纸机器设备多少钱一台|许昌恒源纸品机械有限公司 | 诺冠气动元件,诺冠电磁阀,海隆防爆阀,norgren气缸-山东锦隆自动化科技有限公司 | 工控机-工业平板电脑-研华工控机-研越无风扇嵌入式box工控机 | Copeland/谷轮压缩机,谷轮半封闭压缩机,谷轮涡旋压缩机,型号规格,技术参数,尺寸图片,价格经销商 CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 三轴曲线机-端子插拔力试验机|华杰仪器 | 岩棉板|岩棉复合板|聚氨酯夹芯板|岩棉夹芯板|彩钢夹芯板-江苏恒海钢结构 | 泰国试管婴儿_泰国第三代试管婴儿_泰国试管婴儿费用/多少钱_孕泰来 | 存包柜厂家_电子存包柜_超市存包柜_超市电子存包柜_自动存包柜-洛阳中星 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 中山东港家具集团-酒店-办公-医养家具定制厂家 | 皮带机-带式输送机价格-固定式胶带机生产厂家-河南坤威机械 | 球盟会·(中国)官方网站 | 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 有机废气处理-rto焚烧炉-催化燃烧设备-VOC冷凝回收装置-三梯环境 | 智慧水务|智慧供排水利信息化|水厂软硬件系统-上海敢创 | 贴片电容-贴片电阻-二三极管-国巨|三星|风华贴片电容代理商-深圳伟哲电子 | 顶呱呱交易平台-行业领先的公司资产交易服务平台 | 防水套管-柔性防水套管-刚性防水套管-上海执品管件有限公司 | 全球化工设备网—化工设备,化工机械,制药设备,环保设备的专业网络市场。 | 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 杭州代理记账费用-公司注销需要多久-公司变更监事_杭州福道财务管理咨询有限公司 | 扒渣机,铁水扒渣机,钢水扒渣机,铁水捞渣机,钢水捞渣机-烟台盛利达工程技术有限公司 | ge超声波测厚仪-电动涂膜机-电动划格仪-上海洪富 | 压缩空气冷冻式干燥机_吸附式干燥机_吸干机_沪盛冷干机 | 5L旋转蒸发器-20L-50L旋转蒸发器-上海越众仪器设备有限公司 | 杭州画室_十大画室_白墙画室_杭州美术培训_国美附中培训_附中考前培训_升学率高的画室_美术中考集训美术高考集训基地 | 深圳天际源广告-形象堆头,企业文化墙,喷绘,门头招牌设计制作专家 | 空气能采暖,热泵烘干机,空气源热水机组|设备|厂家,东莞高温热泵_正旭新能源 | 国际线缆连接网 - 连接器_线缆线束加工行业门户网站 | 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 警用|治安|保安|不锈钢岗亭-售货亭价格-垃圾分类亭-移动厕所厂家-苏州灿宇建材 | 山东包装,山东印刷厂,济南印刷厂-济南富丽彩印刷有限公司 | 意大利Frascold/富士豪压缩机_富士豪半封闭压缩机_富士豪活塞压缩机_富士豪螺杆压缩机 | 大流量卧式砂磨机_强力分散机_双行星双动力混合机_同心双轴搅拌机-莱州市龙跃化工机械有限公司 | 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 乳化沥青设备_改性沥青设备_沥青加温罐_德州市昊通路桥工程有限公司 |