UFT Tutorial 22

UFT Class 22 (VBScript Comments, Data Types)



I) Comments inwards VBScript------------------
Comments are English linguistic communication words, nosotros write comments for Code documentation.

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

> Syntax:

Use Rem dominance earlier the disputation followed yesteryear space.

Use ' symbol earlier the statement

Ex:
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 together with utilisation Shortcut commutation (Ctrl + M)
Or
Select statements > Edit card > Format > Comment

> Uncomment

Select Comment block together with utilisation Shortcut commutation (Ctrl + Shift + M)

Or
Select Comment block > Edit card > Format > Uncomment

> Usage of Comments inwards UFT Test Automation

a) To write Test headers

Example:

'*********************************************
'Test Name: Verify the "Total" inwards Flight Reservation.

'Author: abcd

'Data of Creation: twelfth March 2015

'Date of Modification: NA

'Pre-setup together with Pre-requisites

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

'Test Flow:
'Launch the Application
'Login to Flight Reservation window
'Open an Order together with capture Tickets, Price together with Total values
'Covert the information together with 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: twelfth March 2015

'Purpose: Login to Flight Reservation Application.

'Input:
'Agent together with Password

'Output:
'Flight Reservation Window
'*******************************************

c) To explicate the complex logic

d) To write the Automation Resources usage
-----------------------------------------
II) VBScript Data Types
> VBScript doesn't back upwards Explicit proclamation of Data Types, solely Implicit proclamation of Data types.

Note: No information type specification

> VBScript solely Data type is Variant, it tin seat the axe agree whatsoever type of data

Ex:

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 tin seat the axe cheque the Data sub-types.

> Using Conversion functions (Ex: Cint, Cdbl etc...) user tin seat the axe convert the information from ane sub-type to another.

Why nosotros involve to convert tha Data.

Whenever nosotros read information hence VBScript considers the information every bit String type data, inwards club to perform mathematical operations hence nosotros involve to convert the data.

Assigning values to Variables 2 types

i) Initialization

a = 100 'Initialization (* No information 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 inwards Computer Programming/Scripting

a) Value based Result

5 + three = 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
------------------------------------
Ex:
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) ' vii for Date

Set val = CreateObject("Scripting.FileSystemObject")
Msgbox VarType(val) '9 for Automation Object
---------------------------------------
2) Convert the Data from ane 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 information 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 information 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)) ' five 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

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post