Manually Handling Session IDs (URL rewriting)

Imagine that a Web Application implementing session is receiving requests from three different users. For each user request, the Web Application must be able to determine the session of the user request. Each user request can belong to just one of three user sessions being tracked by the Web Application. Cookies provide a fairly simple approach to tracking sessions, but because cookies do not work in all situations, URL rewriting provides an alternative (some browsers do not support cookies, others allow the user to disable cookie support). With URL rewriting, redirected links or links returned to the browser have the session ID appended to them.

If the FMStocks demo site has been downloaded, it can be configured to use URL rewriting (see installation manual).

  1. Locate the first URL that contains a session ID (it is usually easy to recognize a session ID: a abnormal succession of alphanumerical characters):



  2. Select this session ID, right-click on it and select "Find & Replace/Find In HTTP Responses" from the pop-up menu:



  3. The Find In HTTP utility will search for the session id in the HTTP responses saved during the recording. The following dialog will appear:



  4. Click OK and select the Find In HTTP tab in the Output window:



    The session ID "CJIdz5719-70D3792473C8C0FA7BD7657D3382A5" has been found in the response to the request on line 55: "http://test_fmstocks/fmstocks/default.asp," in the HTTP header.

  5. Double-click the item in the Output window to locate: 

    - the corresponding request in the script,
    -
    the server HTTP header containing the Session ID.



    The rewritten URL is located in the Location server header.

  6. Right-Click on the Location header and select "Extract value..." from the pop-up menu:



  7. Enter a new variable name, RELOCATION, in the "Variable Name" field
     
  8. Click OK, a new line is appended to the request in the script:



    The GetHeader function added to this request tells the replay engine that it must load the content of the "Location" header into the RELOCATION variable.

  9. Extracting the session ID from the rewritten URL can be done using the TOKEN statement:

This previously inserted TOKEN statement extracts the third string from the RELOCATION variable using the "/" separator.
The RELOCATION variable has a value similar to the following: "/fmstocks/session_id/home.asp".
Using the TOKEN command with the "/" separator, the first string is "", the second string is "fmstocks" and the third one is the session ID we are looking for.

Note that a new SESSION_ID variable must be defined:


  1. Check that the session ID is extracted correctly: put a breakpoint (F9 key) on the command following the TOKEN command and replay the Script in the AgileLoad Script Editor:



    When the script execution is paused on a breakpoint (or because the Pause button was pressed or the replay is done in step by step mode), the variable's values are shown in the Variables Panel. The screen above shows that the session ID was correctly extracted from the rewritten URL.

  2. The next step is to substitute the SESSION_ID variable in all occurrences of the session ID "CJIdz5719-70D3792473C8C0FA7BD7657D3382A5" captured during recording. Click the Edit menu and select Replace In String..



    Enter the recorded session ID in the Find field and enter SESSION_ID in the Replace field. Check the "+ <Replace String> +" option and then click Replace All:



    All occurrences of "CJIdz5719-70D3792473C8C0FA7BD7657D3382A5" were replaced by ""+ SESSION_ID +"".

  3. It can be useful to check script validity after building models: See Checking Script Validity.


See also:





Go back to the Learning center:


Copyright © AgileLoad. All rights reserved.
Agile Load testing tool| Contact AgileLoad | Terms of Use | Sitemap