Monday 19 August 2013

QTP frequently asked question

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 stepAns:
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 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 on’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

No comments:

Post a Comment