Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Thursday, November 4, 2010

A Sample QTP Real-time Test Script

A Sample QTP Real-time Test Script


#####################################################
'### Test Name: 2Step_1orMoreAcres_Attribute_145_100orMoreAcres
'# ## Created by: Sam Harris
'### Purpose: Verify the 145 Lot Size is 100 or More Acres attribute in the 1 or More Acres Scenario
'### Creation Date: 1/11/2010
'###############################
 

'=======================
'                   SETUP  
'=======================
 
_____________________________________________________________ 
Dim objNet 
Dim strInfo                           
'____________________________________________________________________________________________________________________________________
'Set the initial value of the variables 
i = 1
msgnum = 0
strFail = 1
strTestName = "2Step_1orMoreAcres_Attribute_145_100orMoreAcres"                          
'____________________________________________________________________________________________________________________________________
'Function to open a brower and go to a specified URL 
Function OpenBrowser (browser, URL)
    systemUtil.Run browser, URL
End Function
'____________________________________________________________________________________________________________________________________
'Get Computer Name 
set wshnetwork=createobject("wscript.network")
scomputername=wshnetwork.computername
set wshnetwork=nothing
strServ = scomputername
'msgbox strServ  
'____________________________________________________________________________________________________________________________________
'Turn off the report filter  
CurrentMode = Reporter.Filter
Reporter.Filter = rfDisableAll
'____________________________________________________________________________________________________________________________________
'Get username from the local box 
Set objNet = CreateObject("WScript.NetWork")
strInfo =  objNet.UserName
'msgbox strInfo
'____________________________________________________________________________________________________________________________________
'Create a unique name for the results file each time the test is executed. 
mypath = "\\taz02mon901\Mercury\QTP_Test_Results\2Step_1orMoreAcres_Attribute_145_100orMoreAcres.html" 
      Call CreateFiles() 
'____________________________________________________________________________________________________________________________________
' Set Excel File to be appenced 
strDataSheet = "\\taz02mon901\Mercury\Mercury_QTP_Test\Realtor\2-Step\2STEP_ATTRIBUTES_FAILURE_LOG_QA.xls"
'____________________________________________________________________________________________________________________________________
'Clear the cookies and temp files 
'Call  ClearCookies
'____________________________________________________________________________________________________________________________________
 

'=======================
'                    MAIN    
'=======================
 

'____________________________________________________________________________________________________________________________________
'Database query 
' Connect to the Realtor database
Set dbconn = CreateObject("ADODB.Connection") 
Set recordset = CreateObject("ADODB.recordset")
'MS SQL Server DSNless connection 
'dbconn.Open("Driver={SQL Server};Server=TAZ02SQL832 ;Database=XProperty ;Uid=admin;Pwd=admin")
dbconn.Open("Driver={SQL Server};Server=TAZ02SQL832;Database=XProperty")
dbconn.commandTimeout = 300
' Specify the query
sql = "select top 1 l.listingid,l.postalcode,l.marketingtypeid,l.listingtypeid,l.bedrooms,l.bathrooms,l.listingsqft,l.price,l.address,l.city,l.state,l.createdate,l.geoapproximation from xproperty.dbo.listing (nolock) l join xproperty.dbo.LISTING_ATTRIBUTE (nolock) la1 on l.listingid = la1.listingid left join xproperty.dbo.LISTING_ATTRIBUTE (nolock) la2 on l.listingid = la2.listingid and la2.attributeid in (144,146,147,150,152,154,159,161,166) where l.status = 'a' and l.agentid is not null and l.postalcode is not null and l.postalcode <> '' and l.country = 'usa' and la1.attributeid = 145 and l.geoapproximation = 1 and l.DataSourceID not in (select datasourceid from xproperty.dbo.DATA_SOURCE_ATTRIBUTE where attributeid in (27,31)) and la2.ListingID is null and l.createdate < getdate() - 2 order by l.createdate desc"
' Set the recordset cursor type
recordset.CursorType = 0
' Execute the query
recordset.Open sql, dbconn 
        listingid = recordset.Fields("listingid")&""
        listingid = Trim(listingid)'
        'msgbox listingid
        postalcode = recordset.Fields("postalcode")&""
        'msgbox postalcode
        marketingtypeid = recordset.Fields("marketingtypeid")&""
        'msgbox marketingtypeid
        listingtypeid = recordset.Fields("listingtypeid")&""
        'msgbox listingtypeid
        bedrooms = recordset.Fields("bedrooms")&""
        'msgbox bedrooms
        bathrooms = recordset.Fields("bathrooms")&""
        'msgbox bathrooms
        listingsqft = recordset.Fields("listingsqft")&""
        'msgbox listingsqft
        price = recordset.Fields("price")&""
        'msgbox price
        address = recordset.Fields("address")&""
        'msgbox address
        city = recordset.Fields("city")&""
        'msgbox city
        state = recordset.Fields("state")&""
        'msgbox state
        createdate = recordset.Fields("createdate")&""
        'msgbox createdate 
If bedrooms = "" Then
      'Do Nothing
            Else
                  If  bedrooms >5 Then
                        bedrooms = 5
                  End If
End If 
bathrooms = fix(bathrooms)
If bathrooms = "" Then
      'Do Nothing
            Else
                  If  bedrooms >5 Then
                        bedrooms = 5
                  End If
End If 
If  listingtypeid = 6 Then
      bedrooms = ""
      bathrooms = ""
End If
'____________________________________________________________________________________________________________________________________
' Date and Start Time of the test run 
strDate = date
strStartTime = time
'____________________________________________________________________________________________________________________________________
'Open a browser to the REALTOR.com homepage 
OpenBrowser "iexplore.exe", "http://qap.www.realtor.com/"
wait (3)
'____________________________________________________________________________________________________________________________________
'Find the listing 
'Browser("Real Estate Listings,").WinEdit("Edit").Check CheckPoint("Edit_8")
Browser("Real Estate Listings,").Navigate ("http://qap.www.realtor.com/prop/"&listingid)
Browser("Real Estate Listings,").Sync
strView = "LDP"
'____________________________________________________________________________________________________________________________________
'Check for the text office on the LDP 
'Browser("Real Estate Listings,_5").Page("2275 Youngman Ave Unit:").WebElement("Property Information for").Check CheckPoint("Property Information for 2275 Youngman Ave Unit: 108W Save Listing Property FeaturesCondo/Townhome/Row Home/Co-OpStatus: Active Area: SP-Highland Area County: RAMSEYYear Built: 1980 1 total bedroom(s) 2 total bath(s) Approximately 1130 sq. ft.Style: High Rise (4+ Levels) Office 1 car garage School District: St. Paul Exterior FeaturesHeated garage Listing InformationRefreshed at 9:35 AM PT (19 days ago)Added on Jun 29, 2004 (1940 days ago) To access this page directly, usehttp://qap.www.realtor.com/realestateandhomes-detail/2275-Youngman-Ave-Unit-108W_St-Paul_MN_55116_1038274619 This listing is brokered byEdina Realty, Inc.Office: (651)698-2434")
strPropInfo = Browser("Real Estate Listings,_5").Page("2275 Youngman AveUnit:").WebElement("Property Information for").GetROProperty("innertext")
'msgbox strPropInfo 
strGarageCheck = Instr(strPropInfo, "Lot size is 100 or more acres")
'msgbox strGarageCheck 
If  strGarageCheck <> 0 Then
      'msgbox "Pass"
            Else
                  'msgbox "Fail"
            strEndTime = time
                  Call AppendXL
                  msgnum = msgnum+1
                        Browser("Real Estate Listings,_5").Page("2275 Youngman Ave Unit:").Sync
                        Browser("Real Estate Listings,_5").Close
                        Call SendMail
            ExitTest
End If
'____________________________________________________________________________________________________________________________________
'Close the browser 
Browser("Real Estate Listings,_5").Page("2275 Youngman Ave Unit:").Sync
Browser("Real Estate Listings,_5").Close
'____________________________________________________________________________________________________________________________________
'Open a browser to the REALTOR.com homepage 
OpenBrowser "iexplore.exe", "http://qap.www.realtor.com/"
wait (3)
'___________________________________________________________________________________________________________________________________ 
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebEdit("srchHomeLocation").Set postalcode
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebRadioGroup("ctl00$cphC$MainSearch$ccBuyRen").Select marketingtypeid 
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebElement("More Search Options").FireEvent "onmouseover"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebElement("More Search Options").Click 
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebEdit("tbMinPrice").Set price
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebEdit("tbMaxPrice").Set price
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebList("ctl00$cphC$AdvancedSearchPage$_2").Select bedrooms&"+"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebList("ctl00$cphC$AdvancedSearchPage$_3").Select bathrooms&"+" 
If  marketingtypeid = 2 Then
'Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebElement("WebElement").FireEvent "onmouseover"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebRadioGroup("ctl00$cphC$AdvancedSearchPage$").FireEvent "onmouseover"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebRadioGroup("ctl00$cphC$AdvancedSearchPage$").Select "2"
wait (3)
End If 
If listingtypeid = 1 Then
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$").Set "ON"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_2").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_4").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_5").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_6").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_7").Set "OFF"
ElseIf listingtypeid = 2 Then
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_2").Set "ON"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_4").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_5").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_6").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_7").Set "OFF"
ElseIf listingtypeid = 4 Then
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_2").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_4").Set "ON"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_5").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_6").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_7").Set "OFF"
ElseIf listingtypeid = 3 Then
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_2").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_4").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_5").Set "ON"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_6").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_7").Set "OFF"
ElseIf listingtypeid = 5 Then
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_2").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_4").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_5").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_6").Set "ON"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_7").Set "OFF"
ElseIf listingtypeid = 6 Then
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_2").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_4").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_5").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_6").Set "OFF"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebCheckBox("ctl00$cphC$AdvancedSearchPage$_7").Set "ON"
End If 
Browser("Real Estate Listings,").Page("Real Estate Listings,_3").Link("Lot & Community").FireEvent "onmouseover"
Browser("Real Estate Listings,").Page("Real Estate Listings,_3").Link("Lot & Community").Click
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebList("ctl00$cphC$AdvancedSearchPage$_5").FireEvent "onmouseover"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebList("ctl00$cphC$AdvancedSearchPage$_5").Click
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebList("ctl00$cphC$AdvancedSearchPage$_5").Select "1 or More Acres"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").Link("Search").Click
Browser("Real Estate Listings,_5").Sync
'___________________________________________________________________________________________________________________________________
'Select Listview 
Browser("Real Estate Listings,_5").Page("55116 real estate & 55116").WebElement("WebElement_2").Click
strView = "List" 
Set odesc=description.Create()
odesc("micclass").value="WebElement"
odesc("html tag").value="DIV"
odesc("class").value="listingData"
Set childObjs= Browser("Real Estate Listings,").Page("55116 real estate & 55116").ChildObjects(odesc)
strResults = childObjs.count
'msgbox strResults 
If  strResults <> 0 Then
      Call Listcheck
            Else
                  strFail = 1
End If 
If strFail= 0 Then
      'Do Nothing
            Else
            strEndTime = time
                  Call AppendXL
                  msgnum = msgnum+1
End If
'___________________________________________________________________________________________________________________________________
'Select Galleryview 
Browser("Real Estate Listings,_5").Page("55116 real estate & 55116").WebElement("WebElement_4").Click
strView = "Gallery" 
Set odesc=description.Create()
odesc("micclass").value="WebElement"
odesc("html tag").value="DIV"
odesc("class").value="listingData"
Set childObjs= Browser("Real Estate Listings,").Page("55116 real estate & 55116").ChildObjects(odesc)
strResults = childObjs.count
'msgbox strResults 
If  strResults <> 0 Then
      Call Gallerycheck
            Else
                  strFail = 1
End If 
If strFail= 0 Then
      'Do Nothing
            Else
            strEndTime = time
                  Call AppendXL
                  msgnum = msgnum+1
End If
'___________________________________________________________________________________________________________________________________
'Select Mapview 
Browser("Real Estate Listings,").Page("55116 real estate & 55116").Image("REALTOR.com® - Official").Click
Browser("Real Estate Listings,").Sync 
Browser("Real Estate Listings,").Page("Real Estate Listings,_3").WebElement("More Search Options").Click 
If  marketingtypeid = 2 Then
'Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebElement("WebElement").FireEvent "onmouseover"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebRadioGroup("ctl00$cphC$AdvancedSearchPage$").FireEvent "onmouseover"
Browser("Real Estate Listings,_5").Page("Real Estate Listings,").WebRadioGroup("ctl00$cphC$AdvancedSearchPage$").Select "2"
wait (3)
End If 
Browser("Real Estate Listings,").Page("Real Estate Listings,_3").Link("Display Options").Click
Browser("Real Estate Listings,").Page("Real Estate Listings,_3").WebRadioGroup("ccViewResults").Select "map"
Browser("Real Estate Listings,").Page("Real Estate Listings,_3").Link("Search").Click
Browser("Real Estate Listings,").Sync
wait (10)
strView = "Map" 
'Browser("Real Estate Listings,").Page("55116 real estate & 55116").WebElement("WebElement_3").Check CheckPoint("WebElement_2")
Set odesc=description.Create()
odesc("micclass").value="WebElement"
odesc("html tag").value="DIV"
odesc("class").value="listingData"
Set childObjs= Browser("Real Estate Listings,").Page("55116 real estate & 55116").ChildObjects(odesc)
strResults = childObjs.count
'msgbox strResults 
If  strResults <> 0 Then
      Call Mapcheck
            Else
                  strFail = 1
End If 
If strFail= 0 Then
      'Do Nothing
            Else
            strEndTime = time
                  Call AppendXL
                  msgnum = msgnum+1
End If
'____________________________________________________________________________________________________________________________________
'Close the browser 
Browser("Real Estate Listings,_5").Page("2275 Youngman Ave Unit:").Sync
Browser("Real Estate Listings,_5").Close
'____________________________________________________________________________________________________________________________________ 
               If msgnum = 0 Then
                         intRunStatusID = 1
                               else
                                    intRunStatusID = 0
                  End If
'____________________________________________________________________________________________________________________________________
'Test Run End Time 
strEndTime = time
'____________________________________________________________________________________________________________________________________  
'Call UpdateRun
'____________________________________________________________________________________________________________________________________ 
'Determine which email sub to use based on Pass or Fail
  
If intRunStatusID = 1 Then
      Call SendMail
            else
                  Call SendMail
End If
************************************************

0 comments:

Post a Comment

Loading...