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

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 :                         http://goessner.net/download/prj/jsonxml/j

Read Outlook mail attachment and Body using Vb Script or QTP

Set olApp = CreateObject("Outlook.Application") Set olns = olApp.GetNameSpace("MAPI") Set ObjFolder = olns.GetDefaultFolder(6) j = 0 For each item1 in ObjFolder.Items        iattachCnt = item1.Attachments.Count     Print "Attachments Count: " & iattachCnt     For i = 1 to iattachCnt         Print "FileName :    " & item1.Attachments(i).FileName         Print "Display Name:   " & item1.Attachments(i).DisplayName         Print "Size: " & item1.Attachments(i).Size     Next     Print " Body : " & item1.body     Print "--------------------------------------Mail Num - " & j & " -----------------------------------------------"     j = j+1    Next

Excel Sorting By Rows and Columns

Excel Sorting By Row: Const xlAscending = 1 Const xlNo = 2 Const xlSortRows = 2 Set objExcel = CreateObject(“Excel.Application”) objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”) Set objWorksheet = objWorkbook.Worksheets(1) objWorksheet.Cells(1,1).activate Set objRange = objExcel.ActiveCell.EntireRow objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows set objExcel=nothing Excel Sorting By Column : Const xlAscending = 1′represents the sorting type 1 for Ascending 2 for Desc Const xlYes = 1 Set objExcel = CreateObject(“Excel.Application”)’Create the excel object objExcel.Visible = True’Make excel visible Set objWorkbook = _ objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”)’Open the document Set objWorksheet = objWorkbook.Worksheets(1)’select the sheet based on the index .. 1,2 ,3 … Set objRange = objWorksheet.UsedRange’which select the range of the cells has some data other than blank Set objRange2 = objExcel.Range

How to Read or Select Context Menu or Right Click Menu using QTP.

Select The Item in Right Click Menu or Context Menu: Window("sampleWindow").WinMenu("MenuObjType:=1).Select"File;New" Here MenuObjtype can be 1 r 2 r 3 .......n Check wether the Item is Exist or Not: If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("1","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If                                         Or If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("File","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If Get the Items in Context Menu: For i = 1 to 10 Print  Window("sampleWindow").WinMenu("MenuObjType:=" & i).GetItemProperty("1","Label") Then Next

How to Download a file using VbScript

Following is the code to download a file using Vbscript, without using QTP This code uses the HTMLDom and URLDownloadToFile method from urlmon API. Since VBScript does support calling Native API methods directly, here I am using  Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file Private Declare Function URLDownloadToFile Lib “urlmon” Alias _                                            “URLDownloadToFileA” ( _                                            ByVal pCaller As Long, ByVal szURL As String, _                                            ByVal szFileName As String, _                                            ByVal dwReserved As Long, _                                            ByVal lpfnCB As Long) As Long Sub FileSave(strUrl, Des)     r = URLDownloadToFile(0, strUrl, Des, 0, a)