Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Understanding QTP Testing process


Quick Test Professional  testing process consists of following phases:


Pre-conditions before testing:


Before recording in QTP ,Please ensure following :

1. Application on which to record is open after qtp is launched.

2. Add-ins based on application are loaded.

3. Unnecessary instances of Internet Explorer and other applications are closed.

4. Ensure record and run settings are as expected and will record on the AUT.



Recording a session on your application


Click on record button in QTP and perform actions on AUT. QTP records every action performed and each element on which action is performed is stored as object in object repository. QTP displays each step in keyword view as tree and in expert view as vbscript.
For Recording, press F5 OR Click on record button.



Enhancing your test

1. Add Checkpoint to define pass/fail condition in the test.

2. Break lines of Codes into functions and increase reusability of test code.

3. Use data table to parametrize data used in the test.

4. Add regular expressions, output value in the test.

5. Add logic and conditional or loop statements that enables to add checks in the test.



Debugging your test

Debug a test to ensure that it operates smoothly and without interruption.To use debugging features , please install Microsoft script debugger. Use breakpoints to pause a test at breakpoints.


Running your test

On running a test using QTP, We know whether the expected behaviour of application matches the current behavior. A test will show pass/fail based on checkpoint on error handling defined through Code.


Analyzing the test results

Once a test is run, we have to analyse results to understand the behavior of AUT. We can analyse whether checkpoint pass or user defined error handling is passed or not.


Reporting defects

Once defects are found in application , they should be reported to concerned team and the tests should pass in case error/defects are resolved




How to Use GetElementsBytagName Method in QTP explained with Code

In this post, we will discuss how to use GetElementsbyTagName to input values in a edit box, count number of editbox, links , and count number of rows in a particular table. Please suggest in case user miss anything in the code. We can similarly use GetElementsbyTagName in a variety of purposes and manipulate the html


Code to find number of links in a page.

set objLink = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("a")

intLinks = objLink.length


Code to Identify number of edit box in the page.

set objLink = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("input")

intLinks = objLink.length


Code to input Data in a field using HTML DOM

set objEdit = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("input")

for each editbox in objEdit

       If editbox.classname = <strClassName>

editbox.innertext = <strSetVsalue>

Exit For

     End If

Next


Code to count number of rows in a table

set objTable = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("table")

for each Tbl in objEdit

         If Tbl.classname = <strTableClassName>

set objrow = tbl.getelementsbyTagName("tr")

Msgbox objrow.length

        End If

Next


QTP VBScript - Excel Application - Sorting data in excel worksheet based on column name

Below script or code snippet is very useful in sorting an excel workbook based on the name of columns header . We can sort multiple columns of the excel worksheet. For e.g there are 3 columns with header name as "name","class" and "value" based on which we want to sort the database with priority in order name>class>value. So provide strSortbyfield as "name>class>value". Below piecee of code can be implemented to achieve the same


strWorkBook = InputBox ("Input the workbook with full path")

strWorkSheet = InputBox("Enter the sheet name")

strSortbyFields = Inputbox ("provide the field names, seperated by > in case of multiple sorting of data is required")

Set objExcel = Createobject("Excel.Application")

objExcel.Visible = False

Set XLWorkBook = objExcel.WorkBooks.Open(strWorkbook)

Set objWorksheet = XLWorkBook.Worksheets(strWorkSheet)  

Set objRange = objWorksheet.UsedRange

ColCount = objRange.columns.count

strSortDataArr = split(strSortbyFields,">")

intCnt = ubound(strSortDataArr)

For i = intCnt to 0 step -1

For j = 1 to ColCount step 1

If (objWorkSheet.cells(1,j).value =strSortDataArr(i)) Then

''get the column based on which data needs to be sorted in the excel document

chrCde = Chr(asc("A")- 1+j) & "1"

boolExcelSortData = True

Set objRangeSrt = objExcel.Range(chrCde)

objRange.Sort objRangeSrt, xlDescending, , , , , , xlYes 

XLWorkBook.save

             Exit For

End If  

Next

Next

''save the workbook and close

XLWorkBook.Save

XLWorkBook.Close

objExcel.Quit

Set XLwORKBook = Nothing

Set objExcel = Nothing