Sunteți pe pagina 1din 13

Rational Robot: A Basic Introduction to Automating Functional Testing

TABLE OF CONTENTS

1. WHAT IS RATIONAL ROBOT?.......................................................................................................2

2. CREATING A SCRIPT.......................................................................................................................2

3. NAME(S) OF TEST SCRIPTS............................................................................................................2

4. RECORDING........................................................................................................................................2

5. VERIFICATION POINTS...................................................................................................................2
5.1 TYPES OF VERIFICATION POINTS...................................................................................................3
6. CREATING A WAIT STATE.............................................................................................................4

7. WORKING WITH THE DATA IN DATA GRIDS..........................................................................5

8. SOME USEFUL SQA BASIC SCRIPTING COMMANDS............................................................6


8.1 SQALOGMESSAGE.........................................................................................................................6
8.2 SQAGETPROPERTY........................................................................................................................7
8.3 SQAWAITFOROBJECT...................................................................................................................7
8.4 SQACONSOLEWRITE.....................................................................................................................7
8.5 CALLSCRIPT....................................................................................................................................8
8.6 DELAYFOR.....................................................................................................................................8
8.7 STARTBROWSER.............................................................................................................................8
8.8 STARTAPPLICATION.......................................................................................................................8
9. USING WILDCARDS IN WINDOW CAPTIONS...........................................................................9

10. EDITING, COMPILING, AND DEBUGGING SCRIPTS.........................................................9

11. COMPILING A SCRIPT................................................................................................................9

12. DEBUGGING GUI SCRIPTS......................................................................................................10

13. SETTING AND CLEARING BREAKPOINTS.........................................................................10

14. EXAMINING VARIABLE VALUES..........................................................................................10

15. LIBRARY SOURCE FILES.........................................................................................................11


15.1 SBL/H’S.......................................................................................................................................11
15.2 HOW DO I CREATE AN SBL?........................................................................................................12
16. Document History................................................................................................................................
Rational Robot: A Basic Introduction to Automating Functional Testing

1. What is Rational Robot?


Rational Robot is a tool that allows you to automate your test scripts. Automation is very useful for regression and
performance testing. Regression testing involves re-running previously tested and passed functionality to assure
that any new enhancement(s) has/have not corrupted these parts of the software system. Performance testing
involves a set of performed tests that can allow the tester to evaluate ‘performance related characteristics of the
target-of-test such as the timing profiles, execution flow, response times, and operational reliability and limits.’
Automation can increase the test coverage of your application, speed up the process of testing and make it more
reliable. Repeatable, tedious and mundane actions can be scripted, allowing the tester to get involved in more
creative and challenging tasks.

Rational records in the SQA Basic language; as the name suggests this is a BASIC derived language that is similar
to VB. We should be treating Robot as a programming environment, where we can manually edit scripts, to
include things like conditional statements, loops, custom date types, variables etc. From the libraries in the
SQABAS32 folder we can call sub-routines and functions. We should be looking to put all re-usable code in this
folder.

We can also create datapools which scripts (.rec) files can call from. Datapools are a source of variable test data
that can be used in a script. We can call these through a custom Rational database or from Excel or Access. (We
will deal with creating and using datapools in another document)

1. Creating a script
It will be best to record the scripts through TestManager so we can tie them to requirements or other test inputs.
However if we wish to create a script in Robot we can by just hitting the GUI command button on the toolbar.

As you may well know Robot records the mouse clicks and keystrokes of the user. Try to use keystrokes instead
of mouse clicks and try not to use the scroll-bar as you will find difficulty on playback.
2. Name(s) of Test Scripts
We should name the scripts as much as possible with the names of the requirements that will be input in Test
Manager. So if we a have a requirement that states that ‘Tender Trust must be able to upload a tender’; that script
will be named ‘UploadTenderTrust’ for example. We will talk more about scripting standards at another date.
3.Recording
During recording you will be shown a floatable toolbar that looks like this:

You are able to move this toolbar anywhere within the screen. The movement of the toolbar will not be
recorded in the script. Obviously you will be able to discern what are the pause and stop recording
options. The other two are a little less intuitive.
This button opens the Robot window while recording. I wouldn’t bother about this too much. If I
want to manually enter something in the script while recording the script, I normally pause, then type in
the code.
4. Verification Points
This option you will use more than the stop button. It allows you to create verification points
(VP’s). A verification point is ‘a point in the script that the tester creates in order to confirm the
state of an object across builds of the application under test.’ During recording, a verification point
captures object information (based on the type of verification point) and stores it in a baseline data file.
Rational Robot: A Basic Introduction to Automating Functional Testing
The information in this file becomes the baseline of the expected state of the object during subsequent
builds.

When we play back on a new build, the state of the object is compared against the baselined verification
point. If the captured data does not match the baseline, Robot creates an actual data file. The information
in this file shows that actual state of the object in build.

The results of the verification are now displayed in TestManager in the TestLogViewer. A green flag
shows us that the VP has passed, while a red flag indicates that it has failed. If the VP has failed we can
double-click on the flag and we will be shown where it failed (i.e. there is a comparison of the baselined
data with the actual data.)

5.1 Types of Verification Points


The verification toolbar:

The verification toolbar allows you to choose different types of verification points.

 Alphanumeric: The alphanumeric test captures and tests alphanumeric data in windows
objects that contain text, such as edit boxes. You can use the VP to verify that text has not
changed, to catch spelling errors and to ensure that numeric values are accurate.
 Clipboard: Captures and compares alphanumeric data that has been copied to the clipboard
 File Comparison: A file comparison compares two specified files during playback. To insert of
file comparison VP, click Insert > VP > File Comparison. When you create the VP, you specify
the drive, directory and file name(s). You can use the browse facility. During playback, Robot
compares the files byte-for-byte.
 File Existence: Verifies the existence of a specified file during playback. Click insert > VP >
File Existence. During playback Robot checks to see if the file exists in the specified location.
Could use for example, to see if registry files have been added.
 Menu: The menu VP captures and compares the menu title, menu items, shortcut keys and
the state of selected menus. Robot records information about the top menu and up to five levels of
sub-menus. Robot treats menu items as objects within a menu and tests their content, state, and
accelerator keys regardless of the menu item’s location.
 Object Data: Object Data captures and compares the data inside standard Windows objects.
 Object Properties: The Object Properties VP captures and compares the properties of
standard Windows objects.
 Region and Windows Image comparators - Avoid these like the plague. They are guaranteed to
fail. They capture the screen as a bitmap (pixel by pixel representation) and depending on your
screen resolution, graphics card, colour palette, Operating System ad nauseam. I use window and
region image comparators conditionally:

Result = WindowVP (Exists, "Caption=TenderTrust - Microsoft Internet Explorer", "VP=Window Existence")

3
Rational Robot: A Basic Introduction to Automating Functional Testing
If Result = 0 Then
Result = WindowVP (CompareImage, "Caption=TenderTrust - Microsoft Internet Explorer", "VP=Window Image")
End If
For example, if the Tender Trust window does not exist (note the window existence VP), I want
to know what appeared in it’s place, so I capture the image.

 Web Site Compare


Captures a baseline of a Web site and compares it to the Web site at another point in time. (Not
actually used this so give it a try)
 Web Site Scan
Checks the contents of a Web site with every revision and ensures that changes have not resulted
in defects.

3. Creating a wait state


When you create a verification point, you can add specific wait values to handle time-dependent test
activities. Wait values are useful when the application requires an unknown amount of time to complete a
task. Using a wait value keeps the verification point from failing if the task is not completed immediately
or if the data is not accessible right away.

We’re in the middle of creating a windows existence VP on the Robot window. Note, that I have named
the verification point so it will give me/us an indication as to what it is doing. And notice the post-fix
‘WE’ (short for windows existence). For Object Properties, put a post-fix ‘OP’, Object Data ‘OD’,
Window Image ‘WI’ etc.
So in this dialog we have ticked the ‘Apply wait state to verification point’ checkbox and this enables the
two edit boxes within the dialog. So in the example above, Robot will search for the existence of its own
window; it will look every two seconds and after thirty seconds will forget all about it. We want the
expected result to equal the actual, hence the radio button chosen.
The code in Robot will look like this:

We can change the wait states, by going into Robot and manually editing the figures in the code.
4
Rational Robot: A Basic Introduction to Automating Functional Testing
3. Working with the Data in Data Grids
When you create a Clipboard, Menu, or Object Data verification point and select an object, you are
actually testing the object's data. This data appears in a Robot data grid, which shows data in rows and
columns. You use the data grid to select and edit the data to test.

In the above example, I have done on Object Data VP on the ‘Find’ utility in Microsoft Outlook. We can
edit this data manually (see below) or we can use any of the following methods to select data in the
columns, rows, or cells of the data grid. If we want a range of contiguous cells click and drag the pointer
over a range of cells. If we want to select non-contiguous cells press the CTRL key and click each cell.
Clicking without the CTRL key cancels previous selections. If you want to select an entire column
click a column title. To test an entire row, click on a row number; Robot compares the data and the
number of items in a row. To test all cells click the box in the upper-left corner of the grid.

To edit data in a grid double-click a cell in the data grid and edit the data in the cell. To accept the
changes, press ENTER. To cancel the changes, press ESC.

5
Rational Robot: A Basic Introduction to Automating Functional Testing

8. Some Useful SQA Basic Scripting Commands


8.1 SQALogMessage
Writes a message to a test log viewer in TestManager. It is optional as to whether you set a flag . The
flags that can be set are pass fail, warning or no flag at all. This is useful for notation.

The syntax for this command is: SQALogMessage code%, message$, description

Syntax Element Description


code% sqaPass or True
Inserts Pass (green flag) in the Test Log Viewer result column
sqaFail or False
Inserts Fail (red flag) in the Test Log Viewer result column
sqaWarning
Inserts Warning (yellow flag) in the Test Log Viewer result column
sqaNone
Leaves the Result column blank for the message entry.
Messages$ The message to insert in the log. The message appears in the Event Type
column of the log.
description$ A description of the log message. The description appears in the Failure
Description field of the Log Event – Log Message dialog box.
The Log Event – Log Message dialog box looks like this:
Log Event – Log Message Dialog Box

This dialog is displayed by right clicking the message in the log and clicking
properties.

Example: SQALogMessage SQAFail, “Test Bombed Big-Time”,””

6
Rational Robot: A Basic Introduction to Automating Functional Testing
8.2 SQAGetProperty
Retrieves the value of the specified property.
The syntax for this command is: status% = SQAGetProperty(recMethod$, property$, value)

Syntax Element Description


recMethod$ The recognition method values you use to identify an object depend on the
object you are accessing. For example, if you are accessing a push button
object, use the recognition method values listed for the PushButton user action
command.
property$ A case-sensitive property name e.g “Text”
value An output argument of type variant that will contain the retrieved property
value.
Example: SQAGetProperty("Type=CheckBox;Text=Match case", "State", CheckState)

8.3 SQAWaitForObject
Pauses execution of the script until the specified object can be found.
The syntax for this command is: SQAWaitForObject (recMethod$,timeout&)

Syntax Element Description


recMethod$ The recognition method values you use to identify an object depend on the
object you are accessing.
timeout& The maximum number of milliseconds to look for the object. If the object does
not appear Robot’s search will end.

Example: Result = SQAWaitForObject ("Type=PushButton;Text=OK", 120000)


If Result = sqaSuccess Then
Msgbox “Fail”
End If
8.4 SQAConsoleWrite
Writes the specified text to the Robot console window.
The syntax for this command is: SQAConsoleWrite text$
The console window is in the left hand corner of Robot

Choose the console tab


If we write this in the .rec file, ‘SQAConsoleWrite "Start of Playback"’, you get the above in the
console. The console can help you keep track of you’re script.

7
Rational Robot: A Basic Introduction to Automating Functional Testing
8.5 Callscript
Calls a script from another script and executes it from within the currently-running script.
The syntax is: CallScript script$
Syntax Element Description
script$ Name of the script to be called and executed

8.6 DelayFor
Delays execution of the script for a specified number of milliseconds.The syntax is: DelayFor
TimeInterval&
Syntax Element Description
TimeInterval& Time in milliseconds to delay e.g.

Example: DelayFor 2000

8.7 StartBrowser
Starts an instance of the browser, enables Web testing, and loads a Web page if one is specified.

The syntax is: StartBrowser [URL$,] [WindowTag=Name$]

Syntax Element Description


URL$ The Universal Resource Locator of the Web
page to load.
Name$ An optional name that specifies this instance of
the browser. In subsequent user actions,
WindowTag=Name$ is used in the recMethod$
argument of the Window SetContext command
to identify this instance of the browser.

An example would be: StartBrowser "http://www.rational.com/", "WindowTag=Instance1"

NOTE:
You must use the StartBrowser command within Robot enables Web object recognition. If you start a
Web browser outside of Robot (that is, without using the StartBrowser command), you must open
rbtstart.htm in your browser, or run the Rational ActiveX Test Control that rbtstart.htm references,
before loading Web pages for testing.

8.8 StartApplication
Starts the specified application from within the currently running script.
The syntax is: StartApplication Pathname$

Syntax Element Description


Pathname$ The full path and file name of the application
to be started. Arguments can be included.

An example would be: StartApplication """c:\program files\rational\rational test\rtinspector.exe"""

8
Rational Robot: A Basic Introduction to Automating Functional Testing

3. Using Wildcards in Window Captions


A window caption is located in its title bar. Often, a window caption is used to help identify an object in
a recognition method. When you specify a window caption in a recognition method, you can type the
entire caption, or you can use the following wildcards:

Wildcard character Description


Question mark (?) Matches a single character in a caption
Asterisk (*) Matches any number of caption characters from the asterisk to the next
character or, if there are no characters after the asterisk, to the end of the
caption.

Example: Window SetContext, “Caption = {?otepad}”,””


When using wildcard characters in a caption, enclose the caption within braces.

4. Editing, Compiling, and Debugging Scripts


You can edit the text of any open script. Before starting to edit, you must have a script open. The script
can either be one that has been just recorded or a script that has just been opened.

5. Compiling a script
When you play back a GUI script, or when you debug a GUI script, Robot compiles the script if it has
been modified since it last ran. You can also compile scripts manually, by pressing this
toolbar button.

Locating Compilation Errors


During compilation, the Build tab of the Output window displays compilation results and error messages
with line numbers for all scripts and library source files.

Double-click the error or warning in the Build tab, to locate compilation errors in the Script window.
9
Rational Robot: A Basic Introduction to Automating Functional Testing

6. Debugging GUI Scripts


Robot includes a complete, built-in debugging environment to assist you during the development phase
of your GUI scripts. To debug a GUI script, use the Debug menu commands or toolbar buttons.
The debug commands are:
 GO
Go Plays back the currently open script. It executes the script, until either the next breakpoint or the
end of the script, whichever comes first.

 GO UNTIL CURSOR
Plays back the currently open script, stopping at the text cursor position. It executes until either the
next breakpoint or the end of the script, whichever comes first.

 ANIMATE
Plays back the currently open script, displaying a yellow highlighted line
as it executes. It executes until either the next breakpoint or the end of the script, whichever comes
first.

 SET OR CLEAR BREAKPOINTS


Sets or clears a breakpoint at the cursor position. If you set a breakpoint, Robot inserts a solid red
circle in the left margin or highlights the line. If you clear a breakpoint, Robot removes the circle.
 STEP INTO
Begins single-step execution, that is executes one command at a time.

 INSERT AT CURSOR
We can continuing recording anywhere in the script by clicking this button. Robot will record at the
cursor position.

7. Setting and Clearing Breakpoints


Robot lets you set any number of breakpoints in a script. A breakpoint is a location
in a script where you want execution to stop.

When execution stops at a breakpoint, you can examine the value of a variable or check the state of an
object before it is modified by a subsequent command. You can then resume execution until the next
breakpoint or the end of the script.

To set up a breakpoint, in an open script, click Debug > Go.

8. Examining Variable Values


You can examine variable and constant values in the Variables window as you play back scripts during
debugging. The Variables window appears in the lower-right corner of the Robot main window.
If the Variables window is not open, click View > Variables to open it. We can only see datatypes
passed to variables in the variable window during debug.

This puts the caption of Acrobat Reader into the variable ‘value’ (bit of a pointless exercise, because we
already have the caption property), but we can demonstrate that the value of the variable appears in
bottom right hand corner of Robot.

10
Rational Robot: A Basic Introduction to Automating Functional Testing

9. Library Source Files


Library source files allow us to create custom sub-routines and functions than we can call in our .rec
files. Rational has number of functions that we can use and are held in the ‘SqaUtil’ folder. Most
Rational users will use these ready-made functions on a daily basis: for example SQAGetProperty allows
us to retrieve the property of an object, which we can store in a variable.

In .rec file we would go:

Dim Result As Integer


Dim value As String

Result = SQAGetProperty (“Name=myObject”, “Text”, value)

So the text value will be held in the variable ‘value’ and we could compare it with another value, for
example. The Result is boolean, so if for some reason the text property is not picked up by Robot we will
be returned with a nought ‘0’. The SQA Language Ref is full of Robot internal functions. The manual
comes with TestStudio or it can be accessed on-line.

15.1 SBL/H’s
We cannot automate a project with record and playback. For example if a developer has been given a
requirement to add a dialog box on a PC application and we’ve got 30 scripts that have been recorded
and deal in that area. We’ve got to go into 30 .rec files and copy and paste the code in. What if there
were 100 scripts, a 1000? The time that is wasted could be quite substantial; not only this it is de-
motivating and regression testing is never really done. If however we used the libraries then we could
call a procedure into a .rec file, changing the code only once.

If I can quote from the user guide: ‘Header files have an .SBH extension and contain the procedure
declarations and global variables referred to in your test procedure script files. Source code files have
.SBL extensions and contain the procedure definitions you use in your script files. Header and source
files are stored in *\SQABAS32…’

11
Rational Robot: A Basic Introduction to Automating Functional Testing
15.2 How do I create an SBL?
Go into Robot and choose File > New > SQABasic File. You will be presented with the below
dialog box.

Double click on Library Source file and write your code here:

So for example, the simple function above uses the internal date function, formats it puts it into upper-
case, and stores it in CurrentDate.

Now go into the .SBH file, using the same method: File > New > SQABasic File, but select the Header
File option in the ‘New SQABasic file’ dialog box. Declare the function as below

12
Rational Robot: A Basic Introduction to Automating Functional Testing

We need to reference the header in the .rec file. We do this by using the ‘$Include metacommand.

We can now call the function in a procedure, and we’ve created a msgbox to view the result. And we’ve
got today’s date
13

S-ar putea să vă placă și