Wednesday, January 30, 2008

How-To verify your results in OpenSTA

This article describes how to get the web page response and how to check for a specific string in that web page.
In the code examples we are trying to fetch the web page of www.google.com and verify that it contains the string "Google"


In the bottom of the "definitions" section (just before the "code" section) add this:

CHARACTER*32000 VER_BODY , SCRIPT !Content of the webpage we are testing. Will be filled later by the LOAD RESPONSE_INFO BODY... code below
CHARACTER*512 VER_STRING, SCRIPT !The verification string
INTEGER VER_LOCATION !Location of the found string. If not found result will be -1

The three variables above, wil hold the string that we will apply later

In the code section, just after your GET PRIMARY call, add this:

SET VER_STRING = "Google"
LOAD RESPONSE_INFO BODY ON 2 INTO VER_BODY !Please ensure that you are using the right connection
SET VER_LOCATION = ~LOCATE (VER_STRING,VER_BODY), CASE_BLIND
IF (VER_LOCATION >= 0) THEN
LOG "Verification SUCCES - Page contained the string '", VER_STRING , "'"
ELSE
LOG "Verification FAILED - Page did not contain the string '", VER_STRING , "'"
ENDIF

- That's all, just check your log. The complete google checking script is here:

!Browser:IE5
!Date : 02-05-2005
Environment
Description "Google return verification script"
Mode HTTP
Wait UNIT MILLISECONDS
Definitions
CHARACTER*512 USER_AGENT
CHARACTER*256 MESSAGE
INTEGER USE_PAGE_TIMERS
TIMER T_VERIFICATION_TEST
CONSTANT DEFAULT_HEADERS = &
"Host: www.google.com^J" &
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)"
CONSTANT S_cookie_2_0 = "PREF=ID=3e039eeb146d9ae6:LD=da:TM=1110963658:LM=111096" &
"3658:S=8cVP0TIbiqBvsiiR"
CHARACTER*32000 VER_BODY, SCRIPT !Content of the webpage we are testing. Will be filled later by the LOAD RESPONSE_INFO BODY... code below

CHARACTER*512 VER_STRING, SCRIPT !The verification string
INTEGER VER_LOCATION !Location of the found string. If not found result will be -1
Code
Entry[USER_AGENT,USE_PAGE_TIMERS]
Start Timer T_VERIFICATION_TEST
PRIMARY GET URI "http://www.google.com/ HTTP/1.0" ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*", &
"Accept-Language: en,da;q=0.5", &
"Cookie: "+S_cookie_2_0, &
"Connection: Keep-Alive"}

! --- Verification START ---
!Sample script for verifying that a web page contains a given string
SET VER_STRING = "Google"
LOAD RESPONSE_INFO BODY ON 2 INTO VER_BODY !Please ensure that you are using the right connection
SET VER_LOCATION = ~LOCATE (VER_STRING,VER_BODY), CASE_BLIND
IF (VER_LOCATION >= 0) THEN
LOG "Verification SUCCES - Page contained the string '", VER_STRING , "'"
ELSE
LOG "Verification FAILED - Page did not contain the string '", VER_STRING , "'"
ENDIF
! --- Verification END ---

DISCONNECT FROM 2
WAIT 3735

GET URI "http://www.google.com/images/hp0.gif HTTP/1.0" ON 3 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: */*", &
"Referer: http://www.google.com/", &
"Accept-Language: en,da;q=0.5", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_2_0}

WAIT 1452
GET URI "http://www.google.com/images/hp1.gif HTTP/1.0"ON 4 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: */*", &
"Referer: http://www.google.com/", &
"Accept-Language: en,da;q=0.5", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_2_0}

WAIT 1482
GET URI "http://www.google.com/images/hp2.gif HTTP/1.0" ON 5 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: */*", &
"Referer: http://www.google.com/", &
"Accept-Language: en,da;q=0.5", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_2_0}

WAIT 1462
GET URI "http://www.google.com/images/hp3.gif HTTP/1.0"ON 6 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: */*", &
"Referer: http://www.google.com/", &
"Accept-Language: en,da;q=0.5", &
"Connection: Keep-Alive", &
"Cookie: "+S_cookie_2_0}

DISCONNECT FROM 3
DISCONNECT FROM 5
DISCONNECT FROM 4
DISCONNECT FROM 6
SYNCHRONIZE REQUESTS
End Timer T_VERIFICATION_TEST
Exit
ERR_LABEL:
If (MESSAGE <> "") Then
Report MESSAGE
Endif
Exit

No comments: