JMeter 监控和记录&常用功能

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

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

JMeter录制代理设置(注意这个代理是用来录制脚本的):
WorkBench->right click->Add->Non-Test Elements->[color=red]Http Proxy Server[/color]->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

[url=http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Proxy_Server]HTTP Proxy Server设置[/url]

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就以[color=red]HTTP Header的形式[/color]告诉服务器请求参数编码使用的字符集,而其他没有选上header?单选框的项目以Parameter的形式发送![color=red]注意HTTP GET请求,发送的中文字必须选中Encoder?单选框,而作为POST方式发送时,不需要选中,只需要指定编码![/color]
高级选项:
Encoding编码,
Timeout(ms),
Redirect Automatically(自动重定向-服务器内部进行重定向操作时,HTTP Request自动重定向,然后返回Redict后的Response, 如果选择否的话,服务器就不会进行自动重定向操作,这时,默认只显示第一个重定向前的请求,此时,如果把Follow Redirects选择为true时,那边在结果页面View Result Tree中会把所有的请求都列出来)
一般情况下:[color=red]Redirect Automatically true, Follow Redirects false 否则Redirect Automatically false, Follow Redirects true[/color]
[color=green]有时候在服务器存在多次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请求[/color] ---- 直接从Location中得到的url拼到Path中能正常执行
Use multipart/form-data for POST
Ignore response code

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

[color=red]JMeter日志:[/color]执行脚本时,Jmeter错误日志会输出到控制台中!

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

[color=red]JDBC数据库连接[/color]:
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
[color=red]这里好像必须写死,不能引用properties中的变量[/color]
Add --> Sampler --> JDBC Request
sql中不能用分好结尾
输入的sql中可以直接使用变量,如select * from tbl where s ='${currentTime}'

[color=red]把数据库中查询的值,设置到变量中来使用[/color]:
JDBC Request的responseFormat[color=red]选择xml[/color],然后新建Add->Post Processors->XPath Extractor->在弹出来的界面中,Reference Name为将要被使用的变量名词,XPath query设置为:[color=red]/RecordSet/Record/ITEMNAME[/color]
[color=red]/RecordSet/Record[2]/ITEMNAME[/color]:选取第二行记录中的相应项目的值
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


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

各元素执行[color=red]顺序[/color]:
[list]
[*]Configuration elements
[*]Pre-Processors
[*]Timers
[*]Sampler
[*]Post-Processors (unless SampleResult is null)
[*]Assertions (unless SampleResult is null)
[*]Listeners (unless SampleResult is null)
[/list]
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值的抓取:
参考页面:[url=http://desert3.iteye.com/blog/1394934]JMeter正则表达式提取器[/url]

JMeter 脚本录制:
1,它提供了一个利用本地Proxy Server(代理服务器)来录制生成测试脚本的功能,不太好用
2,使用[url=http://www.badboy.com.au/]Badboy[/url]录制并导出 JMeter 脚本
参考:[url=http://www.cnblogs.com/jackei/archive/2006/11/10/557160.html]《JMeter从入门到精通》之一——开始你的第一个JMeter脚本[/url]

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

jmeter结果保持、JTL文件读取:
[url=http://code.google.com/p/jmeter-plugins/wiki/JMeterPluginsCMD]JMeterPluginsCMD Command Line Tool[/url]
[url=http://stackoverflow.com/questions/4669467/jmeter-how-to-create-summary-report-from-jtl-file]Jmeter: how to create summary report from JTL file?[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值