使用非 GUI 模式运行测试脚本时可以使用的一些命令:
-h 帮助 -> 打印出有用的信息并退出
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
-r 远程执行 -> 启动远程服务
-H 代理主机 -> 设置 JMeter 使用的代理主机
-P 代理端口 -> 设置 JMeter 使用的代理主机的端口号
shell 脚本
export JAVA_HOME=/data/test/jdk1.8.0_172 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar /data/test/scripts/apache-jmeter-3.3/bin/jmeter.sh -n -t xxx.jmx #/data/test/apache-jmeter-3.3/bin/jmeter.sh -n -t xxx.jmx -l test.jtl
jmeter文件修改
<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">200</stringProp>循环次数 </elementProp> <stringProp name="ThreadGroup.num_threads">10</stringProp>线程数 <stringProp name="ThreadGroup.ramp_time">1</stringProp> <longProp name="ThreadGroup.start_time">1531210234000</longProp> <longProp name="ThreadGroup.end_time">1531210234000</longProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.duration">120</stringProp> <stringProp name="ThreadGroup.delay">2</stringProp> </ThreadGroup>
<hashTree> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="${apk}" enabled="true"> <elementProp name="HTTPsampler.Files" elementType="HTTPFileArgs"> <collectionProp name="HTTPFileArgs.files"> <elementProp name="D:\\xxx\\${apk}" elementType="HTTPFileArg"> <stringProp name="File.path">D:\\xxx\\${apk}</stringProp> <stringProp name="File.paramname">file</stringProp> <stringProp name="File.mimetype">Content-Type: application/vnd.android.package-archive</stringProp> </elementProp> </collectionProp> </elementProp> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">x.x.x.x</stringProp> <stringProp name="HTTPSampler.port">8080</stringProp> <stringProp name="HTTPSampler.protocol">http</stringProp> <stringProp name="HTTPSampler.contentEncoding"></stringProp> <stringProp name="HTTPSampler.path">/api/xxxx</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">true</boolProp> <stringProp name="HTTPSampler.embedded_url_re"></stringProp> <stringProp name="HTTPSampler.implementation">Java</stringProp> <stringProp name="HTTPSampler.connect_timeout"></stringProp> <stringProp name="HTTPSampler.response_timeout"></stringProp> </HTTPSamplerProxy> <hashTree>
<CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSV Data Set Config" enabled="true"> <stringProp name="delimiter">,</stringProp> <stringProp name="fileEncoding">UTF-8</stringProp> <stringProp name="filename">D:/xxx.txt</stringProp> <boolProp name="ignoreFirstLine">false</boolProp> <boolProp name="quotedData">false</boolProp> <boolProp name="recycle">false</boolProp> <stringProp name="shareMode">shareMode.all</stringProp> <boolProp name="stopThread">true</boolProp> <stringProp name="variableNames">apk</stringProp> </CSVDataSet>