一、同一个用户的作用
Sameuseroneachiteration是JMeter中非常重要的一个元素,可以用于控制多线程模拟下同一个用户在每个迭代中执行任务的行为。同一个用户可以实现用户状态的保持,使得测试结果更加真实。以下是代码示例:
<ThreadGroup>
<elementProp name="ThreadGroup.main_controller">
<TestFragment guiclass="TestFragmentGui" testclass="TestFragment" testname="Test Fragment" enabled="true">
<elementProp name="TestPlan.comments" elementType="Comment" guiclass="CommentGui" testclass="Comment" testname="Comment">
<stringProp name="TestPlan.comments"></stringProp>
</elementProp>
<elementProp name="ThreadGroup.main_controller">
<LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<elementProp name="LoopController.continue_forever" elementType="bool" guiclass="BooleanPropertyEditor" testclass="BooleanProperty" testname="Continue Forever">
<boolProp name="LoopController.continue_forever">false</boolProp>
</elementProp>
<elementProp name="LoopController.loops" elementType="int" guiclass="SpinnerNumber" testclass="LoopController" testname="Loop Controller">
<intProp name="LoopController.loops">1</intProp>
</elementProp>
</LoopController>
</elementProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="myVar" elementType="Argument" guiclass="ArgumentsPanel" testclass="Argument" testname="User Defined Variables" enabled="true">
<stringProp name="Argument.name">myVar</stringProp>
<stringProp name="Argument.value">value</stringProp>
<stringProp name="Argument.metadata"></stringProp>
</elementProp>
</collectionProp>
</elementProp>
<kg.apc.jmeter.threads.UltimateThreadGroup guiclass="kg.apc.jmeter.threads.UltimateThreadGroupGui" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="Ultimate Thread Group" enabled="true">
<collectionProp name="kg.apc.jmeter.threads.UltimateThreadGroup>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.on_sample_error" elementType="string" guiclass="ComboBoxPanel" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="on_sample_error" enabled="true">
</elementProp>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.num_threads" elementType="string" guiclass="kg.apc.jmeter.threads.UltimateThreadGroupNumericEditor" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="num_threads">
<stringProp name="kg.apc.jmeter.threads.UltimateThreadGroup.num_threads">10</stringProp>
</elementProp>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.ramp_up" elementType="string" guiclass="kg.apc.jmeter.threads.UltimateThreadGroupNumericEditor" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="ramp_up">
<stringProp name="kg.apc.jmeter.threads.UltimateThreadGroup.ramp_up">10</stringProp>
</elementProp>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.duration" elementType="string" guiclass="kg.apc.jmeter.threads.UltimateThreadGroupNumericEditor" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="duration">
<stringProp name="kg.apc.jmeter.threads.UltimateThreadGroup.duration">60</stringProp>
</elementProp>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.delay" elementType="string" guiclass="kg.apc.jmeter.threads.UltimateThreadGroupNumericEditor" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="delay">
<stringProp name="kg.apc.jmeter.threads.UltimateThreadGroup.delay">0</stringProp>
</elementProp>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.scheduler" elementType="string" guiclass="kg.apc.jmeter.threads.UltimateThreadGroupComboBox" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="scheduler">
<stringProp name="kg.apc.jmeter.threads.UltimateThreadGroup.scheduler">false</stringProp>
</elementProp>
<elementProp name="kg.apc.jmeter.threads.UltimateThreadGroup.duration_time" elementType="string" guiclass="kg.apc.jmeter.threads.UltimateThreadGroupDurationEditor" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="duration_time">
<stringProp name="kg.apc.jmeter.threads.UltimateThreadGroup.duration_time">300</stringProp>
</elementProp>
</collectionProp>
</kg.apc.jmeter.threads.UltimateThreadGroup>
</TestFragment>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.on_sample_error">stopthread</stringProp>
<elementProp name="ThreadGroup.num_threads" elementType="int" guiclass="SpinnerNumber" testclass="ThreadGroup" testname="Number of Threads (users)">
<intProp name="ThreadGroup.num_threads">10</intProp>
</elementProp>
<elementProp name="ThreadGroup.ramp_time" elementType="int" guiclass="SpinnerNumber" testclass="ThreadGroup" testname="Ramp-Up Period (in seconds)">
<intProp name="ThreadGroup.ramp_time">10</intProp>
</elementProp>
<longProp name="ThreadGroup.start_time">1629049480000</longProp>
<longProp name="ThreadGroup.end_time">1629049480000</longProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay">0</stringProp>
</elementProp>
<HashTree>
<TestFragment guiclass="TestFragmentGui" testclass="TestFragment" testname="Test Fragment" enabled="true">
<elementProp name="TestPlan.comments" elementType="Comment" guiclass="CommentGui" testclass="Comment" testname="Comment">
<stringProp name="TestPlan.comments"></stringProp>
</elementProp>
<GenericController guiclass="LogicControllerGui" testclass="GenericController" testname="检查用户登录" enabled="true"/>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="请求数据" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="data" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">true</boolProp>
<stringProp name="Argument.value">${__V(myVar)}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</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">http</stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">/test</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<elementProp name="HTTPSampler.use_keepalive" elementType="bool" guiclass="BooleanPropertyEditor" testclass="BooleanProperty" testname="Use KeepAlive">
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
</elementProp>
<elementProp name="HTTPSampler.auto_redirects" elementType="bool" guiclass="BooleanPropertyEditor" testclass="BooleanProperty" testname="Follow Redirects">
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
</elementProp>
<elementProp name="HTTPSampler.use_multipart_for_http_post" elementType="bool" guiclass="BooleanPropertyEditor" testclass="BooleanProperty" testname="Use multipart/form-data for HTTP POST";>
<boolProp name="HTTPSampler.use_multipart_for_http_post">false</boolProp>
</elementProp>
<elementProp name="HTTPSampler.DO_MULTIPART_POST" elementType="bool" guiclass="BooleanPropertyEditor" testclass="BooleanProperty" testname="Send File With Request";>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
</elementProp>
<elementProp name="HTTPSampler.monitor" elementType="MonitorData" guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy">
<boolProp name=&原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/301504.html