Squish tip of the week: How can I run Squish from the command-line interface?

Squish tip of the week: How can I run Squish from the command-line interface?

Interested in scheduling your test suite or scripts to run? Or want to execute your scripts from the command-line interface (CLI)?

While scripts can be run unmanned using 3rd-party integrations, they can also be executed using Squish’s CLI. To record or execute your tests from the CLI, you’ll need to know the following:

  1. squishserver location and IP address (if different than squishrunner)
  2. squishrunner location (default location: <SQUISH_PACKAGE>/bin)
  3. Test suite path

For the squishrunner to communicate with the squishserver, squishserver must be running. If squishserver is on a separate machine than squishrunner, a squishserverrc file must exist specifying allowed hosts, or reconnections from other locations (more information).


Example 1
Execute the following command from <SQUISH_PACKAGE>/bin:

  1. Unix: ./squishserver
  2. Windows: squishserver.exe

Notice: The default, or first available Squish port, 4322, displays.

Instruct squishrunner to run a test suite using the running squishserver by executing:

  1. Unix: ./squishrunner --host <IP_AddressOfSquishServer> --port 4322 --testsuite <PathToTestSuite>
  2. Windows: squishrunner --host <IP_AddressOfSquishServer> --port 4322 --testsuite <PathToTestSuite>

Note: The –port parameter can be omitted when default port is used.



Example 2
Wish to create something simple you can reuse, and easily modify to point to different squishrunner, squishserver and testsuite combinations? How about producing xml execute results and generating an HTML report? Try creating a shell or batch script:

2a: Simple Unix Shell Script
#!/bin/bash
SQUISH_RUNNER_PATH="<SQUISH_PACKAGE>/bin"
SQUISH_SERVER_HOST="<IP_AddressOfSquishServer>"
SQUISH_SERVER_PORT=4322
TESTSUITE="<PathToTestSuite>"
REPORTPATH="<PathToOutputReport>"
cd $SQUISH_RUNNER_PATH/
./squishrunner --host $SQUISH_SERVER_HOST --port $SQUISH_SERVER_PORT --testsuite $TESTSUITE --reportgen xml2.1,$REPORTPATH/report.xml
cd <SQUISH_PACKAGE>/examples/regressiontesting/
./squishxml2html.py --dir $REPORTPATH/HTMLReports $REPORTPATH/*.xml
open $REPORTPATH/HTMLReports/index.html

2b: Simple Windows Batch Script

NOTE: This script requires python installed to convert the report from XML to HTML. PYTHONPATH must reflect local machine python directory.

set SQUISHPATH=<SQUISH_PACKAGE>
set SQUISH_SERVER_HOST=<IP_AddressOfSquishServer>
set SQUISH_SERVER_PORT=4233
set TESTSUITE=<PathToTestSuite>
set REPORTPATH=<PathToOutputReport>
set PYTHONPATH=C:\python27\
cd %SQUISHPATH%\bin
squishrunner --host %SQUISH_SERVER_HOST% --port %SQUISH_SERVER_PORT% --testsuite %TESTSUITE% --reportgen xml2.1,%REPORTPATH%/report.xml
cd %REPORTPATH%
%PYTHONPATH%\python.exe %SQUISHPATH%\examples\regressiontesting\squishxml2html.py --dir HTMLReports *.xml
HTMLReports\index.html
pause



Example 3
Take your script to the next level. The following script, when executed from the squishrunner directory (<SQUISH_PACKAGE>/bin), determines the squishserver path, report path, and in this case the path of a sample test suite:

#!/bin/bash
clear
echo "This script runs a Test Suite and generates an HTML report"
echo "Squish Server must be running in advance"
echo "Script assumes executed from <SQUISH_DIR>"
echo "Press Ctrl+C at any time to terminate script"
read -p "Press any key to begin"
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolute and normalized
if [ -z "$MY_PATH" ] ; then
# error; path is not accessible
exit 1 # fail
fi
echo "$MY_PATH"
SQUISH_RUNNER_PATH="$MY_PATH/bin"
SQUISH_SERVER_HOST="192.168.2.10"
SQUISH_SERVER_PORT=4322
TESTSUITE="$MY_PATH/examples/java/addressbook/suite_py"
REPORTPATH="$TESTSUITE/results"
cd $SQUISH_RUNNER_PATH/
./squishrunner --host $SQUISH_SERVER_HOST --port $SQUISH_SERVER_PORT --testsuite $TESTSUITE --reportgen xml2.1,$REPORTPATH/report.xml
cd $MY_PATH/examples/regressiontesting/
./squishxml2html.py --dir $REPORTPATH/HTMLReports $REPORTPATH/*.xml
open $REPORTPATH/HTMLReports/index.html

For more information, read:
Automated Batch Testing
KB: Automated, Nightly, Batch Testing
CLI Reference Guide