Overview¶
The functions provided by Squish can be replaced. (The original functions can still be used if the replacement is done correctly.)
This can be a convenient way to modify the behavior of the commands that Squish records, without having to modify the recorded script code.
Functions can only be replaced after the AUT has started¶
When replacing Squish script functions it is important to do this after the application has been started by Squish. (This is because Squish creates some of its functions after the AUT has started, so these are not available to be replaced until that point.)
AUTs can be started in one of two ways. The old-style approach is to check the test suite setting's "Automatically start the AUT" checkbox; the new-style approach is to do a call to the startApplication()
function at or near the beginning of the test case's main()
function. If the new-style approach is being used, functions should only be replaced after the startApplication()
call has been made.
When "Automatically start the AUT" is disabled¶
When the setting "Automatically start the AUT" is disabled, a typical test case script that replaced some Squish functions would look like this:
(The
source()
function is discussed below.)
When "Automatically start the AUT" is enabled¶
When the setting "Automatically start the AUT" is enabled the script would look similar to this:
(The
source()
function is discussed below.)
Replacing functions¶
The source()
call is used to execute another script inside this one. The other script can create variables, functions, classes, and so on, that can then be used as if they had been created in the current test case. The advantage of having all this in a separate script is that the script can then easily be used by multiple test cases.
For example, this statement:
Loads the file squish_func_replace.js
which contains the replacement functions and their "registration".
Here is an example of such a file which shows how to replace Squish's mouseClick()
function with a customized version:
Note that the original mouseClick()
function can still be accessed like this: