Click here to Skip to main content
Click here to Skip to main content

ScriptRunner Application

, 25 Mar 2007
Rate this:
Please Sign up or sign in to vote.
An Introduction to ScriptRunner. A scripting tool for user interface Unit Testing.
Screenshot - ScriptRunner.jpg

Introduction

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.

Description

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

Command Description
Trace You 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.
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 executes.
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 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

Function Description
Window Property 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().

Example:

function ScriptHost::OnStarted()
{
  LaunchApp("C:\\Windows\\System32\\Notepad.exe");
  Sleep(500);
  var winObj = FindWindow("Notepad", "Untitled - Notepad");
  if (winObj)
  {
    winObj.SetForegroundWindow();
    winObj.SetFocus();
    SendKey(0x74); // F5
    SendKeys("Hello CodeProject gurus around the world!\r");
    SendKeys("1234567890-=\r");
    SendKeys("!@#$%^&*()_+\r");
    SendKeys("abcdefghijklmnopqrstuvwxyz\r");
    SendKeys("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r");
  }
  else
    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:

History

  • March 25, 2007 - Public release

License

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

Share

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.
-
MCSD (C#, .NET)
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 PinmemberKevin Eastman28-Dec-09 14:41 
GeneralRe: New feature requested PinmemberErnest Laurentin28-Dec-09 15:00 
GeneralWin CE WM5 Pinmemberyossi1314-Jul-08 19:29 
Generalwhy this happened Pinmember089890882-Jan-08 19:33 
AnswerRe: why this happened PinmemberErnest Laurentin3-Jan-08 15:57 
GeneralTrace button never work... Pinmembermichael. zhao26-Oct-07 0:14 
AnswerRe: Trace button never work... PinmemberErnest Laurentin26-Oct-07 4:28 
QuestionCommand Line Execution? PinmemberJeanne Davis25-Jun-07 6:52 
AnswerRe: Command Line Execution? PinmemberErnest Laurentin25-Jun-07 8:01 
QuestionJust for windows apps? Pinmemberchessnovice3-Apr-07 8:37 
AnswerRe: Just for windows apps? PinmemberErnest Laurentin3-Apr-07 13:39 
GeneralAnother free solution Pinmemberbilus3-Apr-07 0:12 
GeneralBug PinmemberDanila Korablin25-Mar-07 21:18 
GeneralRe: Bug [modified] PinmemberDoctor Morey25-Mar-07 21:40 
GeneralRe: Bug PinmemberErnest Laurentin26-Mar-07 5:29 
GeneralThanks PinmemberDanila Korablin25-Mar-07 20:49 
GeneralRe: Thanks PinmemberErnest Laurentin26-Mar-07 5:32 
GeneralRe: Thanks PinmemberErnest Laurentin26-Mar-07 20:28 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 26 Mar 2007
Article Copyright 2007 by Ernest Laurentin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid