affiliate marketing Rajendra, the Tester: March 2010

Friday, March 26, 2010

 

QTP Scripts - 4 - Ordinal Identifiers

An ordinal identifier assigns a numerical value to a test object that indicates its order or location relative to other objects with an otherwise identical description (objects that have the same values for all properties). This ordered value provides a backup mechanism that enables QuickTest to create a unique description to recognize an object when the defined properties are not sufficient to do so.

Location Ordinal Identifier
Index Ordinal Identifier
CreationTime Ordinal Identifier

Thursday, March 25, 2010

 

QTP Scripts - 3

Parameterization
Passing parameters, through this we can pass multiple values.

We use parameterization in Data Driven Testing.

Data Driven Testing: Testing the Same operation with multiple sets of test data.

Types of Parameterization: We can parameterize tests in several ways in QTP

1. Through Loop Statements
2. Dynamic Test Data Submission
3. Through Data Table
4. Fetching Test Data directly from External files (Flat files & Spreadsheets)
5. Fetching Test Data directly from Databases (MSAcess, Oracle etc).
6. Getting Test Data from front end objects.

1. Through Loop Statements: We can use loop statements for passing sequential numbers & Logical Numbers.

Note: We can’t generate Strings.

For orderno=1 to 10 step 1 ' for one increment step keyword is not mandatory
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set orderno
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Next

2.Dynamic Test Data Submission: Through Loop Statements we can give strings also but every time user has to enter data.

For x=1 to 3
Agent =inputbox("enter an Agent Name")
Password=inputbox("enter a password")
invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set Agent
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure password
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Next

3. Through Data Table: QTP adds one data table (Spreadsheet) for every test, we can use Data Table for Data Driven Testing.



It has 3 types of usage .



a. Entering test data directly into data table and use

b. Importing test data from external Flat files

c. Importing test data from external Spread sheets

d. Importing test data from Data bases.



A. Entering test data directly into data table and use.



Steps: Generate the basic test>open data table(View>Data Table)



Click on column header>enter the name of the field (like this we can create number of columns) > Enter Data>connect the data to test



(variable=datatable(“column name”, Sheet id)

Example: agent=datatable(“agent”,1)

Pass parameters.)



Run the test.



Agent = Datatable("Agent",1)

pwd=Datatable ("Password",1)

invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("Login").Activate

Dialog("Login").WinEdit("Agent Name:").Set Agent

Dialog("Login").WinEdit("Agent Name:").Type micTab

Dialog("Login").WinEdit("Password:").SetSecure pwd

Dialog("Login").WinButton("OK").Click

Window("Flight Reservation").Close





b. Importing test data from external files:



Open Data Table (view>Data table)>place mouse pointer on data table and right click>file>import from file>Click ok>Browsw path of the file(it imports data from the flat file)



Connecting Test Data to QTP Test as above and run the test.



c. Importing test data from external Spread sheets:



Open Data Table (view>Data table)>place mouse pointer on data table and right click>file>import from file>Click ok>Browse path of the excel sheet (it imports data from the excel sheet)



Connecting Test Data to QTP Test as above and run the test.



D. Importing test data from Data bases: Through Data table we can import Test Data from Data bases, but first we have to create /get the DSN(Data source Name)& we have to use SQL Commands.



1. Creating a Test Database: open MS Access (or we can use any other database).



Start programs>MS Office>MS Access>file >new>Select blank Database>enter name of the database>Save with mdb extension.



Creating Tables: Select Create table in design view>Enter field name(Agent)and Select data type(text) Like this we can create number of fields>save&enter table name.



Entering Data into Tables: Select table>enter the data.





Creating DSN & importing data



Navigation: view>data table>Place mouse pointer on Data table>sheet>import>from database(Database query wizard opens)>choose ‘specify SQL statements manually>click next >click create>click new>select driver type>click next >browse path to store> enter DSN Name>Click Save>click next>click finish>select>browse the database& select>click ok>click ok>select DSN>click ok>enter SQL statement (select *from login)>click finish.

Note: DSN Creation is one time activity, by using the DSN we can get data for number of tests.

4. Fetching Test Data directly from Flat files

Dim fso, myfile
Set fso=createobject("scripting.filesystemobject")
Set myfile=fso.opentextfile("d:\trigun.txt",1)
myfile.skipline
While myfile.atendofline <> true
x=myfile.readline
S=split(x,"@")

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set s(0)
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure S(1)
Dialog("Login").WinEdit("Password:").Type micReturn
Window("Flight Reservation").Close
Wend

Fetching Test Data directly from Excel Sheets

Fetching Test Data directly from Databases

Option explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.provider=("microsoft.jet.oledb.4.0")
con.open "C:\Documents and Settings\pooja\My Documents\trigun.mdb"
rs.open "select * from login",con
do until rs.eof=true
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set rs.fields ("agent")
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure rs.fields("password")
Dialog("Login").WinEdit("Password:").Type micReturn
Window("Flight Reservation").Close
rs.movenext
loop

 

QTP Scripts - 2

1) Count all opened Browsers on desktop and close them all?


Set oDesc = Description.Create()
oDesc("micclass").Value = "Browser"
Set Browsers =Desktop.ChildObjects (oDesc)
NumberofBrowsers = Browsers.Count()
Reporter.ReportEvent 2,"Res","Number of Browsers are: "&NumberOfBrowsers
For Counter=0 to NumberofBrowsers-1
Browsers(Counter).Close
Next

2) Count, how many links available in Mercury Tours Home Page.

Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Set Lists = Browser("Welcome: Mercury").Page("Welcome: Mercury").ChildObjects (oDesc)
NumberOfLinks = Lists.Count()
Reporter.ReportEvent 2,"Res","Number of Links are: "&NumberOfLinks

 

QTP Scripts - 1

(1)File locating Show Date & Time
Set f1 = CreateObject("Scripting.FileSystemObject")
Set f2 = f1.GetFile("E:\Lak.txt")
S = "File was Created on: "&f2.DateCreated
Msgbox S
----------------------------------------------------
(2)Folder locating Show Date & Time
Set f1 = CreateObject("Scripting.FileSystemObject")
Set f2 = f1.GetFolder("E:\Lak")
S = "Folder was Created on: "&f2.DateCreated
Msgbox S
------------------------------------------------------
(3)Counts the subfolders
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.GetFolder("D:\ssm")
Set c = b.SubFolders
For Each d in c
e=e&d.name&vbnewline
Next
msgbox e

--------------------------------------------------------
(4)Count the Check box in a Page
Set a=Description.Create
a("html tag").value="input"
a("type").value="checkbox"

Set b=Browser("Forms : Check Box - HTML").Page("Forms : Check Box - HTML").childobjects(a)
c=b.count
msgbox c

For i=0 to c-1
b(i).set "on"
Next


(5)Count the RadioButton in a Page(True or False)

Set a=Description.Create
a("html tag").value="input"
a("type").value="radio"

Set b=Browser("Forms : Check Box - HTML").Page("Forms : Radio Button -").childobjects(a)
c=b.count
msgbox c

For i=0 to c-1
b(i)
Next


(6)Creating New Notepad and Write the Data

Set obj=createobject ("scripting.filesystemobject")
Set notepad=obj.createtextfile("e:\\abc.txt")
notepad.writeline("hi sijil")
notepad.writeline("welcome to my blog")


(7)Creating a Folder

Set obj=createobject ("scripting.filesystemobject")
Set folder=obj.createfolder("e:\\kk")


(8)Creating a Folder include a Notepad Data

Set obj=createobject ("scripting.filesystemobject")
Set folder=obj.createfolder("e:\\abc")
Set notepad=obj.createtextfile("e:\\abc\script.txt")
notepad.writeline("hi")
notepad.writeline("welcome to my blog")


(9) Message Box will close by itself in 10seconds so dont click on OK button
Set a=createobject("wscript.shell")
msgbox_message="Message Box will close by itself in 10seconds so dont click on OK button"
msgbox_time="10"
msgbox_title="Testing"
a.popup msgbox_message,msgbox_time,msgbox_title

(10) Script to get count,names of all open browsers and to close them.
Set b=Description.Create
b("micclass").value="Browser"
Set obj=Desktop.ChildObjects(b)
msgbox obj.count
For i=0 to obj.count-1
c=obj(i).getroproperty("name")
msgbox(c)
obj(i).Close
Next

---------------------------------------------------------------------
(11) “Message Box” and “Browser” will close by itself in 10seconds so dont click on OK button

Set a=createobject("wscript.shell")
Set b=Description.Create
b("micclass").value="Browser"
Set obj=Desktop.ChildObjects(b)
For i=0 to obj.count-1
msgbox_message="Message Box and Browser will close by itself in 10seconds so dont click on OK button"
msgbox_time="10"
msgbox_title="Testing"
a.popup msgbox_message,msgbox_time,msgbox_title
obj(i).Close
Next


(12) To Count No. Of Links in WebPage(“A” or “a”[rep hyperlink])

set objlink = description.create
objlink("html tag").value = "A"
set n = browser("Google").page("Google").childobjects(objlink)
c = "Total Links are: "&n.count
msgbox c


(13)To Show the Tool Tip on a Page(Checkbox)

///////////Browser("Google").Page("Google").Link("Images").Click
a=Browser("Google").Page("Google").WebEdit("name:=q").Object.title
msgbox a

(14)To Show the “Links” Tool Tip on a Page

//////Browser("Google").Page("Google").WebEdit("q").Submit
c=Browser("Google").Page("Google").Link("name:=definition").object.title
msgbox c

(15)To Show the “Image” Tool Tip on a Page
b=Browser("Web Templates - Flash").Page("Web Templates - Flash").Image("src:=http://www.templatesbox.com/data/premium.templates/images/full_site/thumbnails/12293353720Zf/12293353720Zf.jpg").getROProperty("alt")
msgbox b
//////////Browser("Web Templates - Flash").Page("Web Templates - Flash").Link("Full Site").Click

(16) To Show Current Date,Time and Date Only
msgbox now
msgbox time
msgbox date
(17)Creating a Word pad and Write the Data
Dim obj
Set obj=Createobject("word.application")
obj.Documents.add
obj.selection.typetext"Welcome"
obj.activedocument.saveas"d:\test.doc"

(18)Creating a Excelsheet and Wirte the Data
Set Excel=createObject("Excel.Application")
Set ExcelSheet=createObject("Excel.sheet")
ExcelSheet.Application.visible=true
Excel.ActiveSheet.cells(1,1).value=1111
Excel.ActiveSheet.cells(1,2).value=2222
Excel.ActiveSheet.cells(2,1).value=3333
Excel.ActiveSheet.cells(2,2).value=4444
ExcelSheet.SaveAs "d:\1.xls"

(19)Taking Value From Excel Sheet with Example
Browser("AutoPallet/AutoLoader™").Page("AutoPallet/AutoLoader™").WebButton("Login").Click

Set ex=createobject("Excel.Application")
Set a=ex.workbooks.open("D:\1.xls")
Set b=a.worksheets("Sheet1")
Dim login
For i=1 to 5
login="UserName: "&b.Cells(i,"A").value
msgbox login
Next
Browser("AutoPallet/AutoLoader™").Page("AutoPallet/AutoLoader™").WebEdit("liUSR").Set "admin"
dim pwd
For i=1 to 5
pwd="Password: "&b.Cells(i,"B").value
msgbox pwd
Next
Browser("AutoPallet/AutoLoader™").Page("AutoPallet/AutoLoader™").WebButton("Login").Click
(20)Counts the value from Excelsheet(initially create a excelsheet with Value)
DataTable.Import("c:\1.xls")
DataTable.SetCurrentRow("1")
For login_id=1 to 3
a=DataTable.Value("login_id")
msgbox a
DataTable.SetNextRow
Next



(21)Creating a Notpad and Write some data

Set f=createobject("scripting.filesystemobject")
Set f1=f.createtextfile("c:/file1.txt")
f1.writeline"aaa bbb"
f1.writeline"ccc ddd"
f1.writeline"eee fff"
f1.writeline"ggg hhh"
f1.writeline"iii jjj"
(22)Display Random Number

x=randomnumber.Value(0,100)
msgbox(x)
(23)Creating a Folder

Set obj=createobject ("scripting.filesystemobject")
Set notepad=obj.createfolder("c:\abc")
(24)Time out Messagebox

Set a=createobject("wscript.shell")
msgbox_message="Message Box will close by itself in 10seconds so dont click on OK button"
msgbox_time="10"
msgbox_title="Testing"
a.popup msgbox_message,msgbox_time,msgbox_title
(25)Value taken from Excel Sheet without Importing

path_of_Excel = "c:\1.xls"
sheet_of_Excel = "sheet1"
row_of_Excel = 1
column_of_Excel = 1
Function value_from_Excel(Excel_path,esheet,erow,ecolumn)
Set excel_object = createobject("Excel.Application")
excel_object.workbooks.open Excel_path
Set my_sheet = excel_object.sheets.item(esheet)
value= my_sheet.cells(erow,ecolumn)
excel_object.application.quit
value_from_Excel=Value
End Function
msgbox value_from_Excel(path_of_Excel, sheet_of_Excel, row_of_Excel ,column_of_excel)
(26)Passing Value From Datatable to Notepad(intialy create a notepad)

Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Sync
Window("Notepad").Activate
Window("Notepad").Move 352,319
Window("Notepad").WinEditor("Edit").Type "a"
Window("Notepad").WinEditor("Edit").Type micReturn
rc = DataTable.Value("A",dtGlobalSheet)
msgbox rc
Window("Notepad").WinEditor("Edit").SetCaretPos 0,0
Window("Notepad").WinEditor("Edit").Type rc
(27) To Get the Background Color

Var=Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Object.bgcolor
msgbox Var

(28)Create and Store Data into Simple XML File

Set doc = XMLUtil.CreateXML( )
doc.CreateDocument "Values"
Set root = doc.GetRootElement( )
root.AddChildElementByName "variable",""
Set node=root.ChildElements()
Set node=node.item(node.count)
node.AddChildElementByName "name","601A4"
doc.SaveFile "e:\data.xml"
(29)PLSQL Procedure(PLEASE CHECK)
http://www.qaforums.com/cgi-bin/forums/ultimatebb.cgi?ubb=next_topic;f=20;t=006805;go=newer

Public Function sqlRunStoredProcedure (sSProcName, sParameter1, sParameter2, sParameter3)
Set oADO_CMD = CreateObject("ADODB.Command") ' Create the database object
sConnectionStr = Environment("SQL_ConnectionStr") 'Get connection string
oADO_CMD.ActiveConnection = sConnectionStr ' Activate the connection
oADO_CMD.CommandType = 4 ' Set the command type to Stored Procedures
oADO_CMD.CommandText = sSProcName ' Set the command type to Stored Procedures
oADO_CMD.Parameters.Refresh ' Define Parameters for the stored procedure
If "" <> sParameter1 Then
oADO_CMD.Parameters(1).Value = sParameter1 ' Pass FIRST input value [optional]
If "" <> sParameter2 Then
oADO_CMD.Parameters(2).Value = sParameter2 ' Pass SECOND input value [optional]
If "" <> sParameter3 Then
oADO_CMD.Parameters(3).Value = sParameter3 ' Pass THIRD input value [optional]
End If
End If
End If
oADO_CMD.Execute() ' Execute the stored procedure
Set oADO_CMD = Nothing 'Clean up objects
End Function





(30)Creating Perfect XML

Dim objWriter,XmlWriter
Set objWriter = DotNetFactory.CreateInstance("System.Xml.XmlWriter","System.Xml")
set XmlWriter=objWriter.Create("e:\Desktop1234.xml")
XmlWriter.WriteStartElement("Books")
XmlWriter.WriteStartElement("Author")
XmlWriter.WriteAttributeString "Name","“Mohan"
XmlWriter.WriteEndElement()
XmlWriter.WriteStartElement("Title")
XmlWriter.WriteAttributeString "Title1","QTP"
XmlWriter.WriteEndElement()
XmlWriter.WriteFullEndElement()
XmlWriter.close()
Set objWriter =Nothing
(31)Simple creating a file and Read the File

Set oFile = DotNetFactory.CreateInstance("System.IO.File")
oFile.WriteAllText "e:\Test.txt","DotNetFactory works great!!"
strContents = oFile.ReadAllText("e:\Test.txt")
MsgBox strContents,,"File Contents"
Set oFile = Nothing

(32) To get count,names of all open browsers and to close them.

Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 21,11
Set b=Description.Create
b("micclass").value="Browser"
Set obj=Desktop.ChildObjects(b)
msgbox obj.count
For i=0 to obj.count-1
c=obj(i).getroproperty("name")
msgbox(c)
obj(i).Close
Next
(33) To Search Particular Value in a Excel Sheet

Set appExcel = CreateObject("Excel.Application")
appExcel.visible=true
Set objWorkBook = appExcel.Workbooks.Open ("c:\1.xls")
Set objSheet = appExcel.Sheets("Sheet1")
With objSheet.UsedRange
Set c = .Find ("user1")
For each c in objSheet.UsedRange
If c="user1" then
c.Interior.ColorIndex = 38
End If
Set c = .FindNext(c)
next
End With

'objWorkBook.save
'objWorkBook.close
'set appExcel=nothing
(34)To OpenFileDialogBox

Set fd=DotNetFactory.CreateInstance("System.Windows.Forms.OpenFileDialog","System.Windows.Forms")
fd.Filter="txt files (*.txt)|*.txt |All files (*.*) |*.*"
fd.FilterIndex=2
fd.ShowDialog()
msgbox fd.FileName
(35) Script for copying a file from One Folder to Another Folder in QTP

Dim f
Set f = CreateObject("Scripting.FileSystemObject")
f.CopyFile "C:\1.xls", "E:\"
Msgbox "File Copied"


(36) The code to copy the contents of a sheet in one excel to another excel sheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("C:\1.xls")
Set objWorkbook2= objExcel.Workbooks.Open("C:\2.xls")
objWorkbook1.Worksheets("Sheet1").UsedRange.Copy
objWorkbook2.Worksheets("Sheet1").Range("A1").PasteSpecial Paste =xlValues
objWorkbook1.save
objWorkbook2.save
'objWorkbook1.close
'objWorkbook2.close
set objExcel=nothing
(37) Comparing two Excel Sheets

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("C:\1.xls")
Set objWorkbook2= objExcel.Workbooks.Open("C:\2.xls")
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
cell.Interior.ColorIndex = 3
Else
cell.Interior.ColorIndex = 0
End If
Next
set objExcel=nothing
(38) Logon Session Information

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_LogonSession")
For Each objItem in colItems
MsgBox "Authentication Package: " & objItem.AuthenticationPackage
MsgBox "Logon ID: " & objItem.LogonId
MsgBox "Logon Type: " & objItem.LogonType
MsgBox "Start Time: " & objItem.StartTime
Next



(39) List the File System Type

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
MsgBox "Device ID: "& vbTab & objDisk.DeviceID
MsgBox "File System: "& vbTab & objDisk.FileSystem
Next
(40) List a Specific Set of Files

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where FileSize > 1000000")
For Each objFile in colFiles
MsgBox objFile.Name & " -- " & objFile.FileSize
Next
(41) List Detailed Summary Information for a File

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("E:\rec")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrHeaders(13)
For i = 0 to 13
arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
For i = 0 to 13
If i <> 9 then
MsgBox arrHeaders(i) _
& ": " & objFolder.GetDetailsOf (strFileName, i)
End If
Next
Next
(42) List Summary Information for a Set of Files
Const FILE_NAME = 0
Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("C:\Work BPO")
For Each strFileName in objFolder.Items
MsgBox "File name: " & objFolder.GetDetailsOf _
(strFileName, FILE_NAME)
Next
(43) Compress a Folder
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c: \\new'")
For Each objFolder in colFolders
errResults = objFolder.Compress
Next

 

QTP Scripts


 Verify Login Boundary
(Check all the boundary conditions of the Login dialog box. Checks to see if the correct message appears in the error window (Flight Reservation Message)

ApplicationDir = Environment("ProductDir")
ApplicationPath = "\samples\flight\app\flight4a.exe"

If Window("Flight Reservation").Exist( Then
Window("Flight Reservation").Close
SystemUtil.Run ApplicationDir & ApplicationPath
Elseif Not Dialog("Login").Exist( Then
SystemUtil.Run ApplicationDir & ApplicationPath
End If
Dialog("Login").WinEdit("Agent Name:").Set Datatable.Value ("AgentName",dtGlobalSheet)
 Dialog("Login").WinEdit("Password:").Set Datatable.Value ("Password",dtGlobalSheet)
 Dialog("Login").WinButton("OK").Click
 If Dialog("Login").Dialog("Flight Reservations").Exist( and Datatable.Value ("Status",dtGlobalSheet)="Fail" Then
 Dialog("Login").Dialog("Flight Reservations").Static("Agent name must be at").Check CheckPoint("Agent name must be at least 4 characters long.")
 Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
 Elseif Window("Flight Reservation").Exist(and Datatable.Value ("Status",dtGlobalSheet)="Pass" Then
 Reporter.ReportEvent PASS,"Login: ","Succeeded"
 Else
 Reporter.ReportEvent Fail,"Login: ","Combination #" & Datatable.GetCurrentRow & " was not according to Excel file"
 End If

 Verify Cancel Operation
(in Login Dialog box, if user selects cancel button, before enter any data after enter data dialog box should be disappeared.)

Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinButton("Cancel").Click
If Dialog("Login").Exist ( =True Then
Reporter.ReportEvent 1,"sd","Fail"
Else
Reporter.ReportEvent 0,"sd","Pass"
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinButton("Cancel").Click
If Dialog("Login").Exist ( =True Then
Reporter.ReportEvent 1,"sd","Fail"
Else
Reporter.ReportEvent 0,"sd","Pass"
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4a993af45dcbd506c8451b274d2da07b38ff5531"
Dialog("Login").WinButton("Cancel").Click
If Dialog("Login").Exist (=True Then
Reporter.ReportEvent 1,"sd","Fail"
Else
Reporter.ReportEvent 0,"sd","Pass"
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4a993af45dcbd506c8451b274d2da07b38ff5531"
Dialog("Login").WinButton("OK").Click

 Verify Addition, Subtraction, Multiplication and Division Operations in Calculator Application.

Dim aRes,sRes,dRes,mRes
VbWindow("VbWindow").Activate
VbWindow("VbWindow").VbEdit("VbEdit").Set "10"
VbWindow("VbWindow").VbEdit("VbEdit_2").Set "20"
v1=VbWindow("VbWindow").VbEdit("VbEdit").GetROProperty ("text")
v2=VbWindow("VbWindow").VbEdit("VbEdit_2").GetROProperty ("text")
VbWindow("VbWindow").VbButton("ADD").Click
aRes=VbWindow("VbWindow").VbEdit("VbEdit_3").GetVisibleText
VbWindow("VbWindow").VbButton("SUB").Click
sRes=VbWindow("VbWindow").VbEdit("VbEdit_3").GetVisibleText
VbWindow("VbWindow").VbButton("MUL").Click
mRes=VbWindow("VbWindow").VbEdit("VbEdit_3").GetVisibleText
VbWindow("VbWindow").VbButton("DIV").Click
dRes=VbWindow("VbWindow").VbEdit("VbEdit_3").GetVisibleText
v1=cdbl(v
v2=cdbl(v
aRes=cdbl (aRes)
sRes=cdbl (sRes)
mRes=cdbl (mRes)
dRes=cdbl (dRes)
If aRes=v1+v2 Then
Reporter.ReportEvent 0,"Res","Addition Passed"
else
Reporter.ReportEvent 1,"Res","Addition Failed"
End If
If sRes=v1-v2 Then
Reporter.ReportEvent 0,"Res","Subtraction Passed"
else
Reporter.ReportEvent 1,"Res","Subtraction Failed"
End If
If mRes=v1*v2 Then
Reporter.ReportEvent 0,"Res","Multiplecation Passed"
else
Reporter.ReportEvent 1,"Res","Multiplecation Failed"
End If
If dRes=v1/v2 Then
Reporter.ReportEvent 0,"Res","Division Passed"
else
Reporter.ReportEvent 1,"Res","Division Failed"
End If

 Verify state of Update Order Button, before open an Order and after open an Order (in Flight Reservation before opening an order Update Order button should be disabled after opening an order enabled.)

 Option explicit
 Dim bo,ao
 If Not window("Flight Reservation").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 Dialog("Login").Activate
 Dialog("Login").WinEdit("Agent Name:").Set "Gcreddy"
 Dialog("Login").WinEdit("Password:").SetSecure "4aa8bce9984f1a15ea187a2da5b18c545abb01cf"
 Dialog("Login").WinButton("OK").Click
 End If
Window("Flight Reservation").Activate
bo=Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled")
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "1"
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
ao=Window("Flight Reservation").WinButton("Update Order").GetROProperty ("Enabled")
If bo=False Then
Reporter.ReportEvent 0,"Res","Update Order Button Disabled"
else
Reporter.ReportEvent 1,"Res","Update Order Button Enabled"
End If
If ao=True Then
Reporter.ReportEvent 0,"Res","Update Order Button Enabled"
else
Reporter.ReportEvent 1,"Res","Update Order Button Disabled"
End If

 Price Consistency, In Flight Reservation (In Flight Reservation, First class price=3*Economy class price and Business class price=2*Economy class price)
 Option explicit
 Dim n,f,b,e
 If Not window("Flight Reservation").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 Dialog("Login").Activate
 Dialog("Login").WinEdit("Agent Name:").Set "asdf"
 Dialog("Login").WinEdit("Password:").SetSecure "4aa8b7b7c5823680cfcb24d30714c9bbf0dff1eb"
 Dialog("Login").WinButton("OK").Click
 End If
For n= 1 to 10 step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set n
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Window("Flight Reservation").WinRadioButton("First").Set
f=Window("Flight Reservation").WinEdit("Price:").GetVisibleText
Window("Flight Reservation").WinRadioButton("Business").Set
b=Window("Flight Reservation").WinEdit("Price:").GetVisibleText
Window("Flight Reservation").WinRadioButton("Economy").Set
e=Window("Flight Reservation").WinEdit("Price:").GetVisibleText
f=cdbl(mid(f,2,len (f-))
b=cdbl(mid(b,2,len (b-))
e=cdbl(mid(e,2,len (e-))
If f=3*e and b=2*e Then
Reporter.ReportEvent 0,"Res","Pricy Consistancy is there"
else
Reporter.ReportEvent 1,"Res","Pricy Consistancy is NOT there"
End If
Window("Flight Reservation").WinButton("Button_2").Click
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("No").Click
Next

 Verify Total, In Flight Reservation (In Flight Reservation, Total = Tickets * Price)

 Option Explicit
 Dim t,p,tot,n
 For n= 1 to 10 step 1
 If Not window("Flight Reservation").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
 Dialog("Login").Activate
 Dialog("Login").WinEdit("Agent Name:").Set "Gcreddy"
 Dialog("Login").WinEdit("Password:").SetSecure "4aa892d62c529f1c23298175ad78c58f43da8e34"
 Dialog("Login").WinButton("OK").Click
End If
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set n
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
t=Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText
p=Window("Flight Reservation").WinEdit("Price:").GetVisibleText
tot=Window("Flight Reservation").WinEdit("Total:").GetVisibleText
t=cdbl (t)
p=Cdbl(mid(p,2,len (p-))
tot=Cdbl(mid(tot,2,len (tot-))
If tot=t*p Then
Reporter.ReportEvent 0,"Res","Calculation Passed"
else
Reporter.ReportEvent 1,"Res","Calculation Failed"
End If
Next

 Verify Flight From & Flight To Combo Boxes (In Flight reservation, select an item from Fly From: combo box and verify weather that item available or not in Fly To: combo box, like this select all items one by one in Fly From and verify weather selected items available or not in Fly To.)

 Option explicit
 Dim qtp,flight_app,f,t,i,j,x,y
 If Not Window("text:=Flight Reservation").Exist (= True Then
 QTP=Environment("ProductDir")
 Flight_app="\samples\flight\app\flight4a.exe"
 SystemUtil.Run QTP & Flight_app
 Dialog("text:=Login").Activate
 Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "asdf"
 Dialog("text:=Login").WinEdit("attached text:=Password:").SetSecure "4aa5ed3daf680e7a759bee1c541939d3a54a5b65"
Dialog("text:=Login").WinButton("text:=OK").Click
End If
Window("text:=Flight Reservation").Activate
Window("text:=Flight Reservation").WinButton("window id:=6").Click
Window("text:=Flight Reservation").ActiveX("acx_name:=MaskEdBox","window id:=0").Type "090910"
f=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").GetItemsCount
For i= 0 to f-1 step 1
Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").Select (i)
x=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").GetROProperty ("text")
t=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:","x:=244","y:=147").GetItemsCount
For j= 0 to t-1 step 1
Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:","x:=244","y:=147").Select (j)
y=Window("text:=Flight Reservation").WinComboBox("attached text:=Fly To:","x:=244","y:=147").GetROProperty ("text")
If x <> y Then
Reporter.ReportEvent 0,"Res","Test Passed"
Else
Reporter.ReportEvent 1,"Res","Test Failed"
End If
Next
Next

 Verify Order No Entry in Flight Reservation. (In Open Order dialog box, Order No object accepts numeric values only.)

 If Not window("Flight Reservation").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 Dialog("Login").Activate
 Dialog("Login").WinEdit("Agent Name:").Set "asdf"
 Dialog("Login").WinEdit("Password:").SetSecure "4aa9ccae3bb00962b47ff7fb0ce3524c1d88cb43"
 Dialog("Login").WinButton("OK").Click
 End If
 Window("Flight Reservation").Activate
 Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "a"
ord=Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").GetVisibleText
If ord= "a" Then
Reporter.ReportEvent 1,"Res","Order No Object is taking invalid data"
else
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "1"
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
End If

 Get Test Data from a Flat file and use in Data Driven Testing (through Scripting)

 Dim fso,myfile
 Set fso=createobject("scripting.filesystemobject")
 Set myfile= fso.opentextfile ("F:\gcr.txt",
 myfile.skipline
 While myfile.atendofline <> True
 x=myfile.readline
 s=split (x, ",")
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set s(0)
Dialog("Login").WinEdit("Password:").SetSecure s(
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
Wend

Count, how many Buttons and Edit boxes available in Flight Reservation main window.

 If Not window("Flight Reservation").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 Dialog("Login").Activate
 Dialog("Login").WinEdit("Agent Name:").Set "Gcreddy"
 Dialog("Login").WinEdit("Password:").Set "mercury"
 Dialog("Login").WinButton("OK").Click
 End If
 Set oDesc = Description.Create()
 oDesc("micclass").Value = "WinButton"
Set Buttons = Window("text:=Flight Reservation").ChildObjects (oDesc)
Num_Buttons = Buttons.Count()
Set oDesc1=Description.Create()
oDesc1("micclass").Value="WinEdit"
Set Editboxes=Window("text:=Flight Reservation").ChildObjects (oDesc
Num_Editboxes= editboxes.count ()
sum= Num_Buttons+Num_Editboxes
Reporter.ReportEvent 2, "Res","Total Buttons: "& Num_Buttons &"Total Edit boxes: "& Num_Editboxes

Verify search options in Open Order Dialog box

(After selecting open order, 3 search options should be enabled and not checked,
After selecting Order No option, other options should be disabled,
After selecting Customer Name, Flight date option enabled and Order No disabled
After selecting Flight date option, Customer Name enabled and Order No disabled)

 If Not window("Flight Reservation").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 Dialog("Login").Activate
 Dialog("Login").WinEdit("Agent Name:").Set "Gcreddy"
 Dialog("Login").WinEdit("Password:").SetSecure "4aa9ed25bc0ebde66ed726ad87d7e991347d8b9c"
 Dialog("Login").WinButton("OK").Click
 End If
 Window("Flight Reservation").Activate
 Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").Activate
oe=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty ("Enabled")
ce=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty ("Enabled")
fe=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty("Enabled")
oc=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty ("Checked")
cc=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty ("Checked")
fc=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty("Checked")
If (oe=true and ce=true and fe=true) and (oc="OFF" and cc="OFF" and fc="OFF") Then
Reporter.ReportEvent 0,"Res","Pass"
else
Reporter.ReportEvent 1,"Res","Fail"
End If
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
ono=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty ("Checked")
If ono="ON" Then
fd=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty ("Enabled")
ono=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty ("Enabled")
fd=false
ono=false
Reporter.ReportEvent 0,"Res","Pass"
else
Reporter.ReportEvent 1,"Res","Fail"
End If
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "OFF"
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"
cn=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty ("Checked")
If cn="ON" Then
ono=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty ("Enabled")
fd=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty ("Enabled")
fd=True
ono=false
Reporter.ReportEvent 0,"Res","Pass"
else
Reporter.ReportEvent 1,"Res","Fail"
End If
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "OFF"
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON"
fd=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").GetROProperty ("Checked")
If fd="ON" Then
ono=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").GetROProperty ("Enabled")
cn=Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").GetROProperty ("Enabled")
cn=True
ono=false
Reporter.ReportEvent 0,"Res","Pass"
else
Reporter.ReportEvent 1,"Res","Fail"
End If

In Login Dialog box, Verify Help message (The message is ‘The password is 'MERCURY')

 If Not Dialog("Login").Exist ( Then
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
 End If
 Dialog("Login").Activate
 Dialog("Login").WinButton("Help").Click
 message=Dialog("Login").Dialog("Flight Reservations").Static("The password is 'MERCURY'").GetROProperty("text")
 If message="The password is 'MERCURY'" Then
 Reporter.ReportEvent 0,"Res","Correct message "&message
 else
Reporter.ReportEvent 1,"Res","Worng message "
End If

Friday, March 19, 2010

 

Identify broken links in QTP

http://www.learnqtp.com/how-to-identify-broken-links-in-qtp/

 

McAfee IPS not compatible with QTP

McAfee comes with a host of security features along with Intrusion Prevention System (IPS).
It seems IPS is not compatible with QuickTest.
If you try to open IE7 while QuickTest is already open, IPS will kill the IE7 process.

Solution: 
Right click on Mcafee icon in taskbar tray
Mcafee Host Intrusion Prevention -> Disable IPS

 

Descriptive Programming

 
  1. Launch Browser.
  2. Check whether the correct browser opened.
  3. Ensure the userName, password edits and the Sign-In button exist.
  4. Set the userName and password and Click Sign-In.
  5. Make sure the browser navigated to the correct page.
 
 
'We will use SystemUtil.Run to launch our target browserSystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com/"
 
If Browser( "title:=Welcome: Mercury Tours" ).Exist( 15 ) Then
   Reporter.ReportEvent micPass, "Step 1- Launch", "Correct browser was launched."
Else
   Reporter.ReportEvent micFail, "Step 1- Launch", "Browser failed to launch."
   ExitTest
End If
 
'Notice the use of the wildcard character belowWith Browser("title:=Welcome:.*").Page("title:=Welcome.*")
   If .WebEdit("name:=userName").Exist(0) Then
      .WebEdit("name:=userName").Set "test"
      If .WebEdit("name:=password").Exist(0) Then
         .WebEdit("name:=password").Set "test"
         If .Image("name:=login").Exist(0) Then
            .Image("name:=login").Click
         Else
            Reporter.ReportEvent micFail, "Sign-In Button Error", "Button not found."
         End If
      Else
         Reporter.ReportEvent micFail, "Password Edit Error", "EditBox not found."
      End If
   Else
      Reporter.ReportEvent micFail, "UserName Edit Error", "EditBox not found."
   End If
End With
 
Browser( "title:=.*Mercury.*" ).Sync
 
If Browser( "title:=Find a Flight.*" ).Exist( 1 ) Then
   Reporter.ReportEvent micPass, "Login", "Login successful"
Else
   Reporter.ReportEvent micFail, "Login", "Login failed"
End If
 
 
 
*Collected from: http://relevantcodes.com/descriptive-programming-dp-4-creating-a-test-script/ 

Monday, March 15, 2010

 

Smoke Vs Sanity Testing


 

Localization Testing (L10N)

Localization (L10N) is the process of customizing a software application that was originally designed for a domestic market so that it can be released in foreign markets. This process involves translating all native language strings to the target language and customizing the GUI so that it is appropriate for the target market. Depending on the size and complexity of the software, localization can range from a simple process involving a small team of translators, linguists, desktop publishers and engineers to a complex process requiring a Localization Project Manager directing a team of a hundred specialists. Localization is usually done using some combination of in-house resources, independent contractors and full-scope services of a localization company.

Focused on internationalization and localization aspects of software.

Focusses on 3 aspects:

1. UI testing (A. Translated pieces of texts, B. Various 
names and images which are not translated but are different)

2. Functional testing (remains mostly same/similar in 
different languages)

3. Location specific functionalities including key-strokes 
and use of other hardware)

The 1st and 3rd of the above aspects are mainly termed as 
localization testing.


Localization testing checklist:

- Spelling Rules
- Sorting Rules
- Upper and Lower case conversions
- Printers
- Size of Papers

- Operating System
- Key boards
- Text Filters
- Hot keys
- Mouse
- Date formats
- Measurements and Rulers
- Available memory  

- Voice User Interface language/accent
- Video Content


Localization testing of the UI and linguistics should cover items such as:

Sunday, March 14, 2010

 

Agile Testing


Wednesday, March 10, 2010

 

Types of Regression Testing

Types of Regression Testing:
We have following four types of regression testing techniques.
1) Corrective Regression Testing: Corrective regression testing applies when specifications are unmodified and test cases can be reused.
2) Progressive Regression Testing: Progressive regression testing applies when specifications are modified and new test cases must be designed.
3) The Retest-All Strategy: The retest-all strategy reuses all tests, but this strategy may waste time and resources due to execution of unnecessary tests. When the change to a system is minor, this strategy would be rather wasteful.
4) The Selective Strategy: The selective strategy uses a subset of the existing test cases to reduce the retesting cost. In this strategy, a test unit must be rerun if and only if any of the program entities, e.g. functions, variables etc., it covers have been changed. The challenge is to identify the dependencies between a test case and the program entities it covers.

 

Unix practice

For a tester unix knowledge is added advantage.
You can practice unix here:

http://linuxzoo.net/

 

DB practice

For a tester Database knowledge is must.
You can practice My SQL/Oracle/DB2/Postgre SQL / Microsoft SQL Server here:
http://sqlzoo.net/

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]