Software Testing Tool
By pbr.qtp
VBScript Operators
Arithmetic Operators:Operators used to perform mathematical calculations.
- Addition +
- Subtraction -
- Multiplication *
- Division /
- Integer Division \
- Exponentiation ^
- Modulus arithmetic Mod
- Unary negation -
- String concatenation &
Assignment Operator:Operator used to assign a value to a property or variable.
- Equality =
- Inequality <>
- Less than <
- Greater than >
- Less than or equal to <=
- Greater than or equal to >=
Comparison Operators:Operators used to perform comparisons.
Concatenation Operators:Operators used to combine strings.
Logical Operators:Operators used to perform logical operations.
- Logical negation Not
- Logical conjunction And
- Logical disjunction Or
- Logical exclusion Xor
- Logical equivalence Eqv
- Logical implication Imp
Using Control Structures to Make Decisions
Using If...Then...Else
Syntax
If condition Then statements [Else elsestatements ]
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If
Ex:
If condition = True Then
... the code that executes if the condition is satisfied
End If
Ex:
If bShowDetail Then MsgBox "More details. . . "
example:
sMsg = "Either you're not born yet or you're getting too old for this stuff!"
If nAge <= 0 Or nAge > 120 Then
MsgBox sMsg
bFail = True
End If
Ex:
If MyFavoriteRestaurantOpen = True Then
Msgbox "Go To My Favorite Restaurant!"
End If
If MyFavoriteRestaurantOpen = False Then
Msgbox "Go Home and Cook!"
End If
Ex:
If MyFavoriteRestaurantOpen = True Then
Msgbox "Go To My Favorite Restaurant!"
Else
Msgbox "Go Home and Cook!"
End If
Ex:
If nAge = 0 Then
MsgBox "Welcome to the human race!"
ElseIf nAge < 0 Then
MsgBox "You have to grow up a bit before you start using VBScript!"
ElseIf nAge > 0 And Age < 10 Then
MsgBox "If you're bold enough, you must be old enough."
ElseIf nAge > 120 Then
MsgBox "You're getting too old for this stuff!"
Else
MsgBox "You're at the perfect age to get started!"
End If
Select Case
Allows for conditional execution of a block of code, typically out of three or
more code blocks, based on some condition. Use the Select Case statement as
an alternative to complex nested If...Then...Else statements.
Syntax
Select Case testexpression
[Case expressionlist-n
[statements-n]] ...
[Case Else
[elsestatements]]
End Select
A Select Case statement provides capability similar to the If...Then...Else
statement, but it makes code more efficient and readable. Select Case
structure is defined as follows:
Select Case expression
Case exp-1
...this is the code that executes if exp-1 matches expression
Case exp-2, exp-3
...this is the code that executes if exp-2 or exp-3 matches expression
Case exp-4
...this is the code that executes if exp-4 matches expression
.
.
.
Case Else
...this is the code that executes if none matches expression
End Select
Example
The following example uses Select Case to read a variable populated by the
user and determine the name of the user's operating system:
Select Case Left(Environment.Value("OSVersion"), 1)
Case 1 : varOSDesc = "Windows NT"
Case 2 : varOSDesc = "Windows 98"
Case 3 : varOSDesc = "Windows 95"
Case 4 : varOSDesc = "Windows 3.11"
Case 5 : varOSDesc = "Windows 2000"
Case 6 : varOSDesc = "Windows ME"
Case 7 : varOSDesc = "Windows XP"
Case Else : varOSDesc = "OS is unknown"
End Select
|
|
BackTrack 5 R2 Penetration Testing Offensive Security Hacking Tools & Metasploit
Current Bid: $4.99
|
|
|
Hard Drive Testing Software Bootable tester Disk easy to use diagnostic tool
Current Bid: $9.99
|
|
|
Professional Software Testing with Visual Studio 2005 Team System: Tools for Sof
Current Bid: $2.45
|
|
|
Thomson Learning Testing Tools: Research Methods PC CD
Current Bid: $27.19
|
|
|
Software Quality: State of the Art in Management, Testing, and Tools by
Current Bid: $11.01
|
Using Control Structures to Make Code Repeat:
Looping allows you to run a group of statements repeatedly. Some loops repeat statements until a condition is False; others repeat statements until a condition is True. There are also loops that repeat statements a specific number of times.
The following looping statements are available in VBScript:
Do...Loop: Loops while or until a condition is True.
While...Wend: Loops while a condition is True.
For...Next: Uses a counter to run statements a specified number of times.
For Each...Next: Repeats a group of statements for each item in a collection or
each element of an array.
>
Using For...Next Statement:
Defines a loop that executes a given number of times, as determined by a loop counter. To use the For...Next loop, you must assign a numeric value to a counter variable. This counter is either incremented or decremented automatically with each iteration of the loop. In the For statement, you specify the value that is to be assigned to the counter initially and the maximum value the counter will reach for the block of code to be executed. The Next statement marks the end of the block of code that is to execute repeatedly, and also serves as a kind of flag that indicates the counter variable is to be modified.
Syntax
For counter = start To end [Step stepcounter]
[statements]
[Exit For]
[statements]
Next
>
Arguments
Argument Description
counter
Numeric variable used as a loop counter. The variable can't be an array
element or an element of a user-defined type.
start Initial value of counter.
end Final value of counter.
step
Amount counter is changed each time through the loop. If not specified, step defaults to one.
statements
One or more statements between For and Next that are executed the specified number of times.
Notes
If start is greater than end, and no step keyword is used or the stepcounter counter is positive, the For...Next loop is ignored and execution Commences with the first line of code immediately following the Next statement.
If start and end are equal and stepcounter is one, the loop executes once. counter can't be a variable of type Boolean or an array element.
counter is incremented by one with each iteration unless the Step keyword is used.
If the Step keyword is used, step specifies the amount stepcounter is incremented if stepcounter is positive or decremented if it's negative.
If the Step keyword is used, and stepcounter is negative, start should be greater than end. If this isn't the case, the loop doesn't execute.
The For...Next loop can contain any number of Exit For statements. When the Exit For statement is executed, program execution commences with
the first line of code immediately following the Next statement.
For Each subObject In myObj
sName = subObject.NameProperty
If Len(Sname) < 10 Then
Exit For
End if
Next
The following example causes a procedure called MyProc to execute 50 times.
The For statement specifies the counter variable x and its start and end values.
The Next statement increments the counter variable by 1 as default.
For x = 1 To 50
MyProc
Next
Using the Step keyword, you can increase or decrease the counter variable by the value you specify. In the following example, the counter variable j is incremented by 2 each time the loop repeats. When the loop is finished, the total is the sum of 2, 4, 6, 8, and 10.
Dim j, total
For j = 1 To 10 Step 2
total = total + j
Next
MsgBox "The total is " & total
To decrease the counter variable, use a negative Step value. You must specify an end value that is less than the start value. In the following example, the counter variable myNum is decreased by 2 each time the loop repeats. When the loop is finished, total is the sum of 16, 14, 12, 10, 8, 6, 4, and 2.
Dim j, total
For j = 16 To 2 Step -2
total = total + j
Next
MsgBox "The total is " & total
For…Next loops can also be nested.
For nDay = 1 To 365
For nHour = 1 To 23
For nMinute = 1 To 59
. . .
Next
Next
Next
When you use a positive step value, make sure the finish value is greater than the start value, or the loop will not execute at all.
For i = 10 to 1 Step 2 ' Incorrect
For i = 1 to 10 Step 2 ' Correct
When you use a negative step value, make sure the start value is greater than the finish value, or the loop won't execute at all.
For i = 1 to 10 Step -1 ' Incorrect
For i = 10 to 1 Step -1 ' Correct
Never use a step value of zero. In this case, VBScript will enter an infinite loop, and your program might run indefinitely.
For i = 1 to 10 Step 0 ' Incorrect
For i = 1 to 10 Step 3 ' Correct
Using For Each...Next Statement
Description
Repeats a group of statements for each element in an array or an object collection.
Syntax
For Each element In group
[statements]
[Exit For]
[statements]
Next
Arguments
Argument Description element
The string argument is any valid string expression. If string contains Null, Null is returned. group Name of an object collection or array. Statements One or more statements that are executed on each item in group.
Notes
The For...Each code block is executed only if group contains at least one element.
All statements are executed for each element in group in turn until either there are no more elements in group, or the loop is exited prematurely using the Exit For statement. Program execution then continues with the line of code following Next.
For Each...Next loops can be nested, but each element must be unique.
For example:
For Each myObj In anObject
For Each subObject In myObject
sName(ctr) = subObject.NameProperty
ctr = ctr + 1
Next
Next
Uses a nested For Each...Next loop, but two different variables, myObj and subObject, represent element.
Any number of Exit For statements can be placed with the For Each...Next loop to allow for conditional exit of the loop prematurely.
On exiting the loop, execution of the program continues with the line immediately following the Next statement.
For example, the following loop terminates once the program finds a name in the myObj collection that has fewer than 10 characters:
For Each subObject In myObj
sName = subObject.NameProperty
If Len(Sname) < 10 Then
Exit For
End if
Next
Tips
Each time the loop executes when iterating the objects in a collection, an implicit Set statement is executed. The following code reflects the "longhand" method that is useful for explaining what is actually happening during each iteration of the For Each...Next loop:
For i = 1 to MyObject.Count
Set myObjVar = MyObject.Item(i)
MsgBox myObjVar.Name
Next
Because the elements of an array are assigned to element by value, element is a local copy of the array element and not a reference to the array element itself. This means that you can't make changes to the array element using For Each...Next and expect them to be reflected in the array once the For Each...Next loop terminates, as demonstrated in the example shown next.
Dim strNameArray(1)
Dim intCtr
strNameArray(0) = "Paul"
strNameArray(1) = "Bill"
intCtr = 0
For Each varName In strNameArray
varName = "Changed"
Msgbox strNameArray(intCtr)
intCtr = intCtr + 1
Next
For example, on the first iteration of the loop, although varName has been changed from "Paul" to "Changed," the underlying array element, strNameArray(0), still reports a value of "Paul."
This proves that a referential link between the underlying array and object variable isn't present; instead, the value of the array element is passed to element by value.
|
|
BackTrack 5 R2 Penetration Testing Offensive Security Hacking Tools & Metasploit
Current Bid: $4.99
|
|
|
Hard Drive Testing Software Bootable tester Disk easy to use diagnostic tool
Current Bid: $9.99
|
|
|
Professional Software Testing with Visual Studio 2005 Team System: Tools for Sof
Current Bid: $2.45
|
|
|
Thomson Learning Testing Tools: Research Methods PC CD
Current Bid: $27.19
|
My Collections:
Click thumbnail to view full-sizeWhy Automate?
A prevalent belief among IT folk is that automation, by default, will enhance the quality of testing.
How true is that belief?
“There is a time and place for everything”, as the popular idiom goes, and that holds true for test automation too.
Certain scenarios in which automation is generally a good option:
1. Repetitive Tests
A system that needs the same tests executed periodically is a good candidate for automation. Take for example, support projects that must perform regression tests for every PR/CR. Manual effort in such cases tends to be huge and error-prone. Automation can prove very efficient in such cases.
It makes sense to opt for a testing tool with a version controlled repository to manage the test scripts.
The cost of automation and the initial effort investment for script creation is usually greater than for manual testing, and it must be analyzed how far this investment will pay off in the end. A few pointers to help make that decision:
- How many repetitions of tests are expected, for how long? A longer “life” of the test scripts tips the scale in favor of automation.
- How expensive is the tool?
- How much time/effort will it take to create the test scripts? Automation may not simply be record-and-play, a lot of design and coding may have to go in to achieve the desired result.
- Are incremental changes expected to the scripts?
- Do testers on the team require training on the tool?
“Repetitive tests => automation” is a fair thumb rule but not an inviolable one. A costly automation setup on one hand and quick-to-build on-the-fly manual tests on the other, and you might just find that automation will not be useful even if you expect a certain number of repetitions.
2. Manually Infeasible Tests
Before an application is deployed in the production environment, it might be critical to determine how the application will behave under huge user load or when dealing with millions of records.
Such test scenarios are usually best simulated with automation. In high risk conditions, where the cost of missing a test might be disastrous, even a single-time use of automation might be a worthwhile decision.
3. Low Severity/Probability Of “Human” Bugs
Automation can perform some jobs far better than a human can hope to do. Give the tool and the human tester two excel sheets with 10,000 rows of data each to reconcile with each other. No prizes for guessing who can do it faster, without errors.
But then, humans are far better at another sort of testing. Humans can notice oddities beyond documented tests. Does the UI look too cluttered? Does the mouse flicker strangely when moved over the button? Did the screen behind the modal window just blink?
Automation is limited to testing what it is programmed to do. Not everything that the human mind can observe/analyze can be programmed, and so, automation will miss out on capturing some bugs. The question to ask is: how important are those missed-out bugs? An unstable system might not be ready for automation, as severe “manual” bugs may get ignored. Automation is better suited to systems in which the “human” bugs are expected to be fewer and are of low severity.
In Closing
A point worth remembering is that automation vs. manual does not have to be an either-or decision. A mix can work. Take a multi-step workflow – a couple of steps might be fit for automation, not the entire flow. Automate only those steps that will benefit from automation.
JA 2 years ago
Are you NUTS???