JMeter MVC Login - DXScript, DXMVCEditorsValues
Categories:
Mastering JMeter Login Scenarios with DXScript and DXMVCEditorsValues
Learn how to effectively simulate complex login flows in JMeter, especially when dealing with dynamic values from DXScript and DXMVCEditorsValues.
Simulating user login is a fundamental aspect of performance testing. However, modern web applications often employ dynamic values, such as anti-forgery tokens or session IDs, which can make direct recording and playback challenging. This article delves into how to handle such dynamic values in JMeter, specifically focusing on scenarios involving DXScript and DXMVCEditorsValues, common in certain enterprise applications. We'll explore techniques to extract, correlate, and reuse these values to ensure robust and realistic login test plans.
Understanding Dynamic Values in Login Flows
Many web applications, particularly those built with frameworks like ASP.NET MVC, use hidden input fields or JavaScript-generated values to enhance security or manage session state. These values are dynamic, meaning they change with each request or session. If not handled correctly, JMeter will send outdated or invalid values, leading to failed login attempts and inaccurate test results. Common examples include __VIEWSTATE
, __EVENTVALIDATION
, anti-forgery tokens (e.g., __RequestVerificationToken
), and custom JavaScript-generated values like those found in DXScript
or DXMVCEditorsValues
.
flowchart TD A[Start Login Process] --> B{Initial GET Request to Login Page} B --> C[Server Responds with Login Page HTML] C --> D{"Extract Dynamic Values (e.g., DXScript, DXMVCEditorsValues)"} D --> E[Prepare POST Request with Extracted Values] E --> F{Submit Login POST Request} F --> G{Server Authenticates User} G --> H[Redirect to Dashboard/Home Page] H --> I[End Login Process]
Typical Login Flow with Dynamic Value Extraction
Extracting DXScript and DXMVCEditorsValues
DXScript and DXMVCEditorsValues are often embedded within JavaScript blocks or hidden input fields. To capture these, JMeter's Regular Expression Extractor is your primary tool. You'll need to analyze the server's response to the initial GET request for the login page to identify the patterns for these values. Look for <input type="hidden"
tags or JavaScript variables that hold the necessary tokens.
<input type="hidden" name="__RequestVerificationToken" value="_some_dynamic_token_here_" />
<script type="text/javascript">
//<![CDATA[
var DXScript = 'some_script_id';
var DXMVCEditorsValues = 'some_editor_value';
//]]>
</script>
Example HTML snippet containing dynamic values
Configuring Regular Expression Extractors
For each dynamic value, you'll add a Regular Expression Extractor as a child of the HTTP Request that fetches the login page. Here's how to configure them:
1. Add a Regular Expression Extractor
Right-click on your 'Login Page GET Request' -> Add -> Post Processors -> Regular Expression Extractor.
2. Configure for __RequestVerificationToken
Set 'Reference Name' to requestVerificationToken
. Set 'Regular Expression' to <input type="hidden" name="__RequestVerificationToken" value="(.+?)" />
. Set 'Template' to $1$
and 'Match No.' to 1
.
3. Configure for DXScript
Add another Regular Expression Extractor. Set 'Reference Name' to dxScriptValue
. Set 'Regular Expression' to var DXScript = '(.+?)';
. Set 'Template' to $1$
and 'Match No.' to 1
.
4. Configure for DXMVCEditorsValues
Add a third Regular Expression Extractor. Set 'Reference Name' to dxMVCEditorsValues
. Set 'Regular Expression' to var DXMVCEditorsValues = '(.+?)';
. Set 'Template' to $1$
and 'Match No.' to 1
.
Using Extracted Values in the Login POST Request
Once the dynamic values are extracted, you can reference them in your subsequent login POST request using the JMeter variable syntax ${variableName}
. For example, if you extracted __RequestVerificationToken
into requestVerificationToken
, you would use ${requestVerificationToken}
in the parameter list of your login POST request.
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Login POST Request" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="username" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">testuser</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">password123</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">password</stringProp>
</elementProp>
<elementProp name="__RequestVerificationToken" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${requestVerificationToken}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">__RequestVerificationToken</stringProp>
</elementProp>
<elementProp name="DXScript" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${dxScriptValue}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">DXScript</stringProp>
</elementProp>
<elementProp name="DXMVCEditorsValues" elementType="HTTPArgument">
<boolProp name="HTTPArgument.always_encode">false</boolProp>
<stringProp name="Argument.value">${dxMVCEditorsValues}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
<boolProp name="HTTPArgument.use_equals">true</boolProp>
<stringProp name="Argument.name">DXMVCEditorsValues</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="HTTPSampler.method">POST</stringProp>
<stringProp name="HTTPSampler.domain">your-app.com</stringProp>
<stringProp name="HTTPSampler.path">/Account/Login</stringProp>
</HTTPSamplerProxy>
JMeter HTTP Request configuration for a login POST request using extracted variables