UFT Class 21(VBScript Fundamentals in addition to Features)
1) Comments
To brand the code readable
To brand the code disable from execution
2) Data Types VBScript supports implicit annunciation of Data Types.
In VBScript, exclusively information type is Variant.
Using VarType business office nosotros tin dismiss depository fiscal establishment check information sub-type
Ex:
Dim a
a ="abcd"
a = 123
a = 1.23
a = #10/10/2010#
3) Declarations
a) Constants Declaration Built in
User defined
They are used to supersede literal values in addition to they never change
Ex:
Const metropolis = "London", num = 100, myDate = #10/10/2010#
------------------------------
b) Variables Declaration Scalar (It tin dismiss concur unmarried value)
Array (It tin dismiss concur serial values based on size of the Array)
Dictionary object (Associated Array) (User tin dismiss define Key (Index), value pairs
Variable, H5N1 named retention place to shop the data.
Ex:
Dim a, b(3), c(), d(4, 5)
-----------------------------------
4) VBScript Operators
Operators are used to perform Mathematical, Comparison in addition to Logical operations.
i) Arithmetic
ii) Comparison
iii) Logical Operators
---------
Concatenation
----------------------------------
5) Flow Control Statements
a) Conditional Statements
i) If Statement
ii) Select Case Statement
Usage of Conditional Statements inwards UFT Test Automation:
i) To insert verification points
ii) For Error Handling
---------
Types of Conditions
------------------
i) Single status (Positive in addition to Negative conditions)
If a = b Then -Positive Condition
If a <> b Then - Negative Condition
----------------
ii) Compound status (Positive in addition to Negative conditions)
If a > b And a > c Then
iii) Nested Conditions (Positive in addition to Negative conditions)
------------------------------
If a > b Then
If a > c Then
If a > d Then
-----------------------------------------
b) Loop statements
i) For...Next
ii) While...Wend
iii) Do While / Until ...Loop
iv) For Each...Next
------------------------------
6) VBScript FunctionsFunction, H5N1 reusable code.
> Whenever nosotros desire to perform an functioning multiple times hence nosotros prefer functions.
Types of Functions
i) Built inwards Functions Array functions
String functions
Date & Time functions
I/O functions
Conversion functions
Math functions etc...
ii) User defined Functions
Sub Procedures
Public (Internal, External)
Private
Function Procedures
Pubic (Internal, External)
Private
-------------------------------------------
7) Coding Conventions
Dim city, num, FSO - No coding standards
Dim strCity, intNum, objFSO -Coding Standards
---------------------------------------------
8) Regular Expressions
Regular Expression, It is a formula for matching patterns
Constant matching
india.doc - india.doc
------------
Pattern matching
i*.
ia....
ib....
.
.
india.doc
Usage of Regular Expression inwards UFT
To handgrip Dynamic objects
For Search operations
----------------------------------------
9) File System Operations
> What is Computer File System?
It is a characteristic of Operating System used to piece of work amongst Drives, Folders in addition to files.
----------
> Examples for File System Operations
Create a Folder
Copy a Folder
Delete a Folder
Create a Text file
Read data
write data
compare data
search operations etc...
--------------------------
> How halt user performs File System Operations
End user performs File organization operations manually amongst the assistance of Input devices.
-----------------
> How to perform automatic File System Operations
Using FileSystemObject nosotros tin dismiss perform automatic File System Operations.
Ex: VBScript for Creating a Folder:
Dim objFso
Set objFso = CreateObject("Scripting.FileSystemObject")
objFso.CreateFolder "C:\Users\G C Reddy\Desktop\UFT"
----------------------------------------------
> File System object is exclusively for performing operations on Drives, Folders in addition to Flat files
> Using File System Object nosotros tin dismiss practise in addition to delete all types of files(Text, Excel, Word, PDF etc...)
> Using File System Object nosotros tin dismiss Perform all operations on Flat files.
-----------------------------------------------------
Syntax for Creating Automation Object
Set Variable = CreateObject ("Class Value")
Set - VBScript Statement
CreateObject - VBScript Built inwards Function
------------------
Class Value for creating FileSystemObject ("Scripting.FileSystemObject")
-----------------------------------------------------
10) Excel Application Operations
Using Excel Application Object nosotros tin dismiss perform Excel operations
Ex:
Create an excel file
Read data
Write data
Compare data
Rename sheets
Add sheets
Move sheets
etc...
--------------------------
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
i) Database Connection Object
It is used to connect to Databases (Any database, connecter string exclusively varies variety out ane database to another)
Class value for creating Database connecter object- ("Adodb.Connection")
------------
ii) Database Recordset Object
It is used to perform operations on database tables(Records)
Class value for creating Database Recordset object - ("Adodb.Recordset")
----------------------------------------
13) Dictionary Object
It is used to define Key, value pairs.
Class value for creating Dictionary Object - ("Scripting.Dictionary")
----------------------------------------
14) Error Handling inwards VBScript
Handling expected in addition to unexpected Errors
Expected Errors: Whenever nosotros occupation invalid input hence nosotros tin dismiss await Errors.
Why nosotros postulate to occupation Invalid input?
We occupation Invalid Input for Negative Testing.
Unexpected Errors:
Resource Response
Insufficient Resource
Availability of Resource
--------------------------------------
Using Conditional Statements
Using VBScript Built inwards Functions
Using Option explicit statement
Using Exit Statement
Using On Error Resume Next statement
Etc...
-------------------------------
Sumber http://www.gcreddy.com/
1) Comments
To brand the code readable
To brand the code disable from execution
2) Data Types VBScript supports implicit annunciation of Data Types.
In VBScript, exclusively information type is Variant.
Using VarType business office nosotros tin dismiss depository fiscal establishment check information sub-type
Ex:
Dim a
a ="abcd"
a = 123
a = 1.23
a = #10/10/2010#
3) Declarations
a) Constants Declaration Built in
User defined
They are used to supersede literal values in addition to they never change
Ex:
Const metropolis = "London", num = 100, myDate = #10/10/2010#
------------------------------
b) Variables Declaration Scalar (It tin dismiss concur unmarried value)
Array (It tin dismiss concur serial values based on size of the Array)
Dictionary object (Associated Array) (User tin dismiss define Key (Index), value pairs
Variable, H5N1 named retention place to shop the data.
Ex:
Dim a, b(3), c(), d(4, 5)
-----------------------------------
4) VBScript Operators
Operators are used to perform Mathematical, Comparison in addition to Logical operations.
i) Arithmetic
ii) Comparison
iii) Logical Operators
---------
Concatenation
----------------------------------
5) Flow Control Statements
a) Conditional Statements
i) If Statement
ii) Select Case Statement
Usage of Conditional Statements inwards UFT Test Automation:
i) To insert verification points
ii) For Error Handling
---------
Types of Conditions
------------------
i) Single status (Positive in addition to Negative conditions)
If a = b Then -Positive Condition
If a <> b Then - Negative Condition
----------------
ii) Compound status (Positive in addition to Negative conditions)
If a > b And a > c Then
iii) Nested Conditions (Positive in addition to Negative conditions)
------------------------------
If a > b Then
If a > c Then
If a > d Then
-----------------------------------------
b) Loop statements
i) For...Next
ii) While...Wend
iii) Do While / Until ...Loop
iv) For Each...Next
------------------------------
6) VBScript FunctionsFunction, H5N1 reusable code.
> Whenever nosotros desire to perform an functioning multiple times hence nosotros prefer functions.
Types of Functions
i) Built inwards Functions Array functions
String functions
Date & Time functions
I/O functions
Conversion functions
Math functions etc...
ii) User defined Functions
Sub Procedures
Public (Internal, External)
Private
Function Procedures
Pubic (Internal, External)
Private
-------------------------------------------
7) Coding Conventions
Dim city, num, FSO - No coding standards
Dim strCity, intNum, objFSO -Coding Standards
---------------------------------------------
8) Regular Expressions
Regular Expression, It is a formula for matching patterns
Constant matching
india.doc - india.doc
------------
Pattern matching
i*.
ia....
ib....
.
.
india.doc
Usage of Regular Expression inwards UFT
To handgrip Dynamic objects
For Search operations
----------------------------------------
9) File System Operations
> What is Computer File System?
It is a characteristic of Operating System used to piece of work amongst Drives, Folders in addition to files.
----------
> Examples for File System Operations
Create a Folder
Copy a Folder
Delete a Folder
Create a Text file
Read data
write data
compare data
search operations etc...
--------------------------
> How halt user performs File System Operations
End user performs File organization operations manually amongst the assistance of Input devices.
-----------------
> How to perform automatic File System Operations
Using FileSystemObject nosotros tin dismiss perform automatic File System Operations.
Ex: VBScript for Creating a Folder:
Dim objFso
Set objFso = CreateObject("Scripting.FileSystemObject")
objFso.CreateFolder "C:\Users\G C Reddy\Desktop\UFT"
----------------------------------------------
> File System object is exclusively for performing operations on Drives, Folders in addition to Flat files
> Using File System Object nosotros tin dismiss practise in addition to delete all types of files(Text, Excel, Word, PDF etc...)
> Using File System Object nosotros tin dismiss Perform all operations on Flat files.
-----------------------------------------------------
Syntax for Creating Automation Object
Set Variable = CreateObject ("Class Value")
Set - VBScript Statement
CreateObject - VBScript Built inwards Function
------------------
Class Value for creating FileSystemObject ("Scripting.FileSystemObject")
-----------------------------------------------------
10) Excel Application Operations
Using Excel Application Object nosotros tin dismiss perform Excel operations
Ex:
Create an excel file
Read data
Write data
Compare data
Rename sheets
Add sheets
Move sheets
etc...
--------------------------
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
i) Database Connection Object
It is used to connect to Databases (Any database, connecter string exclusively varies variety out ane database to another)
Class value for creating Database connecter object- ("Adodb.Connection")
------------
ii) Database Recordset Object
It is used to perform operations on database tables(Records)
Class value for creating Database Recordset object - ("Adodb.Recordset")
----------------------------------------
13) Dictionary Object
It is used to define Key, value pairs.
Class value for creating Dictionary Object - ("Scripting.Dictionary")
----------------------------------------
14) Error Handling inwards VBScript
Handling expected in addition to unexpected Errors
Expected Errors: Whenever nosotros occupation invalid input hence nosotros tin dismiss await Errors.
Why nosotros postulate to occupation Invalid input?
We occupation Invalid Input for Negative Testing.
Unexpected Errors:
Resource Response
Insufficient Resource
Availability of Resource
--------------------------------------
Using Conditional Statements
Using VBScript Built inwards Functions
Using Option explicit statement
Using Exit Statement
Using On Error Resume Next statement
Etc...
-------------------------------