Thursday, September 21, 2006

Correlation in WebLoad

1. Real-life scenario

Consider a following Real-Life Scenario:

1. A website www.XYZmail.com is opened through a browser, a page asking for Username and Password is displayed

2. When a valid username and a password is given and submit button is pressed, an inbox page is displayed

3. The inbox page displayed is specific to that session. This session is represented by a particular session id .(The HTML source for this page will have the session id generated for this particular session)

4. During the same session, if different pages are requested, the URLs for these pages may have session id embedded in the URL.For example, if we are in inbox page and we request a compose page, the URL for the compose page may have the session id embedded in the URL.

2. The real-life scenario when scripted using webload

The above sequence of events could be mapped to following HTTP Gets and Posts. (When we record the above sequence of events using Webload, these HTTP Gets and Posts will be part of the webload script (or the agenda))

/*
Step 1: Opening the XYZmail.com page
*/

wlHttp.Get("http://www.XYZmail.com/cgi-bin/login.cgi")
Sleep(N)

/*
Step 2: Type the and , and press submit button: Inbox page is displayed. The HTML source file for this page will have the session id generated.
*/

wlHttp.Type = "FORM"; wlHttp.ExpectedLocation = ":0"; wlHttp.ExpectedID = ""; wlHttp.ExpectedName = "loginform"; wlHttp.ExpectedText = "";
wlHttp.Url = wlHttp.IdentifyObject("http://mail.XYZ.com/cgi-bin/login.cgi")
wlHttp.ContentType = "application/x-www-form-urlencoded"
// wlHttp.FormData["FormName"] = wlHttp.GetCurrentValue("FormName","existing")// Hidden field
wlHttp.FormData["login"] = ""
wlHttp.FormData["passwd"] = ""
wlHttp.FormData["proceed"] = "GO"
wlHttp.SetCurrentHiddenValues()
wlHttp.Post(wlHttp.Url)
Sleep (N)

/*
Step 3: Click on the write mail link: Compose page is displayed
*/

wlHttp.Type = "A"; wlHttp.ExpectedLocation = ":6"; wlHttp.ExpectedID = ""; wlHttp.ExpectedName = ""; wlHttp.ExpectedText = "Write Mail";

/*
The URL for this page has the session id embedded: The session id has been marked in bold below for understanding purpose
*/

w1Http.URL = wlHttp.IdentifyObject("http://f2mail.XYZ.com/bn/compose.cgi?login =&random_id=2K1KQKK5gSPsYLWcMiueiHwjox80&FormName=compose")
wlHttp.Get(wlHttp.Url)


3. When replaying the script, what is the issue?

Step 1 and Step 2 for a new session would be properly replayed. But the step 3 would have a problem, since a new session id would have been generated during step 2 and the third step would be having old session id“2K1KQKK5gSPsYLWcMiueiHwjox80”.

So we need to have data correlation. This means, ideally we should do the following steps

· We should capture the session id generated in step 2 from the HTML source of the Inbox page.
· Then replace the hard coded session id with captured session id in step 3.


4. Data correlation, how can it be done in webload?

2 correlation methods have been explained below. For both the methods, assume the session id appears in the HTML source file of the Inbox page as below (From this we need to capture the session id):

“……………random_id=2K1KAK7ep5m3hASFYUO11PsMDKAV&name=………….”


4.1. Method 1
(This is the method found in one of the popular Boks in Kshop)

Method:

· The HTML source file for the page in second step (in this case, the inbox page) needs to be saved.
· The position of the left boundary of the session id (in this case the left boundary is “random_id=”) in the source file is determined
· The relative positions of the start of session id and the end of session id from the Left boundary position is determined. (In this case the relative positions are 10 and 28). Using substring function the session id is captured


Using this method the code would look like below. The comments for the changes done have been marked in red

/*
Step 1: Opening the XYZmail.com page
*/

wlHttp.Get("http://www.XYZmail.com/cgi-bin/login.cgi")
Sleep(N)

/*
Step 2: Type the and , and press submit button: Inbox page is displayed. The HTML source file for this page will have the session id generated.
*/

wlHttp.Type = "FORM"; wlHttp.ExpectedLocation = ":0"; wlHttp.ExpectedID = ""; wlHttp.ExpectedName = "loginform"; wlHttp.ExpectedText = "";
wlHttp.Url = wlHttp.IdentifyObject("http://mail.XYZ.com/cgi-bin/login.cgi")
wlHttp.ContentType = "application/x-www-form-urlencoded"
// wlHttp.FormData["FormName"] = wlHttp.GetCurrentValue("FormName","existing")// Hidden field
wlHttp.FormData["login"] = ""
wlHttp.FormData["passwd"] = ""
wlHttp.FormData["proceed"] = "GO"
wlHttp.SetCurrentHiddenValues()
wlHttp.Post(wlHttp.Url)

/*
Save source of the page: The HTML source file of the Inbox page is saved here
*/

wlHttp.SaveSource = "Yes"


/*
See where the left boundary “random_id=” begins
*/

First = document.wlSource.indexOf("random_id=")

/*
Capture sessionid.
*/
sessionid = document.wlSource.substring(First+10, First+28)


/*
Step 3: Click on the Write mail link: Compose page is displayed
*/

wlHttp.Type = "A"; wlHttp.ExpectedLocation = ":6"; wlHttp.ExpectedID = ""; wlHttp.ExpectedName = ""; wlHttp.ExpectedText = "Write Mail";

/*
The captured sessionid is substituted for the hardcoded value
*/

w1Http.URL = wlHttp.IdentifyObject(http://f2mail.XYZ.com/bn/compose.cgi?login =&random_id=”+sessionid+”&FormName=compose")
wlHttp.Get(wlHttp.Url)


There is an issue with this method. This works only if the string being captured (in this a case session id) is always of constant length. (Otherwise we won’t know the relative position of the end of session id from the Left boundary position)

4.2. Method 2 (Using the regular expression concept)

This method is based on the concept of patterns matching regular expressions.

Method:

· The HTML source file for the page in second step (in this case, the inbox page) needs to be saved.
· Identify unique left boundary and unique right boundary for the session id in the source file (in this case say the left boundary is “random_id=” and unique right boundary is “&name=”)
· Define a regular expression represents a pattern of all strings that begins with “random_id=” and ends with “&name=”
· Use exec function to find a pattern in the saved source file that matches the regular expression defined and store the pattern in the array.
· Use substring function to strip the left boundary and the right boundary from the pattern and thus capture the session id.

Using this method the code would look like below. The comments for the changes done have been marked in red

/*
Step 1: Opening the XYZmail.com page
*/

wlHttp.Get("http://www.XYZmail.com/cgi-bin/login.cgi")
Sleep(N)

/*
Step 2: Type the and , and press submit button: Inbox page is displayed. The HTML source file for this page will have the session id generated.
*/

wlHttp.Type = "FORM"; wlHttp.ExpectedLocation = ":0"; wlHttp.ExpectedID = ""; wlHttp.ExpectedName = "loginform"; wlHttp.ExpectedText = "";
wlHttp.Url = wlHttp.IdentifyObject("http://mail.XYZ.com/cgi-bin/login.cgi")
wlHttp.ContentType = "application/x-www-form-urlencoded"
// wlHttp.FormData["FormName"] = wlHttp.GetCurrentValue("FormName","existing")// Hidden field
wlHttp.FormData["login"] = ""
wlHttp.FormData["passwd"] = ""
wlHttp.FormData["proceed"] = "GO"
wlHttp.SetCurrentHiddenValues()
wlHttp.Post(wlHttp.Url)

/*
Save source of the page: The HTML source file of the Inbox page is saved here
*/

wlHttp.SaveSource = "Yes"


/*
Defines a regular expression that represents a pattern of all strings that begins with “random_id=” and ends with “&name=”
*/

RE = /random_id=.*&name=/;



/*
Use exec function to find a pattern in the saved source file that matches the regular expression and store the pattern in an array pattern.
*/
pattern = RE.exec(document.wlSource);

/*
Strip the left boundary, right boundary from the pattern to capture the sessionid: Here please note that when we are evaluating a string length, if the string includes character like double quote (“) or character like / we need to precede the character with \, for example if we are evaluating length of the string “value="”, we should use “value=\"”.length to evaluate the length.
*/


leftlen = “random_id=”.length;
rightlen = “&name=”.length;
patternlen = pattern[0].length;
sessionid = pattern[0].substring(leftlen,patternlen - rightlen);

/*
Step 3: Click on the write mail link: Compose page is displayed
*/

wlHttp.Type = "A"; wlHttp.ExpectedLocation = ":6"; wlHttp.ExpectedID = ""; wlHttp.ExpectedName = ""; wlHttp.ExpectedText = "Write Mail";

/*
The captured sessionid is substituted for the hardcoded value
*/

w1Http.URL = wlHttp.IdentifyObject(http://f2mail.XYZ.com/bn/compose.cgi?login =&random_id=”+sessionid+”&FormName=compose")
wlHttp.Get(wlHttp.Url)


This method works even if string to be captured is not always of same length and hence more flexible. Only thing is the left and the right boundaries should be long enough so that they are unique.

0 Comments:

Post a Comment

<< Home