Tuto #1 : Create your first automated test with Squash TA

[Last update: 29/03/2013]

[Estimated duration: 30 min]

Pre-requisites

Before the creation of your first test :

    • Be sure that you have Squash TA 1.1.0 or a more recent version installed on your workstation.

    • Be sure that all the required components of the software have been installed on your workstation (Install the Squash-TA toolbox)

    • Create a Squash-TA project (Set up a Squash-TA project?')

    • Be sure that you have Mozilla Firefox installed on your workstation (version 12.0 or above)

To create your test project, you will need tools (included in the Squash-TA Toolbox) to edit test project components (test scripts, test resources), then to run it you will need the Squash TA test execution engine. The test execution engine will be automatically downloaded and installed during your first test run (it is integrated as a maven plugin, as we will see later on).

Creating a test and its test resources in the project

You now have a project test. Let's have a look at its contents :

The root of the Squash TA files is the 'src/squashTA' directory. It is subdivided in 5 subdirectories :

    • The 'tests' directory contains Squash TA test scripts. We will come back to that in a moment.

    • The 'targets' directory contains configuration files to define the tested systems. In this tutorial we will define a Web target, which defines a web application URL (its adress).

    • Ignore the 'shortcuts' directory for now, it is used to define macro.

    • The 'resources' directory contains all resources used by test scripts (test data, third party tools, configuration files, ...)

    • Ignore the 'repositories' directory for now, it is used to define advanced configuration that is beyond this tutorial.

    • Let's first define our System Under Test (SUT) by creating a target configuration file. Right click on the 'targets' subdirectory, and choose 'New > File'. Name the new file 'yahoo.properties' and add the following content lines:

#!http

squashtest.ta.http.endpoint.url=http://www.yahoo.fr

The first line tags the file as a Web target definition file, and the second defines the System Under Test (SUT) based URL as 'http://www.yahoo.fr'

You now just have to save the file.

    • The second step consists in creating the SAHI script we will use as a call to the SUT. For that, double-click on the desktop icon to open the Sahi Dashboard. The dashboard displays a list of recognized browsers available on the workstation. Make sure that your chosen browser is completely closed before going on (Using two different browsers, like Firefox and Internet Explorer, to keep this page open in one while you open Sahi in the other might be handy). Click on the button for the browser you want to open the System Under Test in.

Remark : If your browser does not appear in the list, click on Configure. A new window opens with the different browsers. Have a look on your browser and write in the tag <path> its path. When this is done, press on the button save at the bottom of the window and close it. Then, close the Sahi controller and reopen it to check if your browser has been detected.

The Sahi interface opens in the browser you have chosen.

As written, press the ALT key and double click on the page to bring up the controller, then go back to the start page, type the base URL http://www.yahoo.fr in the start URL bar and click on the "Go" button.

    • The yahoo homepage now appears in the browser. We are now connected to the System Under Test. Switch to the SAHI controller window and type a sahi script name (eg: "sahi-tutorial")

    • Now, let's hit the "Record" button, and switch back to the System Under Test (the main browser window where our tested system is opened).

    • We are on yahoo, let's type a search query in the query bar, and hit the "Search" button.

    • After that, go back to the Sahi controller window and hit the "Stop" button. You have created the Sahi script, and you may now close Sahi and internet explorer.

    • Open a file navigator window and browse to the '<your toollbox location>\sahi_v35_20110719\userdata\scripts' directory to copy the 'sahi_tutorial.sah' script file, and paste it in the resources subdirectory of your project.

    • Sahi needs a configuration file. To provide this, create a new file named 'sahiConf.properties' in the resources subdirectory with the following content:

browserType=ie (If you have used Internet Explorer to record your Sahi Script)

browserType=firefox (For Firefox)

The last step is to write the squash TA test script.

    • Create a new file in the tests subdirectory, named for example 'sahi.ta', and add the following contents to it:

test :

# EXECUTE_SAHI sahi-tutorial.sah ON yahoo USING sahiConf.properties

Running the test

Before adding new instructions to our test, let's try to run it with Squash-TA. To do so :

    • Start the Sahi Proxy packaged in the toolbox (Squash-TA Sahi Proxy)

    • Select the 'sahi.ta' file by clicking on it

    • Select 'Run>Configurations' in the toolbar of Eclipse

    • The Run configurations dialog box appears. On it, you can create, modify, and delete running configurations

    • Select 'Maven Build> Run selected test(s)' in the run configurations list, on the left of the dialog box. This run configuration enables you to run the test you have selected in your Squash-TA project (here 'sahi.ta').

    • Click on 'Run'

    • Eclipse starts the test process. You can follow the process on your browser. When the process is finished, refresh your project by right clicking on it and select the Refresh option or press on 'F5'. The sub-directory 'target/squashTA' is created. It contains the result of your test. Please note that the result file uses by default the 'surfire-report' format. You can now open it as a unitary test report. Our Sahi test appears under the name tests 'sahi.ta' in green. The tests 'setup.ta' and 'teardown.ta' elements represent the setup (initialization of the test environment) and teardown (cleaning of the test environment) stages.

    • As an exercise, you may kill the sahi proxy by closing its DOS console window and re-run the tests. After refreshing the project files, you will see the failure report as shown below (as sahi can't be reached, the test fails - the red marking denoting a technical error, while an assertion failure would be marked in blue).