11 Functional Test Module

This chapter provides a complete listing and reference for the methods in the OpenScript FunctionalTestService Class of Functional Test Module Application Programming Interface (API).

11.1 FunctionalTestService API Reference

The following section provides an alphabetical listing of the methods in the OpenScript FunctionalTestService API.

11.1.1 Alphabetical Command Listing

The following table lists the FunctionalTestService API methods in alphabetical order.

Table 11-1 List of FunctionalTestService Methods

Method Description

ft.drag

Perform a drag operation with the mouse.

ft.dragAndDrop

Perform a drag and drop operation with the mouse.

ft.getScreenCapture

Capture the specified region of the screen to a file.

ft.keyDown

Perform key down action on the keys in the form of Key Code.

ft.keyUp

Release key on the keyboard if it is pressed down.

ft.mouseClick

Move the mouse to the specified coordinates on the screen and press the specified mouse button.

ft.mouseDown

Move the mouse to the specified coordinates on the screen and depress the specified mouse button without releasing it.

ft.mouseUp

Move the mouse to the specified coordinates on the screen and release the specified mouse button.

ft.typeCharacters

Simulate typing a string of character keys on the keyboard.

ft.typeKeyCode

Simulate pressing keys on the keyboard by keycodes.

ft.typeKeys

Simulate pressing keys on the keyboard.


The following sections provide detailed reference information for each method and enum in the FunctionalTestService Class of Functional Test Module Application Programming Interface.


ft.drag

Perform a drag operation with the mouse. The mouse button is NOT released after the drag operation finishes.

All coordinates are relative to the entire screen.

Mouse operations are synchronized within the running agent process, but, as of 2.3.0, are NOT synchronized across all running agent processes on the machine. Therefore, if multiple agent processes are running, there is contention for the mouse.

For reliable playback, it is imperative not to move the mouse when this action is being performed during script playback.

Format

The ft.drag method has the following command format(s):

ft.drag(xDragStart, yDragStart, xDragEnd, yDragEnd);

Command Parameters

xDragStart

X coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.

yDragStart

Y coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.

xDragEnd

X coordinate where to stop the drag operation. Coordinates are relative to the screen, and specified in pixels.

yDragEnd

Y coordinate where to stop the drag operation. Coordinates are relative to the screen, and specified in pixels.

Throws

FTCoreException

if the method fails.

Example

Performs a mouse drag starting at screen coordinate x=100, y=100 and ending at corrdinate x=200, y=200.

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
ft.drag(100, 100, 200, 200);

See Also

ft.dragAndDrop


ft.dragAndDrop

Perform a drag and drop operation with the mouse.

All coordinates are relative to the entire screen.

Mouse operations are synchronized within the running agent process, but, as of 2.3.0, are NOT synchronized across all running agent processes on the machine. Therefore, if multiple agent processes are running, there is contention for the mouse.

For reliable playback, it is imperative not to move the mouse when this action is being performed during script playback.

Format

The ft.dragAndDrop method has the following command format(s):

ft.dragAndDrop(xDragStart, yDragStart, xDropTo, yDropTo);

Command Parameters

xDragStart

X coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.

yDragStart

Y coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.

xDropTo

X coordinate where to release the mouse after dragging the item over its target. Coordinates are relative to thescreen, and specified in pixels.

yDropTo

Y coordinate where to release the mouse after dragging the item over its target. Coordinates are relative to thescreen, and specified in pixels.

Throws

FTCoreException

if the method fails.

Example

Performs a mouse drag and drop starting at screen coordinate x=100, y=100 and ending at corrdinate x=200, y=200.

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
ft.dragAndDrop(100, 100, 200, 200);

See Also

ft.drag


ft.getScreenCapture

Capture the specified region of the screen to a file.

The file name must end with .jpg or .png, not case-sensitive, depending on the output format desired.

Coordinates are relative to the screen, and specified in pixels.

Format

The ft.getScreenCapture method has the following command format(s):

ft.getScreenCapture(left, top, width, height, imgFileName);

Command Parameters

left

Left (X) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.

top

Top (Y) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.

width

Right (X) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.

height

Bottom (Y) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.

imgFileName

Local filename to which to write the captured image. Must have write-access to the output file name.Any existing contents in the file will be overwritten. The file name must end with .jpg or .png,not case-sensitive, depending on the output format desired.

Throws

FTCoreException

if the method fails.

Example

Captures the screen image from coordinates x=0, y=0 to coordinates x=400, y=400.

import java.io.File;
import java.io.FileOutputStream;
[...]
String path = getScriptPackage().getScriptPath();
String folder = path.substring(0, path.lastIndexOf("\\"));
String imgName = folder + "\\capturedImg.jpg";
File imgFile = new File (imgName);
[...]
web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
web.textBox("/web:window[@index='0' or @title='Test Web Events']" +
 "/web:document[@index='0']" +
 "/web:input_text[@name='Text' or @index='0']")
 .focus();
if(imgFile.exists()){
 if(imgFile.setReadOnly()){
  imgFile.setWritable(true);
 }
 imgFile.delete();
}
ft.getScreenCapture(0, 0, 400, 400, imgName);
if(!imgFile.exists()){
 warn("getScreenCapture() failed.");
}

ft.keyDown

Perform key down action on the keys in the form of Key Code.

Format

The ft.keyDown method has the following command format(s):

ft.keyDown(keyCodes);

Command Parameters

keyCodes

an int Array specifying the keys to be pressed down.

Throws

FTCoreException

if the method fails.

Example

Simulates pressing down the keys "g" "o" "o" "d".

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
web.textBox("/web:window[@index='0' or @title='Test Web Events']" +
 "/web:document[@index='0']" +
 "/web:input_text[@name='Text' or @index='0']")
 .focus();
ft.keyDown(KeyEvent.VK_G, KeyEvent.VK_O, KeyEvent.VK_O, KeyEvent.VK_D);

ft.keyUp

Release key on the keyboard if it is pressed down.

Format

The ft.keyUp method has the following command format(s):

ft.keyUp(keyCodes);

Command Parameters

keyCodes

an int Array specifying the keys to be pressed down.

Throws

FTCoreException

if the method fails.

Example

Simulates pressing down the keys "g" "o" "o" "d".

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
web.textBox("/web:window[@index='0' or @title='Test Web Events']" +
 "/web:document[@index='0']" +
 "/web:input_text[@name='Text' or @index='0']")
 .focus();
ft.keyUp(KeyEvent.VK_G, KeyEvent.VK_O, KeyEvent.VK_O, KeyEvent.VK_D);

ft.mouseClick

Move the mouse to the specified coordinates on the screen and press the specified mouse button.

This method is different from a DHTML-based click event because it literally moves the mouse before clicking, and it requires the correct window to be in the foreground and visible. All coordinates are relative to the entire screen.

Mouse operations are synchronized within the running agent process, but, as of 2.3.0, are NOT synchronized across all running agent processes on the machine. Therefore, if multiple agent processes are running, there is contention for the mouse.

For reliable playback, it is imperative not to move the mouse when this action is being performed during script playback.

Format

The ft.mouseClick method has the following command format(s):

ft.mouseClick(x, y, clickCount, rightButton, modifiers);

Command Parameters

x

X coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.

y

Y coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.

clickCount

Specifies how many times to click the mouse. For example, specify 2 to double-click, or 1to single-click.

rightButton

Set to true to click the secondary mouse button, false to click the primary mouse button.On most systems, the right mouse button is the secondary mouse button.

modifiers

Specify a string of keyboard modifiers to hold down when clicking the mouse. Example values include any combinationof ALT, SHIFT, and CTRL, surrounded by angle brackets. For example, to hold down the Shiftand Control keys, specify the string: <SHIFT><CTRL>

Throws

FTCoreException

if the method fails.

Example

Performs a mouse click at screen coordinate x=100, y=100.

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
ft.mouseClick(100, 100, 1, false, "");
ft.mouseClick(100, 100, 1, false, "<SHIFT>");

ft.mouseDown

Move the mouse to the specified coordinates on the screen and depress the specified mouse button without releasing it.

This method is different from a DHTML-based onMouseDown event because it literally moves the mouse before clicking, and it requires the correct window to be in the foreground and visible. All coordinates are relative to the entire screen.

Mouse operations are synchronized within the running agent process, but, as of 2.3.0, are NOT synchronized across all running agent processes on the machine. Therefore, if multiple agent processes are running, there is contention for the mouse.

For reliable playback, it is imperative not to move the mouse when this action is being performed during script playback.

Format

The ft.mouseDown method has the following command format(s):

ft.mouseDown(x, y, rightButton);

Command Parameters

x

X coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.

y

Y coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.

rightButton

Set to true to press down on the secondary mouse button, false to press down onthe primary mouse button. On most systems, the right mouse button is the secondary mouse button.

Throws

FTCoreException

if the method fails.

Example

Performs a mouse down at screen coordinate x=500, y=500.

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
ft.mouseDown(500, 500, false);

See Also

ft.mouseUp


ft.mouseUp

Move the mouse to the specified coordinates on the screen and release the specified mouse button.

This method is different from a DHTML-based onMouseUp event because it literally moves the mouse before releasing it, and it requires the correct window to be in the foreground and visible. All coordinates are relative to the entire screen.

Mouse operations are synchronized within the running agent process, but, as of 2.3.0, are NOT synchronized across all running agent processes on the machine. Therefore, if multiple agent processes are running, there is contention for the mouse.

For reliable playback, it is imperative not to move the mouse when this action is being performed during script playback.

Format

The ft.mouseUp method has the following command format(s):

ft.mouseUp(x, y, rightButton);

Command Parameters

x

X coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.

y

Y coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.

rightButton

Set to true to release the secondary mouse button, false to release the primarymouse button. On most systems, the right mouse button is the secondary mouse button.

Throws

FTCoreException

if the method fails.

Example

Performs a mouse up at screen coordinate x=500, y=500.

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
ft.mouseUp(500, 500, false);

See Also

ft.mouseDown


ft.typeCharacters

Simulate typing a string of character keys on the keyboard.

This API would press the keys directly by the sequence of the characters String.

No function keys like "SHIFT","CTRL","ALT","F1" , etc. would be supported.

Format

The ft.typeCharacters method has the following command format(s):

ft.typeCharacters(characters);

Command Parameters

characters

a String specifying the keys to type.

Throws

FTCoreException

if the method fails.

Example

Simulates typing the keys "g" "o" "o" "d".

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
web.textBox("/web:window[@index='0' or @title='Test Web Events']" +
 "/web:document[@index='0']" +
 "/web:input_text[@name='Text' or @index='0']")
 .focus();
ft.typeCharacters("good");
 web.verifyText("tmt", "good", Source.DisplayContent,
 TextPresence.PassIfPresent, MatchOption.Exact);

ft.typeKeyCode

Simulate pressing keys on the keyboard by keycodes.

Special keys should be formated as a Java KEYNAME (without prefix VK_) inside < > characters, i.e. <Insert>, <Less>, <SHIFT-A>, <TAB> This method automatically inserts < > around ASCII characters like A-Z, 0-9. <SHIFT-A><TAB><H>ome types: A home.

Format

The ft.typeKeyCode method has the following command format(s):

ft.typeKeyCode(keyCodes);

Command Parameters

keyCodes

an int Array specifying the keys to type.

Throws

FTCoreException

if the method fails.

Example

Simulates typing the keys "g" "o" "o" "d".

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
web.textBox("/web:window[@index='0' or @title='Test Web Events']" +
 "/web:document[@index='0']" +
 "/web:input_text[@name='Text' or @index='0']")
 .focus();
ft.typeKeyCode(KeyEvent.VK_G, KeyEvent.VK_O, KeyEvent.VK_O, KeyEvent.VK_D);
{
 web.verifyText("tmt", "good", Source.DisplayContent,
 TextPresence.PassIfPresent, MatchOption.Exact);
}

ft.typeKeys

Simulate pressing keys on the keyboard.

Special keys should be formated as a Java KEYNAME (without prefix VK_) inside < > characters, i.e. <Insert>, <Less>, <SHIFT-A>, <TAB> This method automatically inserts < > around ASCII characters like A-Z, 0-9. <SHIFT-A><TAB><H>ome types: A home.

Format

The ft.typeKeys method has the following command format(s):

ft.typeKeys(keys);

Command Parameters

keys

a String specifying the keys to type.

Throws

FTCoreException

if the method fails.

Example

Simulates typing the keys "g" "o" "o" "d".

web.window(5, "/web:window[@index='0' or @title='Test Web Events']")
 .navigate("http://example.com/Web_Event.html");
web.window(7, "/web:window[@index='0' or @title='Test Web Events']")
 .waitForPage(null);
web.textBox("/web:window[@index='0' or @title='Test Web Events']" +
 "/web:document[@index='0']" +
 "/web:input_text[@name='Text' or @index='0']")
 .focus();
ft.typeKeys("<g>");
ft.typeKeys("<o>");
ft.typeKeys("<o>");
ft.typeKeys("<d>");
{
 web.verifyText("tmt", "good", Source.DisplayContent,
 TextPresence.PassIfPresent, MatchOption.Exact);
}