JScript Checks

Sometimes you need to check your page in ways that may be more complicated than just looking for a fixed piece of content. For example, it might be that the location in the page matters, or the style that it is rendered in is important, or sometimes you may even wish to use sophisticated logic to check your page. For example, you might decide that for all of your order forms, the quantity in the "Total" field should always equal the sum of the quantities of the line items in the order. To make sophisticated checks like this, the best way is to use a JScript Check. JScript checks allow you to use any Javascript expression that you can write to check the content of your page.

Adding a JScript Check

To add a JScript Check, drag it from the Checks toolbox in the tabbed view and drop it into your script at the position you would like it to execute. You can drop it inside an existing Assertion to add the Check to that Assertion, or you can drop it outside, in which case a new Assertion will be created.

JScript Check Properties

A JScript Check has a number of properties that control how it works. Below is an example of the Properties dialog showing the options that you can choose:

JScript Check Properties Dialog

Selecting the Frame to Use

Some websites may use frames to create separate windows within the page where content is rendered. If that is the case and you want to check a specific frame, locate the correct frame and choose it in the drop down list of frames.

If you have trouble identifying which is the correct frame, try locating the content using DOM View (Press Ctrl-D) and then checking which frame is the parent of the element(s) you are looking for.

If you want to make an Assertion that checks all of the frames in the document then you can select the "All" option. In that case, Badboy will execute the Javascript in every frame of the document. This is very useful for writing general rules that you think should always be true. For example, if your company policy is that all pages must render in the Standards Compliant mode of the browser, you could write a rule that checks that for every frame of the window by using the "All" option.

Writing JavaScript for JScript Checks

The Javascript for JScript Checks is executed as if it was inside the body of a function. The script should use the "return" keyword to return a value of either "true" or "false" to indicate whether the check passes or not.

Example 1

The following example checks that the Title of the window is not blank:

if(window.title != ''{
  return true; // passed
}
else {
  return false; // failed
}

Example 2

This example checks that IE is rendering in Standards Mode:

return window.document.compatMode == 'CSS1Compat';


Badboy Documentation Generated on Mon Dec 29 22:28:41 EST 2008