This chapter provides a complete listing and reference for the methods in the OpenScript FunctionalTestService Class of Functional Test Module Application Programming Interface (API).
The following section provides an alphabetical listing of the methods in the OpenScript FunctionalTestService API.
The following table lists the FunctionalTestService API methods in alphabetical order.
Table 11-1 List of FunctionalTestService Methods
Method | Description |
---|---|
Perform a drag operation with the mouse. |
|
Perform a drag and drop operation with the mouse. |
|
Capture the specified region of the screen to a file. |
|
Perform key down action on the keys in the form of Key Code. |
|
Release key on the keyboard if it is pressed down. |
|
Move the mouse to the specified coordinates on the screen and press the specified mouse button. |
|
Move the mouse to the specified coordinates on the screen and depress the specified mouse button without releasing it. |
|
Move the mouse to the specified coordinates on the screen and release the specified mouse button. |
|
Simulate typing a string of character keys on the keyboard. |
|
Simulate pressing keys on the keyboard by keycodes. |
|
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.
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.
The ft.drag method has the following command format(s):
ft.drag(xDragStart, yDragStart, xDragEnd, yDragEnd);
X coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.
Y coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.
X coordinate where to stop the drag operation. Coordinates are relative to the screen, and specified in pixels.
Y coordinate where to stop the drag operation. Coordinates are relative to the screen, and specified in pixels.
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);
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.
The ft.dragAndDrop method has the following command format(s):
ft.dragAndDrop(xDragStart, yDragStart, xDropTo, yDropTo);
X coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.
Y coordinate where to start the drag operation. Coordinates are relative to the screen, and specified in pixels.
X coordinate where to release the mouse after dragging the item over its target. Coordinates are relative to thescreen, and specified in pixels.
Y coordinate where to release the mouse after dragging the item over its target. Coordinates are relative to thescreen, and specified in pixels.
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);
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.
The ft.getScreenCapture method has the following command format(s):
ft.getScreenCapture(left, top, width, height, imgFileName);
Left (X) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.
Top (Y) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.
Right (X) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.
Bottom (Y) corner of the region to capture. Coordinates are relative to the screen, and specified in pixels.
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.
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.");
}
Perform key down action on the keys in the form of Key Code.
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);
Release key on the keyboard if it is pressed down.
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);
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.
The ft.mouseClick method has the following command format(s):
ft.mouseClick(x, y, clickCount, rightButton, modifiers);
X coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.
Y coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.
Specifies how many times to click the mouse. For example, specify 2
to double-click, or 1
to single-click.
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.
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>
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>");
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.
The ft.mouseDown method has the following command format(s):
ft.mouseDown(x, y, rightButton);
X coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.
Y coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.
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.
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);
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.
X coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.
Y coordinate to which to move the mouse. Coordinates are relative to the screen, and specified in pixels.
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.
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);
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.
The ft.typeCharacters method has the following command format(s):
ft.typeCharacters(characters);
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);
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.
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);
}
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.
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); }