A presentation on built-in functions.
This post helps you easily understand the mostly used built-in functions in Vb script while using QTP.
You can view/download this presentation also by clicking here.
Wednesday, May 19, 2010
Tuesday, May 11, 2010
A quick recap on Vb script basics!
Please wait as it might take a minute or two for the player to load.
This is a recap of my earlier posts(Vb script - 1 and Vb script -2)
This is a recap of my earlier posts(Vb script - 1 and Vb script -2)
Monday, May 10, 2010
VB Script - 2
VB Script Operators
An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in VB scripting to operate on 'data' and 'variables'.
VB script has following types of Operators.
Click here for the list of operators used in Vb script.
The operator precedence is an important concept.
Always, Parenthesis takes the first precedence.
For example:
a = (2*3*3) / 18
Here, 2*3*3 will be calculated first which is 18 and then divided by 18.
There fore, a = 1.
The standard operator precedence is as follows.
Arithmetic operators - First
Comparison operators - Next
Logical operators - In the end
*************************************************
We are just two more topics away before we start VBScript conditional statements.
*************************************************
VB Script Constants
What is a Constant?
A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constants(built-in). You can get information about these built-in constants by clicking here.
Creating Constants
You create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values.
For example:
Const MyString = "This is my string."
Const MyAge = 49
Note that the string literal is enclosed in quotation marks (" "). Quotation marks are the most obvious way to differentiate string values from numeric values. Date literals and time literals are represented by enclosing them in number signs (#).
For example:
Const CutoffDate = #6-1-97#
You may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign constant values while your script is running. For example, you might want to use a "vb" or "con" prefix on your constant names, or you might name your constants in all capital letters. Differentiating constants from variables eliminates confusion as you develop more complex scripts.
Input / Output operations
--------------------------------
InputBox function
The InputBox function displays a dialog box, where the user can write some input and/or click on a button. If the user clicks the OK button or presses ENTER on the keyboard, the InputBox function will return the text in the text box. If the user clicks on the Cancel button, the function will return an empty string ("").
Syntax
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
Example:
Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)
MsgBox Function
The MsgBox function displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked.
The MsgBox function can return one of the following values:
1 = vbOK - OK was clicked
2 = vbCancel - Cancel was clicked
3 = vbAbort - Abort was clicked
4 = vbRetry - Retry was clicked
5 = vbIgnore - Ignore was clicked
6 = vbYes - Yes was clicked
7 = vbNo - No was clicked
Syntax
MsgBox(prompt[,buttons][,title][,helpfile,context])
Example:
Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
' MyVar contains either 1 or 2, depending on which button is clicked.
*************************************************
Coming soon with my next posting
*************************************************
An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in VB scripting to operate on 'data' and 'variables'.
VB script has following types of Operators.
Click here for the list of operators used in Vb script.
The operator precedence is an important concept.
Always, Parenthesis takes the first precedence.
For example:
a = (2*3*3) / 18
Here, 2*3*3 will be calculated first which is 18 and then divided by 18.
There fore, a = 1.
The standard operator precedence is as follows.
Arithmetic operators - First
Comparison operators - Next
Logical operators - In the end
*************************************************
We are just two more topics away before we start VBScript conditional statements.
*************************************************
VB Script Constants
What is a Constant?
A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constants(built-in). You can get information about these built-in constants by clicking here.
Creating Constants
You create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values.
For example:
Const MyString = "This is my string."
Const MyAge = 49
Note that the string literal is enclosed in quotation marks (" "). Quotation marks are the most obvious way to differentiate string values from numeric values. Date literals and time literals are represented by enclosing them in number signs (#).
For example:
Const CutoffDate = #6-1-97#
You may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign constant values while your script is running. For example, you might want to use a "vb" or "con" prefix on your constant names, or you might name your constants in all capital letters. Differentiating constants from variables eliminates confusion as you develop more complex scripts.
Input / Output operations
--------------------------------
InputBox function
The InputBox function displays a dialog box, where the user can write some input and/or click on a button. If the user clicks the OK button or presses ENTER on the keyboard, the InputBox function will return the text in the text box. If the user clicks on the Cancel button, the function will return an empty string ("").
Syntax
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
Example:
Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)
MsgBox Function
The MsgBox function displays a message box, waits for the user to click a button, and returns a value that indicates which button the user clicked.
The MsgBox function can return one of the following values:
1 = vbOK - OK was clicked
2 = vbCancel - Cancel was clicked
3 = vbAbort - Abort was clicked
4 = vbRetry - Retry was clicked
5 = vbIgnore - Ignore was clicked
6 = vbYes - Yes was clicked
7 = vbNo - No was clicked
Syntax
MsgBox(prompt[,buttons][,title][,helpfile,context])
Example:
Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
' MyVar contains either 1 or 2, depending on which button is clicked.
*************************************************
Coming soon with my next posting
*************************************************
Tuesday, May 4, 2010
VB Script - 1
What is VB scripting?
• VBScript is a scripting language.
• A scripting language is a lightweight programming language.
• VBScript is a light version of Microsoft's programming language Visual Basic.
How VB script works with your OS?
When a Script arrives on your computer. WSH(Windows Script Host) takes care of it.
It is a Windows administration tool. WSH creates an environment for hosting scripts.
It makes objects and services available for the script and provides a set of guidelines within which the script is executed
Create your first script with VB!!
• Open note pad
• Write your script. Exampe: MsgBox "This is my First VB script"
• Save the document in a known location with .vbs extension. For example: MyScript.vbs
• Go to the location where your script is saved and double on it.
• WSH invokes the VB script engine and runs your script. A message box will be displayed with a message "This is my First VB script"
VB Script variables
A variable is a place holder that refers to a Computer memory location where we can store program information that may change during the script run-time.
• VBScript has only one data type called a Variant.
• A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used.
• Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.
• At its simplest, a Variant can contain either numeric or string information.
• Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of information.
• For example, we can have numeric information that represents a date or a time.
• When used with other date or time data, the result is always expressed as a date or a time.
Declaring Variables
We declare variables explicitly in our script using the Dim statement, the Public statement, and the Private statement.
Dim Statement:
• Declares variables and allocates storage space.
• Variables declared with Dim at the script level are available to all procedures within the script.
Ex: Dim MyVar
Public Statement:
• Declares public variables and allocates storage space.
• Public statement variables are available to all procedures in all scripts.
Ex: Public MyVar
Private Statement:
• Declares private variables and allocates storage space.
• Private statement variables are available only to the script in which they are declared.
Ex: Private MyVar
We can declare multiple variables by separating each variable name with a comma.
For example:
Dim x, Top, Bottom, Left, Right
We can also declare a variable implicitly by simply using its name in our script. That is not generally a good practice because we could misspell the variable name in one or more places, causing unexpected results when our script is run. For that reason, the Option Explicit statement is available to require explicit declaration of all variables.
The Option Explicit statement should be the first statement in our script.
Option Explicit
Forces explicit declaration of all variables in a script.
Option Explicit ' Force explicit variable declaration.
Dim MyVar ' Declare variable.
MyInt = 10 ' Undeclared variable generates error.
MyVar = 10 ' Declared variable does not generate error.
Naming Restrictions for Variables
Variable names follow the standard rules for naming anything in VBScript. A variable name:
o Must begin with an alphabetic character.
o Cannot contain an embedded period.
o Must not exceed 255 characters.
o Must be unique in the scope in which it is declared.
Tip: meaningfull prefix to variables to indicate the subtypes i.e
iCounter (integer), strName (String), bFlag (Boolean), dteToday (Date)
Assigning Values to Variables
Values are assigned to variables creating an expression as follows:
The variable is on the left side of the expression and the value you want to assign to the variable is on the right.
For example:
Dim A
A = 200
Dim City
City = “Hyderabad”
Scalar Variables and Array Variables
A variable containing a single value is a scalar variable.
A variable containing a series of values, is called an array variable.
Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses () following the variable name.
Example:
Dim A(3)
Although the number shown in the parentheses is 3, all arrays in VBScript are zero-based, so this array actually contains 4 elements.
We assign data to each of the elements of the array using an index into the array.
Beginning at zero and ending at 4, data can be assigned to the elements of an array as follows:
A(0) = 256
A(1) = 324
A(2) = 100
. . .
A(10) = 55
For example:
Similarly, the data can be retrieved from any element using an index into the particular array element you want.
AnyVariable = A(4)
Arrays aren't limited to a single dimension. We can have as many as 60 dimensions, although most people can't comprehend more than three or four dimensions.
In the following example, the MyTable variable is a two-dimensional array consisting of 6 rows and 11 columns:
Dim MyTable(5, 10)
In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns.
Dynamic Arrays
We can also declare an array whose size changes during the time our script is running. This is called a dynamic array.
The array is initially declared within a procedure using either the Dim statement or using the ReDim statement.
However, for a dynamic array, no size or number of dimensions is placed inside the parentheses.
For example:
Dim MyArray()
ReDim AnotherArray()
To use a dynamic array, you must subsequently use ReDim to determine the number of dimensions and the size of each dimension.
In the following example, ReDim sets the initial size of the dynamic array to 25. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place.
ReDim MyArray(25)
ReDim Preserve MyArray(30)
There is no limit to the number of times we can resize a dynamic array, although if we make an array smaller, we lose the data in the eliminated elements.
• VBScript is a scripting language.
• A scripting language is a lightweight programming language.
• VBScript is a light version of Microsoft's programming language Visual Basic.
How VB script works with your OS?
When a Script arrives on your computer. WSH(Windows Script Host) takes care of it.
It is a Windows administration tool. WSH creates an environment for hosting scripts.
It makes objects and services available for the script and provides a set of guidelines within which the script is executed
Create your first script with VB!!
• Open note pad
• Write your script. Exampe: MsgBox "This is my First VB script"
• Save the document in a known location with .vbs extension. For example: MyScript.vbs
• Go to the location where your script is saved and double on it.
• WSH invokes the VB script engine and runs your script. A message box will be displayed with a message "This is my First VB script"
VB Script variables
A variable is a place holder that refers to a Computer memory location where we can store program information that may change during the script run-time.
• VBScript has only one data type called a Variant.
• A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used.
• Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.
• At its simplest, a Variant can contain either numeric or string information.
• Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of information.
• For example, we can have numeric information that represents a date or a time.
• When used with other date or time data, the result is always expressed as a date or a time.
Declaring Variables
We declare variables explicitly in our script using the Dim statement, the Public statement, and the Private statement.
Dim Statement:
• Declares variables and allocates storage space.
• Variables declared with Dim at the script level are available to all procedures within the script.
Ex: Dim MyVar
Public Statement:
• Declares public variables and allocates storage space.
• Public statement variables are available to all procedures in all scripts.
Ex: Public MyVar
Private Statement:
• Declares private variables and allocates storage space.
• Private statement variables are available only to the script in which they are declared.
Ex: Private MyVar
We can declare multiple variables by separating each variable name with a comma.
For example:
Dim x, Top, Bottom, Left, Right
We can also declare a variable implicitly by simply using its name in our script. That is not generally a good practice because we could misspell the variable name in one or more places, causing unexpected results when our script is run. For that reason, the Option Explicit statement is available to require explicit declaration of all variables.
The Option Explicit statement should be the first statement in our script.
Option Explicit
Forces explicit declaration of all variables in a script.
Option Explicit ' Force explicit variable declaration.
Dim MyVar ' Declare variable.
MyInt = 10 ' Undeclared variable generates error.
MyVar = 10 ' Declared variable does not generate error.
Naming Restrictions for Variables
Variable names follow the standard rules for naming anything in VBScript. A variable name:
o Must begin with an alphabetic character.
o Cannot contain an embedded period.
o Must not exceed 255 characters.
o Must be unique in the scope in which it is declared.
Tip: meaningfull prefix to variables to indicate the subtypes i.e
iCounter (integer), strName (String), bFlag (Boolean), dteToday (Date)
Assigning Values to Variables
Values are assigned to variables creating an expression as follows:
The variable is on the left side of the expression and the value you want to assign to the variable is on the right.
For example:
Dim A
A = 200
Dim City
City = “Hyderabad”
Scalar Variables and Array Variables
A variable containing a single value is a scalar variable.
A variable containing a series of values, is called an array variable.
Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses () following the variable name.
Example:
Dim A(3)
Although the number shown in the parentheses is 3, all arrays in VBScript are zero-based, so this array actually contains 4 elements.
We assign data to each of the elements of the array using an index into the array.
Beginning at zero and ending at 4, data can be assigned to the elements of an array as follows:
A(0) = 256
A(1) = 324
A(2) = 100
. . .
A(10) = 55
For example:
Similarly, the data can be retrieved from any element using an index into the particular array element you want.
AnyVariable = A(4)
Arrays aren't limited to a single dimension. We can have as many as 60 dimensions, although most people can't comprehend more than three or four dimensions.
In the following example, the MyTable variable is a two-dimensional array consisting of 6 rows and 11 columns:
Dim MyTable(5, 10)
In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns.
Dynamic Arrays
We can also declare an array whose size changes during the time our script is running. This is called a dynamic array.
The array is initially declared within a procedure using either the Dim statement or using the ReDim statement.
However, for a dynamic array, no size or number of dimensions is placed inside the parentheses.
For example:
Dim MyArray()
ReDim AnotherArray()
To use a dynamic array, you must subsequently use ReDim to determine the number of dimensions and the size of each dimension.
In the following example, ReDim sets the initial size of the dynamic array to 25. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place.
ReDim MyArray(25)
ReDim Preserve MyArray(30)
There is no limit to the number of times we can resize a dynamic array, although if we make an array smaller, we lose the data in the eliminated elements.
Monday, May 3, 2010
QTP made easy
Well, Friends! You will get plenty of results and help on QTP when you Google.
There are lots of testers who want to get into Automation. Many of them don't know how to start learning QTP and where to start it from!
If you are one search person, trust me you will feel you have landed at the right place.
I am writing a simple way on how to use this wonderful tool. Remember, I promise that you would have got a hard grip on this tool, by the time you finish reading all that is intended to. You will definitely have to explore a lot on your own once you think that you have enough knowledge on QTP - the master of all automation functional testing tool :-)
I will try to keep it as interesting as it is possible and will not try to make it look like a real big tech-blog. But there are certain things(which I would call traditional for Automation) that one can't miss out when you are talking about Test Automation.
I would want all the readers of my blog to explore more on
• Why automation is needed?
• When is automation suitable / needed?
• Pros and cons of test automation.
Unless you have explored on the above I would not recommend you to proceed with my posting.
If you are reading this I assume you have found out the answers for those questions.
Lets go straight to the QTP cafe!!!
Following are the best steps to learn QTP as per me.
• Learn VB scripting - the scripting language used in QTP for automation
• Explore all the features of QTP
• By now, You are surely ready to take up a real time project just by using the combination of two.
There are lots of testers who want to get into Automation. Many of them don't know how to start learning QTP and where to start it from!
If you are one search person, trust me you will feel you have landed at the right place.
I am writing a simple way on how to use this wonderful tool. Remember, I promise that you would have got a hard grip on this tool, by the time you finish reading all that is intended to. You will definitely have to explore a lot on your own once you think that you have enough knowledge on QTP - the master of all automation functional testing tool :-)
I will try to keep it as interesting as it is possible and will not try to make it look like a real big tech-blog. But there are certain things(which I would call traditional for Automation) that one can't miss out when you are talking about Test Automation.
I would want all the readers of my blog to explore more on
• Why automation is needed?
• When is automation suitable / needed?
• Pros and cons of test automation.
Unless you have explored on the above I would not recommend you to proceed with my posting.
If you are reading this I assume you have found out the answers for those questions.
Lets go straight to the QTP cafe!!!
Following are the best steps to learn QTP as per me.
• Learn VB scripting - the scripting language used in QTP for automation
• Explore all the features of QTP
• By now, You are surely ready to take up a real time project just by using the combination of two.
Subscribe to:
Comments (Atom)
