Overview¶
It is possible to automate user interfaces using the Squish API from existing Python scripts using a special Python module called squishtest
.
Obtaining a Squish package with the correct Python configuration¶
The squishtest
module functionality is available free of charge and is included in all Squish packages.
However, if you are using a Python installation with a different point-release (or architecture) from what is included in the Squish package, the Python module will not be compatible with your Python installation. In this case, you need a Squish package custom built with a Python version that matches your Python installation.
To provide such a package we need the following from you:
The file
<SQUISHDIR>/buildinfo.txt
of your existing Squish package (if any; or information which Squish edition and configuration you want to use).The exact Python version in which you plan to use
squishtest
module.If your Python installation is configured for UCS-2 or UCS-4.
To determine the exact version and information about UCS-2 or UCS-4 please send us the output generated by running the following command:
Using the squishtest module in Python scripts¶
A simple Python script using squishtest
might look like this:
Setup¶
The above example test script can be executed with a plain Python interpreter, as long as the environment is configured correctly for finding the squishtest module, its shared library dependencies and a few other items, as shown below.
Apple macOS¶
Before the squishtest module can be used you need to configure the Python that you want to use for Squish, as explained in this article:
Changing the Python installation used by Squish binary packages
Linux (Unix)¶
Microsoft Windows¶
Notable Differences to Regular Test Suites¶
TestCase Name¶
As the squishtest module is used in a Python module and does not follow the test suite - test case structure, the default test case name in the report will be '<embedded>'.
Should you there be a need to change this to something more meaningful, this can be done by changing the test case name on the testSettings object, before you set the Report generator.
This will change the test case name in the report to the value entered.
Squish for Web¶
If you are using squishtest from a Squish for Web package and want to start the web browser via squishtest.startBrowser(), you will find that this function is not available out of the box.
The reason is, that since you are not in a test suite context, the webhook must be started yourself. The two lines below accomplish that and after calling those, it should be possible to start the web browser if the extension has been installed before.
Objects handled by UI Automation (Various Squish editions on Windows)¶
To establish same object lookup/identification behavior as without the squishtest module, the following changes need to be done in the Squish package (whose squishserver is being used):
In
squish_dir/lib/extensions/win/uiautomation.ext
change the entry...
<priority>-10</priority>
...to...
<priority>1</priority>
("1" is the default for test suites of version 3 and higher.)In
squish_dir/lib/extensions/win/uiautomation.ext
change the entry...
<setting>
<name>HandleIndividualObjects</name>
<value>false</value>
</setting>
...to...
<setting>
<name>HandleIndividualObjects</name>
<value>true</value>
</setting>
("true" is the default for test suites of version 3 and higher.)
installEventHandler()¶
The functions that the installEventHandler() and installSignalHandler() functions use for the callback, must registered in the squishtest namespace, otherwise they will not be found.
Example:
Functions provided by the squishtest module¶
setDebugFlags(debugLog_flags_string)¶
This functions allows configuring the verbosity of the 'squishserver' process' diagnostic and status output. (Also see squishrunner --debugLog .)
Status: Optional
Default: Not set
Example:
setHookSubprocesses(boolean)¶
This is the equivalent to enabling sub-process hooking in the settings of a test suite (in the Squish IDE in test suite settings > Hook into sub-processes launched by the application
(in the tab AUT
).
Status: Optional
Default: True
Example:
setResultDir(result_dir_string)¶
Defines the output directory for fail images, etc. to use for certain report generators.
Status: Optional
Default: Not set
Example:
setTestResult(report_generator_name, result_dir_string)¶
Status: Mandatory
Default: Not set
Example:
Related Information¶
Using Squish Functions in Python Modules/Packages (Squish Manual)
Using Squish functions in your own Python modules or packages (kb article)