UFT Tutorial 22

UFT Class 22 (VBScript Comments, Data Types)

I) Comments in VBScript------------------
Comments are English words, we write comments for Code documentation.

> Purpose of Comments:
    To make the code readable
    To make the code disable from execution

> Syntax:

Use Rem command before the statement followed by space.

Use ' symbol before the statement

Dialog("Login").Activate 'abcd xyz eerty
Rem Dialog("Login").WinEdit("Agent Name:").Set "abcd"
'Window("Flight Reservation").Close
> Comment a block of statements

    Select statements and use Shortcut key (Ctrl + M)
Select statements > Edit menu > Format > Comment

> Uncomment

Select Comment block and use Shortcut key (Ctrl + Shift + M)

Select Comment block > Edit menu > Format > Uncomment

> Usage of Comments in UFT Test Automation

a) To write Test headers


'Test Name: Verify the "Total" in Flight Reservation.

'Author: abcd

'Data of Creation: 12th March 2015

'Date of Modification: NA

'Pre-setup and Pre-requisites

'None, Login.tsr, abc.vbs etc...

'Test Flow:
'Launch the Application
'Login to Flight Reservation window
'Open an Order and capture Tickets, Price and Total values
'Covert the data and compare if the Total = Tickets * Price or not?
'Close Flight Reservation Window.

b) To write Function headers

'Function Name: Login

'Author: abcd

'Date of Creation: 12th March 2015

'Purpose: Login to Flight Reservation Application.

'Agent and Password

'Flight Reservation Window

c) To explain the complex logic

d) To write the Automation Resources usage
II) VBScript Data Types
> VBScript doesn't support Explicit declaration of Data Types, only Implicit declaration of Data types.

Note: No data type specification

> VBScript only Data type is Variant, it can hold any type of data


Dim val

val = "London" 'String
val = 100 'Integer
val = "100" 'String
val = 1.23 'Double
val = #10/10/2014# 'Date
> VBScript internally considers Data sub types based on usage of the data

> Using VarType Function user can check the Data sub-types.

> Using Conversion functions (Ex: Cint, Cdbl etc...) user can convert the data from one sub-type to another.

Why we need to convert tha Data.

Whenever we read data then VBScript considers the data as String type data, in order to perform mathematical operations then we need to convert the data.

Assigning values to Variables two types

i) Initialization

a = 100 'Initialization (* No data conversion is required)

ii) Reading (* Data conversion is required)
    from Input devices
    from files
    from databases
    from Application objects

' Without Conversion
Dim num1, num2
num1 = InputBox("Enter Num1 value")
num2 = InputBox ("Enter Num2 value")

Msgbox num1 + num2
'With Data Conversion
Dim num1, num2
num1 = InputBox("Enter Num1 value")
num2 = InputBox ("Enter Num2 value")

Msgbox Cint (num1) + Cint (num2)
1) Check Data Sub types using VarType Function

Types of Result in Computer Programming/Scripting

a) Value based Result

5 + 3 = 8

10^3 = 1000
b) Boolean / Logical Result

Msgbox IsNumeric("UFT") 'False

Msgbox IsNumeric(100) 'True
c) Constant based Result

Msgbox VarType(100) ' 2 for Integer
Dim val
Msgbox VarType(val) '0 for Empty / Uninitialized

val = 100
Msgbox VarType(val) '2 for Integer
Msgbox varType(123) '2 for Integer

val = "abcd"
Msgbox VarType(val) ' 8 for String

val = "100"
Msgbox VarType(val) '8 for string

val = 10.234
Msgbox VarType(val) '5 for Double

val = #10/10/2010#
Msgbox VarType(val) ' 7 for Date

Set val = CreateObject("Scripting.FileSystemObject")
Msgbox VarType(val) '9 for Automation Object
2) Convert the Data from one sub type to another

Note: We can't conver alfabytes into Integer or double sub types.

Example 1:
Dim val, Tickets
val = InputBox ("Entet a value")

Msgbox VarType(val) ' 8 for String

val = Cint(val) 'Cint for converting String type data into Integer sub-type
msgbox VarType(val)

Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text") 

Msgbox VarType(Tickets) '8 for String

Msgbox VarType(Cint (Tickets)) ' 2 for Integer
Exampe 2:

Dim val, Price
val = InputBox ("Entet a value")

Msgbox VarType(val) ' 8 for String

val = Cdbl(val) 'Cdbl Function for converting String type data into Double sub-type
msgbox VarType(val)

Price = Window("Flight Reservation").WinEdit("Price:").GetROProperty("text")
Msgbox VarType(Price) '8 for string

Msgbox VarType(Cdbl(Price)) ' 5 for Double
3) VBScript Variables

What is Variable?

Declaration of Variables

Option explicit Statement

Assigning values to variables

Usage of Variables

Naming restrictions

Scope of Variables

Types of Variables


Post a Comment