Hello Friends,
In this Section, We have tried to explore those questions which are
usually asked during Technical Round. If you are going to face an interview
either in Sapient/Accenture/TCS/HCL etc then wrack your brain for these
questions
- How to find out the regularly changing value
in a single line?
- What is AOM? How we can Launch QTP outside
& Open Test?
- There are 10 checkboxes. How can I check only
first 5 check boxes by using descriptive programing?
- If there are some browsers opened and I don't
know how many browsers are open, now I want to close all the browsers that
I don't know how many are opened. What would be Descriptive programming
for this in QTP using VB Script?
5. Using simple string a[0]=I, a[1]=N, a[2]=D like that it goes
on.. Output I need INDIA. How?
6. How do we run the scripts in QTP? What are the three options?
7. What are the main components of keyword driven automation frame work in
QTP?
8. What are the various extentions in QTP?
9. How to find the particular word in text file and how to split and
capture total line of the founded word using vb scripting?
10. Display the list data in the order-first even position rows and then odd
position rows?
11. I want to open a Notepad window without recording a test and I do
not want to use SystemUtil.Run command as well How do I do this?
12. VB Script to count the no. of links on a web page.
13. How you will display all the upper case alphabet characters in reverse
order except the characters mentioned in the string. Eg: if my string is
"Sumit" then the result should have all the alphabets from "Z to
A" except the following letters "S","U", “M”, “I” and
"T".
14. Explain about scrrun.dll?
15. Explain about ADODB.Stream class?
16. How many types of Parameters are available in QuickTest Professional
(QTP)?
17. What are the different ways to invoke an application using QTP?
18. What is Smart identification?
19. Can an action have 2 shared object repositories associated with them? In
that case, if two of them contain the same object, which one will be
considered?
20. I have developed and executed a script successfully, and saved the same
to QC. When I tried to execute the script from QC, the script is not executing.
What are the possible reasons?”
21. What is the extension of QTP local Repository? If it is .mtr then what
is .bdb extension stands for?
22. How can you close the second opened browser?
23. How to get Nth Highest Salary of the Employee using SQL? Highest, 2nd
Highest, 3rd Highest....
24. What is a self join? Explain it with an example?
25. Suppose we have the Employee table below, and we want to retrieve all of
the cities that the employees live in, but we don’t want any duplicates. How
can we do this in SQL?
26. How to reverse a string without using strreverse in VB?
27. Write a Program to show usage of Output value using QTP?
28. What is Error Handling in QTP? How many types of Errors are there in
QTP?
If you are not able to answer, please
prepare again. However, Below are the solutions for above questions.
1.
What
is AOM? How we can Launch QTP outside & Open Test?
Automation
Object Model (AOM) - It is a mechanism using which we can control various QTP operations
outside QTP. Using AOM, we can launch QTP, Open the Test, Associate Function
Libraries etc. The Following Vbscript should be saved with Extension .vbs and
upon executing the same, QTP will be launched and test would start executing.
'Launch QTP
Set objQTP =
CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True
'Open the test
objQTP.Open
"D:\GUITest2", False, False
Set objLib =
objQTP.Test.Settings.Resources.Libraries
'Associate
Function Library if NOT associated already.
If
objLib.Find("C:\lib1.vbs") = -1 Then
objLib.Add
"C:\lib1.vbs", 1
End
__________________________________________________________________________________
There
are 10 checkboxes. How can I check only first 5 check boxes by using
descriptive programing?
Dim objCheckBox
set objCheckBox=Description.Create()
objCheckBox("micclass").Value="WebCheckBox"
set
objChildObjects=Browser("micclass:=Browser").Page
("micclass:=Page").Childobjects(odesc)
for i=1 to 5
objChildObjects(i).Set "ON"
Next
_________________________________________________________________________________
If
there are some browsers opened and I don't know how many browsers are open, now
I want to close all the browsers that I don't know how many are opened. What
would be Descriptive programming for this in QTP using VB Script?
Set odesc=description.Create
odesc("micclass").value="Browser"
Set a=Desktop.ChildObjects(odesc)
print a.count
For i = 0 to a.count-1
browsername= a(i).getroproperty("name")
print browsername
Next _________________________________________________________________________________
Using
simple string a[0]=I, a[1]=N, a[2]=D
like that it goes on.. Output I need INDIA. How?
You can use the function JOIN
Dim arr(10)
arr(0)="I"
arr(1)="N"
arr(2)="D"
arr(3)="I"
arr(4)="A"
Msgbox Join(arr) - it will display INDIA
__________________________________________________________________________________
How
do we run the scripts in QTP? What are the three options?
1. "Verify Run-Mode"
(Normal Run Mode) F5,
aiming towards testing the application.
2. Debug Run-Mode
(Aim is to know the
syntactical and Logical Errors)
F11- step into
F10 - Step Over
Shift+F11 - step out
3. Update Run-mode (Automation -> update run
mode)
(Aim is to Update the
object physical Description) using this mode qtp can update:
1.
Object Repository Physical Description
2.
Check point Property Values
3.
Active Screen images
________________________________________________________________________________
What
are the main components of keyword driven automation frame work in QTP?
1. Scripts
Library (.vbs, .txt, .qfl)
2. OR
- Object Repository
3. Test
Data (generally in excel format)
4. QTP
- Settings and Environment Variables
5. Reports
- (Generally in HTML format)
6. Test
Driver Script/ Test Engine
__________________________________________________________________________________
What are the various file extensions in QTP?
1. QTP Script
File : .mts ( mercury test script)
2. QTP Local
Repository : .bdb ( berkely
database)
3. Shared
Repository : .tsr ( test shared repository)
4. Load test
configuration file Default.cfg
5. Load test
configuration file Default.usp
6. Test Settings File : Test.tsp
7. Test Parameters file : Parameters.mtr
8. Resources associated information like function
library, recovery, shared repository: Resource.mtr
9. Datatable ( Excel file) : Default.xls
10. Recovery Scenario :.qrs
11. Function library :.vbs / .qfl / .tst
12. Test Batch :.mtb
13. Action Template :.mst ( mercury shared template)
14. Virutal Object :.vot (
virtual object template)
15.
Created when the
QTP test is opened: lock.lck
__________________________________________________________________________________
How to find the particular word in text file and how to split and
capture total line of the founded word using vb scripting?
1. open the text file to search the word in
2. set fso = createobject("scripting.filesystemobject")
3. set mytxt = fso.OpenTextFile("C:\Users\sumit\Desktopf1.txt")
4. c_LineMatch=0
5. o_wordMatch =0
6. regex for the word to be searched
7. Set myregex = new RegExp
8. with myregex
a. .Global = true
b. .Pattern = "QTP"
c. .IgnoreCase = True
9. End With
10. Do until mytxt.AtEndOfStream
a. Read one line at a time
b. str1 = mytxt.ReadLine
c. Set colMatches = myregex.Execute(str1)
d. no of words matched in the Text file
e. o_wordMatch = o_wordMatch +colMatches.Count
f. Count no of lines which have the words to search
g. if colMatches.Count > 0 then
i. c_LineMatch=c_LineMatch+1
h. end if
11. Loop
12. No of words matched in the text file
13. Msgbox o_wordMatch
14. No of lines having the words to be searched
15. msgbox c_LineMatch
__________________________________________________________________________
Display the list data in the order-first even position rows and
then odd position rows?
Suppose
your table is "employee" and column name is "empid" .
Now you want a list which contains EVEN empids first and then ODD empids.
Your query will be like below,
Select empid from employee order by Mod(empid,2),empid;
IF you want a list which contains ODD empids first and then EVEN empids.
Your query will be like below,
Select empid from employee order by Mod(empid,2) desc ,empid;
Now you want a list which contains EVEN empids first and then ODD empids.
Your query will be like below,
Select empid from employee order by Mod(empid,2),empid;
IF you want a list which contains ODD empids first and then EVEN empids.
Your query will be like below,
Select empid from employee order by Mod(empid,2) desc ,empid;
___________________________________________________________________________
I want to open a Notepad window without
recording a test and I do not want to use SystemUtil.Run command as well How do
I do this?
1st
way: insert->step->step generator->select a function
invokeapplication,mention the path to notepad.exe file.Run.2.otherwise in
Expert view write a builtin funtioninvokeapplication"c:/whatever the
path"Run
2nd Way: to open a notepad is
to use ShellObject. Check out with the following example:
Dim aSet a = WScript.CreateObject
("WSCript.shell")a.run "notepad.exe"
3rd Way:
Dim
oShell Set oShell = CreateObject ("WSCript.shell") oShell.run
"cmd /K notepad.exe"
Set
oShell = Nothing
4th Way:
Dim
file1,file2
Set
file1 = CreateObject("Scripting.FileSystemObject")
Set
file2 = file1.OpenTextFile("c:ragu.txt", "2", True)'
---creating
text file file2.WriteBlankLines 2 S="Hi Good morning"file2.write(S)
___________________________________________________________________________
VB Script to count number of links in a web page.
Set Des_Obj = Description.Create
Des_Obj("micclass").Value = "Link"
Set link_col = Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
msgbox link_col.count
Des_Obj("micclass").Value = "Link"
Set link_col = Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
msgbox link_col.count
_________________________________________________________________________
How you will display all the
upper case alphabet characters in reverse order except the characters mentioned
in the string.
Eg: if my string is "Sumit" then the result should have all the alphabets from "Z to A" except the following letters "S","U", “M”, “I” and "T".
Eg: if my string is "Sumit" then the result should have all the alphabets from "Z to A" except the following letters "S","U", “M”, “I” and "T".
set reg=New regexp
s="[^ a-z A-Z]"
reg.Global=True
reg.IgnoreCase=True
s0="ZYXWVUTSRQPONMLKJIHGFEDCBA"
s1="Sumit"
s2=""
for i=1 to len(s1)
a1=mid(s1,i,1)
reg.pattern=a1
s0= reg.replace(s0,s2)
Next
msgbox s0
It’s Output will come as ZYXWVRQPONLKJHGFEDCBA
__________________________________________________________________________
Explain
about scrrun.dll?
|
Scripting Runtime library is very important for
the functioning of Visual basic script because it gives much more
functionality such as File management, text operations and file modification
features. Scrrun.dll is used very much in programming VB.
|
___________________________________________________________________________
Explain
about ADODB.Stream class?
|
ADODB.Stream class can be used as string builder.
VBScript string concatenation can be very costly because of frequent memory
allocation features. Binary file and memory I/O operation is provided by
ADODB.Stream class. This is widely used to convert bytes into string, etc.
|
___________________________________________________________________________
How many types of
Parameters are available in QuickTest Professional (QTP)?
QTP provides three types of Parameter-
Method Argument
Data Driven
Dynamic
Method Argument
Data Driven
Dynamic
__________________________________________________________________________
What are
the different ways to invoke an application using QTP?
a) SystemUtil.Run
SystemUtil.Run ( FileName, Parameters, Path, Operation )
Example: SystemUtil.Run(“iexplorer.exe”,http://www.google.com)
SystemUtil.Run(“test.txt”, “”,”C:\”,”1”)
a) SystemUtil.Run
SystemUtil.Run ( FileName, Parameters, Path, Operation )
Example: SystemUtil.Run(“iexplorer.exe”,http://www.google.com)
SystemUtil.Run(“test.txt”, “”,”C:\”,”1”)
b) InvokeApplication
Example: InvokeApplication “C:\Program Files\Internet Explorer\IEXPLORE.EXE
Example: InvokeApplication “C:\Program Files\Internet Explorer\IEXPLORE.EXE
http://www.google.com”
c) Creating a shell object using VB Script
Example: Create a “WScript.shell” object.
Dim testshell
Set testshell= CreateObject (“Wscript.shell”) testshell.run “%windir%\notepad “
Example: Create a “WScript.shell” object.
Dim testshell
Set testshell= CreateObject (“Wscript.shell”) testshell.run “%windir%\notepad “
_________________________________________________________________________
What
is Smart identification?
If the recorded description does not enable QTP to
identify a specific object then QTP uses “Smart identification”
mechanism. It uses the following additional properties to identify the
object
a) Base Filter Properties (primary) – The set of properties that cannot be changed without
a) Base Filter Properties (primary) – The set of properties that cannot be changed without
changing the object
type
b) Optional Filter Properties (secondary) – additional properties that help identify the object
b) Optional Filter Properties (secondary) – additional properties that help identify the object
uniquely
__________________________________________________________________________
Can
an action have 2 shared object repositories associated with them? In that case,
if two of them contain the same object, which one will be considered?
There can be more than one Shared OR’s associated to the same action. If Shared OR1 and Shared OR2 have one object named OBJ1 each and if the action calls for OBJ1 then the order in which the shared ORs were associated will be considered. That means, if Shared OR1 was first associated then the OBJ1 from Shared OR1 will be taken into account.
There can be more than one Shared OR’s associated to the same action. If Shared OR1 and Shared OR2 have one object named OBJ1 each and if the action calls for OBJ1 then the order in which the shared ORs were associated will be considered. That means, if Shared OR1 was first associated then the OBJ1 from Shared OR1 will be taken into account.
___________________________________________________________________________
I have
developed and executed a script successfully, and saved the same to QC. When I
tried to execute the script from QC, the script is not executing. What are the
possible reasons?”
1. QuickTest Add-In for Quality
Center has to be installed.
2. In the QTP Tools > Options
>run tab you should have ‘Allow other Mercury products to run tests and
components’ selected.
3. Make sure you are running QTP as
an Admin
4. All the test resources have to be
in the correct path
_________________________________________________________________________________
What is the extension of QTP
local Repository? If it is .mtr then
what is .bdb extension stands for?
.bdb is the local OR. .mtr is a binary file that
contains other information about checkpoints and all. To re-verify the .bdb is
the OR, try to rename the file with the extension as .tsr and open it from ORM.
The same objects in the OR will be displayed here. The same will not work if
you try it on .mtr file.
________________________________________________________________________________
How can you close the second opened
browser?
You can know which
browser instance was opened after another can be known by using the “creation
time” property. In simple terms, this is nothing but a counter for each browser
instance that gets launched. For the first one, it is 0 and gets incremented
from then on. To close the second opened browser, you can use the following
code:
Browser(“creationtime:=1″).Close
_______________________________________________________________________________
How to get Nth Highest Salary of the Employee using
SQL?
First, ask ourselves how can we find the highest
salary in a table? Well, you probably know that is actually really easy – we
can just use the MAX aggregate function:
The highest
salary in a table
select MAX(Salary) from Employee;
So, if we
can somehow select the highest value from a result set that excludes
the highest value, then we would actually be selecting the 2nd highest salary
value. Think about that carefully and see if you can come up with the actual
SQL yourself before you read the answer that we provide below. Here is a small
hint to help you get started: you will have to use the “NOT IN” SQL
operator.
The 2nd
highest salary in SQL:
SELECT
MAX(Salary) FROM Employee
WHERE Salary NOT IN (SELECT
MAX(Salary) FROM Employee )
And Now, SQL
query to find the Nth highest salary (Works for all)
SELECT *
FROM Employee Emp1
WHERE (N-1) = (
SELECT
COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary >
Emp1.Salary)
nth
highest salary using the TOP keyword (in SQL Server)
SELECT TOP 1 Salary
FROM (
SELECT DISTINCT TOP N Salary
FROM Employee
ORDER BY Salary DESC
) AS Emp
ORDER BY Salary
nth highest salary using Desc Limit (in MySQL)
SELECT Salary FROM Employee
ORDER BY Salary DESC LIMIT n-1,1
nth
highest salary using rownum (in Oracle)
select * from (
select Emp.*,
row_number() over (order by
Salary DESC) rownumb
from Employee Emp
)
where rownumb = n; /*n is nth highest salary*/
_________________________________________________________________________________
1.
What is a self
join? Explain it with an example
Suppose
we have the following table – that is called employee. The employee table has 2
columns – one for the employee name (called employee_name), and one for the
employee location (called employee_location):
Employee
|
||||||||||||
|
Now,
suppose we want to find out which employees are from the same location as the
employee named Joe. In this example, that location would be New York. Let’s
assume – for the sake of our example – that we can not just directly
search the table for people who live in New York with a simple query like this
(maybe because we don’t want to hardcode the city name) in the SQL query
SELECT
employee_name
FROM
employee
WHERE
employee_location = "New York"
So,
instead of a query like that what we could do is write a nested SQL query
(basically a query within another query – which more commonly called a
subquery) like this:
SELECT
employee_name
FROM
employee
WHERE
employee_location in
(
SELECT employee_location
FROM employee
WHERE employee_name = "Joe")
A self join is basically when a table is joined to
itself. The way you should visualize a self join for a given table is by
imagining that a join is performed between two identical copies of that
table. And that is exactly why it is called a self join –
because of the fact that it’s just the same table being joined to another copy
of itself rather than being joined with a different table.
Self Join Example:
SELECT e1.employee_name
FROM employee e1, employee e2
WHERE e1.employee_location =
e2.employee_location
AND
e2.employee_name="Joe";
This query will return the names Joe and Jack –
since Jack is the only other person who lives in New York like Joe.
________________________________________________________________________________
1. Suppose we have the Employee table below, and we
want to retrieve all of the cities that the employees live in, but we don’t
want any duplicates. How can we do this in SQL?
employee
|
||||||||||||||
|
1st Way: In SQL, the distinct
keyword will allow us to do that. Here’s what the simple SQL would look like:
SELECT DISTINCT
employee_location from employee;
|
Running
this query will return the following results:
employee_location
|
New
York
|
India
|
Russia
|
Canada
|
2nd Way: We can actually
accomplish this with the GROUP BY keyword. Here’s what the SQL would look like:
SELECT employee_location from employee
GROUP BY employee_location
_________________________________________________________________________________________
How to reverse a string without using strreverse in VB?
<body>
<script language="VBScript">
Dim x
x=inputbox("Enter a string")
cnt=len(x)
Do until cnt=0
y = y&mid(x,cnt,1)
cnt=cnt-1
Loop
msgbox y
</script>
</body>
_________________________________________________________________________________________
Write a Program to show usage of Output value using QTP?
Systemutil.Run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set DataTable("Agent_Name", dtGlobalSheet)
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure DataTable("Password", dtGlobalSheet)
Dialog("Login").WinEdit("Password:").Type micReturn
Dialog("Login").Dialog("Flight Reservations").Static("Please enter agent name").Output_ CheckPoint("ErrorMessage")
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
__________________________________________________________________________________________
What is Error Handling in QTP?
How many types of Errors are there in QTP?
There are various
ways on handling errors in QTP. There are three possible kinds of error type
one would encounter while working with QTP.
·
Syntax Errors
·
Logical Errors
·
Run Time Errors
Syntax errors are the typos or a piece of the code that does not confirm with the VBscripting
language grammar. Syntax errors occur at the time of compilation of code and
cannot be executed until the errors are fixed. To verify the syntax one use the
keyboard shortcut as Ctrl+F7 and the result is displayed as shown below. If the
window is NOT displayed one can navigate to "View" ->
"Errors".
LOGICAL ERRORS:
If the script is syntactically correct
but it produces unexpected results. Logical error usually does not interrupt
the execution but produces incorrect results. Logical errors could occur due to
variety of reasons, viz- wrong assumptions or misunderstanding of the
requirement and sometimes incorrect program logics(using do-while instead of
do-Until) or Infinite Loops.
One of the ways to
detect a logical error is to perform peer reviews and also verifying the QTP
output file/result file to ensure the tool has performed what it has intended
to do.
RUNTIME ERRORS:
As The name states, this kind of Error
happens during Run Time. The reason for such kind of errors is that the script
trying to perform something but it is unable to do so and the script usually stops
as it is unable to continue with the execution. Classic Examples for Run Time
Errors are,
1.
File NOT found but the script trying to read the
file.
2.
Object NOT found but script is trying to act on
that particular object.
3.
Dividing a number by Zero.
4.
Array Index out of bounds while accessing array
elements.
Handling Run-Time Errors:
There are various
ways to handle errors in the code.
1. Using Test Settings - Error handling can be
defined the Test Settings by Navigating to "File" >>
"Settings" >> "Run" We can select
any of the specified settings and click "OK".
2. Using On Error Statement - On Error statement is
used to notify the VBScript engine of intentions to handle the run-time errors
by tester, rather than allowing the VBScript engine to display error messages
that are not user friendly.
·
On Error Resume Next - On Error Resume Next informs the VBScript engine
to process executing the next line of code when an error is encountered.
·
On error Goto 0 - This helps the testers to turn off the error handling.
3. Using Err Object - Error object is an
inbuilt object within VBScript that captures the run time error number and
error description with which we will be able to debug the code easily.
·
Err.Number - The Number property returns or Sets a numeric value
specifying an error. If Err.Number value is 0 then No error had occured.
·
Err.Description - The Description property returns or sets a brief
description about an error.
·
Err.Clear - The Clear method resets the Err object and clears all the
previous values associated with it.
EXAMPLE:
'Call
the function to Add two Numbers
Call Addition(num1,num2)
Function Addition(a,b)
On error resume next
If NOT IsNumeric(a) or IsNumeric(b) Then
Print "Error number is
" & err.number &
" and description is : " &
err.description
Err.Clear
Exit Function
End If
Addition = a+b
'disables error handling
On Error Goto 0
End function
4. Using Exit Statement - Exit Statements can
be used along with Err object to exit from a test or action or iteration based
on the Err.Number value. Let us see each one of those Exit statements in
detail.
·
ExitTest - Exits from the entire QTP test no matter what the run-time
iteration settings are.
·
ExitAction - Exits the current action.
·
ExitActionIteration - Exits the current iteration of the action.
·
ExitTestIteration - Exits the current iteration of the QTP test and
proceeds to the next iteration.
5. Recovery Scenarios - Upon encountering an
error, recovery scenarios are triggered based on certain conditions and it is
dealt in detail in a seperate chapter.
6. Reporter Object - Reporter Object helps
us to report an event to the run results. It helps us to identify if the
concerned action/step is pass/fail.
'Syntax:
Reporter.ReportEventEventStatus, ReportStepName, Details, [ImageFilePath]
'Example
Reporter.ReportEvent micFail, "Login", "User is
unable to Login."
_________________________________________________________________________________
No comments:
Post a Comment