VBScript Tutorial


VBScript Tutorial for UFT

I) Introducing VBScript:
> Visual Basic Scripting Edition, It is a light weight language from Microsoft.

> VBScript derived from VB Programming language.

> VBScript is not a case sensitive language.

> No formalities for writing statements.

> It ignores extra spaces.

> It is a platform dependent language.
----------------------------------------
II) Scripting Languages versus Programming Languages
 

a) Scripting Languages:
Example: Shell script, Perl, Java Script, Python, Ruby, Rexx etc...

> No Explicit declaration of Data Types, Ex: Dim a, b, c   

> Scripting Languages are Interpreter based languages.

> Scripting Languages support Explicit and Implicit declaration of Variables.

Example:

Dim a
a = 100 'Explicit variable
b = 200 'Implicit variable
Msgbox a + b

> Limited Support for Application development

> Limited support for UI design.

> Limited support for graphics design.

> Scripting Languages Can be easily integrated with other Technologies.

> Scripting Languages Reduce the code size
----------------
b) Programming Languages:

Example: COBOL, C, C++, Java, VB, VC++, C# etc....   

> Programming Languages support Explicit Declaration of Data types only.

Example:

int a, char b, float c

> Programming Languages are Compiler based Languages.

> Programming Languages support Explicit declaration of Variables only.

> Rich support for Application development.

> Rich support for UI design.

> Rich support for Graphics design.

> Difficult to integrate with other technologies.
> Scripting Languages Increase the code size.                    
-------------------------------------------------------------
III) Usage of VBScript

a) Client side scripting in the Web (HTML) (Browser-IE)

b) Server side scripting in the web (ASP) (Web Server -IIS)

c) Network Administration on Server OS (WSH)

d) System Administration on Client OS or Server OS (WSH)
---------------------------------------
e) Test Automation (UFT) (UFT)
-------------------------------------------
IV) VBScript Fundamentals and Features

1) Adding Comments

Purpose:
    To make the code Readable
    To make the code disable from Execution
------------------------------------
2) Data Types

> No Data type specification in VBScript

> VBScript considers data sub types based on usage of the Data

> using VarType function user can check the data sub types.
----------------------------------------------------
3) Declarations

    a) Constants
    Built in
    User defined

    b) Variables
    Scalar Variables
    Array variables
    * Dictionary object is equilent to Hash variables/ Associated Arrays in Perl Script.
------------------------------------------
4) Operators

Categories of Operators

    a) Arithmetic operators

    b) Comparison operators
   
    c) Logical operators
    ----------------
    * Concatenation operators (Part of Arithmetic operators)
------------------------------------------------------
5) Conditional Statements
 

a) Types of conditional statements
i) If statement

ii) Select Case statement
--------------
b) Types of conditions
i) Single condition

ii) Compound condition

iii) Nested condition
----------------------------- 

c) Usage of Conditional statements
i) Execute a statement when condition is true / simple if

ii) Execute a block of statements when condition True.

iii) Execute a block of statements when condition True, otherwise execute another block
of statements.

iv) Decide among several alternates (Elseif)

v) Execute a block of statements when more than one condition is True (Nested If)

vi) Decide among several alternates (Using select Case)
------------------
d) Purpose of Conditional statements in UFT

i) To insert verification points
ii) Error handling
--------------------------------------------------------
6) Loop Statements

a) For...Next

b) While...Wend

c) Do While / Until...Loop

d) For Each...Next

* Using Exit Statement we can terminate the loops.

Note: we can insert Loop statements within conditions and vice versa
----------------------------------------------
7) VBScript Functions
 

> Function is a Reusable code.

> Whenever we want execute same operations multiple times then we prefer functions.

Types of functions

a) Built-in Functions

    i) Array Functions
    ii) String functions
    iii) Date & Time functions
    iv) Conversion functions
    v) I/O Functions
    vi) Math Functions
    vii) Miscellaneous functions

b) User defined Functions
--------------------------
i) Sub Procedures
        Public, Private - Access control
        Internal, External - Usage

ii) Function Procedures

        Public, Private - Access control
        Internal, External - Usage
---------------------------------------------------
8) Coding conventions

Writing comments

Naming conventions etc...

ex:

Dim num, city, Fso 'Without standards

Dim intNum, strCity, objFso -With naming standards
------------------------------------------------------
9) File System Operations

> What is Computer File System?

> Examples for File System Operations

> How end user performs File System Operations

> How to perform automatic File System Operations

Using File System Object we can perform automatic File System Operations

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

Set Variable = CreateObject("Scripting.FileSystemObject")

Set is VBScript statement

CreateObject is Built function
---------------------------------------------
10) Excel Application Operations
Excel Application Object:

It is used to perform operations on Excel Application/Excel files

Class Value for creating Excel Application object - ("Excel.Application")
-----------------------------------------------
11) Word Application operations

Word Application Object

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

Class value for creating Word Application object - ("Word.Application")
-----------------------------------------------------
12) Database operations

a) Database Connection Object

It is used to connect to Databases

Note: Connection string only varies from One Database to another.

Class value for creating database connection object - ("Adodb.Connection")
----------
b) Database Recordset Object

It is used to perform operations on Database Records.

Class value for creating Database Recordset object - ("Adodb.Recordset")
----------------------------------------------
13) Dictionary Object

It is used to define key, value pairs.

Class value - ("Scripting.Dictionary")
------------------------------------------------------------
14) Regular Expressions

Regular Expression - It is a formula for matching patterns

Constant matching -

india.doc - india.doc

Pattern matching

i*.

ia.....
ib..........
.
.
india.doc
-------------------------------------------------------
15) Error Handling

Handling expected and unexpected Errors.

Expected Error:

Whenever we use invalid input then we can expect the Error.

Note: We use Invalid Input for Negative Testing
----------------
Unexpected Error:

Scenarios:

i) Availability of the Resource

ii) Resource Response

iii) Insufficient Resource.
------------------------------

VBScript features for Error Handling:

a) Conditional statements

b) Using some built in Functions

c) Using Exit Statement

d) Using Option explicit statement

e) Using On error Resume Next

Etc...
-----------------------------------------------

0 comments:

Post a Comment