UFT Class 33 (Debugging Tests, Database Objects too VBScript Examples)
What is Debugging?
Locating too isolating errors thru Step past times pace execution.
Debugging is optional.
When Debugging is required?
Whenever Test is non showing whatsoever errors too non providing right output.
How to debug?
Using VBScript debug commands too breakpoints.
i) Step into (F11)
a) It starts the execution
b) It executes ane tilt at a time.
c) If it is component call, it opens the component too executes ane component tilt at a time.
-------------------------
ii) Step over (F10)
a) It executes ane tilt at a time.
b) It executes all functions tilt at a time.
iii) Step out (Shift + F11)
------------
a) It executes all remaining component statements at a time
Breakpoint (F9)
Types of Test Execution:
i) At a fourth dimension execution (using Run Command)
ii) Step past times pace execution (Using Debug commands)
iii) Hybrid execution (Using Run command, debug commands too Breakpoints)
------------------------
Ex:
Dim a, b, c
a = 10
b = 20
c = a + b
a = 5
b = 3
c = a ^ b
Call Login("abcd", "mercury")
a = 10
b = 20
c = a - b
a = 5
b = 3
c = a * b
a=100
------------------------------
Database Objects
-----------------
i) Database Connection Object
It is used to connect to a Database (any database)
Create Database Connection Object:
Set Variable = CreateObject("Adodb.Connection")
------------------
ii) Database Recordset Object
It is used to perform operations on database tables.
Create Database Recordset Object:
Set variable = CreateObject("Adodb.Recordset")
-------------------------------------
Generate Connection String for MS Access Database:
Launch Notepad -> Save every 2d udl file -> Click on udl File
-> Select database every 2d MS Access-> OK
Open the File amongst Note Pad -> croak the connective string
Examples:
------------
'Read Test information from a database too perform Data driven Testing for Login operation
Dim objConnection, objRecordset
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")
'Create Connection String for MS Access Database
objConnection.Provider =("Microsoft.ACE.OLEDB.12.0")
objConnection.Open ("C:\Users\G C Reddy\Desktop\testdb.accdb")
objRecordset.Open "Select Agent, Password from Login", objConnection
Do Until objRecordset.EOF = True
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objRecordset.Fields("Agent")
Dialog("Login").WinEdit("Password:").Set objRecordset.Fields("Password")
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
Set objRecordset = Nothing
Set objConnection = Nothing
--------------------------------------------
i) Export information from a database to an excel file
Dim objConnection, objRecordset, objExcel, objWorkbook, objWorksheet
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)
objConnection.Provider = ("Microsoft.ACE.OLEDB.12.0")
objConnection.Open "C:\Users\G C Reddy\Desktop\testdb.accdb"
objRecordset.Open "Select Agent, Password from Login", objConnection
objWorksheet.Cells(1, 1) = "Agent"
objWorksheet.Cells(1, 2) = "Password"
i = 2
Do Until objRecordset.EOF = True
objWorksheet.Cells(i, 1) = objRecordset.Fields("Agent")
objWorksheet.Cells(i, 2) = objRecordset.Fields("Password")
objRecordset.MoveNext
i= i+ 1
Loop
objWorkbook.Save
objExcel.Quit
objRecordset.Close
objConnection.Close
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
Set objRecordset= Nothing
Set objConnection= Nothing
-------------------------------------------------------
ii) Export information from a database to a text file.
Dim objConnection, objRecordset, objFso, objTextstream
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt", 2)
objConnection.Provider = ("Microsoft.ACE.OLEDB.12.0")
objConnection.Open "C:\Users\G C Reddy\Desktop\testdb.accdb"
objRecordset.Open "Select Agent, Password from Login", objConnection
objTextstream.WriteLine "Agent Password"
Do Until objRecordset.EOF = True
objTextstream.WriteLine objRecordset.Fields("Agent") &", "& objRecordset.Fields("Password")
objRecordset.MoveNext
Loop
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
objRecordset.Close
objConnection.Close
Set objRecordset= Nothing
Set objConnection= Nothing
---------------------------------------
iii) Export information from an excel file to a text file
Dim objFso, objTextstream, objExcel, objWorkbook, objWorksheet, RowCount
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt", 2)
RowCount= objWorksheet.UsedRange.Rows.Count
objTextstream.WriteLine "Agent Password"
For i = ii To RowCount Step 1
objTextstream.WriteLine objWorksheet.Cells(i, 1) &", "& objWorksheet.Cells(i, 2)
Next
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
----------------------------------------------
iv) export information from a text file to an excel file.
--------------------------------------------
Dim objFso, objTextstream, objExcel, objWorkbook, objWorksheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt")
objTextstream.SkipLine
objWorksheet.Cells(1, 1) = "Agent"
objWorksheet.Cells(1, 2) = "Password"
i = 2
Do While objTextstream.AtEndOfStream = False
myLine = objTextstream.ReadLine
myField = Split(myLine, ", ")
objWorksheet.Cells(i, 1) = myField(0)
objWorksheet.Cells(i, 2) = myField(1)
i = i + 1
Loop
objWorkbook.Save
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
-----------------------------------------
Assignments:
i) Export information from Excel file to database
ii) Export information from Text file to database
-------------------------------------------
What is Debugging?
Locating too isolating errors thru Step past times pace execution.
Debugging is optional.
When Debugging is required?
Whenever Test is non showing whatsoever errors too non providing right output.
How to debug?
Using VBScript debug commands too breakpoints.
i) Step into (F11)
a) It starts the execution
b) It executes ane tilt at a time.
c) If it is component call, it opens the component too executes ane component tilt at a time.
-------------------------
ii) Step over (F10)
a) It executes ane tilt at a time.
b) It executes all functions tilt at a time.
iii) Step out (Shift + F11)
------------
a) It executes all remaining component statements at a time
Breakpoint (F9)
Types of Test Execution:
i) At a fourth dimension execution (using Run Command)
ii) Step past times pace execution (Using Debug commands)
iii) Hybrid execution (Using Run command, debug commands too Breakpoints)
------------------------
Ex:
Dim a, b, c
a = 10
b = 20
c = a + b
a = 5
b = 3
c = a ^ b
Call Login("abcd", "mercury")
a = 10
b = 20
c = a - b
a = 5
b = 3
c = a * b
a=100
------------------------------
Database Objects
-----------------
i) Database Connection Object
It is used to connect to a Database (any database)
Create Database Connection Object:
Set Variable = CreateObject("Adodb.Connection")
------------------
ii) Database Recordset Object
It is used to perform operations on database tables.
Create Database Recordset Object:
Set variable = CreateObject("Adodb.Recordset")
-------------------------------------
Generate Connection String for MS Access Database:
Launch Notepad -> Save every 2d udl file -> Click on udl File
-> Select database every 2d MS Access-> OK
Open the File amongst Note Pad -> croak the connective string
Examples:
------------
'Read Test information from a database too perform Data driven Testing for Login operation
Dim objConnection, objRecordset
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")
'Create Connection String for MS Access Database
objConnection.Provider =("Microsoft.ACE.OLEDB.12.0")
objConnection.Open ("C:\Users\G C Reddy\Desktop\testdb.accdb")
objRecordset.Open "Select Agent, Password from Login", objConnection
Do Until objRecordset.EOF = True
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe”
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objRecordset.Fields("Agent")
Dialog("Login").WinEdit("Password:").Set objRecordset.Fields("Password")
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
Set objRecordset = Nothing
Set objConnection = Nothing
--------------------------------------------
i) Export information from a database to an excel file
Dim objConnection, objRecordset, objExcel, objWorkbook, objWorksheet
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)
objConnection.Provider = ("Microsoft.ACE.OLEDB.12.0")
objConnection.Open "C:\Users\G C Reddy\Desktop\testdb.accdb"
objRecordset.Open "Select Agent, Password from Login", objConnection
objWorksheet.Cells(1, 1) = "Agent"
objWorksheet.Cells(1, 2) = "Password"
i = 2
Do Until objRecordset.EOF = True
objWorksheet.Cells(i, 1) = objRecordset.Fields("Agent")
objWorksheet.Cells(i, 2) = objRecordset.Fields("Password")
objRecordset.MoveNext
i= i+ 1
Loop
objWorkbook.Save
objExcel.Quit
objRecordset.Close
objConnection.Close
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
Set objRecordset= Nothing
Set objConnection= Nothing
-------------------------------------------------------
ii) Export information from a database to a text file.
Dim objConnection, objRecordset, objFso, objTextstream
Set objConnection = CreateObject("Adodb.Connection")
Set objRecordset = CreateObject("Adodb.Recordset")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt", 2)
objConnection.Provider = ("Microsoft.ACE.OLEDB.12.0")
objConnection.Open "C:\Users\G C Reddy\Desktop\testdb.accdb"
objRecordset.Open "Select Agent, Password from Login", objConnection
objTextstream.WriteLine "Agent Password"
Do Until objRecordset.EOF = True
objTextstream.WriteLine objRecordset.Fields("Agent") &", "& objRecordset.Fields("Password")
objRecordset.MoveNext
Loop
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
objRecordset.Close
objConnection.Close
Set objRecordset= Nothing
Set objConnection= Nothing
---------------------------------------
iii) Export information from an excel file to a text file
Dim objFso, objTextstream, objExcel, objWorkbook, objWorksheet, RowCount
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt", 2)
RowCount= objWorksheet.UsedRange.Rows.Count
objTextstream.WriteLine "Agent Password"
For i = ii To RowCount Step 1
objTextstream.WriteLine objWorksheet.Cells(i, 1) &", "& objWorksheet.Cells(i, 2)
Next
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
----------------------------------------------
iv) export information from a text file to an excel file.
--------------------------------------------
Dim objFso, objTextstream, objExcel, objWorkbook, objWorksheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\G C Reddy\Desktop\abc.xlsx")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objfso.OpenTextFile("C:\Users\G C Reddy\Desktop\xyz.txt")
objTextstream.SkipLine
objWorksheet.Cells(1, 1) = "Agent"
objWorksheet.Cells(1, 2) = "Password"
i = 2
Do While objTextstream.AtEndOfStream = False
myLine = objTextstream.ReadLine
myField = Split(myLine, ", ")
objWorksheet.Cells(i, 1) = myField(0)
objWorksheet.Cells(i, 2) = myField(1)
i = i + 1
Loop
objWorkbook.Save
objExcel.Quit
Set objWorksheet= Nothing
Set objWorkbook= Nothing
Set objExcel= Nothing
objTextstream.Close
Set objTextstream = Nothing
Set objFso = Nothing
-----------------------------------------
Assignments:
i) Export information from Excel file to database
ii) Export information from Text file to database
-------------------------------------------