You can add JScript to your tests by right-clicking in the Script tree on a Step or Request and selecting Add-> JScript or Insert->JScript.
When adding a JScript item or if you edit it's properties, you will be shown a dialog where you can enter the JScript for Badboy to run when it plays the given item:
Badboy offers additional features and functions to Badboy Plugins. However you don't need to write a plugin to access these special functions: you can make it possible by checking the box marked "Allow Access to Plugin Privileges". If you do this then your script can access the plugin API by creating a "plugin" object as follows:
var plugin = badboy.plugin(); alert("Badboy is configured to use " + plugin.getPreference("Undo Levels") + " undo levels");
It is important to be mindful of security: Badboy's plugin API can be used to modify your script and could even be manipulated to launch malicious programs on your computer. Therefore you should make sure you do not set references to the "plugin" object outside of your script in case they might be accessed by web pages you do not trust.
JScript can be used to perform advanced operations and thereby extend the functionality of Badboy. This is especially true if you change your security options so that JScript can use ActiveX controls. Here is an example JScript that will let you save a file to your local hard disk when it executes:
var fso, textFile; var ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject"); textFile = fso.OpenTextFile("c:\\test.txt", ForWriting, true); textFile.Write ("This is a test."); textFile.Close();
This script has a difficulty: in order for it to work you must set your Internet Explorer security level to Low for the site that you are accessing so that ActiveX controls can run and access the file system. Otherwise you will get security warnings shown, or it might be simply refused by the browser. To get around this you can use the Badboy Plugin API instead to create the ActiveX object:
var fso, textFile; var ForWriting = 2; fso = badboy.plugin.createObject("Scripting.FileSystemObject"); textFile = fso.OpenTextFile("c:\\test.txt", ForWriting, true); textFile.Write ("This is a test."); textFile.Close();
For this to work you must check the box marked "Allow access to plugin privileges" in your JScript item.
If you are a programmer, you can even write automation objects of your own using your favorite language and access them in the same way.
For more information on controlling Badboy with JScript, see Automating Badboy with OLE. You can call any of these OLE function from JScript itself and thereby control Badboy itself as part of your scripts.