There are many reasons that you may want to extract data from a reply from the server, it may be to perform a logical check, you may need the data (such as a customer account number) for an action later in the script or you may want to use the data for a technical reason such as selecting a random link from a set of links that appear in a response (you can see a video about how to do that here ).
To extract data from the script the simplest way is to use the option available as a right click in the HTTP Data window when it is displaying Recorded Request Details (button with red dot and yellow arrow), it will not work correctly when in the Replay Request Details view (green triangle with yellow arrow). To have the option to make that right click either by placing the cursor on the request that you are interested in (make sure it’s a primary request - see screenshot) then click the Recorded Request Details button. Or simply click on the thumbnail corresponding to the screen where the required data is and the HTTP Data window will be populated with the response details.
Right click over the data that you want to extract and choose ‘Extract Value…’. In this case we are going to extract the order number of a stock trade.
After clicking ‘Extract Value…’ the Parse window appears as below. It is prepopulated with a way to extract the data from the response. Clicking the magnifying glass in the lower right will test the extract conditions and show the result in the dialog box that pops up. In the 1st case we get the <b> </b> tags wrapped around the order number.
To make a cleaner extract we can try out some other techniques, in the case as below simply selecting Text option in the Extract section removes the tags:
Clicking the Hide button on the right (see top right of 1st screenshot where ,<b> tags are) will show where the wizard is extracting the data from:
Here we can see the order number. To adjust the way the extract is made you could also right click to choose ‘Extract value…’ to change the way the extract is made. Below we are extracting the same value but using the Source tab having highlighted the text to extract.
Once you are happy with the extract you can apply it. Don’t forget to give the variable a name first.
In this case we chose to call the variable MyOrderNumber. You can see by doing a text extract the parser is going to look for unique preceding and trailing strings – it’s especially important in a text extract to make sure the patterns are unique. In this case it is as this is the only bold test on the screen that immediately follows the letter ‘r’ – see the left extract string ‘r <b>’.
AgileLoad has now inserted the code into the script to extract the data as follows:
A handy way to check what the value is each time that you run the script is to use the Log command to have the value output to the Replay Details tab in the lower left AgileLoad script editor window.
In the screenshot below you can see the Log command and its output on the bottom line of the replay details tab window preceded by an information icon. In case you are wondering what the red line is, it’s a breakpoint used for debugging. You can introduce this by double clicking in the left most margin of the line where you want the breakpoint to be. Running the script with a break point will cause the script to pause at the breakpoint, replay can be resumed by clicking the playback button again or the next line can be executed in step by step mode by clicking the next track style button (green triangle with vertical line).