Submit a form from the previous request
This tutorial looks at the case where the request type Submit a form from the previous request is used. This is one of the methods provided by NeoLoad for extracting data from an HTML page returned by the server. For more information about the various methods of extracting data, see Choose a data extraction method.
The tutorial describes one of the steps in the methodology relating to designing a Virtual User. For an overview of designing a Virtual User, see Design process.
Understand the problem
An HTML form that is submitted to your application contains control elements (text boxes, radio buttons, checkboxes, and so on) that have been filled in or modified by the user. When NeoLoad plays back the recorded HTML form, submitting it to the application, it must be able to re-generate all the form control values. In most cases, simply submitting the control values entered during the recording phase is sufficient. In the following example, the text entered in the HTML form lastname text box can be played back using the recorded value as many times as desired:
<FORM action="doit.jsp" method="post">
<P>
Last name: <INPUT type="text" name="lastname"><BR/>
<INPUT type="submit" value="Send">
</P>
</FORM>
In certain situations however, the control elements contain values generated by your application each time the HTML form is called. These dynamic values are sent back to the application when the form is submitted. The dynamic values may be hidden, to prevent them being modified by the user. In the following example, you can see that the dynamicID
element contains a value generated by the application that varies each time the form is called:
<FORM action="doit.jsp" method="post">
<P>
Last name: <INPUT type="text" name="lastname"><BR/>
<INPUT type="hidden" name="dynamicID" value="7885">
<INPUT type="submit" value="Send">
</P>
</FORM>
In this type of situation, simply playing back what was recorded will not work, since the dynamic value sent to the application will not be the expected value. Here, the HTML value needs to be extracted in order to inject the appropriate value. This is what you will be looking at in this tutorial.
To deal with dynamic values, NeoLoad provides a mechanism called a Form Extractor , which extracts the dynamic value from the preceding HTTP response and re-injects it in the request containing the HTML form.
Note: To be precise, the value is not extracted from the preceding HTTP request, but from the referrer
of the HTTP request that contains the form parameters.
Extract and re-inject a hidden dynamic value
You may use the following HTML form as an example:
The following screenshot shows the source code for the form used in the example (the HTTP response content). The response sets out a text box control lastname
, a hidden control dynamicID
and a select control country
. You may have recorded the pages that call the form and have completed and submitted the form during the recording.
This screenshot was obtained by selecting the page preceding the page that submits the form. You selected the HTTP request , clicked on the Advanced button and selected the Recorded Response tab.
To tell NeoLoad how the dynamicID
parameter should be extracted and injected in the played-back form, follow these steps:
-
Select the HTTP request containing the HTML form:
-
Go into the Design section.
-
Select the Virtual Users tab.
-
Unfold the nodes of the HTML page and the appropriate recording; this is the HTML page that follows the page that calls the form.
-
Select the HTTP request containing the HTML form parameters, the request that will submit the form. During the recording phases, NeoLoad identifies the fields in the HTML form and therefore the parameters of the HTTP request that will be sent when the form is submitted. In the example, these parameters are
lastname
,dynamicID
andcountry
. To identify those HTTP requests that submit forms, select the current request or Virtual User node, right-click on the node and select Flag requests. Select the POST form type option.
-
-
Change the HTTP request type: In the Type drop-down list, change the HTTP request type from Manually define the request to Submit a form from the previous request.
-
Check the form extraction criteria: In the Form to extract section, click on the picker button to display the form extraction criteria. This dialog box is used to specify how NeoLoad should search the preceding HTML response for the form whose values are to be extracted. The default settings are usually OK to use. Use other, more appropriate criteria if necessary. In this case, the criteria are appropriate.
-
Use the extracted value:
-
In the example, double-click on the
dynamicID
parameter to display the parameter editing pane. -
Select the Use value from extracted form option. This way, when a Virtual User that uses this request is played back, NeoLoad will submit the form with the value extracted from the server preceding HTML response instead of submitting the recorded value.
-
As with all parameters that use extracted values, the
dynamicID
parameter is displayed with a distinctive icon and label.
-
Learn more about form extractors
In the previous example, the HTML form contains a select
control that allows you to choose a country among several values in a country list. If you configure the country
parameter using the same procedure as for the dynamicID
parameter, NeoLoad will randomly select one of the possible country values and re-inject it.
You could have used a variable listing all the country options to obtain a similar behavior by setting the parameter value field to a variable. However, by using data extraction, you avoid having to keep variables synchronized with your application. Also, if other country options are added, you do not have to change the configuration or definition.
For more information about the various options and panes, see Submit a form from the previous request.
Related links
Just as dynamic data can be extracted from a form, a dynamic link can be extracted and followed. For more information, see Follow a link from the previous request.
For more information about extracting arbitrary content, see Variable extractors and Create a variable extractor.