com
Silk Test
THE AUTOMATED TESTING PROCESS
Creating a testplan :
#1#
For QTP Documents visit: www.gcreddy.com
Creating testcases
#2#
For QTP Documents visit: www.gcreddy.com
Getting started
If you are a first-time user and want to get up and running quickly, you
may want to begin with the following:
QuickStart Wizard
SilkTest Web Quick Start
If you are using SilkTest with QA Organizer, you can use the QuickStart
Wizard, which greatly simplifies the four steps of automated testing
described in the preceding section. When you start SilkTest the first time (or
whenever you start and have no open windows), the QuickStart Wizard is
displayed automatically. You can also invoke the wizard at any time by
selecting File/New and clicking the QuickStart Wizard icon.
To use the QuickStart Wizard, you simply follow its prompts. You can use
it to:
Create a testplan.
You simply name the file (giving it the .pln extension) and its
directory.
Create a test frame, which contains descriptions of the GUI objects in
your application that you want to test.
As prompted, you simply open your application and open the
various windows and dialogs that you want to test in the application.
The wizard automatically records all the declarations in a file called
frame.inc. You don’t have to do any coding.
Record testcases.
#3#
For QTP Documents visit: www.gcreddy.com
You name the testcase and provide a description for the testplan,
then simply record the testcase. Again, you don’t have to do any
coding. The wizard automatically saves the testcase in a script (.t) file
with the same name as the testplan.
Run testcases.
Example: The following scenario illustrates how you might get started
testing the Text Editor application that ships with SilkTest. Since the Text
Editor is a standard C application, you don’t need to have any extensions
(which provide support for testing applications created with thirdparty
development environments) enabled before invoking the wizard. Now you
are ready to use the QuickStart Wizard with the Text Editor.
#4#
For QTP Documents visit: www.gcreddy.com
Now you will name a new testplan, which will organize and manage your
tests.
Click Next.
#5#
For QTP Documents visit: www.gcreddy.com
The next step is to record the test frame, which defines all the
windows,
dialogs, menus, and so on that you want to test.
#6#
For QTP Documents visit: www.gcreddy.com
To create a new test frame, leave New Test Frame selected and click
Next.
At this point, the wizard lists all the open (running and not minimized)
applications. If Text Editor is not open, you can open it now (it is in the
directory where you installed SilkTest). After you open the Text Editor, click
on the QuickStart Wizard title bar to see Text Editor added to the list of
applications.
Click Next.
Now you simply open a document window and open all the dialogs that
you want to test in the Text Editor. When you place the mouse pointer
on a window or dialog, the wizard records all the declarations that
SilkTest needs in a file called frame.inc in the same directory as your
testplan. For example, when you capture the Find dialog, you see this:
#7#
For QTP Documents visit: www.gcreddy.com
When you have finished capturing the windows and dialogs in Text
Editor, click Return to Wizard in the Capturing New Windows dialog.
Now that you have created your test frame, you are ready to create a
testcase.
Name the test FindBox and enter the description “Verify controls in
Find dialog.” Click Next. Your test is now being recorded, as indicated
by the Record Status window on your screen.
#8#
For QTP Documents visit: www.gcreddy.com
Now go to Text Editor, select Search/Find to open the Find dialog, place
your mouse pointer over the dialog’s title bar, and press Ctrl+Alt to
verify its state. The Verify Window dialog displays. Click OK to verify all
properties for the dialog. Close the Find dialog (to return to your base
state), then click Done in the Record Status window. You return to the
Wizard and are asked to confirm that the test is what you want.
Click Next.
The wizard reports the results. You can move the wizard to the side
and look at the results file that is created whenever you run a test.
In the wizard, click Next to save your testcase. The testcase is saved in
a script (.t) file with the same name as the testplan (in this case,
edit.t).
Click Close to close the wizard. You see a window containing the
results file from the test you just ran. In another window is the
testplan:
SilkTest has recorded all the needed information for you in the
testplan:
#9#
For QTP Documents visit: www.gcreddy.com
The first line records the script file containing the testcase.
The second section (under Header:) contains information that the
wizard uses to find files. Click the plus sign to the left of “header” to
see the information.
Warning The wizard maintains the information in the header section. You
should not make changes in this section.
Notice the five large buttons at the top of the testplan. Those are
wizard buttons. You can click them anytime to have the wizard step you
through one of the testing processes.
When testing Web applications, the wizard sets the application state to
DefaultBaseState, thus activating the recovery system. When testing non-
Web applications, the wizard sets the application state to none, thus
deactivating the recovery system.
# 10 #
For QTP Documents visit: www.gcreddy.com
TextEditor.File.New.Pick ()
# 11 #
For QTP Documents visit: www.gcreddy.com
Before the first line of your testcase begins running, the recovery system
restores the application to the base state even if an unexpected event
corrupted the application between testcases.
After the testcase completes, if the testcase was not able to clean up after
itself (for example, it could not close a dialog it opened), the recovery
system restores the application to the base state.
SilkTest architecture
# 12 #
For QTP Documents visit: www.gcreddy.com
SilkTest host software The SilkTest host software is the program you use
to develop, edit, compile, run, and debug your 4Test scripts and testplans.
This manual refers to the system that runs this program as the host machine
or the SilkTest machine.
The Agent The 4Test Agent is the software process that translates the
commands in your 4Test scripts into GUI-specific commands. In other words,
it is the Agent that actually drives and monitors the application you are
testing. One Agent can run locally on the host machine. In a networked
environment, any number of Agents can run on remote machines. This
manual refers to the systems that run remote Agents as target machines.
The Agent menu If the Agent has been started, an Agent button appears in
the taskbar. Press the right mouse button over the Agent button to display
the Agent menu. The menu contains the standard menu items for a Window,
plus the following:
# 13 #
For QTP Documents visit: www.gcreddy.com
# 14 #
For QTP Documents visit: www.gcreddy.com
A set of statements, operators, and data types that you use to add
structure and logic to a recorded testcase.
Object-oriented features
Inheritance Classes are organized in a hierarchy. The reason for this is that
classes are related to each other, sharing characteristics common to their
parent classes. For example, the parent class Control defines all the
characteristics common to all kinds of controls: check boxes, text fields,
pushbuttons, and so on. In this way, each class does not need to define all
the methods it needs; the class can just inherit the existing definition from
its ancestor classes. For example, one action you can perform on objects of
class DialogBox is the GetDefaultButton method. This method returns the
identifier of the default pushbutton, which is the pushbutton that is pressed
when the Return or Enter key is pressed. You could not use this method with
objects that were not dialog boxes, such as menus or text fields. When you
record testcases, the proper 4Test methods for each of your manual actions
are recorded automatically for you, so it really is transparent to you which
class the recorded methods belong to. However, if you decide to write or
augment a testcase by hand, you can look up the class and the methods it
supports in the online Help or Library Browser.
The class hierarchy The following illustration shows the hierarchy of the
core classes of GUI objects recognized by SilkTest.
# 15 #
For QTP Documents visit: www.gcreddy.com
Statements
By using 4Test flow-of-control statements, you can add logic and robustness
to a recorded testcase. The following table summarizes the statements.
# 16 #
For QTP Documents visit: www.gcreddy.com
Example The following 4Test code shows how to use the if statement to
conditionally execute a method. The code picks the Close menu item from
# 17 #
For QTP Documents visit: www.gcreddy.com
the File menu of the Text Editor application, which causes a message box to
appear if there is unsaved work. The if statement tests for the existence of
the message box.
TextEditor.File.Close.Pick ()
if MessageBox.Exists () // if the message box exists
MessageBox.No.Click () // then dismiss it
Built-in data types 4Test provides the following built-in data types:
In addition to the 4Test data types, the following C data types are
supported
for use in calling functions in DLLs.
The first two columns above show data types that correspond to the
4Test INTEGER data type. The third column corresponds to the REAL data
type.
User-defined types You can also create new data types, including
enumerated types and records. For example:
# 18 #
For QTP Documents visit: www.gcreddy.com
Built-in functions
# 19 #
For QTP Documents visit: www.gcreddy.com
You interact with testplans, testcases, and results files in the outline
editor, an easy-to-use interactive environment that is consistent throughout
all phases of testing. Because these files contain large amounts of
information, a structured, hierarchical outline provides an ideal
organizational model. For example, the following figure shows a testcase in
the outline editor:
Notice how the statements that make up the body of the expanded
testcase are indented. The outline editor uses indentation to differentiate
levels. A minus icon ( ) indicates that a level is fully expanded. Similarly, a
plus icon ( ) indicates that a level is collapsed and has hidden detail. Click on
the icons to expand and collapse the outline, to show the desired level of
detail.
Outlining commands As you work in the outline editor, you can use menu,
keyboard, or tool bar commands to change indentation levels. The following
table summarizes the
commands:
# 20 #
For QTP Documents visit: www.gcreddy.com
Use Shift+Enter to force a soft line break within a long line of code. The
outline editor considers such lines as one statement.
Typically, you write scripts and testplans using the built-in outline
editor, which is optimized for managing scripts and testplans.
However, you can also use your favorite ASCII text editor to write and
edit scripts and testplans, then open them in the outline editor for execution.
You can even make changes in the outline editor, save the changes, then
reopen the modified file in your ASCII editor for continued editing.
[t n]
where n is the number of spaces that correspond to a tab. For example, if
[t4] is the first line of a file, every 4 spaces will be converted into a tab.
# 21 #
For QTP Documents visit: www.gcreddy.com
You can use these scripts and testplans the same way you use files
created in the outline editor: Select File/Open to open them. You can make
and save changes in the outline editor, then reopen the file in your ASCII
editor for further revision. Using Microsoft Word You can also use
Microsoft Word to develop testplans.
# 22 #
For QTP Documents visit: www.gcreddy.com
comparison tools that let you see just how the results differ from the
baselines, click on the box icon, as shown in this figure:
The debugger
SilkTest comes with a powerful set of debugging tools to help you find
problems with your scripts. Using these debugging tools, you can step
through a script a line at a time and stop at specified breakpoints, as well as
examine local and global variables and enter expressions to evaluate. The
following figure shows a testcase in the debugger with a breakpoint set.
# 23 #
For QTP Documents visit: www.gcreddy.com
CREATING TESTPLANS
Select File/New.
# 24 #
For QTP Documents visit: www.gcreddy.com
A user enters the character(s) to search for in the Find What text field,
checks the Case Sensitive check box to consider case, and selects either the
Up or Down radio button to indicate the direction of the search. Here is what
a partial outline of the testing requirements might look like:
I. Find dialog
A. Case-sensitive
1. Forward search
a. Search for a character
b. Search for a word
2. Backward search
a. Search for a character
b. Search for a word
B. Case-insensitive
1. Forward search
a. Search for a character
b. Search for a word
2. Backward search
a. Search for a character
b. Search for a word
# 25 #
For QTP Documents visit: www.gcreddy.com
Notice that the full description for each of these eight tests is formed
by joining the descriptions along the branch that leads to the test. This can
be seen more clearly when the outline is rewritten as a tree:
# 26 #
For QTP Documents visit: www.gcreddy.com
The scope of a statement refers to the portion of the testplan where the
statement applies. A statement placed at the group description level applies
to all the test descriptions contained by the group. Conversely, a statement
placed at the test description level applies only to that test description.
Levels in QA Organizer are represented by indentation, and you change the
level of a line by using the Outline/Move Left and the Outline/Move Right
commands, both of which have keyboard, tool bar, and popup menu
shortcuts.
Once you have a descriptive outline of the test requirements, you can
associate the outline with the 4Test scripts and testcases that implement the
requirements. You create this association by inserting script and testcase
statements in the appropriate locations in the outline.
You can insert a script and testcase statement for each test
description, although placing a statement at the group level when possible
eliminates redundancy in the testplan. For example, since it is usually good
practice to place all the testcases for a given application feature into a
single script file, you can reduce the redundancy in the testplan by
specifying the script statement at the group level that describes that
feature.
The following testplan illustrates this, specifying the script find.t once for the
entire group of tests of the Find dialog (the script statement is highlighted
for emphasis):
# 27 #
For QTP Documents visit: www.gcreddy.com
There are three ways to associate a testplan with a 4Test script and
testcase:
Use the Testplan Detail dialog to automate the process
Enter the script and testcase statements manually
Record the testcase from within the testplan
For example, the following figure shows how to position the cursor to link the
first test description:
# 28 #
For QTP Documents visit: www.gcreddy.com
The multi-line list box at the top of the dialog displays the line in the
testplan that the cursor was on when the dialog was invoked, as well as its
ancestor lines. The black arrow icon indicates the current line. The current
line appears in black and white, and the preceding lines appear in blue.
# 29 #
For QTP Documents visit: www.gcreddy.com
If you know the names of the script and testcase, enter them in the
Script and Testcase fields, respectively, and skip to step 8.
If you are unsure of the script name, click the Scripts pushbutton to the
right of the Script field to browse for the script file. QA Organizer
invokes the Testplan Detail - Script dialog:
The Testplan Detail Script dialog closes and the script name is entered in the
Script field. For example:
# 30 #
For QTP Documents visit: www.gcreddy.com
This dialog shows the names of the testcases that are contained in the
selected script. Testcases are listed alphabetically, not in the order in which
they occur in the script.
Click OK. The script and testcase statements are entered in the plan.
For example:
# 31 #
For QTP Documents visit: www.gcreddy.com
# 32 #
For QTP Documents visit: www.gcreddy.com
Enter the script and/or testcase statements using the following syntax,
substituting actual names for myscript and MyTestcase:
script: myscript.t
testcase: MyTestcase
For example, to link to the find.t script:
# 33 #
For QTP Documents visit: www.gcreddy.com
testcase: manual.
For example,
# 34 #
For QTP Documents visit: www.gcreddy.com
Tracking manual tests You can describe the state of each of your manual
tests in a dialog in SilkTest. This information is used in reports.
The Update Manual Tests dialog is displayed. It lists all manual tests in the
current testplan.
# 35 #
For QTP Documents visit: www.gcreddy.com
# 36 #
For QTP Documents visit: www.gcreddy.com
# 37 #
For QTP Documents visit: www.gcreddy.com
You can add variables, functions, methods, and properties to the basic
window declarations recorded by SilkTest. For example, you can add
variables to a dialog box declaration that specify what the tab sequence is,
what the initial values are, and so on. You access the values of variables at
runtime as you would a field in a record.
If you plan to test Web applications, make sure you enable the correct
browser extension(s) on your target and host machine. If you do not plan to
test Web applications, you must disable all browser extensions on the host
machine.
Note If you are running local tests—that is, your target and host are the
same machine—you must still ensure that browser extensions are enabled
appropriately by running the Extension Enabler on the host machine.
# 38 #
For QTP Documents visit: www.gcreddy.com
Enable support for the browsers you want to use, if they aren’t already
enabled. In the Primary Extension field for a browser, choose Enabled.
Select any other extensions that the browser needs for testing such as
ActiveX or fault trapping. We recommend that you do not turn on fault
trapping until you really need it.
Click OK to close the Extension Enabler dialog.
You enable support for browsers on the host machine using the
Extensions dialog. Be advised that there is overhead associated with having
more than one browser extension enabled, so do so only if you are actually
testing more than one browser in an automated session.
Start SilkTest.
Select Options/Extensions. The Extensions dialog opens. All the
installed extensions are listed, including the browser extensions, as in
this example:
Enable the browser extension(s) you want to use. In the Primary
Extension field for a browser, choose Enabled. Disable any browser
# 39 #
For QTP Documents visit: www.gcreddy.com
Note If you enable support for ActiveX in this dialog, you must make sure
that it is enabled in the Extension Enabler dialog as well.
Click OK to close the Extensions dialog. You can get information about
the files used by an extension by selecting an extension and clicking
the Details pushbutton.
Start SilkTest.
Select Options/Extensions. The Extensions dialog opens.
Disable any browser extens ions you do not plan to use by choosing
Disabled in the Primary Extension field and unchecking all check boxes
in the Other Extensions columns.
Click OK to close the Extensions dialog.
Two stages Record window declarations for your application in two stages:
Record the window declarations for the main window (including its
menus and controls).
Bring up each dialog one at a time and record a declaration for each.
# 40 #
For QTP Documents visit: www.gcreddy.com
Procedure To record declarations for the main window and menu hierarchy
of your application:
The New Test Frame dialog is displayed, allowing you to create a test
frame file for an application displayed in the Application list box. The
Application list box displays all applications that are open and not minimized;
if your test application is not listed, click Cancel, open your application, and
select File/New again.
The default file name for the new test frame file is frame.inc. (The .inc
extension denotes an include file, a file that stores declarations.) By default,
subsequent frame files in the same directory are named frame1.inc,
frame2.inc, and so on. You can edit the path, file name, or both. Click the
Browse pushbutton if you need help editing the name or path.
Select your application from the Application list box. The Command
Line, Working Directory, and 4Test Identifier fields are updated for your
application:
# 41 #
For QTP Documents visit: www.gcreddy.com
Click OK.
The new test frame file is created. The file contains the 4Test
declarations for the main window and all its menus, as well as a generic
declaration that is valid for each of the standard message boxes in the
application. For example:
When you record a test frame, the full path of the test frame file is
added to the Use Files field of the Runtime Options dialog. This means that
SilkTest can use of the information contained in the declarations and
recognize the GUI objects in your application when you record testcases.
After you record your test application’s main window and menus, you
record all the dialogs you want to test.
Procedure To record your application’s dialogs, use this procedure once for
each dialog in your application:
# 42 #
For QTP Documents visit: www.gcreddy.com
Make sure that the test frame file that contains the declarations for the
application’s main window is open. The dialog declarations will be
appended to this file.
Select Record/Window Declarations. The Record Window Declarations
dialog is displayed.
Make your application active and invoke one of its dialogs, referred to
in this procedure as the target dialog.
If necessary, arrange windows so that you can see the target dialog.
Position the cursor on the title bar of the target dialog. Note that as
you move the cursor toward the title bar, the contents of the Window
Declaration list box change dynamically to reflect the object at which
you’re pointing, as well as any contained objects. When the cursor is
positioned correctly, the Window Detail group box (upper left) shows
the caption of the dialog in the Identifier field.
Press Ctrl+Alt.
# 43 #
For QTP Documents visit: www.gcreddy.com
The wStartup constant When you record the test frame, a constant called
wStartup is created. By assigning the identifier of the login window to
wStartup and by recording a new invoke method, your tests can start the
application, enter any required information into the login window, then
dismiss the login window
Saving the test frame After you finish recording declarations for each one
of your application’s dialogs, save the test frame file.
Procedure To save a test frame, select File/Save when the test frame is the
active window. If it is a new file, it is automatically named frame.inc (if you
already have a frame.inc file, a number is appended to the file name). You
can use File/Save As to select another name. When saving a file, SilkTest
does the following:
Saves a source file, giving it the .inc extension; the source file is an
ASCII text file, which you can edit
Saves an object file, giving it the .ino extension; the object file is a
binary file that is executable, but not readable by you
Example If you name a frame file myframe and save it, you will end up with
two files: the source file myframe.inc, in the location you specify, and the
object file myframe.ino.
# 44 #
For QTP Documents visit: www.gcreddy.com
Introduction This chapter shows you how to use the powerful SilkTest
recorder to automatically capture the actions you perform as you interact
with your application, creating an automated testcase. The cornerstone of an
automated test is the verification stage, in which the test verifies that the
state of the application matches the expected (baseline) state. Using the
recorder, you can record object-appropriate verification of your application’s
state, data, or appearance.
Before you begin to design and record testcases, you should first make
sure that the built-in recovery system can close representative dialogs from
your application. Although the recovery system is robust enough to be able
to close almost any application window, some applications may have
windows that close in an unconventional fashion.
Start SilkTest.
If you have not already done so, record a test frame for your
application.
Make sure your application’s test frame file is listed in the Use Files
field in the Runtime Options dialog (select Options/Runtime).
Start your application and invoke a representative dialog.
Select Run/Application State.
# 45 #
For QTP Documents visit: www.gcreddy.com
This section explains the methodology you use when you design and record
a testcase.
There are two basic types of testcases, each with its own purpose.
Level 1 tests, often called smoke tests or object tests, verify that an
application’s GUI objects function properly. For example, they verify
# 46 #
For QTP Documents visit: www.gcreddy.com
that text fields can accept keystrokes and check boxes can display a
check mark.
Level 2 tests verify an application feature. For example, they verify
that an application’s searching capability can correctly find different
types of search patterns. You typically run Level 1 tests when you
receive a new build of your application, and do not run Level 2 tests
until your Level 1 tests achieve a specific pass/fail ratio. The reason for
this is that unless your application’s graphical user interface works,
you cannot actually test the application itself.
Each testcase that you record should have the following three stages.
It drives the application from the initial state to the state you want to
test.
It verifies that the actual state matches the expected (correct) state.
(Your QA department might use the term baseline to refer to this
expected state.) This stage is the heart of the testcase.
It cleans up the application, in preparation for the next testcase, by
undoing the steps performed in stage 1.
Each testcase you record should perform its own setup in stage 1, and
should undo this setup in stage 3, so that the testcase can be executed
independently of every other testcase. In other words, the testcase should
not rely upon the successful or unsuccessful completion of another testcase,
and the order in which it is executed should have no bearing on its outcome.
If a testcase relies on a prior testcase to perform some setup actions, and an
error causes the setup to fail or, worse yet, the application to crash, all
subsequent testcases will fail because they cannot achieve the state where
the test is designed to begin.
# 47 #
For QTP Documents visit: www.gcreddy.com
When a user enters the criteria for the search and clicks the Find Next
pushbutton, the searching feature attempts to locate the string. If the string
is found, it is selected (highlighted). Otherwise, an informational message is
displayed.
# 48 #
For QTP Documents visit: www.gcreddy.com
# 49 #
For QTP Documents visit: www.gcreddy.com
Preparing to record
Procedure To invoke the Record Testcase dialog and set up the test:
Select Record/Testcase.
If a script file is not the active window, you are prompted for a
file name.
# 50 #
For QTP Documents visit: www.gcreddy.com
Type the name of your testcase in the Testcase Name field of the
Record Testcase dialog. By default the name is Test1 (unless that
name is already used in the current script file, in which case the
default name is Test2, and so on). Testcase names are not case
sensitive; they can be any length and consist of any combination of
alphabetic characters, numerals, and underscore characters.
# 51 #
For QTP Documents visit: www.gcreddy.com
As you move around the application while recording, the Record Status
window dynamically updates to show the object that the recorder thinks the
mouse is currently over or the control that has focus.
Use this information to make sure that the recorder has kept up with
your actions (sometimes the recorder can fall behind if your system’s
resources are low). In particular, check the Record Status window before
pressing Ctrl+Alt to do your verification in order to make sure you are
verifying the correct object.
Interact with your application, driving it to the state that you want to
test. As you interact with your application, your interactions are
recorded in the Testcase Code field of the Record Testcase dialog,
which is not visible.
To review what you have recorded, click the Done button in the Record
Status window. The Record Testcase dialog is redisplayed, containing
the 4Test code that has been recorded for you. To resume recording
your interactions, click the Resume Recording button in the dialog.
To temporarily suspend recording, click the Pause Recording button on
the Record Status window. You might want to halt recording to leave
your desk or to prevent some interactions from being recorded.
# 52 #
For QTP Documents visit: www.gcreddy.com
The Window field, in the top-left corner of the dialog, displays the
name of the object you were pointing at when you pressed Ctrl+Alt.
# 53 #
For QTP Documents visit: www.gcreddy.com
If the name in the Window field is incorrect, press Cancel to close the
dialog and return to the application. Point to the object you want to
verify and press Ctrl+Alt again. The Verify Window dialog has three
tabs. The dialog has these tabs by default.
Select Options/Recorder.
The Recorder Options dialog appears.
Deselect the Verify Using Properties check box.
Note You will not be able to deselect this check box if you have enabled
enhanced support for Visual Basic or PowerBuilder, both of which require
properties for verification.
# 54 #
For QTP Documents visit: www.gcreddy.com
Click OK.
With Verify Using Properties deselected, the next time you go to verify
an object, the Verify Window dialog will have an Attribute tab, instead of a
Property tab.
Caption is the text that appears in the dialog box’s title bar; Children is
a list of all the objects contained in the dialog box, DefaultButton is the
button that is invoked when you press Enter, and so on. In your testcases,
you can verify the state of any of these properties. You can also, in the same
testcase, verify properties of children of the selected object. In the preceding
illustration, notice that the child objects in the Find dialog box (such as the
text field FindWhat and the check box CaseSensitive) are also selected for
# 55 #
For QTP Documents visit: www.gcreddy.com
A bitmap comparison will fail if the image being verified does not have
the same screen resolution, color, window frame width, and window
position when the testcase is run on a different machine than the one
on which the baseline image was captured.
Make sure that your testcase sets the size of the application window to
the same size it was when the baseline bitmap was captured.
Capture the smallest possible region of the image so that your test is
comparing only what is relevant.
If practical, do not include the window’s frame (border), since this may
have different colors and/or fonts in different environments.
# 56 #
For QTP Documents visit: www.gcreddy.com
existing testcase) and drive your application to the state you want to
verify.
When you are ready to record a verification statement, position the
mouse cursor over the object you want to verify, then press Ctrl+Alt.
The Verify Window dialog appears over your application window.
Display the Bitmap tab.
Select the region to update: Entire Window, Client Area of Window
(that is, without scroll bar or title bar), or Portion of Window.
In the Bitmap File Name field, enter the full path of the bitmap file that
will be created. The default path is based on the current directory. The
default file name for the first bitmap is bitmap.bmp (on OSF/Motif, it is
bitmap.xpm). Use the Browse pushbutton if you need help choosing a
new path or name.
Click OK. If you selected Entire Window or Client Area of Window, the
bitmap is captured and you return to your test application. If you select
Portion of Window, position the cursor at the desired location to begin
capturing a bitmap. While you press and hold the left mouse button,
drag the mouse to the screen location where you want to end the
capture. Release the mouse button.
Complete your testcase.
# 57 #
For QTP Documents visit: www.gcreddy.com
To globally set these options for a group of scripts, use the Agent
Options dialog. To locally set these options within a script or testcase, use
the SetOption method, for example:
Agent.SetOption (OPT_BITMAP_MATCH_COUNT, 3)
Each class has a set of methods associated with it, including built-in
verification methods. You can verify an object’s state using one of these
built-in verification methods or by using other methods in combination with
the built-in Verify function.
For example, here is a testcase that verifies that the text in the TextField
Replace.FindWhat is “myText.” It uses the built-in verification method
VerifyValue.
testcase VerifyMethodTest ()
TextEditor.Search.Replace.Pick ()
Replace.FindWhat.VerifyValue ("myText")
Replace.Cancel.Click ()
# 58 #
For QTP Documents visit: www.gcreddy.com
You can use the built-in Verify function to verify that two values are
equal and generate an exception if they are not. Typically, you use Verify to
test something that doesn’t map directly to a built-in property or method.
Verify has the following syntax:
# 59 #
For QTP Documents visit: www.gcreddy.com
Example Say you want to verify the number of radio buttons in the Direction
RadioList in the Replace dialog in the Text Editor. There is no property or
method you can directly use to verify this. But there is a method for
RadioList, GetItemCount, which returns the number of radio buttons. You can
use the method to provide the actual value, then specify the expected value
in the script, as follows:
When doing the verification, position the mouse pointer over the RadioList
and press Ctrl+Alt. Select the Method tab in the Verify Window dialog, and
select the GetItemCount method. Click OK to close the Verify Window dialog,
and complete your testcase. Paste it into a script. You now have the
following script:
testcase VerifyFuncTest ()
TextEditor.Search.Replace.Pick ()
Replace.Direction.GetItemCount ()
Replace.Cancel.Click ()
Now use the Verify function to complete the verification statement. Change
the line
Replace.Direction.GetItemCount () to Verify (Replace.Direction.GetItemCount
(), 2)
That is, the call to GetItemCount (which returns the number of radio buttons)
becomes the first argument to Verify. The expected value, in this case, 2,
becomes the second argument. Your completed script is:
testcase VerifyFuncTest ()
TextEditor.Search.Replace.Pick ()
Verify (Replace.Direction.GetItemCount (), 2)
Replace.Cancel.Click ()
Caret position, which is the current position of the text insertion cursor,
in (line, column) format. For example, a value of {1,1} means that the
text insertion cursor is positioned on line 1, column 1.
Enabled, which is the current enabled status of the text field, either
TRUE or FALSE.
Selected range, which is the beginning and ending position of the text
string currently selected in the field, in (line, column) format. For
# 60 #
For QTP Documents visit: www.gcreddy.com
Note Attributes have been essentially rendered obsolete and have been
replaced by properties.
The list box on the left shows the attributes for the current object.
# 61 #
For QTP Documents visit: www.gcreddy.com
Select an attribute from the list box. The current value of the attribute
(that is, the value that exists when you are recording) is shown in the
Attribute Value field.
If the current value of the attribute is not the value you want to test for
at runtime, edit the attribute value field. The value specified in this
field is the value you expect at runtime, that is, the baseline value.
Click OK to accept the attribute and its value. The Verify Window dialog
is closed, and the Record Status window is opened.
The testcase will verify that the object has the attribute value selected. If
not, an error is written to the results file.
Verifying all attributes By selecting the Verify All Attributes check box,
you can record a test that verifies the state, contents, and value of a GUI
object and any objects it contains. This is commonly called a smoke test or a
Level 1 test. A smoke test uses the VerifyEverything method to verify every
aspect of a particular GUI object.
Defining additional attributes If you need to, you can define and add
your own attributes to the built-in hierarchy of GUI classes.
# 62 #
For QTP Documents visit: www.gcreddy.com
testcase testcase_name ()
If you chose “(none)” as your application state, the testcase is recorded as:
# 63 #
For QTP Documents visit: www.gcreddy.com
When you paste a recorded testcase (or other recorded actions, such as
when you use Record Actions) into a script, SilkTest indents the code under a
recording statement to facilitate playback.
Procedure To save a script file, select File/Save. If it is a new file, you are
prompted for its name and location. When saving a file, SilkTest does the
following:
Saves a source file, giving it the .t extension; the source file is an ASCII
text file, which you can edit
Saves an object file, giving it the .to extension; the object file is a
binary file that is executable, but not readable by you
Example If you name a script file mytests and save it, you will end up with
two files: the source file mytests.t, in the location you specify, and the object
file mytests.to.
Procedure To save a new version of a script’s object file when the script file
is in view-only mode, select File/Save Object File.
Running tests
# 64 #
For QTP Documents visit: www.gcreddy.com
Preparing to run tests If you plan to test Web applications, make sure you
enable the correct browser extension(s), either during installation or using
the Agent Options dialog. If you do not plan to test Web applications, you
must disable all browser extensions using the Agent Options dialog. This is
because the recovery system works differently when testing Web
applications than when testing non-Web applications.
Select Options/Agent.
Select the Extensions tab.
Select the check box of each browser extension you want to enable.
Make sure that the testcase you want to run is in the active window.
Select Run/Testcase. The Run Testcase dialog appears. The Testcase
listbox displays all the testcases contained in the current script.
# 65 #
For QTP Documents visit: www.gcreddy.com
Checking the Disable Multiple Tag Feature check box in the Agent
Options dialog (Compatibility tab).
Specifying the following in your script:
Agent.SetOption (OPT_MULTIPLE_TAGS, FALSE)
After you have turned off multiple-tag support, 4Test discards all segments
of a multiple tag except the first one.
After you have created a number of script files, you might want to
collect them into a test suite. A suite is a file that names any number of
scripts. Instead of running each script individually, you run the suite, which
executes in turn each of your scripts and all the testcases they contain. Suite
files have a .s extension.
For example, the following suite file executes the find.t script first, the goto.t
script second, and the open.t script third.
# 66 #
For QTP Documents visit: www.gcreddy.com
find.t
goto.t
open.t
Make sure the script or suite you want to run is in the active window.
Select Run/Run. SilkTest runs all the testcases in the script or suite and
generates a results file.
Select File/Run.
Select the script or suite name from the Run dialog and browse the
directories to select the name of the script or suite file you want to run.
Click OK. SilkTest runs all the testcases in the script or suite and
generates a results file.
Results files
When you run a testcase, script, suite, or testplan, SilkTest creates a
results file. The following figure shows a results file for a script (find.t). The
menu bar includes the Results menu, which allows you to manipulate the
results file and locate errors. The Results menu appears only when the active
window displays a results file
# 67 #
For QTP Documents visit: www.gcreddy.com
Procedure To hide the overall summary, click on the summary and select
Results/Hide Summary. (You can change the default behavior by deselecting
the Show Overall Summary check box in the Runtime Options dialog.
You can see a summary for an individual test in a results file. For a script or
suite results file, the individual test summaries contain timing information
and errors or warnings. For a testplan results file, the individual test
summaries contain the same information as in the overall summary plus the
name of the testcase and script file.
# 68 #
For QTP Documents visit: www.gcreddy.com
The format for the rest of a testplan results file follows the hierarchy of
test descriptions that were present in the testplan. Test statements in the
testplan that are preceded by a pound sign (# ) as well as comments (using
the comment statement) are also printed in the results file, in context with
the test descriptions.
You can expand the text of an error message yourself or have SilkTest
find the error messages for you.
Clicking on the red plus sign
# 69 #
For QTP Documents visit: www.gcreddy.com
Using Find Error Procedure To find and expand the next error or warning
message in the results file, select Edit/Find Error.
Tip To skip warning messages and find error messages only, deselect Find
Error Stops at Warnings check box in the Runtime Options dialog. You can
also use the Find, Find Next, and Go to Line commands on the Edit menu to
navigate through a results file.
SilkTest provides several ways to move from the results file to the actual
error in the script:
# 70 #
For QTP Documents visit: www.gcreddy.com
Some expanded error messages are preceded by a box icon and three
asterisks, as shown in the following figure.
What happens when you click on the box icon depends on the error
message.
If the error message relates to an application’s appearance, as in
Bitmaps have different sizes, SilkTest opens the bitmap tool for
your platform.
If the error message relates to an application’s behavior, as in Verify
selected text failed, SilkTest opens the Difference Viewer. The
bitmap tool compares baseline and results bitmaps, whereas the
Difference Viewer compares actual and expected values for a given
testcase.
# 71 #
For QTP Documents visit: www.gcreddy.com
SilkTest starts the bitmap tool, reads in the baseline and result bitmaps, and
opens a Differences window and Zoom window.
Bitmap tool The following figure shows the bitmap tool. The baseline
bitmap for the Font dialog in the Text Editor is compared to the result
bitmap, which shows the Font dialog when the testcase was run. The
Differences window shows the area of difference between the two bitmaps,
that is, the different selection for Font Style.
The bitmap tool supports several comparison commands, which let you
closely inspect the differences between the baseline and results bitmaps.
Difference Viewer Clicking on the box icon invokes the Difference Viewer’s
double-paned display-only window (shown in the following figure). It lists
every expected (baseline) value in the left pane and the corresponding
actual value in the right pane. SilkTest highlights all occurrences where
expected and actual values differ. On color monitors, differences are marked
# 72 #
For QTP Documents visit: www.gcreddy.com
with red, blue, or green lines, which denote different types of differences, for
example, deleted, changed, and added items. The highlight is not visible in
the black-and-white
# 73 #
For QTP Documents visit: www.gcreddy.com
Application states Rather than record the same steps over and over again,
it is easier to record the steps as an application state and then associate the
application state with the relevant testcases. An application state is the state
you want your application to be in after the base state is restored but before
you run one or more testcases. By creating an application state, you are
creating reusable code that saves space and time. Furthermore, if you need
to modify the Setup stage, you change it once, in the application state
routine.
A testcase can have, at most, one application state associated with it.
However, that application state may itself be based on another previously
defined application state. For example, assume that
# 74 #
For QTP Documents visit: www.gcreddy.com
Open the file in which you want to place the application state. This can
either be the test frame file for the application or the script file where
the associated testcases are defined. If you put the application state in
the test frame file, it will be available to all testcases. If you put it in
the script file, it will be available only to testcases in that script file.
# 75 #
For QTP Documents visit: www.gcreddy.com
Type the name of your new application state in the Application State
Name field.
Select an application state from the Based On drop-down list.
Press the Start Recording pushbutton. SilkTest closes the Record
Application State dialog and displays the Record Status window. The
Status field flashes Recording.
Drive your application to the state you want to record. At any point,
you can record a verification by pressing Ctrl+Alt.
When you have finished recording an application state, press Done on
the Record Status window. SilkTest redisplays the Record Application
State dialog. The Application State Code field contains all the 4Test
code you’ve just recorded. You can take the following actions:
# 76 #
For QTP Documents visit: www.gcreddy.com
Example Here is a sample application state that performs the setup for all
forward case-sensitive searches in the Find dialog:
Make active the window that contains the application state and select
Run/Application State. The Run Application State dialog appears,
shown in the following figure.
# 77 #
For QTP Documents visit: www.gcreddy.com
Select the application state you want to run and click Run.
If there are compilation errors, SilkTest displays an error window. Fix
the errors and rerun the application state.
# 78 #