8.3. Introducing Verification Points

8.3.1. Choosing a Location for the Verification Point
8.3.2. Selecting Properties to Check
8.3.3. Injecting a Verification Point Into the Script
8.3.4. Verification Points in Action

Now that we have a first script recorded, we need to augment it with some checks verifying some properties of the web page so that we actually test something. With Squish, such checks are done via Verification Points.

A verification point consists of at least one comparison which looks whether some given condition was met. For instance, a verification point could test whether a given button is enabled or not and whether the caption of the button equals a given string.

In Squish there are multiple ways to implement verification points. The most generic and powerful way is to implement verification points manually as script commands. Another, easier approach is to use the Squish IDE to create verification points via point & click.

Inserting verification points via the Squish IDE is much simpler and only in rare cases it is necessary to manually write verification point statements. So we use the Squish IDE here. For more information about manually writing verification points, consult the chapters How to Use Test Statements (Section 15.1.7) and How to Create and Use Verification Points (Section 15.3).

8.3.1. Choosing a Location for the Verification Point

In our example, the final page of the validator's report said how many issues there were with the given website.

A part of the valdiator's output.
A part of the validators output, showing the number of found issues.

As an example, let's create a verification point which checks that the result text (in this case above, Failed validation, 34 errors) does not differ.

To do so, we first decide when to run out verification point. This is done by setting a break point on the line of the script where the verification point should be inserted. In our case, we want the verification point to be executed just before the browser is closed, so we set a break point on the very last line. This is done by clicking on the line number next to the line with the left mouse button.

A picture showing part of the editor with a new break point.
Setting a new break point in the editor of the Squish IDE.

Now, run your test suite by pressing the run button () in the toolbar of the Squish IDE. Squish will the minimize itself and start your browser, replaying the recorded actions.

As soon as the break point is hit though, execution of the script is suspended and Squish un-minimizes itself again. You can see the editor in the Squish IDE, showing that it's halted at the last line. Now we're at the right position in our script to insert a verification point. Below the editor, you can find a monitor showing all variables in your script file and their values. Since we don't have any variables defined, this window most likely just shows the text No variables in scope.

[Note]Note

In case you did not choose JavaScript as the scripting language to use when creating the test suite (see Choosing a Scripting Language (Section 8.1.3)), it might be that you do see some variables since some languages have some global variables by default. This is not the case for JavaScript though.

8.3.2. Selecting Properties to Check

To select the properties of the web page which we want the verification point to check, we use the so-called Spy. You can invoke the Spy by clicking on the corresponding button () in the toolbar of the Squish IDE. The variable watcher will disappear and get replaced with a similar-looking component which is divided vertically. This is the Spy. It's possible that you might need to wait for a few moments for the left hand side of the spy to get populated, depending on how big the page is you're viewing at that moment.

In the left hand side of the spy, you can see a tree showing all HTML objects in your web page. Selecting one object in that tree will populate the right hand side of the spy with a list of all testable properties of that object. In order to be able to test our final web page for the Failed validation, 34 errors message, we first need to find the object which holds that message. Doing so by navigating the tree of the spy is possible, but tedious.

It's much easier to just pick the right object from the web page by clicking on it, and Squish lets you do that. To do so, select the object picker () from the toolbar by clicking on it. The Squish IDE will minimize itself and you get to see the browser window again. Now, click on the text Failed validation, 34 errors - and voila! The Squish IDE shows up again, showing just that one object in the spy's object tree. Select the object by clicking on it to see all the properties:

A picture showing the properties of the HTML object we need from the web page.
The properties of the HTML object we need.

It looks like the innerText and innerHTML properties contain the text we want to check. We'll just use the former (since the innerHTML property can contain markup, and we're not interested in that) for our verification point by checking the box next to that.

That's all that's necessary for our verification point. Now we only need to insert the verification point.

8.3.3. Injecting a Verification Point Into the Script

The verification point is injected into the script using the little green check mark icon at the top of the spy, right next to the input field for the name of the verification point:

A screen shot of the Squish IDE showing the part of the spy which is used for adding a new verification point.
The button in the spy used for adding new verification points.

Click that button and you should see a new verification point called VP1 show up in the tree view at the left hand side of the Squish IDE. To actually insert the verification point into the script, close the spy again by clicking on the spy button () in the toolbar again, and then continuing execution of the script beyond our break point by clicking on the run button ().

When the script finishes, Squish inserts a new statement into the script to test the new verification point: test.vp("VP1"). The test.vp function is used for testing verification points and expects to be given the name of the verification point to test. Since the new verification point is called VP1, we pass that to test.vp.

A screen shot of the script editor in the Squish IDE, showing the newly inserted test.vp statement.
The newly inserted test.vp call.

8.3.4. Verification Points in Action

Now, let's see whether the test really worked. To do so, we first need to remove the break point again we defined a few moments ago. Just click on the little red icon with the white cross in front of the newly inserted test.vp call to remove the break point. Now, run the test again using the run button ().

If everything goes right, the test finishes, and you should see a positive test result in the test results view, which is at the very bottom of the Squish IDE:

A screen shot of the test result view in the Squish IDE, showing the (positive) outcome of checking our first verification point.
Our verification point succeeded!

This is a detailed report of the test run and would also contain occurring failures, errors, etc. If you click on a test log item, the Squish IDE highlights the script line which generated the test result.

[Tip]Tip

The interface to the test results in Squish is very flexible. By implementing custom report generators it is possible to process test results in many different ways, for example to store them in a data base, or to output them as HTML files. You can also save the test results in the Squish IDE as XML by right clicking on the test results and choosing Save Results As.

If you run tests on the command line using squishrunner, you can also export the results in different formats and save them to files. See the chapters Processing Test Results (Section 16.2.3) and How to Use Test Statements (Section 15.1.7) for more information.

Now we have a nice test already, unfortunately it's not terribly robust though. Before we can add this test to a nightly test suite run, we should make sure that it handles differences between test runs more gracefully. We'll do that in the next section.