Mouse Clicks

Browsers are intimately mouse driven tools, so it is not surprising that there are times when nothing other than a real mouse click will replay exactly the effect you are looking for in a test. Some common examples of situations when this can happen are:

  • Your web site uses Java Applets
  • Your web site relies on complicated Javascript effects that are only activated via the mouse
  • Popup boxes, Javascript errors or security dialogs prevent your tests from playing properly.

In all these situations a simple and effective solution can be to control the browser by automating mouse clicks in the window. Fortunately, Badboy makes recording and adding Mouse Clicks easy.

Adding a Mouse Click

To add a mouse click, just drag a Click Item from the Toolbox into your Script. The figure below shows how a Click Item appears in the script:

Click Item

When you add a Click Item, the properties dialog box for the Click Item will show giving a number of options that you can choose to determine how the mouse click is performed. The following paragraphs describe these. The figure below shows how this looks:

Click Properties

Window Name, X and Y Position

These parameters determine the window and the location within the window (in pixels) where the mouse click will occur. The mouse click is always relative to the top left corner of the window specified. This means that you don't need to worry about where the window appears on the screen (which can easily change), but only about where in that window the click needs to occur. Note that sometimes looks can be deceiving - some applications use many layers of windows and consequently if you enter the numbers manually you may have to experiment to get the right X and Y position. Sometimes you may even find that the values you need are negative. The best way to set all these parameters at once is to use the Capture Button (see below).

Capturing the Click from an Existing Window

By far the easiest way to create a Click Item is to capture it from an existing window on your screen. This means that you should set up Badboy (and any other windows you expect to be on the screen and open the Click Item properties and then click the Capture button. The next left click that you do will then be captured, including window title, X and Y position. Note that you are not limited to recording clicks inside Badboy's browser window - you can record clicks on any window on your desktop, even Badboy's menus or the desktop itself!


Badboy offers a shortcut way to create Mouse Click Items: just click (anywhere) in a browser window that you want the click to occur in, position the mouse at the right location and the hit keys "Ctrl-Alt-M". Badboy will add a Mouse Click recorded at the selected location to your script tree.

Restoring Window Size

One problem with using mouse clicks is that sometimes if windows change their size and shape then they may lay out their contents differently. This is especially true with HTML based views such as Badboy's. For this situation you can check the "Attempt to Restore Window Size" box prior to capturing the click with the "Capture" button. In this case the window size will be captured and then restored prior to executing the Click operation. Note: although Badboy will always try to resize windows if you check this option some windows may refuse to let Badboy resize them, preventing it from working. Fortunately, the most important window - Badboy's own window - should always work.

Cascading Click Items

You might wonder, what do I do if I know that a window that I want to click on will appear, but I don't know when? This situation appears more commonly than you might think. Most especially, it occurs when unexpected dialog boxes show during your tests - (examples are javascript Alerts, confirmation boxes, security warnings or Javascript errors). To handle these it can be very useful to be able to say "If this kind of window ever appears, click on it to make it go away". This is exactly what Badboy allows you to do with Cascading Click Items. The term "Cascading" means that the Click will apply for all items following and below the Click Item in the Script, but not outside of the Step in which the Click is positioned. When a Cascading Click Item plays, it starts a background "watchdog" that continuously looks to see if a window matching the name you have given is present. If it finds one, it executes the click. When the play position moves outside of the Step in which the Click is positioned, the watchdog is terminated.

Note: if you want Badboy to click on a window, you must often place the Cascading Click Item before the item that causes the popup to occur in the script. If you put it afterward it may not execute until after the actual popup has been closed.

A Common Problem: Capturing Modal Dialogs

Sometimes you may want to capture a click on a window that only shows up during playback and you may find that you can't open the Click Properties dialog to capture the Click coordinates. A simple trick will help you deal with this: run a second instance of Badboy to cause the window to show, then capture the Click using the first instance. This trick works because Badboy can capture Clicks from the second window, but will still happily play the Click back on windows generated by the first instance . Using this trick you can capture a click for any kind of popup or dialog that may show.

Disadvantages of Mouse Clicks

You could potentially write your whole test using "Click" items. You might find this a very easy away to get your tests working. However there are some disadvantages of creating test scripts this way that you should seriously consider before basing significant portions of your tests on mouse clicks:

  • Because Mouse Clicks are critically dependent on the exact layout of the page to work, they are harder to maintain. A small change to the layout of the page, the size of the font or the width of a table will throw the position of the Click completely off. This means that although your test will be easy to create, as time goes by and your pages change it will begin to break. You will have to go back and re-record the Click items when this happens. When your tests fail, you will have to wonder if they really failed or if perhaps just one of the Mouse Clicks has stopped working.
  • Mouse Clicks may depend on your browser's configuration to work. Different users may have different fonts and other browser settings that may subtly affect the layout of the page. If you record scripts with a lot of Mouse Clicks you will find it harder to share them with others because of this.
  • Mouse Clicks rely on having a real, true, browser window present. This means that if you try to run your scripts with bbcmd, the Badboy command line runner, you will find that they won't work. They also won't get exported if you save your script in JMeter format. You will even find that you can't minimize the Badboy window while the Click Item is playing.

For the reasons above over-use of Click Items is not encouraged. However using them carefully and wisely will let you test things that might otherwise be impossible, and can make your testing life easier when you are confronted with difficult problems!

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