Click here to Skip to main content
15,169,085 members
Articles / Desktop Programming / WTL
Posted 25 Mar 2007


90 bookmarked

ScriptRunner Application

Rate me:
Please Sign up or sign in to vote.
4.97/5 (18 votes)
25 Mar 2007CPOL4 min read
An Introduction to ScriptRunner. A scripting tool for user interface Unit Testing.
Screenshot - ScriptRunner.jpg


One of the most sought after 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 from other unit testing Frameworks. In fact, ScriptRunner is a complement of a traditional unit testing Framework like CPP Unit. A Unit Testing Framework lets you test modules in your application. A module can be a library, a class (or an 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, to 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 a 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

TraceYou can use the Trace button to capture the 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 an output by using ScriptHost.DebugOutput function.
StopStop Trace will stop the capture of the debugger output.
CompareCompare mode can be used to verify the outputs being sent when your program executes.
RunRun 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

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 an 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

WindowProperty to get Window handle. This should be used as read-only since ScriptRunner is responsible for 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 CodeProject 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:


  • March 25, 2007 - Public release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ernest Laurentin
Software Developer (Senior)
United States United States
Ernest is a multi-discipline software engineer.
Skilled at software design and development for all Windows platforms.
Interests: User Interface, GDI/GDI+, Scripting, Android, iOS, Windows Mobile.
Programming Skills: C/C++, C#, Java (Android), VB and ASP.NET.

I hope you will enjoy my contributions.

Comments and Discussions

GeneralNew feature requested Pin
Kevin Eastman28-Dec-09 15:41
MemberKevin Eastman28-Dec-09 15:41 
GeneralRe: New feature requested Pin
Ernest Laurentin28-Dec-09 16:00
MemberErnest Laurentin28-Dec-09 16:00 
GeneralWin CE WM5 Pin
yossi1314-Jul-08 20:29
Memberyossi1314-Jul-08 20:29 
Generalwhy this happened Pin
089890882-Jan-08 20:33
Member089890882-Jan-08 20:33 
AnswerRe: why this happened Pin
Ernest Laurentin3-Jan-08 16:57
MemberErnest Laurentin3-Jan-08 16:57 
GeneralTrace button never work... Pin
michael. zhao26-Oct-07 1:14
Membermichael. zhao26-Oct-07 1:14 
Thanks for the great tool first. However, to my understanding, trace button will help me capture initial operation. But, it doesn't. Can you help?
AnswerRe: Trace button never work... Pin
Ernest Laurentin26-Oct-07 5:28
MemberErnest Laurentin26-Oct-07 5:28 
QuestionCommand Line Execution? Pin
Jeanne Dixon25-Jun-07 7:52
MemberJeanne Dixon25-Jun-07 7:52 
AnswerRe: Command Line Execution? Pin
Ernest Laurentin25-Jun-07 9:01
MemberErnest Laurentin25-Jun-07 9:01 
QuestionJust for windows apps? Pin
chessnovice3-Apr-07 9:37
Memberchessnovice3-Apr-07 9:37 
AnswerRe: Just for windows apps? Pin
Ernest Laurentin3-Apr-07 14:39
MemberErnest Laurentin3-Apr-07 14:39 
GeneralAnother free solution Pin
bilus3-Apr-07 1:12
Memberbilus3-Apr-07 1:12 
GeneralBug Pin
Danila Korablin25-Mar-07 22:18
MemberDanila Korablin25-Mar-07 22:18 
GeneralRe: Bug [modified] Pin
Doctor Morey25-Mar-07 22:40
MemberDoctor Morey25-Mar-07 22:40 
GeneralRe: Bug Pin
Ernest Laurentin26-Mar-07 6:29
MemberErnest Laurentin26-Mar-07 6:29 
GeneralThanks Pin
Danila Korablin25-Mar-07 21:49
MemberDanila Korablin25-Mar-07 21:49 
GeneralRe: Thanks Pin
Ernest Laurentin26-Mar-07 6:32
MemberErnest Laurentin26-Mar-07 6:32 
GeneralRe: Thanks Pin
Ernest Laurentin26-Mar-07 21:28
MemberErnest Laurentin26-Mar-07 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.