执行jmeter记录脚本时出现无效登录令牌错误。

问题描述 投票:0回答:1

我是jmeter的新手。我在jmeter中录制了Moodle的脚本。

录制了ScenarioSteps。

  1. 访问Moodle应用程序。
  2. 用授权用户登录。
  3. 点击课程链接。
  4. 登出。

测试运行细节。

运行有超过50个用户的记录脚本,这些用户拥有相同的用户证书(因为应用程序支持多用户登录)。

服务器监控团队共享的错误(执行jmeter脚本时)。

invalid Login Token

jmeter moodle
1个回答
1
投票

在大多数情况下,你不能只是重播录制的脚本,现代的网络应用广泛使用动态参数,即为。客户端状态跟踪安全原因

在Moodle的情况下,您需要通过 登录令牌 和凭证,它可以从登录页面的响应中提取,即使用 CSS选择器提取器

演示。

enter image description here

完整的测试计划,以备不时之需。

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.2.1">
    <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.tearDown_on_shutdown">true</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="Thread Group" 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">1</stringProp>
                <stringProp name="ThreadGroup.ramp_time">1</stringProp>
                <boolProp name="ThreadGroup.scheduler">false</boolProp>
                <stringProp name="ThreadGroup.duration"></stringProp>
                <stringProp name="ThreadGroup.delay"></stringProp>
                <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
            </ThreadGroup>
            <hashTree>
                <CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="HTTP Cookie Manager" enabled="true">
                    <collectionProp name="CookieManager.cookies"/>
                    <boolProp name="CookieManager.clearEachIteration">false</boolProp>
                    <boolProp name="CookieManager.controlledByThreadGroup">false</boolProp>
                </CookieManager>
                <hashTree/>
                <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Open Moodle Login 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">sandbox.moodledemo.net</stringProp>
                    <stringProp name="HTTPSampler.port"></stringProp>
                    <stringProp name="HTTPSampler.protocol">https</stringProp>
                    <stringProp name="HTTPSampler.contentEncoding"></stringProp>
                    <stringProp name="HTTPSampler.path">/login/index.php</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>
                    <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
                    <stringProp name="HTTPSampler.connect_timeout"></stringProp>
                    <stringProp name="HTTPSampler.response_timeout"></stringProp>
                </HTTPSamplerProxy>
                <hashTree>
                    <HtmlExtractor guiclass="HtmlExtractorGui" testclass="HtmlExtractor" testname="CSS Selector Extractor" enabled="true">
                        <stringProp name="HtmlExtractor.refname">logintoken</stringProp>
                        <stringProp name="HtmlExtractor.expr">input[name=logintoken]</stringProp>
                        <stringProp name="HtmlExtractor.attribute">value</stringProp>
                        <stringProp name="HtmlExtractor.default"></stringProp>
                        <boolProp name="HtmlExtractor.default_empty_value">false</boolProp>
                        <stringProp name="HtmlExtractor.match_number"></stringProp>
                        <stringProp name="HtmlExtractor.extractor_impl"></stringProp>
                    </HtmlExtractor>
                    <hashTree/>
                </hashTree>
                <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Perform 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="username" elementType="HTTPArgument">
                                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                                <stringProp name="Argument.value">admin</stringProp>
                                <stringProp name="Argument.metadata">=</stringProp>
                                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                                <stringProp name="Argument.name">username</stringProp>
                            </elementProp>
                            <elementProp name="password" elementType="HTTPArgument">
                                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                                <stringProp name="Argument.value">sandbox</stringProp>
                                <stringProp name="Argument.metadata">=</stringProp>
                                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                                <stringProp name="Argument.name">password</stringProp>
                            </elementProp>
                            <elementProp name="logintoken" elementType="HTTPArgument">
                                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                                <stringProp name="Argument.value">${logintoken}</stringProp>
                                <stringProp name="Argument.metadata">=</stringProp>
                                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                                <stringProp name="Argument.name">logintoken</stringProp>
                            </elementProp>
                            <elementProp name="anchor" elementType="HTTPArgument">
                                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                                <stringProp name="Argument.value"></stringProp>
                                <stringProp name="Argument.metadata">=</stringProp>
                                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                                <stringProp name="Argument.name">anchor</stringProp>
                            </elementProp>
                        </collectionProp>
                    </elementProp>
                    <stringProp name="HTTPSampler.domain">sandbox.moodledemo.net</stringProp>
                    <stringProp name="HTTPSampler.port"></stringProp>
                    <stringProp name="HTTPSampler.protocol">https</stringProp>
                    <stringProp name="HTTPSampler.contentEncoding"></stringProp>
                    <stringProp name="HTTPSampler.path">/login/index.php</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>
                    <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
                    <stringProp name="HTTPSampler.connect_timeout"></stringProp>
                    <stringProp name="HTTPSampler.response_timeout"></stringProp>
                </HTTPSamplerProxy>
                <hashTree/>
                <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
                    <boolProp name="ResultCollector.error_logging">false</boolProp>
                    <objProp>
                        <name>saveConfig</name>
                        <value class="SampleSaveConfiguration">
                            <time>true</time>
                            <latency>true</latency>
                            <timestamp>true</timestamp>
                            <success>true</success>
                            <label>true</label>
                            <code>true</code>
                            <message>true</message>
                            <threadName>true</threadName>
                            <dataType>true</dataType>
                            <encoding>false</encoding>
                            <assertions>true</assertions>
                            <subresults>true</subresults>
                            <responseData>false</responseData>
                            <samplerData>false</samplerData>
                            <xml>false</xml>
                            <fieldNames>true</fieldNames>
                            <responseHeaders>false</responseHeaders>
                            <requestHeaders>false</requestHeaders>
                            <responseDataOnError>false</responseDataOnError>
                            <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
                            <assertionsResultsToSave>0</assertionsResultsToSave>
                            <bytes>true</bytes>
                            <sentBytes>true</sentBytes>
                            <url>true</url>
                            <threadCounts>true</threadCounts>
                            <idleTime>true</idleTime>
                            <connectTime>true</connectTime>
                        </value>
                    </objProp>
                    <stringProp name="filename"></stringProp>
                </ResultCollector>
                <hashTree/>
            </hashTree>
        </hashTree>
    </hashTree>
</jmeterTestPlan>

0
投票

当你在执行脚本时,你必须将cookie或任何有token的请求头联合起来。录制的脚本不能工作,因为每次登录都会产生新的token。

检查已通过的请求头和cookie

© www.soinside.com 2019 - 2024. All rights reserved.