Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Showing posts with label Programmatic descriptions in QTP. Show all posts
Showing posts with label Programmatic descriptions in QTP. Show all posts

GetRoProperty In QTP

How To : Performing Programmatic Description Checks

You can compare the run-time value of a specified object property with the expected value of that property using either programmatic descriptions or user-defined functions.

Programmatic description checks are useful in cases in which you cannot apply a regular checkpoint, for example, if the object whose properties you want to check is not stored in an object repository. You can then write the results of the check to the Test Results report.

For example, suppose you want to check the run-time value of a Web button. You can use the GetROProperty or Exist operations to retrieve the run-time value of an object or to verify whether the object exists at that point in the run session.

The following examples illustrate how to use programmatic descriptions to check whether the Continue Web button is disabled during a run session.

Using the GetROProperty operation:

ActualDisabledVal = Browser(micClass:="Browser").Page(micClass:="Page").WebButton(alt:="Continue").GetROProperty("disabled")

Using the Exist operation:

While Not Browser(micClass:="Browser").Page(micClass:="Page").WebButton(alt:="Continue").Exist(30)


By adding Report.ReportEvent statements, you can instruct QuickTest to send the results of a check to the Test Results.

If ActualDisabledVal = True Then

Reporter.ReportEvent micPass, "CheckContinueButton = PASS", "The Continue button is disabled, as expected."


Reporter.ReportEvent micFail, "CheckContinueButton = FAIL", "The Continue button is enabled, even though it should be disabled."

You can also create and use user-defined functions to check whether your application is functioning as expected. The following example illustrates a function that checks whether an object is disabled and returns True if the object is disabled:

'@Description Checks whether the specified test object is disabled

'@Documentation Check whether the is enabled.

Public Function VerifyDisabled (obj)

       Dim enable_property

       ' Get the disabled property from the test object

       enable_property = obj.GetROProperty("disabled")

       If enable_property = 1 Then ' The value is True (1)—the object is disabled

              Reporter.ReportEvent micPass, "VerifyDisabled Succeeded", "The test object is disabled, as expected."

              VerifyDisabled = True


              Reporter.ReportEvent micFail, "VerifyDisabled Failed", "The test object is enabled, although it should be disabled."

              VerifyDisabled = False

       End If

End Function 

Retrieving Native Properties

You can use the Object property to access the native properties of any run-time object. For example, you can retrieve the current value of the ActiveX calendar's internal Day property as follows:

Dim MyDay

Set MyDay=Browser("index").Page("Untitled").ActiveX("MSCAL.Calendar.7").Object.Day

The below stuff is very important and very frequently used by any QTP programmer in Object identification using QTP.

QTP codes & Browser

'Create a description for browser
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"  
Set oPage = Description.Create
oPage("micclass").Value = "Page"  

'Get all browsers
Set allBrowser = Desktop.ChildObjects(oBrowser) 
Dim i, iCount 
iCount = allBrowser.Count - 1  
For i = 0 To iCount
    'Get the page object from the browser
    Set oPg = allBrowser(i).ChildObjects(oPage)(0) 
    'Get the URL of the
    If InStr(oPg.GetROProperty("title"), "Quality Center", vbTextCompare) = 0 Then
        'Close the browser
    End If
By now you must be wondering about the line

'Get the page object from the browser
Set oPg = allBrowser(i).ChildObjects(oPage)(0)

'Name/IP of the computer
sComp = "."  

'Get the WMI object
Set WMI = GetObject("winmgmts:\\" & sComp & "\root\cimv2")

'Get collection of processes for with name iexplore.exe
Set allIE = WMI.ExecQuery("Select * from Win32_Process Where Name = 'iexplore.exe'"

'Loop through each process and terminate it
For Each IE in allIE

QTP Wonder codes with Notepad,Explorer,Excel

Dim text
text = ""

Dim rgx
Set rgx = New RegExp
rgx.IgnoreCase = True
rgx.Global = True
rgx.Pattern = "([A-Za-z]{3,9})://([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((/[-\+~%/\.\w]+)?\??([-\+=&;%@\.\w]+)?#?([\w]+)?)?"

Dim match, matches
Set matches = rgx.Execute(text)
For Each match in matches
  MsgBox match.Value, 0, "Found Match"

'Launch a notepad window
SystemUtil.Run "notepad.exe"  
'Close the window just launched using the exact title
SystemUtil.CloseProcessByWndTitle "Untitled - Notepad" 
'Launch a notepad window
SystemUtil.Run "notepad.exe"  
'Close the window just launched using a pattern string
SystemUtil.CloseProcessByWndTitle ".*Notepad", True  
CloseDescendentProcesses can be used to close any process launched by QTP. The code below illustrates the usage 
'Launch explorer
SystemUtil.Run "iexplore.exe"  
'Launch excel using COM
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True  
'Close processes launched by QTP. This will close
'the internet explorer and Excel as well

While Browser("creationtime:=0").Exist(0) 
    'Close the browser