One of the most sought skills for software professionals today is not only the ability to write good quality code but also the ability to test and validate your code. This is where this tool comes into play. ScriptRunner is different than other unit testing framework. In fact, ScriptRunner is a complement of traditional unit testing framework like CPP Unit. A Unit Testing framework let you test modules in your application. A module can be a library, a class (or object) or can be a simple function. ScriptRunner complements unit testing by emulating a user interaction with your software and can display any error in the execution of your program.


Initially, ScriptRunner was created with the intent to simulate a user interaction with an application. But in the end, this tool has evolved. Now, it provides a simple TRACE library to capture the application state and of course, report any error in your program.
Typically with CPP Unit (or other framework), you write the code to test your function passing both correct and error values to verify whether it behaves correctly. These tools are great and if you choose to test enough important functions, you can get very good coverage and find bugs (or broken code) easily in your program.
But one aspect that is lacking, is how do you test the User Interface to achieve the same result? ScriptRunner can help you do that! You can write simple script to interact with your application and use the ScriptRunner TRACE library to display any success or failure.

How Does it Work?

ScriptRunner is a Scripting Host application. It provides a set of interfaces to execute an application, manipulate a window and submit input to your user interface as a user would normally do. Several commands are available to configure and run a test script. I am assuming everyone will recognize the standard icons and know what they are used for. Now, let me describe the other icons to get you started.

ScriptRunner Command

Command Description
Trace You can use the Trace button to capture trace statement (OutputDebugString) directly to this window. Your code can send output strings directly to this window by using the ScriptRunner TRACE library. A script can also send send an output by using ScriptHost.DebugOutput function.
Stop Stop Trace will stop the capture of the debugger output.
Compare Compare mode can be used to verify the outputs being sent when your program execute.
Run Run command will execute a User Interface JavaScript Testing Unit

Several additional features are available to filter your program output. Context menu options are also available to load and save your program output settings.

ScriptRunner ScriptHost API

Function Description
Display(text) Display a message box
DebugOutput(text) Send output text to script runner output window
FindWindow(class,title) Search for a specific window class and title (optional).
SendKey(keyCode,ctrlKey,altKey) Send a virtual Keycode to active window (control with focus). Optionally, simulate CTRL and ALT keys being pressed.
SendKeys(text) Send keystrokes (User emulation).
Sleep(delay) Wait for specified milliseconds
bool LaunchApp(appPath) Run an application
string GetEnvString(sName) Get an environment variable string

ScriptRunner WindowDispatch API

Function Description
Window Property to get window handle. This should be used as read-only since ScriptRunner is responsible of creating and initializing this object.
string GetWindowText() Get current caption text or edit text for edit control.
int GetWindowTextLength() Get current caption text (or edit text) length.
bool SetWindowText(text) Change window text
SetFocus() Change focus to window
ShowWindow(cmdShow) Show/Hides a window
Window GetDlgItem(dlgItem) Get a child window handle
ChildWindowFromPoint(x,y) Get a child window handle from client coordinates
MoveWindow(x,y,w,h) Resize and reposition a window
SetWindowPos(x,y,cx,cy,flg) Resize and reposition a window
Window FindWindowEx(class,title,prev) Find a child window based on class or title
bool SetForegroundWindow() Set window to foreground
Window GetParent() Get current window parent
MouseHover() Move and Center mouse over window object
MouseLClick(x,y,clickNow) Move mouse to window client position, optionally simulate left click at the end of movement.
MouseRClick(x,y,clickNow) Move mouse to window client position, optionally simulate right click at the end of movement.

ScriptRunner Example

ScriptRunner exposes only one event handler OnStarted. It is the recommended main entry point to run your script. In JavaScript, use this prototype
function ScriptHost::OnStarted().

function ScriptHost::OnStarted()
  var winObj = FindWindow("Notepad", "Untitled - Notepad");
  if (winObj)
    SendKey(0x74); // F5
    SendKeys("Hello all gurus around the world!\r");
    Display("Untitled - Notepad window was not found...");

Unit Testing Output to ScriptRunner

As stated before, a C/C++ application can send output to ScriptRunner output window. For this end, you will have to include a set of files in your solution.
CTracer.h : This is used to hook OutputDebugString calls from your program.
SocketHandle.h, cpp : Socket API used to communicate with ScriptRunner.
HookImportFunction.h, cpp : PJ Naughter's Hook Import function (Click here)(Copyright © 1999; PJ Naughter)

Project Info

This tool uses:
BrainChild Editor control : (Copyright © 2002-2007; Jan van den Baard)
WTL7.5 (Copyright © 2006; Microsoft Corp.)
XPCommandBarCtrl (Copyright © 2001-2002; Bjarke Viksoe)


March 25, 2007 - Public Release