Skip to main content

QTP Basic Faqs....


1) How to Stop  the execution of the test.
    Syntax : 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 = fc.Add(folderName)
    Else       
        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
Remarks : 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
Remarks: 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/ 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:
    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/ 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 step
   Ans:Description

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

Example
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 getROproperty

Ans) object.QueryValue(property to get)

11)How to get the number of childs in a tree
 a) Object.children.length
    ex: Browser(“xxx”).Page(“xxx”).Image(“xxx”).Object.children.length

 12)How to know that the table has no records

 a) rs.RecordCount

  13)What are the types of parameters available in QTP

  a) 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 tab
        Syntax: 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 tab
        Syntax: Input parameters—   variable= TestArgs (“name”)
        Output parameters–   TestArgs (“name”)=value

        3)Local Parameters
            These 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 test
            Syntax:Declarationà LocalParameter(“name”)=valueUse: variable= LocalParameter(“name”)

14)what are the different ways to delay the execution steps in QTP

    Ans)3 ways
            1) 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 earlier
            2) Wait(seconds)This is called unconditional wait.i.e it will wait for the specified time
            3) Services.ThinkTime 10Same as wait14) How to minimize QTP while running

            a) Set qtApp = CreateObject(“QuickTest.Application”)
                qtApp.WindowState = “Minimized”
                Set qtApp = Nothing

Source: Mercury Forum’s KB articles

Comments

Popular posts from this blog

PDF Automation in QTP

                                                                            The most challenging issue with PDFs is that it could be of any kind, not just a tabular data; it could have plain text, images or even forms to fill up. So this makes a tester’s life a bit difficult, never mind, we will definitely find an easy of do it… Although there are already some better approaches we have to deal with PDF documents but I found many of us are facing so many difficulties using this. There are lots of queries coming at QTP forums asking for an easy way of doing it with PDFs. keeping those in my mind I started c...

Convert JSON to XML using QTP/UFT/VBScript

Sample Code : Dim strPage,strJSON,objIE strPage = "C:\Jay\JLoader.html" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate2 strPage While objIE.Busy : Wend strJSON = "{""FirstName"":""Jay"", ""LastName"":""Krishna""}" Set objWin = objIE.document.parentWindow objWin.execScript "var jsonStr2XML = function(strJSON) { return json2xml(JSON.parse(strJSON));};" Msgbox  oWin.jsonStr2XML(strJSON) objIE.Quit In Detail: Converting The most popular data interchange format JSON(JavaScript Object Notation) to XML using QTP/UFT. Parsing JSON in UFT could be a challenge so we will use JavaScript in UFT to make it perfect. SO We need :              Java Script API  - To Convert JSON to XML                         JavaScript Files :  ...

Download Test Resource From QC Using QTP

'########################################################################### '* Function Name: QCGetResource '* Designer: Jay '* Date 09-May-2012 '* This script will Download QC Test Resource to a local dir '########################################################################### Function QCGetResource(resourceName,saveTo)     Set qcConn = QCUtil.QCConnection     Set oResource = qcConn.QCResourceFactory     Set oFilter = oResource.Filter     oFilter.Filter("RSC_FILE_NAME") = resourceName     Set oResourceList = oFilter.NewList     If oResourceList.Count = 1 Then         Set oFile = oResourceList.Item(1)         oFile.FileName = resourceName         oFile.DownloadResource saveTo, True     End If         Set qcConn = Nothing     Set oResource = Nothi...

compare Two Text files using Vb Script

Public Function CompareFiles (FilePath1, FilePath2) Dim FS, File1, File2 Set FS = CreateObject(“Scripting.FileSystemObject”) If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then CompareFiles = True Exit Function End If Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0) Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0) CompareFiles = False Do While File1.AtEndOfStream = False Str1 = File1.Read(1000) Str2 = File2.Read(1000) CompareFiles = StrComp(Str1, Str2, 0) If CompareFiles <> 0 Then CompareFiles = True Exit Do End If Loop File1.Close() File2.Close() End Function Return value: The function returns 0 or False if the two files are identical, otherwise True. Example: File1 = “C:\countries\apple1.jpg” File2 = “C:\countries\apple3.jpg” If CompareFiles(File1, File2) = False Then MsgBox “Files are identical.” Else MsgBox “Files are different.” End If    Source: Mercury Forum’s KB articles

CreateImageFromClipBoard using QTP

'-------------------------------------------------------------------------' Method : CreateImageFromClipBoard' Author : Jai Purpose : It gets the clipboard image and convert as a image file.' Parameters: FileName - String, contains the BMP file name' iIndex - Integer, contains the Worksheet index' Returns : String. The replaced file name it gives.' Caller : - Nil' Calls : - Nil' ------------------------------------------------------------------------- Sub CreateImageFromClipBoard(sFileName) Dim wshShell,ShellReturnCode, sCmdExec Set WshShell = WScript.CreateObject("WScript.Shell") sCmdExec = "D:\autostuff\i_view32.exe /silent /clippaste /convert="& sFileName ShellReturnCode = WshShell.Run(sCmdExec, 1, True) End Sub