VBScript Tutorial for UFT

VBScript Fundamentals & Features
-----------------------------------
i) Comments
    To make the code readable
    To make the code disable from execution
 

ii) Data Types
    Implicit Declaration of Data Types
    Only data type is Variant, VBScript considers data sub types based on usage of data.
Dim x
x= "abcd" 'String type
x = 123 'Integer
x= 1.23 'Double
x #10/10/2010# 'Date
    Check Data sub types using VarType Function
    Data conversion using Conversion functions


iii) Variables
    a) Scalar Variables
    b) Array Variables
    Dictionary object is equal to Associated Arrays / Hash variables in Perl Script

Dim a, b(3)
a =1
b(0) = "India"
b(1) = #10/10/2010#
b(2) = 20
b(3) = 30
Index    Values


iv) Constants
    Built-in constants
    User defined Constants
-------------------------------


v) Operators
    Arithmetic
    Comparison
    Logical
    -------
    Concatenation operators
-----------------------------------------------


vi) Conditional statements
    1) If statement
    2) Select Case
a) Single condition
If a > b Then
b) Compound condition
If a > b And a > c Then
c) Nested Condition
If a > b Then
 If a > c Then
  If a > d Then
---------------

Positive condition

If a > b Then
Negative condition
If Not a = b Then
------------------------
Usage of Conditional statements in UFT Test Automation
1) To insert verification points
2) For Error handling
------------------------------------


vii) Loop Statements
    1) For...Next
    2) While...Wend
    3) Do While / Until...Loop
    4) For Each...Next
------------------------------------


viii) Functions
What is a Function?
It is a Reusable code
    Built-in Functions
    (Array Functions, String Functions, Date & Time Functions, Conversion Functions, I/O Functions, Math Functions and Miscellaneous Functions)
    User defined functions
    Sub Procedures (Public (Internal, External Function), Private)
    Function Procedures (Public (Internal, External Function), Private)
ix) Coding conventions
Writing comments
Declarations
Dim city, num, x
With coding standards
Dim strcity, intnum, objx
----------------------------------------------


X) Regular Expressions
It is a formula for matching patterns
india.doc - india.doc -Constant matching
i*. -
ia...
ib....
ic...
.
.
india.doc
-------------------------------
Usage of Regular Expressions in UFT
a) To handle dynamic objects
b) For search operations
Regular expression Object
-------------------------------------------
 

xi) File System Operations
    What is Computer File System?

    Examples for File System Operations
Create a folder
Copy a folder
Delete a folder
Create a text file
Write data
Read data
Compare data
Search for data
Delete a text file etc...
    How end user performs File System Operations
    How to perform automatic File System Operations using VBScript
    Using File System Object
Object
Property
Method / Operation
Create Automation Object
Syntax:
Set Variable = CreateObject ("ClassValue")
Set - VBScript statement
CreateObject - Built-in Function

Class value for creating File System Object ("Scripting.FileSystemObject")
---------------------------------------
 

xii) Excel Application Object
Excel Application
    Excel File / Excel Work Book
        Excel Sheet / Excel Work sheet
It is used to automate Excel Application Operations
Create Excel
Take Row Count
Take Column count
Read data
Write data
Compare data etc...
------------------------
Class value for creating Excel Application Object ("Excel.Application")
--------------------------------------
 

xiii) Word Application Object
It is used to automate Word Application Operations
Class value for creating Word Application Object ("Word.Application")
-------------------------------------
 

xiv) Database Operations
    a) Database Connection Object
It is used to connect to Databases
Class value for creating Database Connection Object ("Adodb.Connection")
    b) Database Recordset object
It is used to perform operations on Database Tables /Records
Class value for creating Database Recordset Object ("adodb.Recordset")
--------------------------
 

xv) Dictionary object
It is used to define Key, value pairs
Class value for creating Dictionary object ("Scripting.Dictionary")
---------------------------------------------
 

xvi) Error Handling
Handling expected and unexpected errors
    Using Conditional statements and Exist property
    Using some Built-in Functions
    Using Option Explicit statement
    Using Exit Statement
    Using On Error Resume Next statement
---------------------------------------

0 comments:

Post a Comment