Pages

Saturday, 23 June 2012

QTP Functions


QTP Functions
SUBROUTINES   
1) Subroutine to clear the browser cookies and temp files 
Sub ClearCookies 
OpenBrowser "iexplore.exe", "http://qap.www.realtor.com/"
wait (3) 
Browser("Real Estate Listings,").WinToolbar("ToolbarWindow32").Press "&Tools"
Browser("Real Estate Listings,").WinMenu("ContextMenu").Select "Internet Options"
Browser("Real Estate Listings,").Dialog("Internet Options").WinButton("Delete").Click
Browser("Real Estate Listings,").Dialog("Internet Options").Dialog("Delete Browsing History").WinButton("Delete all").Click
Browser("Real Estate Listings,").Dialog("Internet Options").Dialog("Delete Browsing History").Dialog("Delete Browsing History").WinButton("Yes").Click
Browser("Real Estate Listings,").Dialog("Internet Options").WinButton("OK").Click 
Browser("Real Estate Listings,").Page("Real Estate Listings,").Sync
Browser("Real Estate Listings,").Close 
End Sub                         
Subroutine to create a file to store results of this test 
Sub CreateFiles 
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set filetxt = fso.CreateTextFile(mypath, true)
            filetxt.WriteLine("<html><font face=Arial color=blue><h3><b>2Step_1orMoreAcres_Attribute_145_100orMoreAcres&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" ) & Date&"<br>"
            filetxt.WriteLine("</b></font></h3><br>")  
             filetxt.WriteLine("<br><font face=Arial></html>")     
             filetxt.Close
          
End Sub
'____________________________________________________________________________________________________________________________________
'Report the results of  the test 
Sub ReportPass 
      Const ForReading = 1, ForWriting = 2, ForAppending = 8
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set filetxt = fso.OpenTextFile(mypath, ForAppending, True) 
    filetxt.WriteLine(val &"<br>")
      filetxt.WriteLine("<br>") 
End Sub  
'____________________________________________________________________________________________________________________________________
'Report the results of  the test 
Sub ReportFail 
      Const ForReading = 1, ForWriting = 2, ForAppending = 8
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set filetxt = fso.OpenTextFile(mypath, ForAppending, True)       
      filetxt.WriteLine("<font color=red>"&val&"<br>")
      filetxt.WriteLine("URL = " & strTargetURL &"</font><br>")
      filetxt.WriteLine("<br>") 
End Sub
'____________________________________________________________________________________________________________________________________
'Update execution result in dbo.Automation_Run table 
Sub UpdateRun 
      Set dbConnection = CreateObject("ADODB.Connection")
      dbConnection.Open("Driver={SQL Server};Server=TAZ02MON901;Database=Automation")
      sqlUpdateRun = "EXEC dbo.sp_AUTOMATION_RUNS_MOD @SCRIPTID = '186', @RUNSTATUSID = " & intRunStatusID
       
      dbConnection.Execute(sqlUpdateRun)
      dbConnection.Close
      Set dbConnection = Nothing
         
End Sub                        
'____________________________________________________________________________________________________________________________________
'Subroutine to send an email notification of test results 
Sub SendMail  
                        If msgnum = 0 Then
                              msgstr = "2Step_1orMoreAcres_Attribute_145_100orMoreAcres Test Results:" &vbcrLf &"All Test Cases Passed "
                                    Else
                                          msgstr = "2Step_1orMoreAcres_Attribute_145_100orMoreAcres Test Results:" &vbcrLf &"One or more of the Test Cases Failed." &vbcrLf &"See attachment for details."
                        End If 
            Set objMessage = CreateObject("CDO.Message")
            objMessage.Subject = "~2Step_1orMoreAcres_Attribute_145_100orMoreAcres"
            objMessage.From = "sam.harris@move.com"  
            objMessage.To = "sam.harris@move.com"
            'objMessage.To = "sam.harris@move.com; erica.kubitsky@move.com; seema.alexander@move.com" 
            'objMessage.To = "QA-Realtor@move.com" 
            objMessage.TextBody = msgstr  
            doc = mypath   'Local
            objMessage.AddAttachment (doc) 
            '________________________________________________________________________________________________________________________________
            'This section provides the configuration information for the remote SMTP server. 
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
            'Name or IP of Remote SMTP Server
           'smtpServer = "apmx01.homestore.com"
             smtpServer = "smtp.phx.move.com"
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = (smtpServer)
                
            'Type of authentication, NONE, Basic (Base64 encoded), NTLM
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNONE 
            'Your UserID on the SMTP server
            'objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid" 
            'Your password on the SMTP server
            'objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword" 
            'Server port (typically 25)
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
            'Use SSL for the connection (False or True)
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 
            'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
            objMessage.Configuration.Fields.Update 
            '________________________________________________________________________________________________________________________________   
            'Send the notification    
            objMessage.Send  
End Sub
'____________________________________________________________________________________________________________________________________
'Subroutine to send an email notification of test results to the Realtor group 
Sub SendMail2  
                        If msgnum = 0 Then
                              msgstr = "2Step_1orMoreAcres_Attribute_145_100orMoreAcres Test Results:" &vbcrLf &"All Test Cases Passed "
                                    Else
                                          msgstr = "2Step_1orMoreAcres_Attribute_145_100orMoreAcres Test Results:" &vbcrLf &"One or more of the Test Cases Failed." &vbcrLf &"See attachment for details."
                        End If 
            Set objMessage = CreateObject("CDO.Message")
            objMessage.Subject = "~2Step_1orMoreAcres_Attribute_145_100orMoreAcres"
            objMessage.From = "sam.harris@move.com"  
            'objMessage.To = "sam.harris@move.com"
            objMessage.To = "QA-Realtor@move.com" 
            objMessage.TextBody = msgstr  
            doc = mypath   'Local
            objMessage.AddAttachment (doc) 
            '________________________________________________________________________________________________________________________________
            'This section provides the configuration information for the remote SMTP server. 
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
            'Name or IP of Remote SMTP Server
           'smtpServer = "apmx01.homestore.com"
             smtpServer = "smtp.phx.move.com"
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = (smtpServer)
                
            'Type of authentication, NONE, Basic (Base64 encoded), NTLM
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNONE 
            'Your UserID on the SMTP server
            'objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid" 
            'Your password on the SMTP server
            'objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword" 
            'Server port (typically 25)
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
            'Use SSL for the connection (False or True)
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 
            'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
            objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
            objMessage.Configuration.Fields.Update 
            '________________________________________________________________________________________________________________________________   
            'Send the notification    
            objMessage.Send  
End Sub
'____________________________________________________________________________________________________________________________________
'Subroutine to append an Excel file 
Sub AppendXL 
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Visible = True
Set wb = ExcelObj.Workbooks.Open (strDataSheet) 
r = 1
Do Until Len(ExcelObj.Cells(r, 1).Value) = 0
  r = r + 1
Loop 
ExcelObj.Cells(r, 1).Value = strTestName
ExcelObj.Cells(r, 2).Value = strView
ExcelObj.Cells(r, 3).Value = listingid
ExcelObj.Cells(r, 4).Value = postalcode
ExcelObj.Cells(r, 5).Value = marketingtypeid
ExcelObj.Cells(r, 6).Value = listingtypeid
ExcelObj.Cells(r, 7).Value = bedrooms
ExcelObj.Cells(r, 8).Value = bathrooms
ExcelObj.Cells(r, 9).Value = price
ExcelObj.Cells(r, 10).Value = address
ExcelObj.Cells(r, 11).Value = city
ExcelObj.Cells(r, 12).Value = state
ExcelObj.Cells(r, 13).Value = strDate
ExcelObj.Cells(r, 14).Value = strStartTime
ExcelObj.Cells(r, 15).Value = strEndTime 
ExcelObj.DisplayAlerts = False
ExcelObj.Save
ExcelObj.Quit
Set ExcelObj = Nothing 
End Sub
'____________________________________________________________________________________________________________________________________
'Subroutine to check the list view
Sub ListCheck 
For Counter=0 to strResults-1
      strTextDesc=childObjs(Counter).GetROProperty("outerhtml")
      'msgbox strTextDesc 
      ListingCheck = InStr (strTextDesc,listingid)
      'msgbox ListingCheck 
      If  ListingCheck <> 0 Then
            'msgbox "Pass"
                  strFail= 0
                        Exit For
             Else
      'msgbox "Fail"
                  strFail = 1
      End If 
Next 
End Sub
'____________________________________________________________________________________________________________________________________
'Subroutine to check the galery view
Sub GalleryCheck 
For Counter=0 to strResults-1
      strTextDesc=childObjs(Counter).GetROProperty("outerhtml")
      'msgbox strTextDesc 
      ListingCheck = InStr (strTextDesc,listingid)
      'msgbox ListingCheck 
      If  ListingCheck <> 0 Then
            'msgbox "Pass"
                  strFail= 0
                        Exit For
             Else
      'msgbox "Fail"
                  strFail = 1
      End If 
Next 
End Sub
'____________________________________________________________________________________________________________________________________
' Subroutine to check the map view 
Sub Mapcheck 
strPnum = 0 
For Counter=0 to strResults-1 
      strPropertyDesc = childObjs(strPnum).GetROProperty("outerhtml")
      'strPropertyDesc=Browser("Real Estate Listings,_5").Page("55116 real estate & 55116").Image("Community Photo").GetROProperty("outerhtml")
      'msgbox strPropertyDesc 
      ListingCheck = InStr (strPropertyDesc,listingid)
      'msgbox ListingCheck 
      If  ListingCheck <> 0 Then
            'msgbox "Pass"
                  strFail= 0
                        Exit For
             Else
      'msgbox "Fail"
                  strFail = 1
      End If
'
strPnum =strPnum+1 
Next 
End Sub
'____________________________________________________________________________________________________________________________________





No comments:

Post a Comment