Re-Dim: Handle Exceptions in QTP

Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 12

Hybrid framework

Re- Dim

Option Explicit

Function & Action

Array
db connection

dynamic value
regular expression

handle exceptions in QTP


how to select from cell

variable

GetROProperty
GetTOProperty
SetTOProperty
GetAllROProperties Method

ToString Method

WaitProperty Method
ChildObjects Method
User-Defined Functions

function library

associate the function library


On Error Statement
On Error GoTo 0 

What is Object Repository?

Smart Identification in QTP?

open application

Test Results
import entire Excel file

Cross Browser Testing:

 types of error need to be handle


in UFT

 handle run time errors?

option explicit’ keyword is used in


QTP?
A hybrid framework is a combination of Data Driven Framework (DDF) and Keyword Driven Framework (KDF) where several test cas
with several inputs can be executed in the same test.

The ReDim statement is used to size or resize a dynamic array that has already been formally declared by using a Private, Public, or Dim
statement with empty parentheses (without dimension subscripts).
You can use the Re-Dim statement repeatedly to change the number of elements and dimensions in an array.

Option Explicit to avoid incorrectly typing the name of an existing variable or To avoid confusion in code where the scope of the
variable is not clear.
you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variab
name, an error occurs.

Actions parameters are passed by value only.


Function parameters are passed either by by value or by reference value.
Actions may or may not be reusable. Functions are always reusable
There are three different Action calls present in UFT: 1. Call to copy of action. 2.

Array can be defined in 3 ways in QTP


a) Fixed size array in QTP [ Dim A (10) – single dimension]
Dim MyTable (5,10) – multi-dimension
b) Dynamic array-size not fixed [ Dim MyArray()ReDim MyArray(25)
c) Using Array Function in QTP [ A= Array (10, 20,30) B= A(2) ‘ B is now 30

Set db= createobject (“ADODB.Connection”)


db.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\guru99\vb6\admission_project.mdb;
Persist Security Info= False”
Set rst=createobject(“ADODB.Recordset”)
rst.Open “select*from Course”, db, 3
id=rst. RecordCount
For i=0 to id-1
Print rst.field (0) & rst.fields (1) & rst.fields (2) & rst.fields (3)
rst.Movenext
Next

a. Recovery Scenarios. [1. Triggered Events. , 2. Recovery steps. . 3. Post Recovery Test-Run. ]
b.Using “On Error” statement

Variable is a name assign to a storage area that the program can manipulate. A variable type determines the size and layout of the
variable’s memory.
Local Variable is defined as a type of variable declared within programming block or subroutines. It can only be used inside the
subroutine or code block in which it is declared. The local variable exists until the block of the function is under execution. After that, i
will be destroyed automatically.

A Global Variable in the program is a variable defined outside the subroutine or function. It has a global scope means it holds its value
throughout the lifetime of the program.
returns the current property value of the object in the application during the test run.
returns the value from the test object's description.
changes the property values used to identify an object during the test run.
Returns the collection of properties and current values from the object in the application.
Returns a string that represents the test object.
Retrieve the test object name and type from within a function or keyword.
Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next
step.
Returns the collection of child objects contained within the object.

A function library is a separate document that contains Visual Basic script. Any text file written in standard VBScript syntax can be used
as a function library.
Access their functions during the run session. Public functions stored in function libraries can be called from any associated test or
component, whereas private functions can be called only from within the same function library.
Enables or disables error-handling.
anywhere in your code, any run-time error that occurs can cause an error message to be displayed and code execution stopped.
to disable error handling if you have previously enabled it using On Error Resume Next

Information about the Test Objects is stored in Object Repository


2 Types of Object Repository in QTP
Local Object Repository :It is specific to actions and can be used only for a particular action , Not dynamic & cannot be reused
Shared Object Repository :Global or Shared Object Repository is preferable when an application is dynamic and object description
change frequently
1. Mandatory properties will be stored by default for that object
2. Assistive properties In case during record time of script QTP can NOT create a unique description of the object it will store
the assistive properties
object identification process fails, Micro Focus UFT triggers Smart Identification, which is a more flexible mechanism for identifying
objects provided it is enabled in Object Identification settings.
Smart Identification uses two categories of properties
Base Filter Properties.
1. Optional Filter Properties. Other properties that can help identify objects

SystemUtil.Run "C:\Program Files\HP\samples\flight\app\flight.exe"


Dialog("Login").WinEdit("Agent Name:").Set "Guru"
Reporter.ReportEvent to report custom test steps
You can use results.xml to create an XSL which will present the test results as per your preferences
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
Getrowcount to get number of rows in the sheet
method SetCurrentRow

Using this code Eg. Browser(“Core Values”).GetROProperty(“version”) you can extract the Browser

a) Syntax Errors
b) Logical Errors
c) Runtime Errors

a) Using test settings


b) Using on error statement
c) Using err Object
d) Using Exit Statement
e) Recovery Scenarios
f) Report Object

To specify that all variable must be declared before use in QTP


syntax

Call fnFunction()'.

public int add(){


int a =4; int b=5;
return a+b; }
int a =4; int b=5;
public int add(){
return a+b; }
object.GetROProperty (Property, [PropertyData])

object.GetAllROProperties

object.ToString

object.WaitProperty (PropertyName, PropertyValue, [TimeOut])
object.ChildObjects ([Description])
local /Per-Action repository is “.mtr” .
Global extension .tsr 
Select Resources > Object Repository Manager.

Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

DataTable.Import(FileName)
Datatable.import "D:\Automation\Sales.xls"row = Datatable.getsheet(1).Getrowcount MsgBox row
Datatable.import "D:\Automation\Sales.xls"DataTable.SetCurrentRow(1)
Environment
Environment variables are dynamic in nature, and it can be changed.
Environment variables are those variables that can be used globally in the tests. There are two types of
environment variables
Built-in variables
User-defined variables (Has 2 sub-types)
Internal
External
Array
Dynamic array is possible
Size of array must be set before the use of array
We have to use redim statement before adding extra element
into dynamic array
There is no particular method to release the memory if
particular element is not required
Dictionary
There is no concept of dynamic dictionary
The size of dictionary do not need to be set
To add extra element there is no need to write any
statement.  We just use add method
Element which is not required any longer can be
removed from the dictionary
Parameter Local
Scope It is declared inside a function.
Value If it is not initialized, a garbage value is stored
It is created when the function starts execution and lost
Lifetime when the functions terminate.
Data sharing is not possible as data of the local variable
Data sharing can be accessed by only one function.
Parameters passing is required for local variables to access
Parameters the value in other function

Modification of When the value of the local variable is modified in one


variable value function, the changes are not visible in another function.

Local variables can be accessed with the help of


Accessed by statements, inside a function in which they are declared.
Memory storage It is stored on the stack unless specified.
Global
It is declared outside the function.
If it is not initialized zero is stored as default.
It is created before the program’s global execution starts and lost when
the program terminates.
Data sharing is possible as multiple functions can access the same global
variable.
Parameters passing is not necessary for a global variable as it is visible
throughout the program

When the value of the global variable is modified in one function changes
are visible in the rest of the program.

You can access global variables by any statement in the program.


It is stored on a fixed location decided by the compiler.

You might also like