JMeter使用记录2 -- Web测试

Web测试用例 
 

新建线程组,配置起3线程,循环1次,1秒启动所有线程,进行login,循环1个主要页面的读写,并对另外一个主要页面进行读操作,最后logout并在aggregate graph/graph resluts/view results tree查看测试结果。 

HTTP Request Defaults 
HTTP Cookie Manager 
CSV Data set Config 
Login 
Counter 
display userinfo page 
search userinfo 
edit use rinfo 
display riskrank page 
display customerlnfo page 
search customerlnfo 
logout 
Aggregate Graph 
Graph Results 
View Resuts Tree 
csMSJoacTest 
Workaench

 
 

1. 建立线程组,启动3个线程(1s起完),每个线程循环执行所有步骤1次,某个步骤出错也继续执行: 

Thread Group 
Name: CSMswebTest 
Comments: 
Action to be taken after a Sampler error 
@ Continue 
Thread Properties 
Number of Threads (users): 3 
Ramp-Up Period (in seconds): 1 
Loop Count: Forever 1 
C] Delay Thread creation until needed 
C] Scheduler 
O Start Next Thread Loop 
O Stop Thread 
O Stop Test 
O Stop Test Now

2. 创建http request defaults,把所有请求的default value定义在其中, web server ip + port localhost:8080 

3. 加入http cookie manger管理cookie 

4. 创建login http request, 系统使用了spring security,加入j_username/j_password/_spring_security_remember_me字段的值,这里由于每个线程使用自己的用户名密码,所以配置了CVS Data Config参数,选择post方法 

HTTP Request 
Name: Login 
Comments: 
Web Serve 
Server Name or 'P: 
HTTP Request 
Implementation: 
Protocol [http]: 
Method: POST 
Path: /CustomerSecurityManagementSystem/j_security_check 
Timeouts (milliseconds) 
Port Number: 
Content encoding: 
Connect: 
Response: 
C] Redirect Automatically @ Follow Redirects @ use KeepAlive C] Use multiparbform-dataforPOST D Browser-compatible headers 
Parameters Body Data 
Name: 
username 
•_password 
spring_security_remember_me 
Send Parameters With the Request: 
Value 
S{username} 
S{password) 
false 
Add from Clipboard 
Send Files With the Request: 
File Path: 
Encode? Include E uals? 
Parameter Name: 
MIME T

 

CVS Data Config参数从指定文件(运行根目录jmeter.dat)中按照指定的格式读取多组用户id,username,password信息,每个线程取其中一组 

CSV Data Set Config 
Name: CSV Data Set Config 
Comments: 
Configure the CSV Data Source 
Filename: -Imeterdat 
File encoding: utf-8 
Variable Names (comma-delimited): id,username,passwor 
Delimiter (use nt' for tab): 
Allow quoted data?: True 
Recycle on EOF ?: False 
Stop thread on EOF ?: True 
Sharing mode: All threads

 5. 创建login系统响应断言,保证测试正确性,这里断言响应页面里面含有用户名信息 

6. 创建循环控制器,执行10次循环 
 

0b 」 a a 亅 0 丨 」 : un00d001 
: S ua Ⅲ 山 00 
」 | 0 u00 d001

 
 

7.在循环体内部分被执行显示默认页面,按用户名和用户所在组查询以及更新用户三种操作 

7.1显示默认页面并加入响应断言 

7.2 按用户名和用户所在组查询 

HTTP Request 
Name: search userinfo 
Comments: 
Web Serve 
Server Name or 'P: 
HTTP Request 
Implementation: Java 
Timeouts (milliseconds) 
Port Number: 
Content encoding: 
Connect: 
Response: 
Method: POST 
Protocol [http]: http 
Path: /CustomerSecurityManagementSystem/userlnfo/listaction 
C] Redirect Automatically @ Follow Redirects @ Use KeepAlive C] Use multiparbform-dataforPOST C] Browser-compatible headers 
Parameters Body Data 
Name: 
conditiomusername 
conditiomsearch8ranch 
Send Parameters With the Request: 
Value 
S{username} 
Encode? Include Equals?
Response Assertion 
Name: Response Assertion 
Comments: 
Apply to: 
@ Main sample and sub-samples O Main sample only O Sub-samples only O JMeterVi 
FResponse Field to Test 
@ Text Response O Document (text) O URL Sampled O Response Code O 
Pattern Matching Rules 
@ Contains O Matches O Equals O 
Patterns to Test 
Patterns to Test 
d><a href=NCustomerSecurityM anagementSystemVus erlnfoVre move act onl?i d)

这里由于显示页面有下一个步骤提交修改用户请求的数据,所以使用regular expression extractor取出相应的数据(我取的都是页面的第一个)放入指定的参数 
 

Regular Expression Extractor 
Name: user token 
Apply to: 
O Main sample and sub-samples @ Main sample only O Sub-samples only O JMeterVariable 
Response Field to check 
@ Body O Body (unescapéd) C) Body as a Document O Headers O URL O 
Reference Name: 
Regular Expression: 
Template: 
loopToken 
<input 
SIS 
Match No. (O for Random): O 
Default Value:
Regular Expression Extractor 
Name: user version 
Comments: 
Apply to: 
O Main sample and sub-samples @ Main sample only O Sub-samples only O JMeter 
Response Field to check 
@ Body O Body (unescaped) O Body as a Document O Headers 
Reference Name: 
Regular Expression: 
Template: 
loopVersion 
<td 
SIS 
Match No. (O for Random): 0 
Default Value:

 
 

7.3执行用户修改,为了保证唯一性,建立了一个Counter,从1开始自加,为每个线程维护自己的counter 

Counter 
Name: Counter 
Comments: 
Start 1 
Increment 1 
Maximum 1000000 
Number format 000000 
Reference Name counterForRealName 
@ Track counter independently for each user 
C] Reset counter on each Thread Group Iteration

输入需要的参数提交修改用户信息的action,并加入返回断言 
 

8. 同样对cuostmerinfo页面做一些基本测试,对于暂时没有完成的功能,可以选择disable掉 

9.最后logout 

HTTP Request 
Name: logout 
Comments: 
Web Serve 
Server Name or 'P: 
HTTP Request 
Implementation: 
Protocol [httpl: 
Method: GET 
Content el 
Path: /CustomerSecurityManagementSystem/j_security_logout 
C] Redirect Automatically @ Follow Redirects @ Use KeepAlive D use multipartfform-data for 
Parameters Body Data 
Send Parame 
Name:

 
 

10. 执行ctrl+R,在Aggregate Graph里面可以看测试数据汇总 

posted @ 2017-11-28 11:50  春田花花同学会  阅读(105)  评论(0编辑  收藏  举报