background image
<< Running the recorded test | Expand the testcase LogMouseMoves >>

Extending the test programmatically

<< Running the recorded test | Expand the testcase LogMouseMoves >>
Working with Java Applications
15
Step 9: Extending the test programmatically
So far, we've verified that the Event Log records the Button Down and Button Up mouse events
correctly when we click once to draw a single point in the drawing canvas. To extend this test, we
really should verify whether the Event Log also records the correct coordinates of the point we draw in
the canvas.
To make this a more general test, we'll create two integer variables to store the X and Y coordinates of
a point. In addition, we will set each variable to a 2-digit random number within a range of values that
falls inside the drawing canvas.
At this point, we assume that the sample Java application is running and not minimized, and that your
test script draw.t is still open.
To expand the test to verify point coordinates:
1 Determine the range of acceptable values for point coordinates by checking the Rect property of
the drawing canvas, as follows:
·
In the sample Java application, select Control/Drawing area.
·
In
SilkTest,
select
Record/Actions.
·
Click in the title bar of Drawing area window and move your mouse pointer into the drawing
canvas. When you see Press <Ctrl-Alt> to verify window Canvas appear at the bottom of the
Record Actions dialog, press Ctrl-Alt to bring up the Verify Window.
·
The values for the Rect property in the Properties to Verify window. On our system, the values
showed that the range of acceptable X coordinates was 0 to 314 and the range of acceptable Y
coordinates was 0 to 60. These values might be different on your system, depending on your
display settings and other system configuration parameters.
·
Click
Cancel to close the Verify Window, and then click Close to close the Record Actions
window.
·
Click
Exit to close the Drawing Area window.
2 Expand the testcase LogMouseMoves in your draw.t file and make the following changes:
·
Above the recording block, declare two integer variables, iX to store an X-coordinate value and
iY to store a Y-coordinate value. Use the RandInt function to set iX and iY to two-digit random
numbers that fall within the range of acceptable coordinates, as determined from the Rect
property of the drawing canvas. See "RandInt function in the online Help for more details. We
set iX to between 10 and 99 and iY to a random number between 10 and 60. Here is some
sample code which you can copy and paste line by line into your test script. Substitute different
numbers in the RandInt function calls, if necessary.
int iX = RandInt(10,99)
int iY = RandInt(25,60)
·
Inside the recording block, substitute iX and iY as the second and third arguments in the
command DrawingArea.Canvas.Click. This code forces your test to always draw a point at a
random location within the boundaries of the drawing canvas. The following is sample code
which you can copy and paste into your test script.
DrawingArea.Canvas.Click (1, iX, iY)