Extent Badboy to write a CSV-Logfile by using a JScript Tool Element 
From time to I use tool "Badboy" from Simon Sadedin to create functional tests for websites or web-based applications. Now I needed to extend the tests for logging the runtime of certain steps and the whole test, but the Badboy Tool doesn't offer such a counter out of the box. To I created some lines of JavaScript that can be used in Badboy via the the "JScript" tool element to log into a csv-file, which can be processed in Excel or Openoffice later on.
Instructions to setup
- Create a variable called "logfile" and set it's value to the name of the desired logfile, e.g. mylogfile.csv. (You can also define it with a path like "c:
myfile.csv")
- Create a test file called "logentry.js" and place it in the same directory as your test. The content of the file is the script shown at the end of this blog entry.
- Add a "JScript Tool" to your testplan at the points where you want to write a timestamp into the logfile, select checkbox "Allow Access to Plugin Priviliges" and set the source to to the formerly created "logentry.js" file. (You can reference the script file with absolute or relative pathes. If you go for relative ones, the whole test can be simply transferred to other machines)
That's it! You can copy that element to all that points in your test, where you want to log a line. The logline will contain the host-Variable as well as the parent steps name and the name you gave to the JSctipt tool element.
The Code:
var datumzeit = new Date();
var stepname = badboy.script.find(badboy.current).parent.get('name');
var value = '"' + badboy.getVariable('host') + '","' + stepname + '","' + badboy.script.find(badboy.current).get('name') + '","' + datumzeit.toUTCString() + '","' + datumzeit.getTime() + '"' + " rn";
var fso = badboy.plugin.createObject("Scripting.FileSystemObject");
var textFile = fso.OpenTextFile( badboy.getVariable('logfile') + '-' + badboy.getVariable('host') + '.csv', 8, true);
textFile.Write (value);
textFile.Close();