Testing a web site can be a frustrating, tedious and monotonous task. Badboy helps you ease the task by automating the playback of testing scripts, but you will still get sick of watching every screen to see if it worked the way you expected. You might wonder, can't Badboy help with this too? This is where Assertions come into play.
Assertions are a way that you can tell Badboy to perform automatic checks to make sure that your web site is working as you expect. You can think of an Assertion as a "statement of truth" - something that you say is true about your web site. If you make this statement, Badboy can make sure it is true and warn you if it is not.
Assertions in Badboy are made up of two parts:
You can add an Assertion anywhere in your script just by dragging one from the Toolbox. A new Assertion added to your script appears as a question mark symbol as shown below:
The question mark indicates that the assertion has not been tested yet. When the assertion plays, it will change to either a tick or a cross depending on whether the assertion was found to be true.
An Assertion by itself won't check anything and will always pass - you need to add Checks from the Toolbox to it to describe which properties of the page to check. There are several different kinds of Check items that Badboy supports. The table below shows some of the different types:
|Content Check||Checks for the presence of some text on the page.|
|Response Check||Checks characteristics of the response time and size|
|Color Check||Checks for particular colors on the page. You can specify a range of colors and approximate location to allow for slight variations.|
|Summary Check||Checks the summary information for items in the script. For example, it can check the number of times an item has played, errored or timed out.|
|JScript Check||Executes JScript that you provide and passes or fails the assertion based on whether your JScript returns "true" or "false".|
|Variable Check||Checks the value of a variable to see if it matches a regular expression that you provide.|
The most common kind of Check is the Content Check, so Badboy provides an especially easy way to add Assertions with Content Checks to your script. To use this function all you have to do is select with the mouse the content you would like the Assertion to check and then click the "Easy Assertion" button (shown below).
You can find more information about Content Checks in the topic Content Checks.
By default the Easy Assertion button adds a positive Assertion, ie. an Assertion that states that the content should exist on your page. If you want to add a negative Assertion, ie. that the selected content should not exist on the page, hold down the SHIFT key while clicking the button.
An Assertion has a number of properties that control how it works. Below is an example of the Assertion Properties dialog showing the options that you can choose:
Cascading Assertions differ in that they have a longer lifetime than just the moment they are played. When you check the "Cascade to following items" box Badboy will test the Assertion after every item is played until the parent Step, Test or Suite of the Assertion is exited. Thus Cascading Assertions are useful for detecting general error conditions. For example, you could specify that no page anywhere on your site should ever contain the words "Internal Server Error". By adding this as a "Cascading" Assertion at the top of your script you can ensure that Badboy will flag such an error no matter when or where this text occurs.
The scope of a Cascading Assertion is limited to the Step, Test or Suite that is the direct parent of the Assertion. This means that the Assertion flows "downward" into all the Steps that are children of the Assertion's parent Step. Once the play position moves out of the Assertion's parent item the Assertion no longer applies. If you would like your Assertion to apply across a whole Suite of Tests then you can put it immediately under the Suite item in your script, so that it plays before any of the Tests execute and it stays active for the whole Suite.
Violation Actions and ContinuationVery often an Assertion failure may represent a severe error in your web site or application. In such a case you may not want your test to continue, but rather to abort either the whole script or the Step that is playing. To achieve this, select the action you would like from the "Continuation" box in the Assertion properties.
Capturing a ScreenshotOften just the fact that an Assertion failed won't be enough to describe in detail what the problem was that occurred. For example, if you matched "Error 500" in your Assertion text, you would want to see what else was on the screen at the time to tell what the problem really was. Badboy makes this easy by giving you the option to automatically capture a Screen Shot of the browser window any time an Assertion fails. You will then be able to view the Screen Shot at any later time by opening the captured image in your Script. It will also be exported if you save an HTML Report of your Script's execution.