Saturday, November 24, 2007

Dynamic Correlation in Opensta

Dynamic Location in OpenSTA
If in a particular application you need to fetch the parameter values from HTTP Requests for correlation and position of the parameters is not fixed in page, In this case you can not rely on HTML DOM addressing.
OpenSTA has its ability to fetch the values dynamically,
Following is the sample code for that:
Where you need to supply the left & right boundary with Page Response, by using Locate & Extract it will fetch the values
! Standard Defines
CHARACTER*65535 ServerResponse, LOCAL
CHARACTER*65535 parameter, LOCAL
INTEGER Offset
CHARACTER*512 RIGHT_BOUNDARY, LOCAL
CHARACTER*512 LEFT_BOUNDARY, LOCAL
! OpenSTA Code
LOAD RESPONSE_INFO BODY ON 1 INTO ServerResponse1
! Loading the page response into variable please check the connection ID should
! Be same as in request
IF (ServerResponse1 = "") THEN
Log " Error in Page No Data Available”
Detach Thread
ENDIF
SET LEFT_BOUNDARY=''
CALL FetchByDynamic [ServerResponse1, LEFT_BOUNDARY, RIGHT_BOUNDARY]
SET viewstate = parameter ! Set the Fetching value in required parameter
!*******************************************************************************
SUBROUTINE FetchByDynamic [ServerResponse, LEFT_BOUNDARY, RIGHT_BOUNDARY]
SET offset= ~LOCATE (LEFT_BOUNDARY, ServerResponse)
IF (offset <= 0) THEN
LOG “ERROR at OFFSET while Fetching value”
REPORT “ERROR at OFFSET while Fetching value ", ServerResponse
Detach Thread
ENDIF
SET offset = offset + ~LENGTH (LEFT_BOUNDARY)
SET parameter = ~EXTRACT (offset, 65535, ServerResponse)
SET offset=~LOCATE(RIGHT_BOUNDARY,parameter)
SET parameter = ~EXTRACT (0, offset, parameter)
RETURN
END SUBROUTINE
!*******************************************************************************
Limitation:
If page response is greater than 64k in that case if required parameter value is not within 64k then it will not able to capture the values, As page can be loaded of maximum 64k in variable.
Also while implementing this code please crosscheck from page response that required value is set properly.

Example Script and Data files For Dynamic Correlation in Opensta

Script :

!Browser:IE5
!Date : 01-Dec-2007
Environment
Description ""
Mode HTTP
Wait UNIT MILLISECONDS

Definitions
! Standard Defines
Include "RESPONSE_CODES.INC"
Include "GLOBAL_VARIABLES.INC"

CHARACTER*512 USER_AGENT
Integer USE_PAGE_TIMERS
CHARACTER*256 MESSAGE
CHARACTER*512 ALL_DATA1, FILE ="zoniac_all", SCRIPT

CHARACTER*512 ALL_DATA, LOCAL

Timer T_GOOGLE_EXAM_1
Timer T_GOOGLE_EXAM_2
Timer T_GOOGLE_EXAM_3
Timer T_GOOGLE_EXAM_4
Timer T_GOOGLE_EXAM_5
Timer T_GOOGLE_EXAM

Integer Length
Integer Length1
Integer Length2
Integer Length3
Integer Length4
Integer Length5
Integer Length6

Integer sep1
Integer sep2
Integer sep3
Integer sep4
Integer sep5

Integer Offset1
Integer Offset2
Integer Offset3
Integer Offset4
Integer Offset5
Integer Offset6

CHARACTER*512 username
CHARACTER*512 accname
CHARACTER*512 req_title
CHARACTER*512 search_name
CHARACTER*512 candidate_name
CHARACTER*512 consultant_name
CHARACTER*512 LC-String ("demo_28")
CHARACTER*512 UC-String

CONSTANT DEFAULT_HEADERS = "Host: www.google.com^J" &
"Accept-Encoding: gzip, deflate^J" &
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;"&
" Mailinfo [1108417]; InfoPath.1; MEGAUPLOAD 2.0; .NET CLR 2.0.50727)"
CONSTANT S_cookie_1_0 = &
"PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj"

Code
!Read in the default browser user agent field
Entry[USER_AGENT,USE_PAGE_TIMERS]

Start Timer T_GOOGLE_EXAM
!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj

If (USE_PAGE_TIMERS=1) then
Start Timer T_GOOGLE_EXAM_1
EndIf

ACQUIRE TEST-WIDE MUTEX "SCRIPT1"

NEXT ALL_DATA1
SET ALL_DATA=ALL_DATA1

LOG ALL_DATA

RELEASE TEST-WIDE MUTEX "SCRIPT1"

SET Length = ~LENGTH(ALL_DATA)

LOG Length

SET sep1 = ~LOCATE('*', ALL_DATA), CASE_BLIND
SET sep2 = ~LOCATE(',', ALL_DATA), CASE_BLIND
SET sep3 = ~LOCATE('#', ALL_DATA), CASE_BLIND
!SET sep4 = ~LOCATE('$', ALL_DATA), CASE_BLIND
!SET sep5 = ~LOCATE('&', ALL_DATA), CASE_BLIND

SET Offset1 = 0
SET Offset2 = sep1+1
SET Offset3 = sep2+1
SET Offset4 = sep3+1
!SET Offset5 = sep4+1
!SET Offset6 = sep5+1


SET Length1 = sep1
SET Length2 = (sep2 - 1) - Length1
SET Length3 = (sep3 - 1) - (Length1+Length2)-1
SET Length4 = (sep4 - 1) - (Length1+Length2+Length3)-2
!SET Length5 = (sep5 - 1) - (Length1+Length2+Length3+Length4)-3
!SET Length6 = Length - (sep5 - 1)





SET username = ~EXTRACT(Offset1, Length1, ALL_DATA)
SET accname = ~EXTRACT(Offset2, Length2, ALL_DATA)
SET req_title = ~EXTRACT(Offset3, Length3, ALL_DATA)
SET search_name = ~EXTRACT(Offset4, Length4, ALL_DATA)
!SET candidate_name = ~EXTRACT(Offset5, Length5, ALL_DATA)
!SET consultant_name = ~EXTRACT(Offset6, Length6, ALL_DATA)

LOG username
LOG accname
LOG req_title
! LOG search_name
!LOG candidate_name
! LOG consultant_name

FORMAT(UC-String, "Name in uppercase is %U", LC-String)

LOG UC-String


!Fake Cookies:
PRIMARY GET URI &
"http://www.google.com/" &
"search?q=tesing&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7 HTTP/1.1" ON 1 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, " &
"application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, " &
"application/msword, */*", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

!Wait 797

!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj
!Fake Cookies:
GET URI "http://www.google.com/extern_js/f/CgJlbiswCTgALA/cyZsHpoJsEI.js HTTP/1.1" ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: */*", &
"Referer: " &
"http://www.google.com/" &
"search?q=tesing&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

!Wait 360

!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj
!Fake Cookies:
GET URI "http://www.google.com/images/phone_icon.gif HTTP/1.1" ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: */*", &
"Referer: " &
"http://www.google.com/" &
"search?q=tesing&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

!Wait 5625

!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj
SYNCHRONIZE REQUESTS


If (USE_PAGE_TIMERS=1) then
End Timer T_GOOGLE_EXAM_1
EndIf


If (USE_PAGE_TIMERS=1) then
Start Timer T_GOOGLE_EXAM_2
EndIf

!Fake Cookies:
PRIMARY GET URI &
"http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=testing HTTP/1.1" &
ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, " &
"application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, " &
"application/msword, */*", &
"Referer: " &
"http://www.google.com/" &
"search?q=tesing&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

DISCONNECT FROM 1

DISCONNECT FROM 2

!Wait 12312

!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj
SYNCHRONIZE REQUESTS


If (USE_PAGE_TIMERS=1) then
End Timer T_GOOGLE_EXAM_2
EndIf


If (USE_PAGE_TIMERS=1) then
Start Timer T_GOOGLE_EXAM_3
EndIf

!Fake Cookies:
PRIMARY GET URI &
"http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=forwarded HTTP/1.1" &
ON 3 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, " &
"application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, " &
"application/msword, */*", &
"Referer: http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=testing", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

DISCONNECT FROM 3

!Wait 469

!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj
SYNCHRONIZE REQUESTS


If (USE_PAGE_TIMERS=1) then
End Timer T_GOOGLE_EXAM_3
EndIf


If (USE_PAGE_TIMERS=1) then
Start Timer T_GOOGLE_EXAM_4
EndIf

!Fake Cookies:
PRIMARY GET URI &
"http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=forwarded HTTP/1.1" &
ON 12 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, " &
"application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, " &
"application/msword, */*", &
"Referer: http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=testing", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

!Wait 7703

!Cookie Header:
!> PREF=ID=c3d38bfac174facd:TM=1196484740:LM=1196484740:S=OMD3o9aRmFk7PsFj
SYNCHRONIZE REQUESTS


If (USE_PAGE_TIMERS=1) then
End Timer T_GOOGLE_EXAM_4
EndIf


If (USE_PAGE_TIMERS=1) then
Start Timer T_GOOGLE_EXAM_5
EndIf

!Fake Cookies:
PRIMARY GET URI &
"http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=top+search HTTP/1.1" &
ON 12 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, " &
"application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, " &
"application/msword, */*", &
"Referer: " &
"http://www.google.com/search?hl=en&rls=com.microsoft%3A*%3AIE-SearchBox&q=forwarded", &
"Accept-Language: en-us", &
"UA-CPU: x86", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_1_0}

DISCONNECT FROM 12

SYNCHRONIZE REQUESTS

End Timer T_GOOGLE_EXAM

If (USE_PAGE_TIMERS=1) then
End Timer T_GOOGLE_EXAM_5
EndIf

Exit

ERR_LABEL:

If (MESSAGE <> "") Then
Report MESSAGE
Endif

Exit

Data File .fvr Examples


user1*Java,Niteo Partners#
user2*Java,Lead Ltd#
user3*J2EE,Prompt Technologies#
user4*COBOL,Miller Ltd#
user5*Unix,Lithyam Corporation#
user6*Pascal,Computer Mangement#
user7*Oracle 9i,Tom Infosys#
user8*Data Structures,Thomas InfoTech#
user9*Open STA,Diamond Enginnering#
user10*C#.Net,Murugappa Company#
user11*Red Hat Linux,Deccanet Designs#
user12*J2ME,Diksha Technologies#
user13*Load Runner,Bangalore Softsell#
user14*Web Logic,Delphi Automotive#
user15*QA Run,Digital-X India#
user16*Apache Tomcat,System Domain#
user17*SQL Server 2005,Paxonet#
user18*ASP.Net,Base Holdings#
user19*Fortran 77,Alps Infosys#
user20*VB.Net,Amritanet #
user21*Unix,Answerpal#
user22*PostgreSQL,Icode Software #
user23*DB2,iCelerate#
user24*C++,i2 Technologies#
user25*VC++,IBC Solutions India#
user26*Visual Programming,IBEX Technologies#
user27*Oracle 9i,Hughes#
user28*QA Load,IBM Global#
user29*Test Partner,Hewlett Packard#
user30*Win Runner,Hical#
user31*QTP,Honeywel#
user32*Microprocessor 8085,Suyog Impex#
user33*Open STA,Guru InfoTech#
user34*Photoshop,GPS Corporation#
user35*Flash,Gothi Software#
user36*VB,Genesys#
user37*C shap,Genesis IT#
user38*ADO.Net,Supreme#
user39*Red Hat Linux,Geekay Imaging#
user40*Websphere,GE Power#
user41*Jboss,Future Software#
user42*Silk Performer,Synectics#
user43*Jmeter,ExcelSoft#
user44*SQL Server 7.0,ExaNet#
user45*Load Runner,Eximsoft#
user46*Ajax,EWI Engineers#
user47*MS Access,Surya Soft-Tech#
user48*MS Office,FI Sofex#
user49*XML,First Ring#
user50*COM+,Force Computers#

No comments: