JMeter 监控和记录&常用功能

使用https连接时,如果对应站点的CA 证书错误,会直接报连接不到服务器的错误,org.apache.commons.httpclient.NoHttpResponseException,把错误证书删除后【证书发行商,证书有效时间,证书对应的站点3部分信息】,或者使用正确的证书,就可以!

工具栏按钮:
Find, Clear All, Start, Function Helper, Help(鼠标点到某个项目,然后点击该按钮弹出相应帮组)

JMeter录制代理设置(注意这个代理是用来录制脚本的):
WorkBench->right click->Add->Non-Test Elements-> Http Proxy Server->Start

Firefox代理设置:
Tools->Options->Advanced->Network->Connection Settings->Manual proxy configuration
HTTP Proxy:127.0.0.1 Port:8080 Use this proxy server for all protocols
注意:No proxy for: localhost, 127.0.0.1

HTTP Proxy Server设置

JMeter执行代理设置(通过代理服务器来执行JMeter,当把代理设置成127.0.0.1 8888,默认就可以和Fiddler集成,即Fiddler会抓到JMeter发出的请求):
    -H [proxy server or IP address]
    -P [proxy server port]
    -u [username for the proxy authentication]
    -a [password for the proxy authentication]
jmeter.bat -H 192.168.10.1 -P 8012
jmeter.bat -H 192.168.10.1 -P 8012 -u my_user_name -a my_password

HTTP Request HTTPClient 选项:
基础选项:
Add:
对于POST请求,Content-Type:application/x-www-form-urlencoded;charset=UTF-8;charset=UTF-8,
对于GET请求,Content-Type:charset=UTF-8;charset=UTF-8,
然后选中header?单选框,jmeter就以 HTTP Header的形式告诉服务器请求参数编码使用的字符集,而其他没有选上header?单选框的项目以Parameter的形式发送! 注意HTTP GET请求,发送的中文字必须选中Encoder?单选框,而作为POST方式发送时,不需要选中,只需要指定编码!
高级选项:
Encoding编码,
Timeout(ms),
Redirect Automatically(自动重定向-服务器内部进行重定向操作时,HTTP Request自动重定向,然后返回Redict后的Response, 如果选择否的话,服务器就不会进行自动重定向操作,这时,默认只显示第一个重定向前的请求,此时,如果把Follow Redirects选择为true时,那边在结果页面View Result Tree中会把所有的请求都列出来)
一般情况下: Redirect Automatically true, Follow Redirects false 否则Redirect Automatically false, Follow Redirects true
有时候在服务器存在多次Redirect或者对POST请求做了Redirect转发的时候,JMeter会处理不正常,这时候可以
1,使用HTTP Request而不是HTTP Request HTTP Client 或者
2,使用GET请求来替换POST请求 或者
3,把Redirect Automatically和Follow Redirects都设置成false,然后用正则表达式Location: (.*)从响应头中提取Redirect的URL,然后根据提取的URL建立新的HTTP请求
   ----  直接从Location中得到的url拼到Path中能正常执行
Use multipart/form-data for POST
Ignore response code

JMeter保存执行结果
在View Results Tree界面以树状结构保存结果,在该画面上点击Configure的弹出画面中,选择Save Field Names, Save Assertion Failure Message,点击Done 【注意:Write results to file不要选中自己的脚本文件,不然就会丢失脚本!! 默认显示所有结果:错误的和正确的】

JMeter日志:执行脚本时,Jmeter错误日志会输出到控制台中!

JMeter使用系统时间作为 唯一值
Add->Pre Precessors->User Parameters->currentTime=${__time(YMD)}${__time(HMS)}, Update Once Per Iteration checked
使用的地方:${__threadNum()}_${currentTime}, 也可以不定义变量直接使用

JDBC数据库连接
Add --> Logic Controller --> Case
Add --> Config Element --> JDBC Connection Configuration
    Database URL:jdbc:oracle:thin:@192.168.0.1:1521:dbinst
    JDBC Driver class:oracle.jdbc.driver.OracleDriver
    Variable Name Bound to Pool(数据库连接池设置,和下面的JDBC Request中的相应项目的值一致!):prjdata
    这里好像必须写死,不能引用properties中的变量
Add --> Sampler --> JDBC Request
    sql中不能用分好结尾
    输入的sql中可以直接使用变量,如select * from tbl where s ='${currentTime}'

把数据库中查询的值,设置到变量中来使用
JDBC Request的responseFormat 选择xml,然后新建Add->Post Processors->XPath Extractor->在弹出来的界面中,Reference Name为将要被使用的变量名词,XPath query设置为: /RecordSet/Record/ITEMNAME
/RecordSet/Record[2]/ITEMNAME:选取第二行记录中的相应项目的值
Reference Name:    refName - set to first (or only) match; if no match, then set to default;    refName_matchNr - set to number of matches (may be 0);    refName_n - n=1,2,3 etc. Set to the 1st, 2nd 3rd match etc.
Use Tidy:从HTML中提取时,选择Yes,从XHTML或者XML提取时,选择false


使用__StringFromFile函数读取错误,**ERR**,原因是改函数读取的文件是相对与JMeter launch directory目录的,即要把数据文件放到bin目录下! 或者绝对路径

各元素执行 顺序
  • Configuration elements
  • Pre-Processors
  • Timers
  • Sampler
  • Post-Processors (unless SampleResult is null)
  • Assertions (unless SampleResult is null)
  • Listeners (unless SampleResult is null)

JMeter调试:
添加Debug Sampler或者Debug PostProcessor 后,在执行结果View Results Tree中可以在相应的Response标签中看到JMeter Properties,JMeter Variables,System Properties,Sampler Properties(Debug PostProcessor) 的值!
Debug PostProcessor:给Sample建立一个子Sample以监听Sampler Properties以及其他的值!

JMeter Cookie值的抓取:
参考页面: JMeter正则表达式提取器

JMeter 脚本录制:
1,它提供了一个利用本地Proxy Server(代理服务器)来录制生成测试脚本的功能,不太好用
2,使用 Badboy录制并导出 JMeter 脚本
参考: 《JMeter从入门到精通》之一——开始你的第一个JMeter脚本

Response Assertion:
匹配规则 Contains, Matches: Perl5-style 正则表达式; Equals, Substring: 大小写敏感的文本匹配
(?i) - 大小写不区分; (?s) - 多行模式, i.e. "." matches new-line; (?is) - 上面2种模式

jmeter结果保持、JTL文件读取:
JMeterPluginsCMD Command Line Tool
Jmeter: how to create summary report from JTL file?

猜你喜欢

转载自desert3.iteye.com/blog/1379182
今日推荐