首页 > 代码库 > JMeter使用记录2 -- Web测试
JMeter使用记录2 -- Web测试
Web测试用例
新建线程组,配置起3线程,循环1次,1秒启动所有线程,进行login,循环1个主要页面的读写,并对另外一个主要页面进行读操作,最后logout并在aggregate graph/graph resluts/view results tree查看测试结果。
1. 建立线程组,启动3个线程(1s起完),每个线程循环执行所有步骤1次,某个步骤出错也继续执行:
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方法
5. 创建login系统响应断言,保证测试正确性,这里断言响应页面里面含有用户名信息
6. 创建循环控制器,执行10次循环
7.在循环体内部分被执行显示默认页面,按用户名和用户所在组查询以及更新用户三种操作
7.1显示默认页面并加入响应断言
7.2 按用户名和用户所在组查询
这里由于显示页面有下一个步骤提交修改用户请求的数据,所以使用regular expression extractor取出相应的数据(我取的都是页面的第一个)放入指定的参数
7.3执行用户修改,为了保证唯一性,建立了一个Counter,从1开始自加,为每个线程维护自己的counter
输入需要的参数提交修改用户信息的action,并加入返回断言
8. 同样对cuostmerinfo页面做一些基本测试,对于暂时没有完成的功能,可以选择disable掉
9.最后logout
10. 执行ctrl+R,在Aggregate Graph里面可以看测试数据汇总
完整JMeter脚本
<?xml version="1.0" encoding="UTF-8"?> <jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548"> <hashTree> <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"> <stringProp name="TestPlan.comments"></stringProp> <boolProp name="TestPlan.functional_mode">false</boolProp> <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="TestPlan.user_define_classpath"></stringProp> </TestPlan> <hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="CSMSWebTest" enabled="true"> <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">1</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">3</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp> <longProp name="ThreadGroup.start_time">1403165278000</longProp> <longProp name="ThreadGroup.end_time">1403165278000</longProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.duration"></stringProp> <stringProp name="ThreadGroup.delay"></stringProp> </ThreadGroup> <hashTree> <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain">localhost</stringProp> <stringProp name="HTTPSampler.port">8080</stringProp> <stringProp name="HTTPSampler.connect_timeout"></stringProp> <stringProp name="HTTPSampler.response_timeout"></stringProp> <stringProp name="HTTPSampler.protocol"></stringProp> <stringProp name="HTTPSampler.contentEncoding"></stringProp> <stringProp name="HTTPSampler.path"></stringProp> <stringProp name="HTTPSampler.concurrentPool">4</stringProp> </ConfigTestElement> <hashTree/> <CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="HTTP Cookie Manager" enabled="true"> <collectionProp name="CookieManager.cookies"/> <boolProp name="CookieManager.clearEachIteration">false</boolProp> </CookieManager> <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">Jmeter.dat</stringProp> <boolProp name="quotedData">true</boolProp> <boolProp name="recycle">false</boolProp> <stringProp name="shareMode">shareMode.all</stringProp> <boolProp name="stopThread">true</boolProp> <stringProp name="variableNames">id,username,password</stringProp> </CSVDataSet> <hashTree/> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Login" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"> <elementProp name="j_username" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">true</boolProp> <stringProp name="Argument.value">${username}</stringProp> <stringProp name="Argument.metadata">=</stringProp> <boolProp name="HTTPArgument.use_equals">true</boolProp> <stringProp name="Argument.name">j_username</stringProp> </elementProp> <elementProp name="j_password" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">true</boolProp> <stringProp name="Argument.value">${password}</stringProp> <stringProp name="Argument.metadata">=</stringProp> <boolProp name="HTTPArgument.use_equals">true</boolProp> <stringProp name="Argument.name">j_password</stringProp> </elementProp> <elementProp name="_spring_security_remember_me" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">true</boolProp> <stringProp name="Argument.value">false</stringProp> <stringProp name="Argument.metadata">=</stringProp> <boolProp name="HTTPArgument.use_equals">true</boolProp> <stringProp name="Argument.name">_spring_security_remember_me</stringProp> </elementProp> </collectionProp> </elementProp> <stringProp name="HTTPSampler.domain"></stringProp> <stringProp name="HTTPSampler.port"></stringProp> <stringProp name="HTTPSampler.connect_timeout"></stringProp> <stringProp name="HTTPSampler.response_timeout"></stringProp> <stringProp name="HTTPSampler.protocol"></stringProp> <stringProp name="HTTPSampler.contentEncoding"></stringProp> <stringProp name="HTTPSampler.path">/CustomerSecurityManagementSystem/j_security_check</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">false</boolProp> <boolProp name="HTTPSampler.monitor">false</boolProp> <stringProp name="HTTPSampler.embedded_url_re"></stringProp> </HTTPSamplerProxy> <hashTree> <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="响应断言" enabled="true"> <collectionProp name="Asserion.test_strings"> <stringProp name="1685720944">${username}</stringProp> </collectionProp> <stringProp name="Assertion.test_field">Assertion.response_data</stringProp> <boolProp name="Assertion.assume_success">false</boolProp> <intProp name="Assertion.test_type">2</intProp> </ResponseAssertion> <hashTree/> </hashTree> <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true"> <boolProp name="LoopController.continue_forever">true</boolProp> <stringProp name="LoopController.loops">10</stringProp> </LoopController> <hashTree> <CounterConfig guiclass="CounterConfigGui" testclass="CounterConfig" testname="Counter" enabled="true"> <stringProp name="CounterConfig.start">1</stringProp> <stringProp name="CounterConfig.end">1000000</stringProp> <stringProp name="CounterConfig.incr">1</stringProp> <stringProp name="CounterConfig.name">counterForRealName</stringProp> <stringProp name="CounterConfig.format">000000</stringProp> <boolProp name="CounterConfig.per_user">true</boolProp> </CounterConfig> <hashTree/> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="display userinfo page" enabled="true"> <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="HTTPSampler.domain"></stringProp> <stringProp name="HTTPSampler.port"></stringProp> <stringProp name="HTTPSampler.connect_timeout"></stringProp> <stringProp name="HTTPSampler.response_timeout"></stringProp> <stringProp name="HTTPSampler.protocol"></stringProp> <stringProp name="HTTPSampler.contentEncoding"></stringProp> <stringProp name="HTTPSampler.path">/CustomerSecurityManagementSystem/userInfo/list.action</stringProp> <stringProp name="HTTPSampler.method">GET</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">false</boolProp> <boolProp name="HTTPSampler.monitor">false</boolProp> <stringProp name="HTTPSampler.embedded_url_re"></stringProp> </HTTPSamplerProxy> <hashTree> <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Response Assertion" enabled="true"> <collectionProp name="Asserion.test_strings"> <stringProp name="1268646970"><td><a href=http://www.mamicode.com/"/CustomerSecurityManagementSystem/userInfo/remove.action/?id=>