Pages

Thursday, March 12, 2015

From a QTP to Selenium User - Get Transformed!

There are many tester's who are well versed with QTP but not selenium , here is a quick start - a reference cheat-sheet for Selenium and QTP. The image below has all the basic operations that you would perform on a web browser. The left side are Selenium and the right side are the corresponding QTP commands.

So get ready to get transformed : From QTP to Selenium 

source: From one of the site.

Tuesday, March 1, 2011

Code for Data Driven testing in QTP

On Error Resume Next

'Path of the Input Folder
FilePath_Home="c:\TestData.xls\"
exe_Name="NY_UI Automation Scenarios_Attachment K_latest1"
'Kill the Processes
endprocess("EXCEL.EXE")
endprocess("Iexplore.exe")
'Get the TimeandDate
ResFile = Creationfiletime

Set vExcel = CreateObject("Excel.application")
'vExcel.Workbooks.Open FilePath & "TestData.xls"
vExcel.Workbooks.Open FilePath_Home & exe_Name

'print FilePath_Auto & exe_Name&space(2)& ResFile & ".xls"
VExcel.Activeworkbook.saveas FilePath_Home & exe_Name&space(2)& ResFile & ".xls"

vExcel.application.visible = True
'Num_Sheets=vExcel.sheets.count
IntNoofrows=vExcel.Sheets(1).usedrange.rows.count 'No of used rows

set vExcelSheet=vExcel.Sheets(1)' Focus on First Sheet

systemutil.Run "IEXPLORE.EXE","https://www.google.com"




Row_No=2

for Row=Row_No to IntNoofrows


strBrowserName=trim(vExcelSheet.cells(Row,2))
strScreenName=trim(vExcelSheet.cells(Row,3))
strFieldName=trim(vExcelSheet.cells(Row,4))
strObjectType=trim(vExcelSheet.cells(Row,5))
strAction=trim(vExcelSheet.cells(Row,6))
strvalue=trim(vExcelSheet.cells(Row,7))
strExpectedResult=trim(vExcelSheet.cells(Row,8))


Set BrowserPage=Browser(strBrowserName).page(strScreenName)
'err.clear
'On error goto 0
'On error resume next

BrowserPage.Sync

err.clear
strStatus=""
Select Case Lcase(strObjectType)


Case "webedit"

'If BrowserPage.WebEdit(strFieldName).Exist(5) Then
bWeb_Edit=BrowserPage.WebEdit(strFieldName).Exist
If bWeb_Edit="True" and err.number=0 Then

Select Case Lcase(strAction)

Case "verify"
App_Val=BrowserPage.WebEdit(strFieldName).GetROProperty("value")
'msgbox App_Val & strvalue
If trim(lcase(App_Val))=trim(lcase(strvalue)) Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "set"
' wait 3
If BrowserPage.WebEdit(strFieldName).exist Then
BrowserPage.WebEdit(strFieldName).Set Trim(strvalue)
strStatus="PASS"
else
strStatus="FAIL"
End If
Case "disable"
val=BrowserPage.WebEdit(strFieldName).GetROProperty("disabled")
If Strcomp(val,strvalue)=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "enable"
val=BrowserPage.WebEdit(strFieldName).GetROProperty("disabled")
If Strcomp(val,strvalue)=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "mandatory"
val=BrowserPage.WebEdit(strFieldName).GetROProperty("class")
If strcomp(lcase(val),"mandatoryfield")=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "visible"
Val=BrowserPage.WebEdit(strFieldName).exist
If Strcomp(lcase(Val),Lcase(strvalue))=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
' val=BrowserPage.WebEdit(strFieldName).GetROProperty("visible")
' If Strcomp(lcase(val),Lcase(strvalue))=0 Then
' strStatus="PASS"
' Else
' strStatus="FAIL"
' End If
End Select

else
strStatus="FAIL_Field NotPresent"
' msgbox "yes"
wait 2
End If

Case "wait"
Wait strvalue


'--------------------------WebList ----------------------

Case "weblist"

'If BrowserPage.WebList(strFieldName).Exist(3) Then
bWeb_List=BrowserPage.WebList(strFieldName).Exist
If bWeb_List="True" and err.number=0 Then
'If bWeb_List=True or bWeb_List="" Then
Select Case Lcase(strAction)
Case "verify"
App_val=BrowserPage.WebList(strFieldName).GetROProperty("all items")
' msgbox App_val & strvalue
If Instr(Trim(App_Val),trim(strvalue))>0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If

Case "verifylist"
App_val=BrowserPage.WebList(strFieldName).GetROProperty("all items")
' msgbox App_val & strvalue
If Instr(Trim(App_Val),trim(strvalue))=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "select"
If BrowserPage.WebList(strFieldName).exist Then
BrowserPage.WebList(strFieldName).Select Trim(strvalue)
strStatus="PASS"
else
strStatus="FAIL"
End If
Case "disable"
val=BrowserPage.WebList(strFieldName).GetROProperty("disabled")
If val=1 Then
strStatus="PASS"
else
strStatus="FAIL"
End If
Case "enable"
val=BrowserPage.WebList(strFieldName).GetROProperty("disabled")
Case "mandatory"
val=BrowserPage.WebList(strFieldName).GetROProperty("class")
Case "visible"
val=BrowserPage.WebList(strFieldName).GetROProperty("visible")
Case "verifydefault"
val=BrowserPage.WebList(strFieldName).GetROProperty("selection")

If strcomp(val,Trim(strvalue))=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End if
End Select
else
' msgbox err.description
strStatus="FAIL_Field NotPresent"
' msgbox "yes"

wait 2
End If

Case "image"
'If BrowserPage.Image(strFieldName).Exist(10) Then
bWeb_Image=BrowserPage.Image(strFieldName).Exist
If bWeb_Image="True" and err.number=0 Then
Select Case Lcase(strAction)
Case "click"
'msgbox Row
wait 2
If BrowserPage.Image(strFieldName).exist Then
BrowserPage.Image(strFieldName).Click
strStatus="PASS"
else
strStatus="FAIL"
End If
End Select
else
strStatus="NotPresent"
' msgbox "yes"
wait 2
End If

Case "webbutton"
'If BrowserPage.WebButton(strFieldName).Exist(10) Then
bWeb_Button=BrowserPage.WebButton(strFieldName).Exist
If bWeb_Button="True" and err.number=0 Then
Select Case Lcase(strAction)
Case "click"
BrowserPage.WebButton(strFieldName).Click
strStatus="PASS"
Case "disable"
val=BrowserPage.WebButton(strFieldName).GetROProperty("disabled")
Case "visible"
val=BrowserPage.WebButton(strFieldName).object.disabled
If strcomp(val,Trim(strvalue))=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End if
End Select
else
strStatus="FAIL_Field NotPresent"
' msgbox "yes"
wait 2
End If


Case "webradiogroup"
Web_radio_group=BrowserPage.WebRadioGroup(strFieldName).Exist

If Web_radio_group="True" and err.number=0 Then
Select Case Lcase(strAction)
Case "verify"
App_Val=BrowserPage.WebRadioGroup(strFieldName).GetROProperty("all items")
If Instr(Trim(App_Val),trim(strvalue))>0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "select"
If BrowserPage.WebRadioGroup(strFieldName).exist Then
BrowserPage.WebRadioGroup(strFieldName).Select Trim(strvalue)
strStatus="PASS"
Else
strStatus="FAIL"
End If
Case "disable"
val=BrowserPage.WebRadioGroup(strFieldName).GetROProperty("disabled")
Case "enable"
val=BrowserPage.WebRadioGroup(strFieldName).GetROProperty("disabled")
Case "mandatory"
val=BrowserPage.WebRadioGroup(strFieldName).GetROProperty("class")
Case "visible"
val=BrowserPage.WebRadioGroup(strFieldName).GetROProperty("visible")
Case "verifydefault"
val=BrowserPage.WebRadioGroup(strFieldName).GetROProperty("selection")

If strcomp(ucase(val),ucase(Trim(strvalue)))=0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End if
End Select
else
strStatus="FAIL_Field NotPresent"
' msgbox "yes"
wait 2
End If


Case "link"
'msgbox "LINK"

Select Case Lcase(strAction)
Case "click"
'msgbox Row
wait 2
'If BrowserPage.Link(strFieldName).Exist(5) Then
bWeb_Link=BrowserPage.Link(strFieldName).Exist
If bWeb_Link="True" and err.number=0 Then
BrowserPage.Link(strFieldName).Click
strStatus="PASS"
Else
strStatus="FAIL_Field NotPresent"
' msgbox "yes"
wait 2
End If

End Select

Case "webtable"
Select Case Lcase(strAction)
case "verifyvalidation"
If BrowserPage.webtable(strFieldName).exist Then
NoR=BrowserPage.webtable(strFieldName).rowcount
For R=1 to NoR
App_val=BrowserPage.webtable(strFieldName).GetCellData(NoR,1)
MsgBox App_val
vExcelSheet.cells(Row,R+9)=App_val
If instr(1,lcase(trim(App_val)),lcase(trim(strvalue)))>0 Then
strStatus="PASS"
Else
strStatus="FAIL"
End if
Next
else
strStatus="FAIL_Field NotPresent"
' msgbox "yes"
wait 2
End If


Case "verifyvalue"

EV_Split_Value=split(We2,"=")
'msgbox EV_Split_Value(0)
For i=1 to BrowserPage.WebTable(strFieldName).rowcount
If instr(1,BrowserPage.WebTable(strFieldName).getcelldata(i,1),EV_Split_Value(0))>0 Then
AV= BrowserPage.WebTable(strFieldName).getcelldata(i,1)
'MsgBox AV
Split_Value=split(AV,EV_Split_Value(0))
If instr(1,Split_Value(1),EV_Split_Value(1) )>0 Then
strStatus= "PASS"
else
strStatus= "FAIL"
End If
Exit for
End If
next

End select

Case "webelement"
bWeb_Element=BrowserPage.WebElement(strFieldName).Exist
If bWeb_Element="True" and err.number=0 Then
Select Case Lcase(strAction)
Case "click"
If BrowserPage.WebElement(strFieldName).Exist Then
BrowserPage.WebElement(strFieldName).click
End If
Case "verify"
If BrowserPage.WebElement(strFieldName).Exist Then
' val= BrowserPage.WebElement(strFieldName).getroproperty("innertext")
'If Instr(val,Trim(strvalue))>0 Then
strStatus="PASS"
Else
strStatus="FAIL"
'End if
End If
Case "visible"
val=BrowserPage.webelement("name:="&strFieldName).GetROProperty("visible")
If strcomp(ucase(val),ucase(Trim(strvalue)))=0 or val=empty Then
strStatus="PASS"
Else
strStatus="FAIL"
End if
End Select
else
strStatus="FAIL_Field_Not Present"
' msgbox "yes"
wait 2
End if


Case "popup"

Set BrowserPage = Browser(strBrowserName)
BP=BrowserPage.exist
If BP="True" and err.number=0 Then
Select Case Lcase(strAction)

Case "click"

If BrowserPage.Dialog( strScreenName).Exist Then
BrowserPage.Dialog( strScreenName).WinButton(strFieldName).Click
strStatus="PASS"
Else
strStatus="FAIL"
End If

Case "set"
If BrowserPage.Dialog( strScreenName).Exist Then
BrowserPage.Dialog( strScreenName).WinEdit(strFieldName).Set Trim(strvalue)
strStatus="PASS"
Else
strStatus="FAIL"
End If

End Select
End If
Set BrowserPage = Nothing

End Select

Set BrowserPage = Nothing
vExcelSheet.cells(Row,9)=strStatus
Next



VExcel.Activeworkbook.save
Set VExcel = Nothing
set vExcelSheet = Nothing

A function for Convert System date to Sepcified format date:

Public Function dateManipulate(sDate)

If Len(sDate) > 10 Then
Reporter.ReportEvent micWarning, "Error! Bad Input", "Bad Input. Actual: " & sDate & ". Expected: m-d/yyyy"
End If

locDelimOne = InStr(1, sDate, "-")
locDelimTwo = InStr(1, sDate, "/")

If locDelimOne = 2 Then
sMonth = Left(sDate, 1)
sMonth = "0" & sMonth
ElseIf locDelimOne = 3 Then
sMonth = Left(sDate, 2)
Else
Reporter.ReportEvent micWarning, "Error! Bad Input", "Bad Input. Actual: " & sDate & ". Expected: m-d/yyyy"
End If

sDay = Mid(sDate, locDelimOne + 1, locDelimTwo - locDelimOne - 1)

If Len(sDay) = 1 Then
sDay = "0" & sDay
End If

sLen = Len(sDate) - locDelimTwo
sYear = Mid(sDate, locDelimTwo + 3, sLen)

iDate = sMonth & "/" & sDay & "/" & sYear

dateManipulate = iDate

End Function

Monday, December 27, 2010

QTP-Database connection

1st Method:

set conn=Createobject("ADODB.Connection")
Srvname="Driver={Microsoft ODBC for
Oracle}:Server=DBserver,UID=Sa,Password=sa"
conn.open Srvname
Set Rec = CreateObject("ADODB.Recordset")
SQL="select * from Users"
Rec.open SQL ,conn
Username=Rec.fields("employee name")
Msgbox Username




Microsoft ADO (ActiveX Data Objects) is a Component object
model object for accessing data sources.The ADO Recordset
object is used to hold a set of records from a database
table. A Recordset object consist of records and columns
(fields).
In ADO, this object is the most important and the one used
most often to manipulate data from a database.

Srvname is a connection string.if u already installed
oracle in your system..using that path u can connect oracle
database...if u dont have oracle give the conncetion string
path..whatever connection string created used in database
checkpoint by default...

Example:DSN=QT_Flight32;DBQ=C:\Program
Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\flight32.mdb;

Driver=C:\WINDO
WS\system32\odbcjt32.dll;DriverId=281;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;

2nd Method:
(Through Self scripting:)

set conn=createobject("adodb.connection")
set rs=createobject("adodb.recordset")
' Oracle client is required to be installed on your box
conn.open= "Provider=OraOLEDB.Oracle.1;Password=***;Persist
Security Info=True;User ID=****;SERVER=****;Data
Source=****;DBQ=****;"
sql="your sql"
rs.open sql,conn

rs.close
set rs=nothing

conn.close
set conn=nothing

Saturday, August 28, 2010

Descriptive Programming

Introduction to Descriptive Programming:
Descriptive programming is used when we want to perform an operation on an object that is not present in the object repository. There can be various valid reason to do so. We will discuss them later in this article.

How to write Descriptive Programming?

There are two ways in which descriptive programming can be used

1. By giving the description in form of the string arguments.
2. By creating properties collection object for the description.

1. By giving the description in form of the string arguments.

This is a more commonly used method for Descriptive Programming.
You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object’s
name. The general syntax is:

TestObject("PropertyName1:=PropertyValue1", "..." , "PropertyNameX:=PropertyValueX")

TestObject—the test object class could be WebEdit, WebRadioGroup etc….

PropertyName:=PropertyValue—the test object property and its value. Each property:=value pair should be separated by commas and quotation
marks. Note that you can enter a variable name as the property value if you want to find an object based on property values you retrieve during a run session.

Consider the HTML Code given below:

<--!input type="”textbox”" name="”txt_Name”"-->
<--!input type="”radio”" name="”txt_Name”"-->

Now to refer to the textbox the statement would be as given below

Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”

And to refer to the radio button the statement would be as given below

Browser(“Browser”).Page(“Page”).WebRadioGroup(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”

If we refer to them as a web element then we will have to distinguish between the 2 using the index property

Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html tag:=INPUT”,”Index:=0”).set “Test” ‘ Refers to the textbox
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html tag:=INPUT”,”Index:=1”).set “Test” ‘ Refers to the radio button

To determine which property and value pairs to use, you can use the Object Spy:
1. Go to Tools -> Object Spy.
2. Select the "Test Object Properties" radio button.
3. Spy on the desired object.
4. In the Properties list, find and write down the properties and values that can be used to identify the object.


2. By creating properties collection object for the description.

Properties collection also does the same thing as string arguments. The only difference is that it "collects" all the properties of a particular object in an instance of that object. Now that object can be referenced easily by using the instance, instead of writing "string arguments" again and again. It is my observation that people find "string arguments" [1] method much easier and intuitive to work with.

To use this method you need first to create an empty description
Dim obj_Desc ‘Not necessary to declare
Set obj_Desc = Description.Create

Now we have a blank description in “obj_Desc”. Each description has 3 properties “Name”, “Value” and “Regular Expression”.

obj_Desc(“html tag”).value= “INPUT”

When you use a property name for the first time the property is added to the collection and when you use it again the property is modified. By default each property that is defined is a regular expression. Suppose if we have the following description

obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*”

This would mean an object with html tag as INPUT and name starting with txt. Now actually that “.*” was considered as regular expression. So, if you want the property “name” not to be recognized as a regular expression then you need to set the “regularexpression” property as FALSE

obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt.*”
obj_Desc(“name”).regularexpression= “txt.*”

This is how we create a description. Now below is the way we can use it

Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test”

When we say .WebEdit(obj_Desc) we define one more property for our description that was not earlier defined that is it’s a text box (because QTPs WebEdit boxes map to text boxes in a web page).

If we know that we have more than 1 element with same description on the page then we must define “index” property for the that description

Consider the HTML code given below

<--!input type="”textbox”" name="”txt_Name”"-->
<--!input type="”textbox”" name="”txt_Name”"-->

Now the html code has two objects with same description. So distinguish between these 2 objects we will use the “index” property. Here is the description for both the object

For 1st textbox:
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “0”

For 2nd textbox:
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”
obj_Desc(“index”).value= “1”

Consider the HTML Code given below:

<--!input type="”textbox”" name="”txt_Name”"-->
<--!input type="”radio”" name="”txt_Name”"-->

We can use the same description for both the objects and still distinguish between both of them
obj_Desc(“html tag”).value= “INPUT”
obj_Desc(“name”).value= “txt_Name”

When I want to refer to the textbox then I will use the inside a WebEdit object and to refer to the radio button I will use the description object with the WebRadioGroup object.

Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test” ‘Refers to the text box
Browser(“Browser”).Page(“Page”).WebRadioGroup(obj_Desc).set “Test” ‘Refers to the radio button

But if we use WebElement object for the description then we must define the “index” property because for a webelement the current description would return two objects.

Getting Child Object:

We can use description object to get all the objects on the page that matches that specific description. Suppose we have to check all the checkboxes present on a web page. So we will first create an object description for a checkboxe and then get all the checkboxes from the page

Dim obj_ChkDesc

Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”

Dim allCheckboxes, singleCheckBox

Set allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)

For each singleCheckBox in allCheckboxes

singleCheckBox.Set “ON”

Next

The above code will check all the check boxes present on the page. To get all the child objects we need to specify an object description.

If you wish to use string arguments [1], same thing can be accomplished by simple scripting.

Code for that would be:

i=0
Do While Browse(“Browser”).Page(“Page”).WebCheckBox("html tag:=INPUT",type:=checkbox, "index:="&i).Exist
Browse(“Browser”).Page(“Page”).WebCheckBox("html tag:=INPUT",type:=checkbox, "index:="&i).Set "ON"
i=i+1
Loop
Possible Operation on Description Objects

Consider the below code for all the solutions
Dim obj_ChkDesc

Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”

Q: How to get the no. of description defined in a collection
A: obj_ChkDesc.Count ‘Will return 2 in our case

Q: How to remove a description from the collection
A: obj_ChkDesc.remove “html tag” ‘would delete the html tag property from the collection

Q: How do I check if property exists or not in the collection?
A: The answer is that it’s not possible. Because whenever we try to access a property which is not defined its automatically added to the collection. The only way to determine is to check its value that is use a if statement “if obj_ChkDesc(“html tag”).value = empty then”.

Q: How to browse through all the properties of a properties collection?
A: Two ways
1st:
For each desc in obj_ChkDesc
Name=desc.Name
Value=desc.Value
RE = desc.regularexpression
Next

2nd:
For i=0 to obj_ChkDesc.count - 1
Name= obj_ChkDesc(i).Name
Value= obj_ChkDesc(i).Value
RE = obj_ChkDesc(i).regularexpression
Next

Hierarchy of test description:

When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions
from that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have
been described using programmatic descriptions, QuickTest cannot identify the object.

For example, you can use Browser(Desc1).Page(Desc1).Link(desc3), since it uses programmatic descriptions throughout the entire test object hierarchy.
You can also use Browser("Index").Page(Desc1).Link(desc3), since it uses programmatic descriptions from a certain point in the description (starting
from the Page object description).

However, you cannot use Browser(Desc1).Page(Desc1).Link("Example1"), since it uses programmatic descriptions for the Browser and Page objects but
then attempts to use an object repository name for the Link test object (QuickTest tries to locate the Link object based on its name, but cannot
locate it in the repository because the parent objects were specified using programmatic descriptions).


When and Where to use Descriptive programming?

Below are some of the situations when Descriptive Programming can be considered useful:

1. One place where DP can be of significant importance is when you are creating functions in an external file. You can use these function in various actions directly , eliminating the need of adding object(s) in object repository for each action[If you are using per action object repository]

2. The objects in the application are dynamic in nature and need special handling to identify the object. The best example would be of clicking a link which changes according to the user of the application, Ex. “Logout <>”.

3. When object repository is getting huge due to the no. of objects being added. If the size of Object repository increases too much then it decreases the performance of QTP while recognizing a object. [For QTP8.2 and below Mercury recommends that OR size should not be greater than 1.5MB]

4. When you don’t want to use object repository at all. Well the first question would be why not Object repository? Consider the following scenario which would help understand why not Object repository
Scenario 1: Suppose we have a web application that has not been developed yet.Now QTP for recording the script and adding the objects to repository needs the application to be up, that would mean waiting for the application to be deployed before we can start of with making QTP scripts. But if we know the descriptions of the objects that will be created then we can still start off with the script writing for testing
Scenario 2: Suppose an application has 3 navigation buttons on each and every page. Let the buttons be “Cancel”, “Back” and “Next”. Now recording action on these buttons would add 3 objects per page in the repository. For a 10 page flow this would mean 30 objects which could have been represented just by using 3 objects. So instead of adding these 30 objects to the repository we can just write 3 descriptions for the object and use it on any page.

5. Modification to a test case is needed but the Object repository for the same is Read only or in shared mode i.e. changes may affect other scripts as well.

6. When you want to take action on similar type of object i.e. suppose we have 20 textboxes on the page and there names are in the form txt_1, txt_2, txt_3 and so on. Now adding all 20 the Object repository would not be a good programming approach.


References:
1) QuickTestProfessional Documentation
2) Tarun Lalwani's DP Document

Friday, March 13, 2009

Reading the data from excel sheet in QTP

There is two methods are there to retrieve data from excel sheet.

1st method:
datatable.importsheet "path of the excel file.xls",source sheetID,desination sheetID
n = datatable.getsheet("desination sheetname").getrowcount
for i = 1 to n
columnname = datatable.getsheet("destination sheetname").getparameter(i).name
if colunmname = knowncolumnname then
value = datatable.getsheet(destinationsheetname).getparameter(i)
end if
next

2nd method:
set objexcel = createobject("excel.application")
Set objWorkbook = objExcel.WorkBooks.Open("path of the file.xls")
Set objDriverSheet = objWorkbook.Worksheets("name of the sheet")
columncount = objDriverSheet.usedrange.columns.count
rowcount = objDriverSheet.usedrange.rows.count
for i = 1 to colunmcount
columnname = objDriversheet.cells(i,1)
if columnname = knowncolumnname
then
for j = 1 to rowcount
fieldvalue = objdriversheet.cells(j,i)
next
end if
next

Monday, March 2, 2009

Framework

A test automation framework is a set of assumptions, concepts, and practices that provide support for automated software testing

Benefits for Framework:

• Allow highest possible reusability
• Support different application versions
• Should support different environments
• Self Configurable
• Easy to use and understand
• Flexible

General types of framework:
• The Test Script Modularity Framework
• The Test Library Architecture Framework
• The Keyword Driven Testing Framework
• The Data Driven Testing Framework
• The Hybrid Test Automation Framework

Test script Modularity Frame work:
The test script modularity framework requires the creation of small, independent scripts that represent modules of the application-under-test. These small scripts are then used in a hierarchical fashion to construct larger tests, realizing a particular test case.

The Test Library Architecture Framework
The test library architecture framework is very similar to the test script modularity framework but it divides the application-under-test into procedures and functions instead of scripts. This framework requires the creation of library files that represent modules, sections, and functions of the application-under-test. These library files are then called directly from the test case script.

The Keyword Driven Testing Framework
Keyword-driven testing framework requires the development of data tables and keywords, independent of the test automation tool used to execute them and the test script code that "drives" the application-under-test and the data. Keyword-driven tests look very similar to manual test cases. In a keyword-driven test, the functionality of the application-under-test is documented in a table as well as in step-by-step instructions for each test. It is an application independent automation framework.

The Data Driven Testing Framework
Data-driven testing is a framework where test input and output values are read from data files (datapools, ODBC sources, cvs files, Excel files, DAO objects, ADO objects, and such) are loaded into variables in captured or manually coded scripts. In this framework, variables are used for both input values and output verification values. Navigation through the program, reading of the data files, and logging of test status and information are all coded in the test script.

The Hybrid framework:
“Hybrid” frame work, where we use Data driven framework and Key word Driven Frame work.