Quick test professional

QTP Tips QTP codes QTP Faqs and more

QTP Additional Faqs

QTP Additional Faqs

1) How to Stop  the execution of the test.


   Services.Abort 2)How to add folders

Sub AddNewFolder(path, folderName)     Dim fso, f, fc, nf   
  Set fso = CreateObject("Scripting.FileSystemObject")    
 Set f = fso.GetFolder(path)

     Set fc = f.SubFolders    
 If folderName <> "" Then

        Set nf = 

Set nf = fc.Add("New Folder")

    End If End Sub

An error occurs if the folderName already exists.

3 )How to get the ASCII valuse for a character


In the following example, Asc returns the ANSI character code of the first letter of each string:

Dim MyNumber  MyNumber = Asc("A")    

   ' Returns 65.

 MyNumber = Asc("a")

       ' Returns 97.

 MyNumber = Asc("Apple")   ' Returns 65.

Note   The AscB function is used with byte data contained in a string. Instead of returning the character code for the first character, AscB returns the first byte. AscW is provided for 32-bit platforms that use Unicode characters. It returns the Unicode (wide) character code, thereby avoiding the conversion from Unicode to ANSI.

4) How to get Character fron ASCII value


Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character.

The following example uses the Chr function to return the character associated with the specified character code:

Dim MyChar
 MyChar = Chr(65)   ' Returns A.
 MyChar = Chr(97)   ' Returns a.
MyChar = Chr(62)   ' Returns >.  MyChar = Chr(37)   ' Returns %.

Note   The ChrB function is used with byte data contained in a string. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte. ChrW is provided for 32-bit platforms that use Unicode characters. Its argument is a Unicode (wide) character code, thereby avoiding the conversion from ANSI to Unicode.

5)Accessing User-Defined Properties of Web Objects

You can use the attribute/<property name> notation to access native properties of Web objects and use these properties to identify such objects with programmatic descriptions. For example, suppose a Web page has the same company logo image in two places on the page: <IMG src=”logo.gif” mce_src=”logo.gif” LogoID=”122″> <IMG src=”logo.gif” mce_src=”logo.gif” LogoID=”123″> You could identify the image that you want to click using a programmatic description by including the user-defined property LogoID in the description as follows: Browser(“Mercury Tours”).Page(“Find Flights”).Image(“src:=logo.gif”,”attribute/LogoID:=123″).Click 68, 12 Note: The attribute/<property name> notation is not supported in Netscape 4.x.

6)How to Run Your Automation Program

There are several applications available for running automation programs. You can also run automation programs from command line using Microsoft’s Windows Script Host. For example, you could use the following command line to run your automation program: WScript.exe /E:VBSCRIPT myScript.vbs 7) What is the other way of making coments instead of astrik(‘)

Ans: “Hello” : Rem Comment after a statement separated by a colon.

8)How to run commands in command prompt from qtpAns:You can run standard DOS commands in your QuickTest test using the VBScript Windows Scripting Host Shell object (WSCript.shell). For example, you can open a DOS command window, change the path to C:\, and execute the DIR command using the following statements: Dim oShell Set oShell = CreateObject (“WSCript.shell”) oShell.run “cmd /K CD C:\ & Dir” Set oShell = Nothing 9) what is optional stepAns:


Causes a step to be bypassed if an object in that step is not found.




The following example uses the OptionalStep object to make the Paris selection from the Depart WebList an optional step. OptionalStep.Browser(“Mercury Tours”).Page(“Find Flights”).WebList(“depart”).Select “Paris” 10)What is the alternative way to getROpropertyAns) object.QueryValue(property to get)11)How to get the number of childs in a tree a) Object.children.lengthex: Browser(“xxx”).Page(“xxx”).Image(“xxx”).Object.children.length11)How to know that the table has no recordsa) rs.RecordCount 12)What are the types of parameters available in QTPa) 3 types   1)  Action Parameters(Input ,output)These parameters are restricted to that action only.i.e we can not use them for another action.Note:Don’t think that the output action parameter can pass values between action.The only purpouse with output action parameter is to assign the values at run time rather than design time from the external source(application)Advantage: These parameters are bound to the action even this action is called from another test.How to Declare: Using Action property tabSyntax: Input parameter —variable= parameter(“name”)              Output parameter—Parameter(“name”)=value              2)  Test Parameters(Input ,output)These parameters are not restricted to that action i.e we can use them for any nother action.Note These parameters are not found and unable to use them in any action  is called from another test.Advantage: test  parameters can pass values between action.How to Declare: Using  Test Setting-à parameters tabSyntax: Input parameters—   variable= TestArgs (“name”)Output parameters–   TestArgs (“name”)=value3)Local ParametersThese are also same as test parameters but we need to Declare and use them from code not from IDE.Advantage:These parameters still can used even the actions are called from any testSyntax:Declarationà LocalParameter(“name”)=valueUse: variable= LocalParameter(“name”)13)what are the different ways to delay the execution steps in QTPAns)3 ways1) object.waitProperty ”propertyName”,”value”,”time in milli sec”This is called conditional wait  This will pauses the execution as long as the specified value of the property exist in the AUT or specified time out which ever is earlier2) Wait(seconds)This is called unconditional wait.i.e it will wait for the specified time3) Services.ThinkTime 10Same as wait14) How to minimize QTP while runninga) Set qtApp = CreateObject(“QuickTest.Application”)
    qtApp.WindowState = “Minimized”
     Set qtApp = Nothing

  Source: Mercury Forum’s KB articles

Author : Tarun Lalvani


February 14, 2008 - Posted by | QTP Additional Faqs | , , , , , , , ,


  1. Hi Mohan Kumar,
    I am going through your blog from quite some time and it has been a knowledge repository for me when it comes to QTP. thanks a lot

    Can you please help me in solving the below issue. I am struggling with this from quite a long time.It will be a great help, if you can give me some solution.

    ‘My aim is to rename the file using DOS in QTP.
    DIM oShell,oFolder,lres,lTimeStamp
    oFolder = “C:XYZ”
    lres =”RES.txt”
    lTimeStamp = “RESULT!.txt”

    Set oShell = CreateObject (“WSCript.shell”)
    oShell.run “cmd /K CD & oFolder /K”
    oShell.run “ren & lres & lTimeStamp”

    Comment by Naga Praveen | October 20, 2008 | Reply

  2. Hi,

    I have question On QTP.

    I have installed QTP with web,java ,visual basic and Active-X addins.I tried recording my Java Applet Application by selecting Web and JAva.But failed record the script.

    But if i try Record my applet application by selecting Web it records but if any new Dialog pop up then its fails during Run.

    Can you please help me to do this?


    Comment by Aruna | March 23, 2009 | Reply

  3. //Belwo code will be help full to search “String Value” in a text file /////

    Record_Found = 0 ‘ initialize the “Record_Found” flag…

    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set MyFile = fso.OpenTextFile(FilePath)

    Do while MyFile.AtEndofStream True
    currentLine = MyFile.ReadLine

    find_report_record = instr(1,currentLine,”VERSION”,1)
    Record_Found= Record_Found +find_report_record
    If find_report_record > 0 Then
    MyVersion = Trim(mid(currentLine,2,50))
    If MyVersion ” ” Then
    VersionNumber=replace(splitstring(1),” “,””)
    msgbox VersionNumber
    Reporter.ReportEvent micPass, “Version Number Exist”, “The Version Number was displayed in “&TDMRPT_File&” File ”
    ‘ Valid_Version_Number ExpectedVersion, VersionNumber
    Reporter.ReportEvent micFail, “Version Number Exist”, “The Version Number was NOT displayed in “&TDMRPT_File&” File ”
    End If
    End If
    Loop ‘ AtEndOfStream

    If Record_Found = 0 Then
    Reporter.ReportEvent micFail, “Version Number Exist”, “The Version Number was NOT displayed in “&TDMRPT_File&” File ”
    End If

    Comment by Ayyappa Kulli | April 22, 2009 | Reply

  4. Message:
    I have few queries,which i want to know
    1. How to map test cases with your Automation Script?
    2.What is selection criteria from Test cases for automation

    Please explain in brief

    Comment by Rakesh | September 2, 2009 | Reply

  5. ‘ BELOW code creates a New test and associates Repository to an Action
    ‘HERE I want to Change my Action name, Please help me, Thanks Thangaraj – 9841313748

    Dim qtApp
    Dim qtRepositories

    Set qtApp = CreateObject(“QuickTest.Application”)
    qtApp.SetActiveAddins Array(“Web”, “ActiveX”, “Visual Basic”)
    qtApp.Visible = False

    msgbox qtApp.Test.Actions(“Action1”).Name

    Set qtRepositories = qtApp.Test.Actions(“Action1”).ObjectRepositories

    If qtRepositories.Find(“C:\FRAMEWORK\Project1\OR\Testl_Home.tsr”) = -1 Then
    qtRepositories.Add “C:\FRAMEWORK\Project1\OR\Testl_Home.tsr”, 1
    End If

    qtApp.Test.SaveAs “C:\Documents and Settings\tgurunat\Desktop\FRAMEWORK\NewTest” ‘ Save the test
    qtApp.Quit ‘ Exit QuickTest

    Set qtRepositories = Nothing
    Set qtStdLauncher = Nothing ‘ Release the Windows Applications launcher object
    Set qtApp = Nothing ‘ Release the Application object

    Comment by Thangaraj | December 23, 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: