UFT Tutorial 4

UFT Class 4: VBScript for UFT

Visual Basic Scripting Edition Fundamentals and Features

Vendor: Microsoft

Launched in 1997

It is a lightweight version of VB Programming Language.

> VBScript is not a case sensitive Language

> VBScript is Platform dependent Language.

> VBScript ignores extra spaces.

> No formalities for writing statements.
Usage of VBScript

> Client side and Server side scripting in the Web.

> Network and System Administration.

> Test Automation
1) Comments

> To make the code Readable

> To make the code disable from execution.

2) Data Types

> Check Data sub types

> Convert the data from one type to another.
3) Variables

    Scalar Variables

    Array Variables
* Note: Dictionary Object is equivalent to Associate Array in Perl Script.

Dim a(3)

a(0) = "India"
a(1) = 100
4) Operators

    Arithmetic Operators
    Comparison Operators
    Logical Operators
    Concatenation Operators
Flow Control Statements
    Conditional Statements
    Loop Statements
5) Conditional Statements

    If Statement
    Select Case

Types of Conditions

i) Single condition (Positive/Negative Condition)

If a > b Then

ii) Compound condition (Positive/Negative Condition)

If (a > b) And (a < c) Then

iii) Nested Condition (Positive/Negative Condition)

If a > b Then
 If a > c Then
  If a > d Then
Usage of Conditional Statements in UFT

> To Insert Verification Points

> For Error Handling
Usage of Conditional statements

> Execute a Statement when condition is true

> Execute a block of Statements when condition is true

> Execute a block of Statements when condition is true otherwise executing another block of statements.

> Select among Several alternates (ElseIf)

> Execute a block of Statements when more than one condition is true otherwise execute another block of statements.

> Select among Several alternates (Using Select Case)
6) Loop Statements

    Do While / Until...Loop
    For Each...Next

Repetitive Execution (Parameterization)
7) Procedures / Functions

A Reusable code.

Whenever we want execute a block of statements multiple times then we choose Functions.

2 Types of Functions

i) Built-in Functions

a) Array Functions

b) String Functions

c) Date and Time Functions

d) Conversion Functions

e) Math Functions

f) Miscellaneous Functions

ii) User defined Functions

a) Sub Procedures (Public/Private) (Internal/External)

b) Function Procedures (Public/Private) (Internal/External)
8) Coding conventions


Coding standards in declarations

Dim city, num, fso -without Coding standards

Dim StrCity, intNum, objFso -with Coding standards
Writing Script headers

Writing Function headers

9) Error Handling

Handling expected and unexpected Errors

Expected Error:

Whenever we use invalid input then we can expect errors.

Unexpected Errors:

> Resource Availability

> Resource Response

> Insufficient Data
    Using Conditional Statements
    Using Some built in functions
    Using Option explicit statement
    Using On Error Resume next statement
10) Regular expressions

It is a formula for matching patterns

Constant matching

india.doc - india.doc
Pattern matching   


Apart from formulas Regular Expression Object also there.

Usage of Regular Expressions in UFT

> To handle Dynamic Objects

> For Search operations
11) File System Operations

> What is Computer File System?

It is a feature of Operating System to work with drives, folders and files.

> Examples for File System Operations

Create a Folder, Delete a Folder, Copy a Folder,

Create a Text File, Read data, Write data, Compare data and Search operations etc...

> How End User performs File System Operations?

End user performs File System Operations manually using input devices

> How to conduct automatic File System Operations in VBScript?

Using File System Object

Class Value -("Scripting.FileSystemObject")

> Create File System Object

Set variable = CreateObject("Scripting.FileSystemObject")
12) Excel Application Object

It is used to perform operations on Excel Application /Excel Files.

 Excel Application

 Excel File / Workbook

 Excel Sheet /Worksheet

Class Value -("Excel.Application")
Create Excel file

Write data

Read data

Compare data

Save workbook

Close workbook

13) Word Application Object

It is used to perform operations on Word Application / Word documents

Class Value -("Word.Application")
14) Database object Models

a) Database Connection Object

It is used to connect to a Database (Any database)

Note: Connect String only varies from one database to another.

Class Value: ("Adodb.Connection")
b) Database Recordset Object

It is used to perform operations on Databases tables (Records)

Class Value: ("Adodb.Recordset")
15) Dictionary Object

It is used to define key, value pairs.

Class Value: ("Scripting.Dictionary")

No comments:

Post a Comment