On this blog you will find top 50 QTP interview questions .
These QTP questions are frequently asked in qtp interviews in any IT company
like Cognizant, TCS, CTS, Mahindra Satyam, Wipro, Geometric, Barclays, Sungard,
Amdocs, Syntel, Capgemini, SAS, Polaris, IBM, JPMC, BNP PARIBAS, Bank of
America, Accenture, Synechron etc
If you are planning to switch your job and want to join big
IT company as QTP automation tester, You must know all qtp questions and
answers listed on this blog.
On left hand side of this page, you will find the list of
top 50 QTP interview questions. Please go through all of them before you face
any QTP interview. This will really help you in cracking the QTP interview and
getting a lucrative job as a QTP automation Tester.
QTP Miscellaneous Questions
1. If you wish to enter 1234567 in datatable then write it
as '1234567
2.Find the palindrome for string - if str1 = strreverse
(str1) then -> Palindrome
3. How to capture screenshot - obj.capturebitmap
"s:\sd.png",true
4. Difference
between QFL and VBS files – Vbs is executable file. QFL is very specific to QTP
and we need to necessarily associate it to Test unlike vbs file which can be
included using executefile statement
5. Difference
between Eval and Execute and Executeglobal. Eval will compare while execute
will assign value. Executeglobal is used to execute the execute the expression
in global scope. These keywords are used to create/include the code at runtime.
6. Difference
between Executefile and loadfunctionlibrary. With executefile, we can’t debug
the statements. With loadfunctionlibrary, we can load multiple library files
separated by comma and we can debug as well. If you want to debug, you can
associate files with action.
7. Difference
between execute and executefile – Same only difference is execute accepts
string as argument while executefile uses file as argument.
8. Difference
between invokeapplication and systemutil.run is that invokeapplication is used
to launch only .exe application.
9. MercuryTimers
a. retTime =
MercuryTimers.Timer(TimerName).ElapsedTime ……..Returns the total accumulated
time in milliseconds since the timer started. The ElapsedTime property is the
default property for the MercuryTimer object.
b.
MercuryTimers("Timer1").Start 'Start measuring time using
Timer1. Wait 1 MercuryTimers("Timer1").Stop
'After one second, stop Timer1. 'Two
seconds later, restart Timer1 (which will continue to measure time from 'the
time it stopped). Wait 2 MercuryTimers("Timer1").Continue
10. What is
registeruserfunc? You can use the RegisterUserFunc statement to instruct
QuickTest to use your user-defined function as a method of a specified test
object class for the duration of a test run, or until you unregister the
method. RegisterUserFunc in QTP can be used for both Method Overriding as well
as Method Reuse. In method overriding, we can override the default
implementation of the function and replace with a new custom implementation.
For example, we can create a function, say fnClick, which will not only click
on an element, but it also first verify if the element we want to click exists
and is enabled. In method reuse, we can create a function which we can bind
with multiple controls & then use this function for all these controls. For
example, we can create a function fnClick, which can be used to click on a
button, on a link on an image and so on.
11. How can we launch
multiple instances of a web application?
Set
IE1=CreateObject("InternetExplorer.Application")
IE1.Visible=True
IE1.Navigate "http:\\Yahoomail.com"
Set IE2=CreateObject("InternetExplorer.Application")
IE2.Visible=True
IE2.Navigate "http:\\Rediffmail.com"
12. e_pwd =
Crypt.Encrypt(pwd)
Browser("dfgd").Dialog("pass").WinEdit("pwd").SetSecure
e_pwd
13. sheetcount =
DataTable.GetSheetCount
14. DataTable.Import
("C:\flights.xls")
15. DataTable.ImportSheet
"C:\name.xls" ,1 ,"name"
16. The following
example uses the SetNextRow method to
change the active row to the next row in the run-time Data Table.
DataTable.SetNextRow
17.
Browser("Welcome:= Mercury").Page("Welcome:=
Mercury").WebEdit(EditDesc).Set "MyName"
18.
DotNetFactory
(System.Environment, System.DateTime, System.Collection)
var_CreateInstance =
DotNetFactory.CreateInstance("System.Environment")
msgbox var_CreateInstance.CurrentDirectory
Dim SystemDate , oDate
Set SystemDate =
Dotnetfactory.CreateInstance("System.DateTime")
Set oDate = SystemDate.Parse("Fri, 9 Oct 2009")
FormattedDate = oDate.Day & "/" &
oDate.Month & "/" & oDate.Year
msgbox FormattedDate
Set SystemDate = Nothing
Set oDate = Nothing
The .NET
SortedList class provides a hash table with automatically sorted key/value
pairs.
The following code creates a SortedList and populates it
with some key/value pairs:
Set objSortedList = Dotnetfactory.CreateInstance (
"System.Collections.Sortedlist" )
objSortedList.Add "First", "Hello"
objSortedList.Add "Second", ","
objSortedList.Add "Third", "world"
objSortedList.Add "Fourth", "!"
For i = 0 To objSortedList.Count - 1
WScript.Echo
objSortedList.GetKey(i) & vbTab & objSortedList.GetByIndex(i)
Next
' this code creates and populates an ArrayList
Set myArrayList = CreateObject(
"System.Collections.ArrayList" )
myArrayList.Add "F"
myArrayList.Add "B"
myArrayList.Add "D"
myArrayList.Add "C"
' [1] add the new element to the ArrayList
myArrayList.Add "Z"
' [2] sort the ArrayList
myArrayList.Sort
And how about deleting an element?
In an array you would need to "shift" the elements
to fill the gap and then ReDim the array again.
In an ArrayList you would use either myArrayList.Remove
"element_value" or myArrayList.RemoveAt "element_index".
19.
Environment.Value("MyVariable")=10
20.
MyValue=Environment.Value("MyVariable")
21. Extern.Declare
micHwnd, "FindWindow", "user32.dll",
"FindWindowA", micString, micString … Enables you to declare calls to external
procedures from an external dynamic-link library (DLL).
22. x=RandomNumber
(0,100)
23. ExitTest - Exits
the entire QuickTest test or Quality
Center business process
test, regardless of the run-time iteration settings. The pass or fail status of
the test remains as it was in the step prior to the ExitTest statement.
24. SystemUtil.Run
SystemUtil.Run ( FileName, Parameters, Path, Operation )
FileName - The name of the file you want to run.
Parameters – For executable file, use the Parameters
argument to specify any parameters to be passed to the application.
Path - The default directory of the application or file.
Operation - The action to be performed. If this argument is
blank (""), the open operation is performed.The following operations
can be specified for the operation argument of the SystemUtil.Run method: Open
– Opens files edit - Launches an editor
and opens the document for editing.
explore - Explores the folder specified by the FileName argument. find -
Initiates a search starting from the specified folder path. print - Prints the
document file specified by the FileName argument. SystemUtil.Run "D:\My
Music\Breathe.mp3","","D:\My
Music\Details","open"
25. InvokeApplication
"C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.yahoo.com"
26. VBscript to
invoke application
Dim oShell
Set oShell = CreateObject ("Wscript.shell")'
oShell.run "F:\jdk1.3.1\demo\jfc\SwingSet2.bat"'
oShell.Run Chr(34) & "C:\Program Files\Internet
Explorer\IEXPLORE.EXE" & Chr(34)
Set oShell = Nothing
27. Window("Notepad").WinEdit("Edit").Type
micF5
28. Set WshShell =
CreateObject("WScript.Shell")
WshShell.AppActivate "Put the label of the
browser" ' Activate the window
wait(3)
WshShell.SendKeys "^f" ' the caret (^) represents
the CTRL key.
You can also send special characters such as SHIFT, CTRL,
and ALT, which are
represented by plus sign (+), the
caret (^), and the percent sign (%),
29. Use Analog or
low-level recording when entering keyboard input
30. Use Mercury
Device Replay feature
Set obj = CreateObject("Mercury.DeviceReplay")
Window("Notepad").Activate
obj.PressKey 63 The
PressKey method uses the appropriate ASCII or IBM Scan Code value for the key.
31. Set ssr0XML =
XMLUtil.CreateXMLFromFile("D:\temp\XML\ServiceStatus\SSR0.xml")
XMLstr = ssr0XML.ToString
WebService("XOAService_2").SendRequest("ServiceStatus",
XMLstr) You can
retrieve the response to the message sent with this method by inserting a
LastResponse statement after it.
32. How can i check
if a parameter exists in DataTable or not?
The best way would be to use the below code:
on error resume next
val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if
33. How can i check
if a checkpoint passes or not?
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check
(Checkpoint("Check1"))
if chk_PassFail then
MsgBox "Check Point passed"
else MsgBox "Check Point failed"
end if
34. What is the
difference between an Action and a function?
Action is a thing specific to QTP while functions are a
generic thing which is a feature of VB Scripting. Action can have a object
repository associated with it while a function can't. A function is just lines
of code with some/none parameters and a single return value while an action can
have more than one output parameters.
Where to use function or action?
Well answer depends on the scenario. If you want to use the
OR feature then you have to go for Action only. If the functionality is not
about any automation script i.e. a function like getting a string between to
specific characters, now this is something not specific to QTP and can be done
on pure VB Script, so this should be done in a function and not an action. Code
specific to QTP can also be put into an function using DP. Decision of using
function/action depends on what any one would be comfortable using in a given
situation.
35. What are the
files and subfolders of a QuickTest Professional test?
The files and folders hold binary and text data that are
required for the test to run successfully.
The following table provides a description, the type, and
comments regarding the files that make up a QuickTest Professional test.
ü Test.tsp -
Test settings Binary
ü Default.xls -
Data Table Parameters
ü Script.mts -
QTP test script
ü Resource.mtr -
Object Repository
36. What is the
lservrc file in QTP?
The lservrc file contains the license codes that have been
installed..The lservrc file contains the license codes that have been
installed. Whenever a new license is created, the license code is automatically
added to this file. The lservrc file is a text file, with no extension.
37. How to return
array from function?
as a normal variable
38. Difference
between dictionary and array – advantages / disadvantages
ü The Dictionary
object is used to store information in name/value pairs (referred to as key and
item). The Dictionary object might seem similar to Arrays, however, the
Dictionary object is a more desirable solution to manipulate related data.
ü Keys are used to
identify the items in a Dictionary object
ü You do not have to
call ReDim to change the size of the Dictionary object
ü When deleting an
item from a Dictionary, the remaining items will automatically shift up
ü Dictionaries cannot
be multidimensional, Arrays can
ü Dictionaries have
more built-in functions than Arrays
ü Dictionaries work
better than arrays on accessing random elements frequently
ü Dictionaries work
better than arrays on locating items by their content
39. Significance of
Action 0 – to define the sequence in which QTP runs remaining actions
How to access Excel
sheet using database..
Function ReadExcel(
myXlsFile, mySheet, my1stCell, myLastCell, blnHeader )
Dim arrData( ), i,
j
Dim objExcel,
objRS
Dim strHeader,
strRange
Const
adOpenForwardOnly = 0
Const
adOpenKeyset = 1
Const
adOpenDynamic = 2
Const
adOpenStatic = 3
' Define header
parameter string for Excel object
If blnHeader Then
strHeader =
"HDR=YES;"
Else
strHeader =
"HDR=NO;"
End If
' Open the object
for the Excel file
Set objExcel =
CreateObject( "ADODB.Connection" )
' IMEX=1 includes cell content of any format;
tip by Thomas Willig.
' Connection
string updated by Marcel Niënkemper to open Excel 2007 (.xslx) files.
objExcel.Open
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
myXlsFile & ";Extended Properties=""Excel
12.0;IMEX=1;" & _
strHeader & """"
' Open a recordset
object for the sheet and range
Set objRS =
CreateObject( "ADODB.Recordset" )
strRange = mySheet
& "$" & my1stCell & ":" & myLastCell
objRS.Open
"Select * from [" & strRange & "]", objExcel,
adOpenStatic
' Read the data
from the Excel sheet
i = 0
Do Until objRS.EOF
' Stop reading
when an empty row is encountered in the Excel sheet
If IsNull(
objRS.Fields(0).Value ) Or Trim( objRS.Fields(0).Value ) = "" Then
Exit Do
' Add a new
row to the output array
ReDim Preserve
arrData( objRS.Fields.Count - 1, i )
' Copy the
Excel sheet's row values to the array "row"
' IsNull test
credits: Adriaan Westra
For j = 0 To
objRS.Fields.Count - 1
If IsNull(
objRS.Fields(j).Value ) Then
arrData( j, i ) = ""
Else
arrData( j, i ) = Trim( objRS.Fields(j).Value )
End If
Next
' Move to the
next row
objRS.MoveNext
' Increment
the array "row" number
i = i + 1
' Close the file
and release the objects
objRS.Close
objExcel.Close
Set objRS = Nothing
Set objExcel =
Nothing
' Return the
results
ReadExcel =
arrData
End Function
40. How to store OR
and function library in QC..
41. How to close the
browser no 2 and 4. – First find out the browser collection using desktop
object and then using creation time property .
You may also like
- QTP Questions and Answers for Experienced guys
- Advanced QTP Questions and answers
- Advanced QTP Tutorial
What do you think on this topic? Please provide your feedback.
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs