Leveraging Python Packages For Better UI Testing

Leveraging Python Packages For Better UI Testing

Python is a very popular language, and for good reason. A wealth of production-quality packages for performing all kinds of tasks is freely available on the Internet. But did you know that all this power is readily available in Squish tests, too? This article explains how to extend the Python interpreter shipped with Squish with different popular Python packages.

The Powerful Python Ecosystem

It comes as no surprise that many Squish users choose Python for developing automated GUI tests. Powerful language features, a clean and straightforward syntax, plus a wealth of documentation make it a perfect fit for professional GUI test automation scripts using froglogic’s Squish. However, one big advantage of Python over e.g. JavaScript is often neglected during GUI test development.

A wide range of Python programming tasks doesn’t need to be solved from scratch. Instead, a vast ecosystem of Python packages for solving all kinds of common (and uncommon) tasks is readily available – free of charge. Reusing this battle-tested code can prove to be a real accelerator for developing robust and reliable GUI test scripts.

To keep things manageable, these thousands of packages are maintained in a single place: the Python Package Index (PyPI). This provides a single point of contact to the Python package ecosystem, and an efficient search facility will typically find an existing Python package to solve most common tasks.

Installing Packages For Squish Tests To Use

PyPI is typically accessed using a command line tool called pip. This utility performs common maintenance tasks such as listing, installing, removing or updating installed Python packages. However, the Python installation shipped with Squish does not include the pip utility out of the box – this is to keep the package lean.

The first step to making packages stored in PyPI accessible to Squish test scripts is to install pip. This is a very simple three-step process:

  1. Download the get-pip.py installer script (if you are using Python 3, you will need to get the get-pip.py script for Python 3 instead)
  2. Open a command window and navigate to the Squish installation directory (e.g. C:\Users\Frerich\Squish for Web 6.4.3)
  3. Run the command python\python.exe C:\path\to\get-pip.py

The get-pip.py script will be executed, downloading the pip program and installing it. This will cause plenty of output to be printed to the console, like this:

C:\Users\Frerich\Squish for Web 6.4.3>python\python.exe C:\Users\Frerich\Desktop\get-pip.py
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting pip
Using cached https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/c8/b0/cc6b7ba28d5fb790cf0d5946df849233e32b8872b6baca10c9e002ff5b41/setuptools-41.0.0-py2.py3-none-any.whl
Collecting wheel
Using cached https://files.pythonhosted.org/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
The script wheel.exe is installed in 'C:\Users\Frerich\Squish for Web 6.4.3\python\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-19.0.3 setuptools-41.0.0 wheel-0.33.1

The installation should finish within a couple of moments. At the end, the pip utility can be found in the Scripts subdirectory.

Verify that the installation worked by asking pip to print its version number:

C:\Users\Frerich\Squish for Web 6.4.3>python\Scripts\pip -V
pip 19.0.3 from c:\users\frerich\squish for web 6.4.3\python\lib\site-packages\pip (python 2.7)

Congratulations! Thousands of Python packages are now available to your GUI test scripts!

Popular Python Packages

At this point, installing Python packages is just a mere pip install invocation away. In a command shell window, navigate to your Squish installation directory and run

python\Scripts\pip install PACKAGE 

where PACKAGE is the name of whatever awesome package whetted your appetite when browsing PyPI.

To get you started, here are a few great Python packages we used when creating Squish tests ourselves:

  • RPyC (install via ‘pip install rpyc’) is a lightweight but extremely powerful module for automating remote computers. After launching a tiny Python script on the remote machine, your Squish tests are able to execute arbitrary actions on the remote system in a very convenient way. This is great for e.g. preparing the remote system before a test, fetching system information during a test or cleaning up afterwards.
  • untangle (install via ‘pip install untangle’) is a tiny module which can be used to parse arbitrary XML files into Python objects – in a single line of code. This is great for reading all kinds of configuration files and is much easier to use than the standard xmllib Python module. Of course, it’s not as powerful — but sometimes you’d rather want to have just as much complexity as necessary instead of getting as much power as possible.
  • requests (install via ‘pip install requests’) is the de-facto standard for everything related to HTTP. Need to access a REST API in your Squish test? Upload some data to a web server? Fetch a status page? Look no further – the requests module has you covered. As the home page puts it: requests is “HTTP for Humans™”.

Final Words

At this point. you’re ready to augment your GUI test scripts by reusing any of the thousands of Python packages. Head over to the Python Package Index and see whether there’s a ready made package you can use instead of reinventing the wheel again and solving the problem manually!

What are your preferred Python packages when developing GUI tests using Squish? Let us know in the comments – we’d love to hear from you!

Software engineer working at froglogic since 2005. When he's not currently at the swimming pool or busy building awesome Lego creations with his son, he can typically be found playing video games.


Leave a reply

电子邮件地址不会被公开。 必填项已用*标注