Using Squish as a module in other Python scripts, applications

Last edited on

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:

To determine the exact version and information about UCS-2 or UCS-4 please send us the output generated by running the following command:

python -c "import sys; print sys.version; print sys.maxunicode"
Execute in a shell

Using the squishtest module in Python scripts

A simple Python script using squishtest might look like this:

import squishtest


# For Squish 6.4+ script-based Object Map:
import names


# Must set a test result:
squishtest.setTestResult("xml3", "results.xml")


# Must specify which GUI toolkit support Squish
# should use for this application.
# 
# This depends on the Squish edition; possible values:
#
#  Android, iOS, Java, Mac, Qt, Tk, Web, Windows
squishtest.testSettings.setWrappersForApplication("addressbook", "Qt")


# Launch the application:
squishtest.startApplication("addressbook")


# For pre-Squish 6.4 string-based objects.map:
squishtest.objectMap.load(r"C:\myuser\myobjects.map")


# Start interacting with the application...

squishtest.mouseClick(squishtest.waitForObject(...))

...
myscript.py

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:

# Path to Squish package:
export SQUISH_DIR=/home/squish-6.4.3


# To find the "squishtest" module:
export PYTHONPATH=$SQUISH_DIR/lib:$PYTHONPATH


# To find shared libraries squishtest depends on:
export LD_LIBRARY_PATH=$SQUISH_DIR/lib:$LD_LIBRARY_PATH


# To find these Squish modules:
#  objectmaphelper (possibly used in names.py)
#  remotesystem
#  screen
#  toplevelwindow
export PYTHONPATH=$SQUISH_DIR/lib/python:$PYTHONPATH


# Launch squishserver in background:
"$SQUISH_DIR/bin/squishserver" --verbose &


# Execute Python script that uses squishtest:
python myscript.py
On Unix: Execute in a shell/terminal
:: Path to Squish package:
set SQUISH_DIR=C:\Users\myuser\squish-6.4.3


:: To find the "squishtest" module:
set PYTHONPATH=%SQUISH_DIR%\bin;%PYTHONPATH%


:: To find shared libraries squishtest depends on:
set PATH=%SQUISH_DIR%\lib;%PATH%


:: To find these Squish modules:
::  objectmaphelper (possibly used in names.py)
::  remotesystem
::  screen
::  toplevelwindow
set PYTHONPATH=%SQUISH_DIR%\lib\python;%PYTHONPATH%


:: Launch squishserver in background:
start "" "%SQUISH_DIR%\bin\squishserver" --verbose


:: Execute Python script that uses squishtest:
python myscript.py
On Windows: Execute in cmd.exe

Related Information