This chapter documents the script APIs which can be used by Squish test scripts. First the differences between the supported scripting languages will be discussed.
Squish supports the same APIs in all scripting languages. Here we will discuss the differences between the scripting languages.
This table shows equivalent script functions for the most basic tasks. It gives merely a quick overview to find out what the syntactical differences are.
All entries assume an example C++ class C defined as
class C
{
public:
C();
C(const char *s);
void doA(bool b);
static void doB();
int p;
...
}
and a class instance named c.
| Feature | Tcl | Python | JavaScript | Perl |
|---|---|---|---|---|
| Construct a default object | set c [construct C] | c = C() | var c = new C(); | my $c = C->new(); |
| Construction with argument | set c [construct C "apple"] | c = C("apple") | var c = new C("apple"); | my $c = C->new("apple"); |
| Get a property | set x [property get $c p] | x = c.p | x = c.p; | $x = $c->p; |
| Set a property | property set $c p 10 | c.p = 10 | c.p = 10; | $c->p(10); |
| Call a member function | invoke $c doA true | c.doA(True) | c.doA(true); | $c->doA(1); |
| Call a class (static) function | invoke C doB | C.doB() | C.doB(); | C::doB(); |
| Test for equality | test compare [property get $c p] 2 | test.compare(c.p, 2) | test.compare(c.p, 2); | test::compare($c->p, 2); |
| Comparison with application objects | compare $s "Max" | s == "Max" | s == "Max" | |
| Convert to native string | set s [toString $c] | s = str(c) | s = String(c); | |
| Send key presses | invoke type "namewidget" "Max" | type("namewidget", "Max") | type("namewidget", "Max"); | type("namewidget", "Max"); |
| Native boolean values | true, false | True, False | true, false | - (use 1 and 0) |
In the following sections the APIs will be described generally. Examples will be given for Python. Using the table above it will be easy to convert the respective code to any other scripting language.
This chapter introduces Squish's API modules. These extensions are useful for controlling the test framework and the AUT from test scripts.
object.exists(objectName);
Returns whether the object with the name
objectName exists.
findObject(objectName);
Finds and returns the object via the path specified by
objectName. The object name contains dots to
represent the object hierarchy. The names of the single objects are
not necessarily the QObject names, but a unique name. This can also be
another unique property like the caption, a groupbox title, etc. In
the worst case this is the class name plus a number (e.g. QLineEdit5).
Squish objects blend in with native objects of the scripting language quite smoothly. This means that you can use standard language features to construct objects of the wrapped types, invoke member functions or get, set or iterate over properties on these objects.
The best way to show how that works is to look at the example code below:
# create an object of type QPoint
p = QPoint(10, 20)
# read a property of a widget
x = mywidget.x
# set a property of a widget
mywidget.y = 33
# call a member function
mywidget.setCaption("My Widget")
# call a static function
QApplication.setOverrideCursor(Qt.busyCursor)
isNull(object);
Returns True (1) if object is null (a
NULL pointer in C), False (0) otherwise.
typeName(object);
Returns the class name of the
object.
objectName(object);
Returns the object name of the
object.
isPointer(object);
isReference(object);
isValue(object);
isArray(object);
Returns whether object is a pointer,
reference, value or array in C++.
cast(object, type);
Casts the <object> to the type <type> and returns a reference to that object. <type> can either be specified by name (as a string) or via a type object.
This modifies the <object> itself. If the cast fails, 0 is returned.
This set of functions implements functions that can be used to verify that the AUT's state is as expected during a test run.
test.verify(condition, [info]);
Verifies that condition is True (1). If the
condition is True a test result of type PASS is added to the test log,
otherwise a test result of type FAIL is added.
Returns True on PASS and False on FAIL.
You may use the optional info parameter to
specify an arbitrary string (comment, bug number, test plan reference
etc.) that will be added to the test result.
test.compare(val1, val2, [info]);
Compares val1 and val2
and if they are equal a test result of type PASS is added to the test
log, otherwise a test result of type FAIL is added.
Returns True on PASS and False on FAIL.
You may use the optional info parameter to
specify an arbitrary string (comment, bug number, test plan reference
etc.) that will be added to the test result.
test.xverify(condition, [info]);
This function is used for expected failures in test scripts.
Verifies that condition is not True (1). If
the condition is True a test result of type FAIL is added to the test
log, otherwise a test result of type PASS is added.
Returns True on PASS and False on FAIL.
You may use the optional info parameter to
specify an arbitrary string (comment, bug number, test plan reference
etc.) that will be added to the test result.
test.xcompare(val1, val2, [info]);
This function is used for expected failures in test scripts.
Compares val1 and val2
and if they are equal a test result of type FAIL is added to the test
log, otherwise a test result of type PASS is added.
Returns True on PASS and False on FAIL.
You may use the optional info parameter to
specify an arbitrary string (comment, bug number, test plan reference
etc.) that will be added to the test result.
test.exception(code, [info]);
If executing code throws an exception, a
test result of type PASS is added to the test log, otherwise a test
result of type FAIL is added.
![]() | Note |
|---|---|
|
You may use the optional info parameter to
specify an arbitrary string (comment, bug number, test plan reference
etc.) that will be added to the test result.
test.log(message, [detail]);
test.warning(message, [detail]);
test.pass(message, [detail]);
![]() | Note |
|---|---|
As |
test.fail(message, [detail]);
test.fatal(message, [detail]);
Adds a test result of type PASS, FAIL, FATAL, LOG or WARNING with the
message and an optional
detail to the test log.
test.vp(name, [record]);
Executes the verification point vp. If the
verification point references a data set, record
references the record of the data set which should be used.
Returns True on PASS and False on FAIL.
findFile(where, filename);
Looks for the file filename. If the first
argument is "scripts", the search begins in the
test case's scripts directory and if it isn't found there, the shared
scripts directory of the test suite is searched. If the first argument
is "testdata", the search begins in the test
case's testdata directory, and if the file isn't there, then the test
suite's shared testdata directory is searched.
If the file is found the absolute file name is returned, otherwise an error is thrown.
testData.put(filename);
Copies the test data file filename from the
test case's testdata directory or the test suite's shared testdata
directory into the AUT's current working directory.
testData.get(filename);
Copies the file filename from the AUT's
current working directory to the test case's testdata
directory.
testData.remove(filename);
Removes the file filename from the AUT's
current working directory.
testData.exists(filename);
Returns whether the file filename exists in
the AUT's current working directory.
testData.dataset(filename);
testData.field(datasetrecord, fieldname|fieldindex);
These functions are used for data-driven testing. They allow
opening a dataset (e.g. a TSV file) and
retrieving fields from the datarecord by
fieldindex or fieldname.
testData.fieldNames(datasetrecord);
This function returns a tuple containing the field names of the specified record.
testData.create(where, filename);
This function returns a valid filename you can write to. The
file will be located in the shared test data directory when
where is "shared" or in the
local test data directory when where is
"local".
This function should be used when you are running a script in a learning mode to create test data dynamically.
objectMap.add(object);
Adds object to the object map.
objectMap.symbolicName(object|realName);
Returns the symbolic name for the given
object, or the object referenced by
realName.
objectMap.realName(object|symbolicName);
Returns the real name for the given object,
or the object referenced by symbolicName.
objectMap.symbolicNames();
Returns a tuple containing all mapped symbolic names. The element order is not defined.
startApplication(aut, [host], [port], [timeout]);
Starts the specified application and returns a reference to its
context. aut must be an application whose path is
already registered to squishserver. In addition to the application
name command line parameters can be specified in the string passed to
this function.
Optionally, as second and third parameter a
host and port can be passed
to this function. This way instead of connecting to the default host
and port (as specified in the Squish IDE's settings or squishrunner's
command line), a connection to squishserver on the specified host
listening to the specified port will be established. This allows to
control multiple applications on multiple computers from one test
script.
Also optionally, as fourth parameter a timeout (in seconds) can be passed to specify how long Squish should wait for the application to come up before throwing an error. This value overrides squishrunner's default AUT timeout.
attachToApplication(aut, [host], [port], [timeout]);
Attaches to the specified application and returns a reference to its
context. aut must be an application that is
registered as an attachable AUT.
The meaning of the optional arguments
host,port, and
timeout are the same as with the
startApplication function.
See Attaching to Running Applications (Section 16.12.2) for more information.
setApplicationContext(ctx);
This function can be used to switch the current application
context. The ctx handle is is either the one
returned from a setApplicationContext(), defaultApplicationContext()
or applicationContextList() call. If the argument is omitted the
default context is activated.
defaultApplicationContext();
Returns a handle to the default application context.
applicationContextList();
Returns a list of handles to all existing application contexts.
The ApplicationContext object provides the following properties and functions:
name Name of the
application.
commandLine Complete command line
the application was started with.
pid The process identifier of the
application.
cwd The current working directory
of the application.
isRunning Returns whether the
application is still running.
startTime Returns the time when
the application was started.
usedMemory Amount of memory used
by the application (This property is only available in
conjunction with the Squish memory module
add-on).
isFrozen(timeout) Returns False
if the application answers before the timeout (in seconds)
expired.
readStdout() Reads everything
which has been written to STDOUT by the application since the last
call to readStdout() and returns it.
readStderr() Reads everything
which has been written to STDERR by the application since the last
call to readStderr() and returns it.
installEventHandler([object|class], event, handlerFunction);
Installs an event handler on an object
class, an object or globally
(if no class or object is
specified). The script function handlerFunction
will be called when the event of the type event
occurs.
event can be any event type such as
QKeyEvent (Qt), ButtonPressed (XView, Tk),
etc. Squish adds the following convenience event types:
MessageBoxOpened
DialogOpened
MainWindowOpened
ToplevelWidgetOpened
Crash
squishinfo.major
A numeric property holding the Squish major version number.
squishinfo.minor
A numeric property holding the Squish minor version number.
squishinfo.patch
A numeric property holding the Squish patch level version number.
squishinfo.version
A numeric property holding a unique number representing the Squish version. The number is made up of a hexadecimal representation of major, minor, patch and release level. The individual values are shifted and packed into a single 4-byte number. The release levels Alpha, Beta and Final are denoted by the values 0xAA, 0xBB and 0xFF, respectively. As an example, 0x030001FF stands for the final 3.0.1 release.
This kind of representation looks odd on first sight but simplifies version tests in script code. Here's some JavaScript sample code that does a single comparison for conditional code:
if (squishinfo.version >= 0x030100AA) {
// code meant for version 3.1.0-alpha or higher
}
squishinfo.version_str
A property of type string holding the human-readable Squish version number, e.g. "3.0.0-alpha".
squishinfo.settingsGroup
A property that denotes the currently active settings group of the test.
source(filename);
Reads and evaluate the contents of
filename. Use this function to parse shared
script files.
snooze(secs);
Sleep for the specified nominal number of seconds. Fractions of seconds can be specified as well by using decimal numbers. The effective delay will depend on the current <snoozeFactor>.
waitFor(condition, [timeout]);
Evaluates condition until it becomes true
or the waiting times out after the number of specified milliseconds. The
timeout parameter is optional. This is useful if
you want to synchronize your script execution to a certain state in
the AUT.
waitForObject(objectname, [timeout]);
Waits until the object with the name
objectname exists and is accessible. This is
useful if you want to synchronize your script execution. By default,
it waits for maximum 20 seconds. With the optional
timeout parameter a different timeout (in
milliseconds) can be specified.
waitForApplicationLaunch();
Waits for a new application, which Squish will hook into, to start. This is used by Squish for test scripts which access multiple applications which are started by the AUT.
sendNativeEvent(window, sequence);
Send a sequence of low-level native
events to the specified window with the name
window. This function may be of use when
interacting with windows from another application or controls
implemented with a foreign toolkit. For interaction with standard
application controls use of type() and other function is
recommended.
Example:
sendNativeEvent("Login", "username");
Currently, the only supported type of events are simple keystrokes. Support for complex keystrokes and mouse events might be added in a future version. Please contact technical support to voice your demand.
sendEvent(eventName, receiverObject|receiverObjectName, ...);
Sends an event of type eventName to the
object receiverObject or to an object called
receiverObjectName. All remaining arguments are
arguments of the event constructor (coordinates, button states,
etc). eventName is any event supported by
Qt.
![]() | Note |
|---|---|
In all functions below, |
clickButton(object);
Clicks the button referenced by
object.
type(object, text);
Types text into the editable widget
referenced by object. If the text is surrounded by
< and >, the contents is interpreted as a key combination, e.g
<Ctrl+Return>. If the key combination is
surrounded by additional < and >, an accelerator event is sent
instead of a key event.
activateItem(object, item);
Activates the menu item with the item text
item in the popup menu or menu bar referenced by
object.
mouseClick(object, x, y, state, button);
Sends a mouse click at position x and
y with the button button and
modifier state state to the widget referenced by
object. Possible values for the button and state
are the ones defined in
QTDIR/include/qnamespace.h.
openContextMenu(object, x, y, state);
Sends a mouse click at position x and
y with the modifier state
state to the widget referenced by
object to open a context menu. Possible values
for the button and state are the ones defined in
QTDIR/include/qnamespace.h.
doubleClick(object, x, y, state, button);
Sends a mouse double click at position x
and y with the button button
and modifier state state to the widget referenced
by object. Possible values for the button and
state are the ones defined in
QTDIR/include/qnamespace.h.
clickItem(object, item, x, y, state, button);
Sends a mouse click at position x and
y (in item's coordinates) with the button
button and modifier state
state to the item with the name
item to the view widget referenced by
object. Supported view widgets are QListView,
QListBox, QIconView, QTable, QAbstractItemView and widgets deriving
from those classes. Possible values for the button and state are the
ones defined in
QTDIR/include/qnamespace.h.
doubleClickItem(object, item, x, y, state, button);
Sends a mouse double click at position x
and y (in item's coordinates) with the button
button and modifier state
state to the item with the name
item to the view widget referenced by
object. Supported view widgets are QListView,
QListBox, QIconView, QTable, QAbstractItemView and widgets deriving
from those classes. Possible values for the button and state are the
ones defined in
QTDIR/include/qnamespace.h.
openItemContextMenu(object, item, x, y, state);
Sends a mouse click at position x and
y (in item's coordinates) with the modifier state
state to the item with the name
item to the view widget referenced by
object to open a context menu. Supported view
widgets are QListView, QListBox, QIconView, QTable, QAbstractItemView
and widgets deriving from those classes. Possible values for the
button and state are the ones defined in
QTDIR/include/qnamespace.h.
clickTab(object, tab);
Clicks on the tab with the name tab on the
tab widget referenced by object.
scrollTo(object, position);
Scrolls the widget referenced by object to
the pixel position position.
dragAndDrop(source_object, sx, sy, target_object, tx, ty, action);
Starts a drag on the widget referenced by
source_object at the position
sx and sy and releases the
drop on the widget referenced by target_object at
the position tx and
ty.
castToQMenuData(object);
Function for Qt 2 and 3 application testing that casts an
object of class QMenuBar, QPopupMenu or
subclass thereof to an object of type QMenuData. A common problem in
test scripts is to access QMenuData's API of a QPopupMenu or
QMenuBar. Due to squishidl's limitation of single inheritance this
is not possible. Squish's cast function cannot be
used in this case because it only allows to cast up or down in the
inheritance chain.
This function is neither required nor available for Qt 4 testing as the menu structure has been redesigned and works without multiple inheritance.
grabWidget(object);
Takes a secreenshot of the window referenced by
object and returns it.
sendEvent(eventName, receiverObject|receiverObjectName, ...);
Sends an event of type eventName to the
object receiverObject or to an object called
receiverObjectName. All remaining arguments are
arguments of the event (coordinates, button states, etc).
The following eventNames are supported:
ButtonEvent
KeyEvent
MotionEvent
clickButton(objectname);
Clicks the button referenced by the object with the name
objectname.
type(objectname, text);
Types text into the editable widget
referenced by the object with the name
objectname. If the text is surrounded by < and
>, the contents is interpreted as a key combination.
activateItem(objectname, item);
Activates the menu item with the item text
item in the popup menu or menu bar referenced by
the object with the name objectname.
mouseClick(objectname, x, y, state, button);
Sends a mouse click at position x and
y with the button button and
modifier state state to the widget referenced by
the object with the name objectname.
doubleClick(objectname, x, y, state, button);
Sends a mouse double click at position x
and y with the button button
and modifier state state to the widget referenced
by the object with the name objectname.
clickItem(objectname, item, x, y, state, button);
Sends a mouse click at position x and
y (in item's coordinates) with the button
button and modifier state
state to the item with the name
item to the view widget referenced by the object
with the name objectname .
doubleClickItem(objectname, item, x, y, state, button);
Sends a mouse double click at position x
and y (in item's coordinates) with the button
button and modifier state
state to the item with the name
item to the view widget referenced by the object
with the name objectname.
scrollTo(objectname, position);
Scrolls the widget referenced by the object with the name
objectname to the pixel position
position.
closeWindow(objectname);
Closes the window referenced by the object with the name
objectname.
tcleval(code);
Evaluates code in the AUT's Tcl interpreter
and returns the result.
grabWidget(object);
Takes a secreenshot of the window referenced by
object and returns it.
sendEvent(eventName, receiverObject|receiverObjectName, ...);
Sends an event of type eventName to the
object receiverObject or to an object called
receiverObjectName. All remaining arguments are
arguments of the event (coordinates, button states, etc).
The following eventNames are supported:
ButtonEvent
KeyEvent
WindowEvent
ResizeEvent
DestroyEvent
clickItem(object, x, y, state, button, action);
Sends a mouse click at position x and
y (in item's coordinates) to the panel item (such
as a button, choice item, etc.) with the button
button, modifier state state
and action action of the panel referenced by the
name object.
type(object, text);
Sends key events to the editable panel item
object so the text text is
typed into it.
activateItem(menu, item);
Activates the item referenced by item in
the menu menu.
openFrame(frame);
Opens (shows) the frame with the name
frame.
closeFrame(frame);
Closes (hides) the frame with the name
frame.
closeNotice(button, result);
Closes the currently open notice (if there is an open one) using
the specified button so it returns the specified
results.
isNoticeOpen();
Returns whether currently a notice is opened.
lastNoticeMessage();
Returns the message of the last opened message.
findItem(itemName);
Finds and returns a reference to a panel item given its fully
qualified name itemName.
The available API which can be called on web objects can be found here. This section documents the convenience APIs available in addition to that.
![]() | Note |
|---|---|
In all functions below, |
loadUrl(url);
Opens a browser and loads the URL
url.
setContext(context);
When working with multiple browser windows, this functions is
used to make a certain window with the URL matching
context active for the test, i.e. script
commands will be executed in the context of the active window.
hasContext(context);
Returns whether a window with the URL matching
context is open and can be accessed by the test
script.
contextList(
Returns a list containing the URLs of the open browser windows which can be accessed by the test script.
contextOf(window);
Returns the context string of the given
window.
currentContext(
Returns the context string of the currently active browser window.
setText(object, text);
Sets the text of the editable form element (text or textarea)
referenced by object to
text.
clickButton(object);
Clicks the button (button, radio, checkbox, submit, image)
referenced by object.
mouseClick(object);
Clicks the element referenced by
object.
clickLink(object);
Clicks the anchor/link referenced by
object.
setFocus(object);
Sets the input focus on the element referenced by
object.
selectOption(object, text);
Selects the option with the text text on
the select form element (select, select-one) referenced by
object. If the element is a multi-selection
box, multiple options to be selected can be passed as
text separated by commas.
evalJS(code);
Evaluates the JavaScript code in the web
browser's context. The result of the last statement in the
code is returned.
closeWindow(object);
Closes the browser window reference by
object.
isPageLoaded(
Returns wether the page has been completely loaded and all its
objects can be accessed. Together with waitFor
this can be used to wait for a page to be loaded before accessing it
from a test script.
![]() | Note |
|---|---|
In all functions below, |
clickButton(object);
Clicks the button referenced by
object.
type(object, text);
Types text into the editable widget
referenced by object. If the text is surrounded by
< and >, the contents is interpreted as a key combination, e.g
<Ctrl+Return>. Note the SWT buttons from a
ToolBar are selected with the clickItem function
below.
activateItem(object, item);
Activates the menu item with the item text
item in the popup menu or menu bar referenced by
object.
mouseClick(object, x, y, state, button);
Sends a mouse click at position x and
y with the button button and
modifier state state to the widget referenced by
object. Possible values for state is
toolkit dependent. The values for button are
SWT.NoButton, SWT.Button1, SWT.Button2
and SWT.Button3 for SWT and
AWT.NoButton, AWT.Button1, AWT.Button2
and AWT.Button3 for the AWT/Swing toolkit.
doubleClick(object, x, y, state, button);
Sends a mouse double click at position x
and y with the button button
and modifier state state to the widget referenced
by object. For possible values for the button and
state, see above.
clickItem(object, item, x, y, state, button);
Sends a mouse click at position x and
y (in item's coordinates) with the button
button and modifier state
state to the item with the name
item to the view widget referenced by
object. Supported view widgets are List, Combo and
ToolBar for the SWT toolkit and JList, JTable, JTree,
List and Choice for the AWT/Swing toolkit.
Possible values for the button and state, see above.
closeWindow(object);
Closes the Window (or Shell in
SWT) referenced by object as if
it was closed by its window system menu.
clickTab(object, tab);
Clicks on the tab with the name tab on the
tab widget referenced by object.
grabWidget(object);
Takes a secreenshot of the window referenced by
object and returns it.
clickButton(object);
Clicks the button referenced by
object.
type(object, text);
Types text into the editable widget
referenced by object. If the text is surrounded by
< and >, the contents is interpreted as a key combination, e.g
<Ctrl+Return>.
activateItem(object);
Activates the menu item referenced by object.
object must reference an object of class
NSMenuItem. The menu item can be part of the
application menu or a menu item inside a
NSPopUpButton.
clickItem(object, x, y, state, button);
Sends a mouse click on the item object in a
table view (NSTableView or the popup of a
NSComboBox). The position of the click is at the
coordinates x and y (relative
to the item's visible rect), with the mouse button
button and modifier state
state.
mouseClick(object, x, y, state, button);
Sends a mouse click at position x and
y with the button button and
modifier state state to the widget referenced by
object.
clickTab(object);
Clicks on the tab view item referenced by object.
object must reference an object of class
NSTabViewItem.
The extension modules are loaded automatically by internally executing the equivalent of the statements
import test import testData import object import objectMap from squish import *
before the script is executed. It's therefore not necessary to
import them by yourself unless you are developing
your own standalone module.
Note the drawback of above wild card import of the wrapped API:
native Python functions like int() and
type() will be shadowed as their names conflict with
the wrapped int C type and the
type() function used to send key events to the
AUT. To access the built-in functions just import the
__builtin__ module and access them with their fully
qualified name, e.g. __builtin__.int().
Besides the Squish extension API the full set of Python language features and modules is available for scripting. The Python Documentation page lists a few books and also has the current documentation available for download and online browsing.
For documentation on the Tcl language and standard extension packages see the Tcl/Tk Documentation page on the Tcl home page. Next to links to the man pages you'll find a tutorial there.
Theoretically you could pick up any
JavaScript book or online resource to learn about the language or look
up a function. Unfortunately most authors don't draw a clear line
between features that are part of the language proper and those
specific to a web browser. When browsing such HTML programming
documentation beware of any example code that operates on the
window or document
object.
When keeping this distinction in mind you'll still be able to draw the required information from a variety of books and online resources. Here are some online resources that we have collected for your convenience:
Netscape's Core JavaScript Reference
Microsoft's JScript Language Reference at msdn.microsoft.com
DevGuru JavaScript Quick Reference at www.devguru.com
The JavaScript engine shipped with Squish is compliant with the ECMAScript language specification (ECMA 262 Edition 3). This corresponds with Netscape's JavaScript 1.5 and Microsoft's JScript 5.5. The language core that is defined in this standard encompasses operators, control structures, objects and other features commonly found in a scripting language. A handful of built-in classes provide functions for the most common data handling. These objects are:
Object
String
Number
Boolean
RegExp
Date
Function
Error
You may notice the lack of classes such as file or network I/O typically found in languages like Python and Tcl. This is because pure JavaScript (or rather ECMAScript) has been designed to be a small language that can safely be embedded into an application. It's meant to be extended by custom API specific to the embedding application, though. In the case of web browsers there are hundreds of functions and properties that allow manipulation of HTML documents via the DOM API for example. In the case of Squish we have added numerous functions specific to testing. We also added some general purposes classes described below. If you need anything else please file an enhancement request.
File.exists(path);
Returns true when a file or directory path
does exist on the local hard disk; false otherwise.
File.remove(path);
Attempts to remove the file with path
from the local hard disk. Returns true on sucess; false
otherwise.
File.open(path, [mode]);
Will attempt to open file path and return
a File instance. In case of failure an exception will be thrown. The
mode can either be "r" for read access or "w"
for write access. If undefined it will default to "r".
Functions like read(),
write() and access() can be
called on the returned File instance.
read();
Reads in and returns the content of a file. The file content is assumed to be UTF-8 encoded.
Example:
var f = File.open("input.txt", "r");
var t = f.read();
inputField.setText(t);
write(string);
Writes the string to the file using UTF-8
encoding. The file has to be opened in write-mode.
close();
Closes the file. Afterwards no data can be read or written anymore.
OS.name ;The name property of the
OS object holds the name of the operating system
that squishrunner is running on. On Microsoft Windows systems the
value will be "Windows". On Unix-like systems the value will be
identical to the output of uname -s,
i.e. "Linux", "Solaris", "Darwin" etc.
OS.system(command);
Executes command by calling the system
command line shell. In case of a successfull execution the return
status of the command will be returned. On errors -1 will be
returned.
command can not only hold the name of an
executable but also command line arguments to be interpreted by the
application or shell.
Example:
var ret = OS.system("readresult.exe > output.txt");
if (ret != 0)
test.warn("readresult failed");
OS.capture(command);
Analogous to OS.system() will execute
command from a system shell. The commands Stdout
output will be read and returned.
Example:
var files = OS.capture("ls out/*.dat");
for (var f in files) {
...
}
OS.getenv(name);
Obtains the current value of the environment variable,
name.
Example:
var homeDir = OS.getenv("HOME");
test.log("Current user's home directory: " + homeDir);
OS.setenv(name, value);
Inserts the environment variable name into
the current environment. If the variable name
does not exist, it is inserted with the given
value. If the variable does exist, its value
is overwritten.
Example:
var preferableEditor = "vim";
OS.setenv("EDITOR", preferableEditor);
OS.pause(msecs);
Pauses the script for the specified number of
milliseconds. Unlike snooze() the delay is fixed
and not influenced by the current
<snoozeFactor> setting.
OS.listDir(path);
Returns the list of files and directories in the directory
specified by path. The special directories
. and .. are
excluded.
Here is an example that logs all files that were generated in an output directory:
var files = OS.listDir("output");
for (var f in files)
test.log("Found generated file: " + files[f]);
XML.parse(markup);
Attempts to parse the given string of XML markup. In case of success, a document node is returned which represents the root of the document ree. In case of an error, an exception is thrown.
node.isNull ;Returns whether this node is a null node.
node.nodeName ;Returns the name of the node. For elements, it's the tag name. For the document node, the string “<anonymous xml document>” is returned.
node.nodeType ;Returns the type of the nodename of the node. Possible return values are:
XML.DocumentNode
XML.ElementNode
XML.CommentNode
XML.TextNode
XML.DeclarationNode
XML.UnknownType
node.parentNode ;Returns the parent node of this node. If there is no parent node (which is true for the document node) then a null node is returned.
node.firstChild ;Returns the first child node of this node. If this node does not have any children, a null node is returned.
node.nextSibling ;Returns the next sibling node of this node. This this node does not have any siblings, a null node is returned.
node.textContent ;Returns the text contained within this node. Note that this function
does not recursively collate the text of all child nodes (assuming that
aElem always points to the “a” element):
// XML markup is '<a>Hello<a>'
test.log( aElem.textContent ); // prints 'Hello' to the test log
// XML markup is '<a><b>Hello</b></a>'
test.log( aElem.textContent ); // prints an empty string to the test log
![]() | Note |
|---|---|
This function can only be called on element nodes (where
|
node.hasAttribute(attrName);
Returns a boolean indicating whether the given node has an attribute
called attrName.
![]() | Note |
|---|---|
This function can only be called on element nodes (where
|
node.getAttribute(attrName);
Returns a string with the value of the attribute with the name
attrName. If there is no such attribute with that
name, the behaviour is undefined. If attrName is
an empty string, an exception is thrown.
![]() | Note |
|---|---|
This function can only be called on element nodes (where
|
SQL.connect(informationObject);
Attempts to create a connection to some SQL database. The information required is expected to be passed via an object whose properties are then interpreted. Here's a sample invocation showing how to connect to a MySQL server on the host “dulsberg”:
var c = SQL.connect( { Driver: "MySQL",
Host: "dulsberg",
Port: 1342,
Database: "mydatabase",
UserName: "test",
Password: "secretPhrase" } );
The settings have the following meanings:
The driver to use when connecting to the database. Possible values are:
| ODBC | ODBC Driver (includes Microsoft SQL Server) |
| Oracle | Oracle Call Interface Driver |
| PostgreSQL | PostgreSQL v6.x and v7.x Driver |
| Sybase | Sybase Adaptive Server |
| MySQL | MySQL Driver |
| DB2 | IBM DB2, v7.1 and higher |
| SQLite | SQLite Driver |
| IBase | Borland Interbase Driver |
The host name (or IP address) of the computer on which the SQL database is installed.
The port on the remote computer to which the connection should be established. If this is omitted, the default port (depending on the driver) is used.
Specify the name of the database to which a connection should be established here.
This setting is only necessary when using the ODBC driver, in which case this is expected to specify the Data Source Name (DSN) to use.
The user name to use when logging into the SQL server.
The password to use when logging into the SQL server. If omitted, an empty password is assumed.
In case there was some problem while connecting to the SQL server, an exception is thrown. If there is no error, an object of type 'SQLConnection' is returned which can be used to evaluate SQL statements. The connection object provides the following functions:
connection.close();
Closes the given SQL connection.
connection.query(statement);
Executes an SQL query on the given connection object <connection>. In case of an error, an exception is thrown. Otherwise an object of type 'SQLResult' is returned which can be used to iterate over the returned data. Here is an example how to execute a SQL query on some connection object:
var result = connection.query( "SELECT last_name, first_name FROM persons WHERE country LIKE 'A%';" );
The result objects returned by this function provide the following functions and properties:
result.isValid ;Returns whether this result object is in a valid state. Some functions return invalid result objects to flag an error or otherwise special condition (see below).
result.toNext();
Selects the next row in this SQL result. Marks
<result> as invalid in case there is no other row
to navigate to. This function and the isValid property
above let you iterate over the rows returned by some SQL
query easily, as in this example:
var result = connection.query( "SELECT last_name, first_name FROM persons WHERE country LIKE 'A%';" );
while ( result.isValid ) {
// do something with the result
result.toNext();
}
result.toFirst();
Navigate to the first row in this result. This is useful if you want to
iterate over the rows many times: after processing the rows using
toNext, call toFirst to jump back
to the first result so that you can use toNext
again.
result.size ;Returns the number of rows which this result contains.
result.value(fieldNumber);
result.value(columnName);
These two functions can be used to get the data in the given column of the current row. The column can either be addressed using a number (counting from zero), or using the name of the column (case insensitive). The data in the given column is implicitely converted into a string. Note that you can also use the bracket-syntax as a shortcut. This little example will execute a sample SQL query and then iterate over the returned data rows, printing the first and last name of all matching entries in the persons table:
var result = connection.query( "SELECT last_name, first_name FROM persons WHERE country LIKE 'A%';" );
while ( result.isValid ) {
var s = "First name: ";
s += result.value( 1 ); // same as result["first_name"] or result.value( "first_name" );
s += ", Last name: ";
s += result["last_name"]; // same as result.value( 0 ) or result.value( "last_name" );
test.log( s );
result.toNext();
}
The Perl documentation contains a manual page perlintro that can serve as a good starting point. Links to other manual pages, tutorials and FAQs can be found on the Online Documentation and the perldoc page.
There is a great numer of Perl books available for purchase. A listing can be found at the Perl Books page. Among the most popular ones are probably "Learning Perl" and "Programming Perl" both published by O'Reilly & Associates.