Tuesday 23 October 2012

Data Table Methods



QTP Data Table Methods

(1) 
Add Sheet:
We can use this method to “add” one new sheet to the run time data table.
Syntax: DataTable.AddSheet "sheet name"
Ex: DataTable.AddSheet "gcreddy"

(2) 
Delete Sheet:

We can use this method to “delete” one specified sheet from the Run Time Data table.


Syntax: datatable.DeleteSheet (Sheet_ID)
Ex: datatable.DeleteSheet (3)


(3) 
GetSheetCount


We can use this method to count number of sheets in the run time data table.


Syntax:
datatable.GetSheetCount
msgbox datatable.GetSheetCount

(4) 
GetRowCount


We can use this method to count number of rows in the 1st sheet
(longest column) of the Run time data table.


Syntax: datatable.GetRowCount


Ex: msgbox datatable.GetRowCount

(5) 
GetSheet


We can use this method to return a specified sheet from the Run Time data table.


Syntax: datatable.GetSheet(SheetID)


Ex: msgbox datatable. GetSheet(1).GetRowCount


(6) 
Value

We can use this method to set or get value of cell in the specified parameter and the current row of the Rum time data table.


To set data


Syntax: datatable.Value(Parameter_Name, Sheet_Name) = Value / variable Or

datatable(Parameter_Name, Sheet_Name) = Value / variable


To get data

Syntax: Variable = datatable.Value(Parameter_Name, Sheet_Name) Or

Variable = datatable(Parameter_Name, Sheet_Name)


Ex:

Option explicit Dim a, b, c


a=datatable.Value (1,1) b=datatable.Value (2,1) c=cint(a)+cint(b) datatable.Value (3,1) = c

Note: Default property of Datatable is value

(7) 
SetCurrentRow


We can use this method to take a specified row as current row in the Run Time Datatable (By default it is 1st Row of 1st Sheet)

Syntax: datatable.SetCurrentRow(Row_Number)

g="gcreddy"
datatable.SetCurrentRow (3) datatable.Value (1,1) = g


(8) 
SetNextRow


We can use this method to take the row after the current Row as New Current Row in the Run time data table.


Syntax: datatable.SetNextRow

Ex: g="gcreddy"

datatable.SetCurrentRow (3) datatable.SetNextRow datatable.Value (1,1) = g


(9) 
SetPrevRow

We can use this method to take the row before the current Row as New Current Row in the Run time data table.


Syntax: datatable.SetPrevRow


Ex: g="gcreddy"


datatable.SetCurrentRow (3) datatable.SetPrevRow datatable.Value (1,1) = s


(10) 
Import

We can use this method to import Microsoft Excel File to the Runtime Data Table (Including all sheets)


Syntax: datatable.Import “Path of File”

Ex: datatable.Import “F:\Inputdata.xls”

11) 
ImportSheet 

We can use this method to import a specified sheet of Microsoft Excel Sheet to the Runtime Data table.


Syntax: datatable.ImportSheet “Path of File”, “Source Sheet”, “Destination Sheet”

Ex: datatable.ImportSheet “E:\gcreddy.xls”,3,1

(12) 
Export


We can use this method to export a copy of Run Time Data table to another location (Including all sheets)


Syntax: datatable.Export “Path of File”


Ex: datatable.Export “F:\gcreddy.xls”


13) 
ExportSheet 


We can use this method to export a copy specified sheet of Run Time Data table to the existing or new Excel File.

Syntax: datatable.ExportSheet “Path of File”, “Sheet Name / Source Sheet”


Ex: datatable.ExportSheet “F:\gcreddy.xls”, 2

**********************
Data Driven Testing for Login Operation using Data Table methods


Datatable.AddSheet "Login"
Datatable.ImportSheet "C:\Documents and Settings\gcr\Desktop\gcreddy.xls",1,3
Rows_count=Datatable.GetSheet(3).GetRowCount

For i= 1 to Rows_count
    Datatable.SetCurrentRow(i)
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set Datatable("Agent",3)
Dialog("Login").WinEdit("Password:").Set Datatable("Pwd",3)
Dialog("Login").WinButton("OK").Click

If window("Flight Reservation").exist(10) Then
    Login="Login Operation Successful"
    Datatable("Result",3)=Login
    Reporter.ReportEvent micPass,"res","Passed"
    else
Reporter.ReportEvent micFail,"res","Failed"
Login="Login Operation Failed"
Datatable("Result",3)=Login

Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinButton("Cancel").Click
End If

If Window("Flight Reservation").Exist(3)Then
    Window("Flight Reservation").Close
    End if
Next


Database connections


Database connections

Database connection is a facility in computer science that allows client software to communicate with database server software, whether on the same machine or not.


SQL Server connection strings

SQL ODBC connection strings

Standard Security:

"Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Uid=Your_Username;Pwd=Your_Password;"

Trusted connection:

"Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Trusted_Connection=yes;"
SQL OLE DB connection strings

Standard Security:

"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;"

Trusted connection:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL OleDbConnection .NET strings
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;"

Trusted connection:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL SqlConnection .NET strings
Standard Security:
1. "Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;" < br>2. "Server=Your_Server_Name;Database=Your_Database_Name;UserID=Your_Username;Password=Your_Password;Trusted_Connection=False"

Trusted connection:
1. "Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
2."Server=Your_Server_Name;Database=Your_Database_Name;Trusted_Connection=True;"

MS Access connection strings

MS Access ODBC connection strings
Standard Security:
"Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\App1\Your_Database_Name.mdb;Uid=Your_Username;Pwd=Your_Password;"

Workgroup:
"Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\App1\Your_Database_Name.mdb; SystemDB=C:\App1\Your_Database_Name.mdw;"

Exclusive "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\App1\Your_Database_Name.mdb; Exclusive=1; Uid=Your_Username; Pwd=Your_Password;"
MS Access OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; User Id=admin; Password="

Open connection to Access database using Workgroup (System database):
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:System Database=c:\App1\Your_System_Database_Name.mdw"

Open connection to password protected Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:Database Password=Your_Password"

Open connection to Access database located on a network share:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\Server_Name\Share_Name\Share_Path\Your_Database_Name.mdb"

Open connection to Access database located on a remote server:
"Provider=MS Remote; Remote Server=http://Your-Remote-Server-IP; Remote Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb"


MySQL connection strings

MySQL ODBC connection strings
Open connection to local MySQL database using MySQL ODBC 3.51 Driver
"Provider=MSDASQL; DRIVER={MySQL ODBC 3.51Driver}; SERVER= localhost; DATABASE=Your_MySQL_Database; UID= Your_Username; PASSWORD=Your_Password; OPTION=3"
MySQL OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to MySQL database:
"Provider=MySQLProv;Data Source=Your_MySQL_Database;User Id=Your_Username; Password=Your_Password;"


Oracle connection strings

Oracle ODBC connection strings
Open connection to Oracle database using ODBC
"Driver= {Microsoft ODBCforOracle};Server=Your_Oracle_Server.world;Uid=Your_Username;Pwd=Your_Password;"
Oracle OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to Oracle database with standard security:
1. "Provider=MSDAORA;Data Source= Your_Oracle_Database;UserId=Your_Username;Password=Your_Password;"
2. "Provider= OraOLEDB.Oracle;Your_Oracle_Database;UserId=Your_Username;Password=Your_Password;"

Open trusted connection to Oracle database
"Provider= OraOLEDB.Oracle;DataSource=Your_Oracle_Database;OSAuthent=1;"


AOM Scripting (Automation Object Model)



Object Model:

An object model is a structural representation of software objects (classes) that comprise the implementation of a system or application. An object model defines a set of classes and interfaces, together with their properties, methods and events, and their relationships. 

We can use QTP Automation object Model to write scripts, that automate our QTP operations.

QTP Automation object model provides objects, methods and properties that enable us to control QTP from another application.

We can use Scripting languages or programming languages such as VBscript, Java script or VC++, .Net for automating QTP operations.


Example:
1) Write an AOM Script to launch QTP Tool, Execute Tests and to close the QTP Tool
option explicit
Dim qtApp
Set qtApp=createobject ("Quicktest.Application")
qtApp.Launch
qtApp.visible=True

qtApp.open "C:\Documents and Settings\admin\My Documents\login"
qtApp.Test.Run
qtApp.Test.Close

qtApp.open "C:\Documents and Settings\admin\My Documents\open order"
qtApp.Test.Run
qtApp.Test.Close

qtApp.quit
Set qtApp=Nothing

Note: AOM Script can be used in Automation framework as an Initialization script.
'------------------------------------------------------------------
 
2) Write an AOM script to execute series of tests

Dim objFso,objQtp,myFile,i,gcreddy

Set objQtp = CreateObject("Quicktest.Application")
objQtp.Visible = True
objQtp.Launch

Set objFso =CreateObject("Scripting.FileSystemObject")
Set myFile = objFso.OpenTextFile("C:\Users\Chinni\Desktop\Test\gcreddy.txt")
i =1
Do Until myFile.AtEndOfStream =True
testurl =  myFile.ReadLine

objQtp.Open gcreddy
objQtp.Test.Run
objQtp.Test.Close
i = i+1
Loop

objQtp.Quit
Set objQtp = Nothing
'******************************************
 

Analyzing Test Results & Reporting


Analyzing the Test Result is not a responsibility of QTP. After Running Tests, User (Test Engineer) has to analyze the test result. and send defect reports.

QTP Result Window:

After Running/Executing a test, then QTP Provide result window. we export test result from result window in Document (.Doc), HTML, XML and PDF formats.

Note: QTP doen't provide batch wise test result, if we execute test batches. It provides test wise result only.

Status of the Result:

QTP has 4 types of result status

a) Pass
b) Fail
c) Done
d) Warning
Defining our own Result:
Generally QTP provides, test results, if we use qtp tool features like checkpoints. suppose if we use flow control statements (conditional and Loop statements), then we have to define our own result.

For defining our own results, QTP is providing an utility object called "
Reporter"

by using reporter, we can define our own results.

Syntax:

Reporter.ReportEvent status of the Result,"Result Step","message"

Example"

Reporter.ReportEvent micPass,"Res","Login operation Successful"

exaplanation:

Reporter- Utility object
ReportEvent-Method
micPass-Status of the Result.
Res-Result step
"Login operation Successful"- Message

Status of the Result:

1) Pass -micPass or 0

2) Fail  -micPass or 1

3) Done- micDone or 2

4) Warning- micDone or 3


Adding Comments to Scripts



Comments are statements that are ignored by the script host when the script runs. 

To ensure that the script host does not attempt to interpret a comment as a command, we must preface each comment with a comment delimiter.
 

 VBScript allows two delimiters: the single quotation mark (') and the REM statement.
 

For example, both of the following lines of code are valid comments:

' This is a comment using a single quote delimiter.

REM This is a comment using the REM statement as a delimiter.



Although most script writers use the single quotation mark, you might consider following the single quotation mark with an asterisk when commenting your code:

'* This is another comment.

This approach has two advantages over the single quotation mark alone. First, it makes the comment stand out from the rest of the text; a single quotation mark by itself can be difficult to see at times.
 

Second, the single quotation mark is a valid VBScript character that has uses beyond delimiting comments.
 

This can be a problem if we use an automated procedure to extract comments from a script; such a procedure might also retrieve items that are not comments. Because we are less likely to use '* anywhere else in our script, it makes a good delimiter.

Always include comments on separate lines except for comments that accompany the declaration of a variable.
 

Comments included on the same line as a VBScript statement (end-of-the-line comments) are valid but can be difficult to read.
 

For example, compare the two commenting styles in the following script snippet; in the first half of the script, comments are placed on the same line as a VBScript statement, while in the second half of the script, the comments are placed on separate lines.

Most people find it easier to quickly identify the comments used in the second half of the script.

 -----------------------------------------------

On Error Resume Next
 

Set WshNetwork = WScript.CreateObject("WScript.Network")
 

WshNetwork.MapNetworkDrive "Z:", "\\RemoteServer\Public" '* Map drive Z.
 

If Err.Number <> 0 Then '* Check to make sure the operation succeeded.
   

Err.Clear
   

Wscript.Echo "The drive could not be mapped."
 

End If

'* Map drive Z.
 

WshNetwork.MapNetworkDrive "Z:", "\\RemoteServer\Public"
 
'* Check to make sure the operation succeeded.
 

If Err.Number <> 0 Then
    

Err.Clear
    

Wscript.Echo "The drive could not be mapped."
 

End If
-----------------------------------------------

Code Commenting Conventions

All procedures should begin with a brief comment describing what they do.
 

This description should not describe the implementation details (how it does it) because these often change over time, resulting in unnecessary comment maintenance work, or worse, erroneous comments.
 

The code itself and any necessary inline comments describe the implementation.

Arguments passed to a procedure should be described when their purpose is not obvious and when the procedure expects the arguments to be in a specific range. 


Return values for functions and variables that are changed by a procedure, especially through reference arguments, should also be described at the beginning of each procedure.

Procedure header comments should include the following section headings.
 

Section Heading:

Comment Contents:

Purpose:

Assumptions:

Remember the following points:

Every important variable declaration should include an inline comment describing the use of the variable being declared.

Variables, controls, and procedures should be named clearly to ensure that inline comments are only needed for complex implementation details.

At the beginning of your script, you should include an overview that describes the script, enumerating objects, procedures, algorithms, dialog boxes, and other system dependencies. Sometimes a piece of pseudocode describing the algorithm can be helpful.


QTP Actions



Action: Set of Statements for perfoming a Task(s)
We divide our test into actions to streamline the process of testing.


Purpose of Actions:

For understandability

For reusing components

Types of Actions:

1) Non Re usable actions
2) Re usable actions
3) External actions

Operations on Actions:

• Creating Actions

• Splitting Actions

• Renaming Actions

• Deleting Actions

• Calling an Action

• Copying an Action

• Making an Action Reusable/Non Reusable

Creating an Action:
Insert>call to new action>enter name of the action>click ok
Steps:

1. Create required actions(ex login, insert,delte)
2. Prepare Scripts for those actions.

Splitting an action:

Navigation: Place cursor in desired location>Edit menu>action>split action>Enter Action 1 name & action 2 name.


Steps:

1. Generate total test in the default action
2. Split into meaningful actions.

Note: At a time we can split one actions into 2 actions.

Renaming actions:
Select desired action in action drop down box> edit menu>action>rename action>modify the name>click ok.

Deleting Actions:
Select desired action in action drop down box>edit menu>action>delete action>confirm deletion.

Calling an action:
Insert>call to existing action>browse path of the test>select desired action>click ok.

Note: U can’t edit

Copying an action:
Insert>call to copy of action>browse path of the test>select desired action>click ok.

Note: we can edit this action.

Making an action reusable:
Select Non Reusable action >edit >action>action properties>check reusable action check box >click ok.