Friday, June 27, 2014

QTP Functions- Part 1

EXIT Statements
The following are the exit statements used in different scenarios,

  1. ExitTest
  2. ExitTestIteration
  3. ExitAction
  4. ExitActionIteration
  5. ExitComponent
  6. ExitComponentEx
  7. ExitComponentIteration
ExitTest:

Exits the entire UFT test or ALM business process test, regardless of the run-time iteration settings.

Syntax:
ExitTest[(Return Value)]

Argument:  Return Value
Type: Variant
Description: Optional. The Return Value.

Example:

Result = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("username").Check (CheckPoint("username") )
If Result = False Then
ExitTest
End If
The above test exits if the checkpoint on the username edit box fails.

ExitTestIteration:

Exits the current iteration of the UFT test or ALM business process test and proceeds to the next iteration, or exits the test run if there are no additional run-time parameter iterations.

Syntax
ExitTestIteration [(RetunValue)]

Argument : RetunValue
Type : Variant
Description : Optional. The return value.

Example:

Result = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Check ( CheckPoint("userName") )
If Result = False Then
ExitTestIteration
End If

The above example uses the ExitTestIteration statement to end the test run if a checkpoint on the userName edit box fails

ExitAction:

Exits the current action, regardless of its local (action) iteration attributes. The ExitAction statement and its return value are displayed in the Run Results.

Syntax
ExitAction[(ReturnValue)]

Argument : ReturnValue
Type : Variant
Description: Optional. The action's return value. The value can be a string or number, but it must be a constant value. It cannot be the name of a variable. The value is returned to the statement that called the action.

Example:

' Action "CheckForm"
FormVersion = RunAction("GetFormVersion", oneIteration)
If FormVersion = 2 Then
Call RunAction("CheckOldForm", oneIteration)
Else
Call RunAction("CheckNewForm", oneIteration)
End If
' Action "GetFormVersion"
If IsNewForm Then
ExitAction(2)
Else
ExitAction(1)
End If

In the above example,the CheckForm action calls the GetFormVersion action. The GetFormVersion action checks whether the form is in the new version or the old version. If IsNewForm is True, then the action uses the ExitAction function to return the value 2. If IsNewForm is False, then the action uses the ExitAction function to return the value 1. The CheckForm action stores the value returned by the ExitAction statement in the FormVersion variable, and uses it in the following steps.

ExitActionIteration:

Exits the current iteration of the action. The ExitActionIteration statement and its return value are displayed in the Run Results. Using this statement overrides other end-of-iteration settings.

Syntax
ExitActionIteration[(ReturnValue)]

Argument : ReturnValue
Type : Variant
Description : Optional. The action iteration's return value. The return value is displayed in the run results.

Example

Name = DataTable("Name", dtLocalSheet)
If Name = "Ram" Then ExitActionIteration("Skipping Ram")

The above example uses the ExitActionIteration function to stop running the current action iteration when the value in the current row of the Name column in the action's data sheet is Ram.


Instr Function:

Instr-Returns the first occurrence of one string in another string.

Syntax:

Instr(start, string 1,string 2,compare)

strat: starting position for each search and its optional.
string1: string being searched and its mandatory argument
string2: string searched for in string 1 and its mandatory argument.
compare-it’s a numeric value indicating the type of comparison.

Compare argument can have the following values,

0-for binary comparison
1-for text comparison


Instr function returs the following values,

0 -if string1 is zerolenth
Null- if string1 is null
Start position-if string2 is zero length
Null-if string2 is Null
0-if string2 is not found
Postion at which string is found-if string2 is found within string1
0-if start>len(string2)

Example:

Dim string1, string2, Result
string1="Quick Test Professional"
string2="Test"
Result=instr(1, string1,string2)

msgbox Result


Output:




1 comment: