Monday 27 January 2014

How to trigger the web events like change, click, mouseup in QTP?

Testing the web application with QTP involves the biggest challenge of events bound to the html elements with jquery by developers not getting triggered. 

Example - 

Problem (Issue)

For instance, when we select the value from the web combobox (dropdown), HTML dom of the webpage changes. It may change the visibility of the some of the controls like edit boxes or drop downs. It may do some ajax calls to the server by using javascript code.
So basically when we do some operation on the web elements , specific event handlers ( java script code or function) get called. But performing the same operation with QTP may not call these event handlers leading to inability to automate the test cases.

Solutions
To handle this issue we can trigger any event like change, click, double click, mouseup, mousedown etc by using FireEvent method. But if it does not work, you can use the vbscript code as depicted below.

'Create the event object
Set evt =  Browser("ABC").Page("XYZ").Object.createEvent("HTMLEvents")

'Set the event type like change, click, mouseup, mousedown
evt.initEvent "change", true, true

'Dispatch the event on desired object.
Browser("ABC").Page("XYZ").WebList("pqr").Object.dispatchEvent(evt)

Above code was tested on internet explorer 10 and QTP 10. If you have faced similar issue while automating web application, please give details in comment and I will try to help you.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Wednesday 22 January 2014

How to access the excel as a database using adodb.connection in QTP?

Below example demonstrates how we can access the excel workbook as a Database using ADODB.Connection object.

Set objConnection = createobject("ADODB.CONNECTION")
'Set objRecordSet = createobject("ADODB.RECORDSET")
objConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
objConnection.ConnectionString = "Data Source=C:\mybook1.xls;Extended Properties=Excel 8.0;"

'objConnection.Open "Data Source=excelDSN"
'We can also provide the Data Source in DSN style as mentioned above. excelDSN is the DSN I have created for the excel workbook using ODBC

'Open the database connection
objConnection.Open



'Execute sql query using connection object
'Please note how we have written the query to get data from sheet. "AA" is the name of the sheet.
'Note that you have to give the name of the sheet inside square brackets with $ as the last character.
'If you are having column names in your query you will have to put them inside square brackets as well.

 Set  objRecordSet = objConnection.Execute( "Select * from [AA$]")

 'recordcount property of the recordset object does not work in Excel So we have used EOF property to check the end of records.
Do While (not objRecordSet.EOF)

If  not  isnull(objRecordSet.Fields(8).Value) Then
print objRecordSet.Fields(8).Value
End If

'Move to next record in sheet - AA
objRecordSet.MoveNext

Loop

'Close the adodb connection
objConnection.Close

Advantages of using Excel as a Database.

  1. We can access one row at a time. So memory consumption is less
  2. Faster access to records.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Saturday 18 January 2014

What are the challenges while automating the test cases in QTP?

Automation with QTP does involve lot of challenges. Based upon my experience I am stating some of the frequent challenges that may be faced by QTP engineers.

  1.  Automation of third party controls like infragistic controls in .net based applications.
  2. Automation of the PDF file comparison.
  3. Working with the controls inside tables.
  4. Selecting the drop down value will not trigger the onchange event in webpage.
  5. Automation of the web applications involving frames/iframes/framesets.
  6. All edit boxes having same properties..
  7. Elements like checkboxes, buttons, radiobuttons inside nested tables.
This is the list of most frequent challenges faced in automation projects. You can easily handle these challenges if you know how to access native properties of the objects.

QTP does provide the way to access native properties and methods using object property.
You can solve most of the issues in web application testing using html DOM in QTP. Please try to avoid index to identify any object as this will make your script very weak.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

How to select specific webcheckbox in QTP?

Sometimes there are webpages having multiple check boxes. You have to select specific check box.

We can solve this problem by 3 ways as mentioned below in QTP.

  1. Using index property
  2. Using Description object
  3. Using HTML DOM

Selecting the web check box using index -


if Browser("myb").page("myp").webcheckbox("index:=2").getROProperty("checked") = false then
     Browser("myb").page("myp").webcheckbox("index:=2").click
end if
'Above code will select the third checkbox on the webpage.

Selecting the web check box using Description Programming -

Set DescObject = Description.create()
DescObject("micclass").value = "webcheckbox"

set col = Browser("myb").page("myp").childobjects(DescObject)
col(2).click

Selecting the web check box using HTML DOM -

set col = Browser("myb").page("myp").object.getElementsByTagName("input")

'Please note that above statement will give you all the elements on the webpage having input tag.
You can check the innerhtml property of each element to see if the given input element's type is a checkbox or not.

for i=0 to i<col.count
x = col(i).getAttribute("type")
if lcase(trim(x)) = "checkbox" then
col(i).checked = true
end if
next

'Above code will select the first checkbox on the web page in QTP.

We can use same concept to select the specific check box in other environments like Java, .Net etc.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Friday 17 January 2014

What are the different software testing metrics in automation projects?

Testing Metrics are used to measure the quality of the software product. In automation testing projects involving tools like QTP, Selenium, Rational Robot etc, We can have below kinds of metrics.

We can categorize the metrics in below parts.

  1. Test Progress
  2. Test Coverage
  3. Test Quality

Automation Metrics to measure the progress of automation.


  1. Test Cases Automated per Day.
  2. Test Cases Executed per Day.
  3. Test Cases Failure Rate.
  4. Test Cases Pass Rate.
  5. Average Execution time per test case.
  6. Total execution time required to execute all test cases.

Automation Metrics to measure the Coverage.

  1. % of test Cases that can be automated from all test cases.
  2. % of total test cases automated till now from all test cases that can be automated(Progress).
  3. Requirements/Test Cases Coverage.

Automation Metrics to measure the quality of product.

  1. Test Effectiveness - How many good defects uncovered by automation.
  2. No of Defects  Found by Automation.
  3. ROI
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Thursday 16 January 2014

How to calculate return on investment (ROI) for automation projects?

Usually we automate the applications to get the benefits like cost saving, faster regression testing, overnight execution, accurate testing etc.

But automating the application also involves some upfront cost involved in it. We need to buy the automation tool like QTP, we need to train people on the tool then design the automation framework.

To measure the benefit of the automation projects, we need to calculate the return on the investments. We measure what all benefits we have got after automation of the project.

Effort Saved = Manual Efforts Required for Execution  - Efforts required for automated Execution.

Once we calculate effort saved for the entire testing cycle of the project, we can find ROI by below formula.

ROI = Total Effort Saved for all regression cycles - (A+B+C+D)

where

A = Total effort required for designing automation framework
B = Effort required for the maintenance of the automation scripts
C = Effort required for the automation of testing 
D = Licensing Cost of the tool

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

How to trigger the web element events like click, mouseover, mousedown in QTP?

As  the web applications are growing rapidly, the complexity is also increasing. Web toolkits, Ajax frameworks are being introduced to design web applications. This is making automation of such applications bit complex.

sometimes the automated steps of QTP does not trigger the events. Thus the javascript behind the web page does not get called.

In such scenarios we can use fireevent methods or we can also use HTML DOM to automate some part of the application.

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

How to do automation estimations in QTP Projects?

Estimating the efforts required to automate the given application is very important steps in any automation project involving QTP or any other testing tool.

Below is the list of important factors to look at while estimating the automation project.

  1. Skill sets of the employees.
  2. Tool Support.
  3. Application Size.
  4. Test Scenarios to be automated.
  5. Complexity of the test cases to be automated.
  6. Scope of the automation (Features to be tested/ not be tested)
  7. Number of automation testers available.
  8. Framework availability in the organization.
  9. Productivity of automation testers in similar testing projects.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Explain Loadfunctionlibrary in QTP.

Loadfunctionlibrary is used to associate new library files in QTP.
The advantage of this function is that we can attach multiple files to script in single line.

Example -
loadfunctionlibrary "c:\abc.vbs","c:\xyz.vbs"


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

How to create constructor in class in vbscript/QTP?

QTP does support object oriented programming to some extent.

We can create constructors and destructors in vbscript classes using class_initialize and class_terminate methods.

class_initialize method acts like constructor function which gets called automatically when we create an object of the class.

Example - 

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Explain Err.Number in QTP

Err object is very important in QTP. We can handle errors using this object. Whenever you think that error might occur, you can check if the error really occured or not using err.number

Example -

on error resume next
a = 2/0
'Above statement contains error - divide by zero.

if err.number <> 0 then
print "Error number is " & err.number & err.description
end if

Remember that you can use on error resume next anywhere and any number of times in the code.

To stop suppressing errors in QTP code you can use below statement.

On error goto 0
After this statement, if any error occurs, script will prompt you with the error message.

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

On Error Resume Next in QTP

Usually in keyword driven frameworks, we call the functions to perform specific operation like createOrder(), CancelOrder(). If error occurs in any of these functions, it is not important that we come back to main driver script and continue with next test case.

Code structure below demonstrates how we can do this in QTP.

'Code inside driver script.
On error resume next
'The advantage of the on error resume next is that we can continue to next statement if any error occurs in current statement.
Call createOrder()
If err.number <> 0 then
print err.description & err.source
End if
'*************************************************
'If error occurs at statement2, control of the script goes back to the caller. It does not execute any statment after statement2. This saves lot of time .

Function createOrder()
statement1......
statement2......
..........
more statements

End Function
**************************************************************************
Please note that if error occurs, control goes to next line of code and not the next block of code.
Example 1 -
on error resume next
a = 3/0
msgbox "hello"
msgbox "end"
'****************************************************************

Example 2 -
Consider below piece of code.
on error resume next
if (2/0) = 2 then
msgbox "true"
else
msgbox "false"
msgbox "end of code"
'************************************************************
Example 3 -
Consider below piece of code.
on error resume next
call myproc()
msgbox "end"
-------------------------------------------------------------------------------------
sub myproc()
if (2/0) = 2 then
msgbox "true"
else
msgbox "false"
end sub


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

How to access the excel as a database using adodb.connection in QTP?


We can work with excel in 3 ways in QTP as mentioned below.

  1. Using Excel.Application
  2. Using Adodb.Connection
  3. Using DataTable

To know how we can use Excel.Application to read or write the excel files, you can refer these links.

To know how to use datatable to load excel into it, use these links.

In this article we will see how we can read or write excel files using Adodb.Connection object.
Excel workbook is considered as a database. Each sheet in the excel workbook is considered as a table.
First row in the sheet is considered as column header and all other rows are considered to be records.

Here is the sample code to connect to excel database.

Set excelConnection = createobject("Adodb.Connection")
excelConnection.open "Data Source=c:\abc.xlsx;Provider=Microsoft.Jet.OLEDB.4.0"
Set rs = excelConnection.execute "Select * from [sheet1$]"
For i=0 to rs.recordCount-1
For j=0 to rs.fields.count-1
print rs.fields(j).name & rs.fields(j).value
Next
Next

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

How to click on the links or buttons in webtable in QTP?

Consider below web table. It has got 4 rows. Now what we have to do is – we have to click on the edit or delete link in front of the given employee.


Employee Name Operation  
Sagar                Edit  / Delete  
Amol                Edit  / Delete  
ajit                        Edit  / Delete


If we try to save links in OR, QTP uses the index property to identify the edit or delete buttons. But using index is not reliable because if new employee is added in the middle index of the existing links will also change.

To handle such situations, we can use html dom. We can solve the problem using below approach.
1. First get the row number in which given employee exists.
2. Then find the links in that row using getElementsByTagName method.
Here is the code to find the row number for the given employee.

function getRow(byval Employee)
Set tableObject = Browser(“MyB”).Page(“Myp”).WebTable("Mytable")
For i=1 to tableObject.object.rows.count
if tableObject.getCellData(i,1) = Employee Then
print "row found " & i
getRow = i
exit function
end if
Next
getRow = -1
End function

Above function will get the rownumber for the given employee. After this we can get the links in front of the given employee using below code.

Set tableObject = Browser(“MyB”).Page(“Myp”).WebTable("Mytable")
Set rowElement = tableObject.object.getElementsByTagName("tr")(rowNumber+1)
set links = rowElement.getElementsByTagName("A")
'Above statement will return all the links inside given row.
if links(0).innerText = "Edit" then
links(0).click()
End If

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Thursday 9 January 2014

SQL - QTP Interview Questions and Answers

Hello friends,
In this article I am going to discuss some questions based on sql queries. We will see some queries that are frequently asked in QTP Interviews.

1. SQL Query to find the second highest salary of the employee

This query is very popular among interviewers. Answer is also very simple
select max(salary) from emp where salary not in (select max(salary) from emp)

As you can see, we have used nested query to get the second highest salary of the employee. But above query can not be generalised to find the nth max salary.
Below code will solve the issue easily.
Select min(salary) from (select top 2 distinct salary from emp order by salary desc)  

Above query will get the second highest salary. To get the nth highest salary, you have to just replace 2 by n.
So the query to get the 4th highest salary will be 
Select min(salary) from (select top 4 distinct salary from emp order by salary desc)  

Please note that above query works in sql server and microsoft access but not in other databases like oracle or mysql.

2. SQL Query to find the duplicate values from the column.

Sometimes we need to find the duplicate values from the given column.
select city, count(city) from table group by city having count(city) > 1
Above query will print all cities that have appeared more than twice in the column city.

3. SQL Query to find the employees whose names start with s.

select * from emp where name like 's%'

To get the employees whose names start with s, a or b

select * from emp where name like '[sab]%'

4. SQL Query to copy records from one table to another.

select * into newtable from emp
Above query will copy all records from emp table to newtable.

To insert records in the existing table, you can use below queries.

insert into table1
select * from table2

insert into table1(name, city)
select name, city from table2.

5. How to execute the stored procedure in QTP?


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.