Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to use GETROProperty to extract value using descriptive programming in QTP

We can use descriptive programming to display the value stored for object e.g the value displayed in a edit box or a webelement or default value in a webList.


We can learn following key points from the code below:


  • How to create a description object using description.create
  • How to implement descriptive programming for object uniquely identified by using multiple properties
  • How to use getROProperty to extract information at runtime
  • How to return value by a function.


Public Function ValueDisplayedForObject(DescObj,ObjType)
On error resume next
Set objDesc= Description.create
'Set of Property value are delimited by ,
If (instr(1,DescObj,",") >0) Then
   ''Split multiple links based on delimiter. ,
arrDesc = split(DescObj,",")
intPropSet = Ubound(arrDesc)
''Loop through each of the link and click the required link
for i = 0 to intPropSet
'' Property and value for property are seperated by |
strDesc = split(arrDesc(i),"|")
objDesc(strDesc(0)).value = strDesc(1)
Next
''In case of only one property value set of image
Else
strDesc = split(DescObj,"|")
objDesc(strDesc(0)).value = strDesc(1)
End If
If (ucase(ObjType) = "WEBELEMENT")  Then
ValueDisplayedForObject = Browser("Browser_Encompass").Page("title:=.*").WebElement(objdesc).GetRoProperty("innertext")
ElseIf (ucase(ObjType) = "WEBLIST") Then
ValueDisplayedForObject = Browser("Browser_Encompass").Page("title:=.*").WebList(objdesc).GetRoProperty("value")
Else
ValueDisplayedForObject = Browser("Browser_Encompass").Page("title:=.*").WebEdit(objdesc).GetRoProperty("value")
End If
If (err.number<>0) Then
Reporter.ReportEvent micpass,"Value displayed for object",err.description
End If 

End Function.

 Please see below links for more on descriptive programming

qtp descriptive programming basics

descriptive programming examples and comparison with OR

Script to execute specific QTP tests from Test Set in Quality Center using VBScript

Below code will execute tests in a test set in QC based on name of the test set. The code can run all the scripts in test set, only passed test script, only failed test script. This can be manipulated further based on requirement. Also an html file with test status will be displayed once test set execution is completed.




 UserName = InputBox("Enter the user name for QC Login", "QC UserName")  
 Password = InputBox("Enter the password for QC Login", "QC Password")  
 strExecFlag = InputBox("Enter the option for test execution" & vbcrlf & "Valid Values - P, A,F" & vbcrlf & "A: Run All test Scripts"& vbcrlf & "F: ExecuTe script not passed Only"& vbcrlf & "P: Execute Passed Test Scripts","Test Execution Option")  
 'Return the TDConnection object.  
 Set QCConnection = CreateObject("TDApiOle80.TDConnection")  
 QCConnection.InitConnectionEx QCurl  
 QCConnection.login UserName, Password  
 QCConnection.Connect DomainName, ProjectName  
 Set TSetFact = QCConnection.TestSetFactory   
 Set tsTreeMgr = QCConnection.TestSetTreeManager   
 Dim qtApp 'As QuickTest.Application ' Declare the Application object variable   
 Dim qtLibraries 'As QuickTest.TestLibraries ' Declare a test's libraries collection variable   
 Set tsFolder = tsTreeMgr.NodeByPath(<QC Test Set Path>) ' test set starts with "Root"  
 Set tsList = tsFolder.FindTestSets(<TestSetName>) 'Testset name  
 strTable = ""  
 Set theTestSet = tsList.Item(1)  
 For Testset_Count=1 to tsList.Count  
    Set theTestSet = tsList.Item(Testset_Count)   
    Set TSTestFact = theTestSet.TSTestFactory  
    TSName = theTestSet.Name  
    Set TestSetTestsList = TSTestFact.NewList("")   
   For Each theTSTest In TestSetTestsList   
      TestName = theTSTest.Test.Name    
      TestScript = <Test Script path in QC> & TestName    
      TestStatus = theTSTest.Status  
      If ((TestStatus ="Passed" and ucase(strExecFlag) = "P") OR (TestStatus <>"Passed" and ucase(strExecFlag) = "F") or (ucase(strExecFlag) = "A")) Then  
         Set qtApp = CreateObject("QuickTest.Application")   
         If qtApp.launched <> True then   
             qtApp.Launch   
         End If  
        qtApp.Visible = "true"  
       If Not qtApp.TDConnection.IsConnected Then  
           qtApp.TDConnection.Connect QCurl,DomainName,ProjectName,UserName,Password,False  
       End If  
  ' Create the Application object  
      qtApp.Open TestScript, True  ' Open the test in read-only mode  
      Set qtTest = qtApp.Test  
     Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")   
     ' Create the Run Results Options object   
     ' New Run Results in Quality Center option  
     qtResultsOpt.TDTestInstance = 1  
     qtResultsOpt.TDRunName= "Run_" & Month(Now) & "-" & Day(Now) & "_" & Hour(Now) & "-" & Minute(Now) & "-" & Second(Now)  
    qtResultsOpt.TDTestSet = TestSetPath ' Path to the Test Set where we should save the results  
    Set fso=createobject("Scripting.FileSystemObject")   
    If fso.FolderExists("C:\Res1") Then   
         fso.DeleteFolder("C:\Res1")  
    End If  
    qtResultsOpt.ResultsLocation = "C:\Res1"  
    qtTest.Run qtResultsOpt,True  
    TestStatus = qtTest.LastRunResults.Status  
    qtTest.Close  
    qtApp.quit  
    Set qtApp = Nothing    strTable = strTable & "<tr><td>"&TestName&"</td><td>"&TestStatus&"</td></tr>"  
    End If   
   Next  
 Next  
 Set objFSO = CreateObject("scripting.filesystemObject")  
 If (objFSO.FolderExists("c:\Temp") = False) Then  
    objFSO.CreateFolder("c:\Temp")  
 End If  
 strTable = "<html><h1>Test Results<h1><table border =""""2""""<tr><td>TestCaseName</td><td>Test Execution Status</td></tr>" & strTable &"</table></html>"  
 Set objFl = objFSO.CreateTextFile("c:\Temp\Test.html")  
 objFl.Write strTable  
 Set objFl = nothing  
 CreateObject("WScript.Shell").Run "c:\Temp\Test.html"  

Different Ways to exit from a QTP test: Using ExitTest, AOM and LoadandRunAction

In QTP, Framework should ensure that test is exited as soon test is failed, since there is no point in going forward with execution.
To ensure proper exit from QTP test, we can either use error handling using recovery scenario or vb script. In case of error handling using vbscript, we can exit a test at runtime in following ways.


Using ExitTest Statement

ExitTest statement exits a test once executed in script.But in scripts with functions called from other functions in different libraries and in case if there is multiple nesting of functions within different libraries, ExitTest statement on execution does not stop the test execution.
To understand this, suppose there is Test A and there are 4 different libraries(vbs files) f1,f2,f,3,f4  in which functions are stored and the action in Test A calls function from library f1 which further calls function from library f2 ans so on. In such cases, sometimes exitTest does not get executed and moves to next test without exiting the test.
To exit from test in scenario where ExitTest is not working properly, we can exit from test in below ways:


 Using QTP AOM

 Use following code to exit test in case exitstatement is not working.
Dim qtAppObj
Set qtAppObj = CreateObject("quicktest.application")
qtAppObj.Test.Stop

Using LoadandRunAction

Create a test with Action  Action1. In Action , only write ExitTest. Save the test.
Now in the test, where exitTest is not working properly, instead of ExitTest, write below code:

LoadandRunAction "c:\Test1","Action1"

Once this line of code is executed, QTP will exit the test.

Please go through the below posts for understanding of :