Form Populators

HTML Forms are the core of many modern web applications. Form Populators help you populate and submit forms as part of your Badboy scripts.

You often don't have to use Form Populators at all - Badboy automatically records and sends the data from the Forms as Request parameters, so it typically isn't necessary to actually populate the form on the page. There are some times, however, when certain visual or functional effects are explicitly linked to the population of a form. Form Populators are here to help you when you need to test these kinds of pages.

Some examples are:

  • A web site may perform scripted operations based on the content of Forms prior to submitting them. For example, sometimes the content of one field may be dynamically calculated from another field at the time the form is submitted by DHTML scripting. When Badboy operates in Request mode it may bypass the calculation and send an incorrect value.
  • A web site may send back many fields in a form pre-populated. In Request mode, Badboy ignores the values that are pre-populated and instead sends a request containing all the values that were recorded originally. Although it is possible to make Badboy extract the values from the page and send them in the Request, it may be much easier to use a Form Populator to populate only the fields you need and submit the form.
  • Many web sites take measures to prevent automated access which detect Badboy's Request mode and prevent it working. This is especially common on important pages such as login pages and order submission pages. Since Form Populators are a more realistic simulation of user activity, they often provide a work around when normal Badboy Requests fail.

Creating a Form Populator Manually

A new Form Populator added to your script appears as shown below:

New Form Populator

Adding fields to a Form Populator

Once a Form Populator has been created, you need to add the fields that you would like populated to it. There are several ways to do this. The easiest is to let Badboy do the work by capturing the form automatically. You can do this very simply in a couple of ways:

  • Click in a field of the form you want to capture and hit "Ctrl-Alt-f" on your keyboard. This will capture a Form Populator for the form where you clicked.
  • Drag a Form Populator into your script, and click the "Capture" button in the Form Populator's Properties dialog.

The Figure below shows how the Form Populator properties dialog appears:

Form Populator Properties Dialog

In order to use the Capture button, you should first choose the form that you would like to populate from by selecting either it's index (ie. the position of the form based on the order the forms appear on the screen), or its name. If you aren't sure which form to populate from then the easiest method is to simple try capturing different indexes until the element you want appears. It is often useful to use the DOM View to help select the correct form. When you have selected the form you would like to populate from, just hit the Capture button and Badboy will capture form elements along with their current values from the form that you selected.

Using Regular Expressions

Occasionally you may need to populate a form whose name is not the same each time it appears in the page, but follows a fixed pattern. For example, in some applications the form may have a constant name followed by a number that changes. For these cases you can enable the "Use Regex" option and enter a Regular Expression that matches the pattern of the of the form you wish to populate. For example, if the form is always called "logonForm" followed by a 4 digit number, you can use an expression like this:

logonForm[0-9]{4}

Automatic Capture of Form Populators

Sometimes Badboy may automatically record Form Populators for you. This occurs when you record a Navigation (see Navigation Items) and you have modified some fields in a form on the page that you are recording. In this case, Badboy detects the modified fields and creates a Form Populator for those fields so that when you play back they fields will be populated correctly.

Playing Form Populators

Form Populators are easy to play - the behave the same way as other Badboy elements and can be played either using the right-click menu or as part of the normal flow of your script. You should be aware that if the form that you attempt to populate does not exist on the page, Badboy will generate a warning in the log file, but will continue playing without error. If you want to be assured that the form populated correctly, you may like to use an Assertion.

Form Values

Form Populators work by recording the values present in forms as "Form Values" that are children of the Form Populator in the script. When a Form Populator is played, each of its child Form Values is populated into the form. If you want to change which values are populated by a Form Populator, you can do that by modifying the Form Values by editing their properties.

Indexed Form Values

As well as a name for the field, each Form Value has an "index". Indexed Form Values are used when there are multiple elements in a form that have the same name or id. When this occurs, Badboy will record a form value for each form field that has the same name and an index that specifies which instance of the field having that name should be populated.

Select / Dropdown Boxes

Selection boxes present a minor complication in form population because each entry in the dropdown menu is in fact represented by two different values that are both useful in populating them on playback:

  • The value submitted by the field to the server - this is often a code or a number
  • The value displayed to the user - this is usually human readable text

By default Badboy records the first of these options - the value submitted to the server, and on playback it selects the option in the select box that has that same submitted value. This often works well but in some cases it may fail or be more difficult to use. For example, if the page uses arbitrary values for the options that change each time the script is played back then playback will not work because the original recorded value may be incorrect next time the script is played back, even though the text of the option values stays the same. It may be also may easier to select the option based on the displayed value when you are doing data driven testing such as loading the values from a spread sheet or other external source where the codes are not externally known but the text values are.

For these cases where the human readable value is more appropriate, open the Form Value properties and select the option "Match Visible Text for Select / Dropdown Fields". This will change playback to select the option where the text displayed in the dropdown matches the script Form Value rather than the code submitted to the server.

Using Form Populators to Submit Forms

If you wish, Badboy can also submit the populated form after it has populated it. This allows you to use Form Populators as an alternative to the usual Request and Navigation Mode playback mechanisms. Used in this way, Form Populators can often assist to automate operations that experience problems using other methods.


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