January 18, 2006

Thou shalt not waste time doing repetitive and mundane tasks

Filed under: Automation, General — Marcus Tettmar @ 1:53 pm

This is the 10th commandment of system administration according to Brian Warshawsky’s article “Ten Commandments of system administration” over at NewsForge. I couldn’t agree more. You’ll find the article with links to the other nine commandments here. These articles are for Linux administrators so much of the content and the example scripts won’t be much use to Windows admins. But the message is perfectly valid. Linux admins have always had the power of scripting at their disposal and the benefit of an operating system which is powered by command line interfaces. Windows, though, is primarily GUI based, designed more for desktop users. That’s why you need Macro Scheduler to automate Windows applications and obey the 10th commandment!

Keyboard Shortcut Correction

Filed under: General — Tags: — Marcus Tettmar @ 8:56 am

Tim Jones emailed me to point out an error in my keyboard shortcut article. Tim is a proper keyboard junky. Not even sure he has a mouse!

___________________

> SHIFT-RIGHT on its own just moves the cursor to the end of the
> word and then to the next word and so on. Reverse it with
> SHIFT-LEFT.

SHIFT, marks next/prev letter, CTRL moves a word. I know you
know that, but the blog entry seems to kinda have it the other
way around.

___________________

Thanks Tim!

January 17, 2006

How to Start Writing an Automation Script

Filed under: Automation, Scripting — Tags: — Marcus Tettmar @ 11:35 am

These are my tips for getting started with writing an automation script.  While I’m, writing this with our Windows Automation tool, Macro Scheduler, in mind, these tips will be appropriate whichever automation tool you are using.

The most important thing before attempting to write a routine to automate a software process is to be familiar with the process itself. Run through the full process several times and find the simplest path. If you’re using the mouse excessively try to find keyboard alternatives.

Write down every step you take. Make a note of the keys you press, note down the title of each new window and how long each step takes. Try to determine what indicates the completion of each step. Make a note of it. You’ll end up with a list of keystrokes and window titles. This is the basis of your script. You’re now most of the way there. This list will translate well into a Macro Scheduler script.

I find it is best to break the script down into manageable chunks. Don’t try to write the whole thing at once. Start by just scripting the first few steps. E.g. write the code that opens the app, waits for it to be active and sends the first keystroke. Run it and make sure the process ends up where you expected. Tweak it if necessary. Now add the next couple of steps. Run it again. And so on. Building the script up in this way will iron out issues as you go rather than leaving you desperately trying to hunt down the cause of an error amongst one long script. You can also use the debugger to step through the script line by line.

Use SetFocus! When sending keystrokes Macro Scheduler just simulates what you do when you press keys on the keyboard. When you do that the keystrokes land on the active window. So you need to make sure the window you want the keystrokes to land in is the active window. Use SetFocus to do this. Get into the habit of using SetFocus even after running a program with the Run Program command. When you start a program it nearly always becomes the active window, but other applications can steal the focus. So it’s a good habit to get into to use SetFocus before sending a set of keystrokes.

Try not to use absolute wait times to wait for events to complete. The process may take longer on another occasion and fail. Also remember that when you do something manually you will subconsciously wait for the outcome of each action. A script isn’t quite so clever and unless you tell it to wait for certain actions to complete it will blindly move on to the next step. Always use WaitWindowOpen after running a program or sending an event that causes a new window to appear. This will ensure the script waits for that window to appear before continuing. Use WaitWindowClosed after issuing a command that causes the window to close. There are ways to wait for all sorts of other events to take place too, some more advanced than others. You can wait for pixel colors to change, mouse cursors and windows to change, detect object captions and wait for files, and portions of the screen to change amongst other things. When starting an application with Run Program use RP_WAIT=2 to tell it to wait until the application is ready for input before continuing.

Sometimes you do need a small Wait between events. Sometimes you need to slow down the key send rate. Scripts run faster than a human can type and not all applications can cope with that many keystrokes in such a short space of time. So the odd Wait>0.5 here and there can help. You can also slow down the key send rate with SK_DELAY.

When issuing shortcut keys such as ALT-F for the File menu use lowercase for the underscored character. E.g.:

Press ALT
Send>f
Release ALT

I have seen some applications fail to recognise shortcuts when Macro Scheduler sends the character in upper case. This is probably because it treats an upper case character send as having the Shift key pressed at the same time. So I always recommend issuing characters used in shortcut keystrokes in lower case.
It is best to avoid mouse events as much as possible, but if you do find you need to use the mouse for a particular action – maybe there’s no keyboard alternative – try to work out the relative mouse coordinates. Use the cursor monitor, set it to relative, and find the position relative to the window. Then use MouseMoveRel. This ensures that the mouse will always click on a position relative to the window rather than on an absolute screen position so that if the window opens in a different position next time around the macro will still work.

Clearly this article is all about automating via user simulation – by sending keyboard events to applications. Often there are better ways to automate an application such as via VBScript/ActiveX or DDE, or by reading data from files and databases. Before sitting down to automate an application by simulating user input stop to consider whether there are alternatives. For example, I’ve seen people write scripts to automate getting data from Excel by sending keystrokes to Excel to copy and paste. There’s no need to go to this trouble when Excel provides a DDE interface and can also be scripted with VBScript. See the sample script that comes with Macro Scheduler for an example of retrieving data from Excel directly. I’ve even seen macros which get data from a text file by driving Notepad with keystrokes. This is unnecessary and cumbersome when all you need to do is read data directly from the text file with the ReadLn command. If you need to get data from a database, you don’t need to send keystrokes to the query tool – you can read data directly into the script using VBScript/ADO/ODBC. Equally you can automate Internet Explorer elegantly via VBScript/ActiveX or with WebRecorder. There are usually at least two ways to automate something. Before writing your script stop and question whether there’s a better way.

Before writing your first script read Scripting Windows for Beginners in the Macro Scheduler help file/manual.

And browse the examples at the Scripts & Tips forum.

And if you don’t already have Macro Scheduler, you can download a trial version here.

January 16, 2006

Keyboard Shortcuts

Filed under: Automation, Scripting — Tags: — Marcus Tettmar @ 9:19 am

As mentioned in my last post, the easiest, most reliable way to automate an application is via keyboard shortcuts. But I’ve found that many people are so used to using the mouse that they don’t even realise you can use the keyboard to move around Windows applications.

Some things I take for granted are completely new to others. For example, moving from one field to the next is accomplished with the Tab key. After entering some information into an edit box just hit Tab to move to the next edit box. This is surely faster than moving your hand away from the keyboard, moving the mouse, clicking in the next edit box, moving back to the keyboard … and so on. Tab is all you need. Something a lot of people don’t realise is that this even works on web pages. Tab will move from form field to form field, but also from link to link. Try it now while you are reading this post. Press Tab a few times. You’ll notice a faint hashed box around the focused link. Press Tab again and the box moves to the next link. And so on. When you’re on a clickable object, or link, the Enter key will select or “click” it. Tab to a link and then press Enter and you will go to that page. In a Windows application you can tab to any standard object. You can tab through edit boxes as well as check boxes, menu items and buttons, and pretty much anything else. If you tab to a button pressing Enter will “click” it.

Checkboxes can be toggled from checked/unchecked and back again by pressing the space bar. Tab to a checkbox and hit the space bar. Its checked status will change. To select an item in a list box you can use the up and down arrows. Same goes for treeviews and combo boxes. But what you might not realise is that many list boxes and combo boxes have a kind of “drill down” feature. Type the first few characters of an entry and the selected item will change to the first item that starts with those characters. Type more characters in one go to narrow down the selection. This can be really useful when automating applications where you want to select an item in a list box or drop down – you can just send the text of the item you want to select. E.g. the following script automates the Regional Settings control panel applet to automatically change the default input language to Chinese (Hong Kong):

//Set to Chinese (Hong Kong …)
ExecuteFile>intl.cpl
WaitWindowOpen>Regional and Language Options
SetFocus>Regional and Language Options
Let>SK_DELAY=10
Send>Chinese (Hong Kong
Press Enter

This works by sending the first few characters unique to the entry we want to select. Unfortunately not all list boxes work like this. That’s why Macro Scheduler has advanced commands like GetListItem to determine the index of an item given it’s text caption.

Most of us know that we can select menu items using the Alt key. When you press the Alt key you should see certain characters in the menu items and on other objects become underscored. These are the shortcut keys. So to select the file menu in most applications you would press ALT-F. If an application has been designed properly other fields and buttons will have underlined characters also. Even labels associated with objects should have shortcut keys so that when you press ALT and that key you move focus immediately to that object. All this makes automation so much easier.

Other key combinations that are useful include CTRL-TAB to move from page to page or tab to tab in a tabbed window, such as Firefox. Try CTRL-TAB in firefox with several tabs open. You’ll move from one to the next.

Did you know you can select the next word in an editor by pressing CTRL-SHIFT-RIGHT? SHIFT-RIGHT on its own just moves the cursor to the end of the word and then to the next word and so on. Reverse it with SHIFT-LEFT. SHIFT-END will highlight to the end of the line. SHIFT-CTRL-END to go to the end of the document.

This is just the beginning. There are all sorts of keyboard shortcuts that make working in Windows so much faster and make automation so much easier and more reliable. I don’t know them all. But it’s worth getting to know them if you want to get the best out of Windows Automation.

Here are links to some pages that list useful keyboard shortcuts:

List of the keyboard shortcuts that are available in Windows XP
http://support.microsoft.com/default.aspx?scid=kb;en-us;301583

Shortcut keys in Windows 95,98,Me:
http://support.microsoft.com/default.aspx?scid=kb;en-us;q126449

Getting the most out of your Windows Keyboard
http://www.internet4classrooms.com/winkeyboard.htm

January 13, 2006

Why it’s Good to Automate

Filed under: Automation, Scripting — Marcus Tettmar @ 1:21 pm

One of the best ways to learn to use a software product fully is to try to automate it. Testers and automators have to learn the software’s interface really well, possibly better than the people who wrote it. Ok, the developers know the algorithms better than anyone else, but it is the person automating it who knows the ins and outs, pitfalls and quirks of the interface.

We all know how badly designed some Windows programs are. And in these days of fancy hi-res graphics and snazzy toolbar buttons it’s easy for the designers to forget about shortcut keys and keyboard navigation. The most productive way to use a PC is to forget the mouse and learn the keyboard shortcuts. You can get things done much more quickly. Yet even the most experienced Windows users don’t know half the keyboard shortcuts that exist in Windows (tips for keyboard navigation in Windows could be a post for another day).

Knowing these shortcuts makes automation so much easier and more reliable. Automating an application by sending mouse events and mouse clicks is unreliable and depends on the screen resolution never changing. Although you can use relative mouse coordinates, sooner or later something is going to change and the button you want to click is not in the place it was when the script was created.

The automation/test engineer is the one who figures out the keyboard shortcuts and finds the simplest, most reliable way of navigating an application. People who automate applications regularly have a good understanding of the different ways to move around Windows and Windows applications. Automated Software Testing can help find issues in the interface just from the process of building the automated test, even before the test script has been run. Building an automation routine for an application will help you find those missing or duplicated shortcut keys and other objects that can’t be driven by the keyboard.
Automators spend so much time fiddling with the software’s interface that they will often become more knowledgeable than the “power-users”. Testers also have the great advantage of being allowed to try unusual scenarios that developers never think about or are too busy to try. They are allowed to break things!

So it goes both ways. Find out the windows keyboard shortcuts and the hot-keys for the application you’re scripting and you can create a better script. Build an application with good keyboard support and your application can be automated more easily. If it can be automated easily it will be easy to use!

January 11, 2006

Macro Scheduler and the Zebra Fish

Filed under: General — Marcus Tettmar @ 2:25 pm

What has Macro Scheduler got to do with Zebra fish? Well, it seems Macro Scheduler was used to automate some of the experiments written about in this book: The Zebrafish: Cellular and Developmental Biology

Amazing huh? Macro Scheduler has been used for all sorts of incredible things. Unfortunately I’m not always able to get permission to write about them and often I have no idea what people use Macro Scheduler for at all. If you have put Macro Scheduler to some novel uses I’d be thrilled to hear about it. Let me know.

I know that Macro Scheduler is used by Sirius Satellite Radio for automatically inserting audio files into radio broadcasts, and on a similar note the BBC has used it for automatically uploading recently recorded programs onto their website. A well known high street bank in the UK installed Macro Scheduler in their branches to simplify a process for the counter clerks that involved pulling information from one legacy system and typing it into another. Another bank uses Macro Scheduler to automate the production of financial reports every morning. It’s great to know how Macro Scheduler helps so many different kinds of businesses.

I remember learning of a very elaborate experiment at NASA which used Macro Scheduler. Now, Macro Scheduler macros can be made very reliable, but whether or not they went as far as to use Macro Scheduler for the Shuttle’s auto-pilot system I have no idea ….

January 10, 2006

Macro Scheduler Translation

Filed under: Announcements — Marcus Tettmar @ 3:57 pm

We should have a couple of language packs available on the site very soon. Japanese and Norwegian translations are done for the software and we have others in various states of completion. We’re keen to get any help we can, so if anyone would like to volunteer please step up. The help file is perhaps the biggest hurdle but it could be a group project so don’t feel you can’t offer to help just because someone else is already working on your language. The more people the better! We can give translators affiliate commission and a special link in the translated software so that they get credited for sales. Ones we really want to get finished off are Spanish and French versions. Details on how to help can be found at:
http://www.mjtnet.com/usergroup/viewforum.php?f=11

Chained AutoLogon Sequence

Filed under: Scripting — Tags: — Marcus Tettmar @ 3:46 pm

Someone recently asked if we could add a new feauture to AutoLogon that would allow several macros to be scheduled one after the other without logging off in between.  At present AutoLogon works at the macro level.  It logs in, runs the macro and then logs out again.  What if you want to schedule several macros, one after the other, and just log in before the first and log out again after the last?  Well one way you could do that right now is to use the Macro> function.  Create one main macro which calls all the other macros, one after the other, with the macro command.  Then schedule this main macro with AutoLogon enabled.  The macro would look something like:

Macro>%SCRIPT_DIR%\macroA.scp
Macro>%SCRIPT_DIR%\macroB.scp
Macro>%SCRIPT_DIR%\macroC.scp

If you need a delay between each one you can add a Wait> command.

We’ll look at adding more AutoLogon options in future.  Our priority at the moment is getting AutoLogon to work with Windows Vista which uses a different logon mechanism.  We will have AutoLogon working on Vista by the time Vista is officially released.

January 4, 2006

Macro Scheduler 8.0 Released

Filed under: Announcements, Macro Recorder — Tags: — Marcus Tettmar @ 1:53 pm

The eagerly awaited new version of Macro Scheduler, version 8.0, was released this morning. We’ve added some really cool new features which allow macros to be scheduled even when Windows is logged out and automatically log back into Windows (or unlock the workstation) when needed. AutoLogon will automatically log into Windows, run the macro and then log out again. This means macros which require full access to the GUI, network resources, and user-level access rights can be scheduled to run even when Windows has been logged out or locked. We’ve also added new commands to get list box elements and tree nodes and improved existing script functions. The Macro Recorder has been improved, more debug functions have been added and we’ve added Unicode support so that double-byte characters can be sent to other applications … plus lots of other improvements. More info: Macro Scheduler 8.0
Thanks to everyone who helped beta test this major new release!

January 3, 2006

Image Recognition

Filed under: Scripting — Tags: — Marcus Tettmar @ 4:43 pm

When we are automating Windows applications we nearly always need to be able to detect new windows and wait for windows to open and close and be ready etc.  Unfortunately there are times when this is not possible.  Flash applications for example are just exposed as graphics and expose no windowed controls that we can grab a hold of.  Java applets are also a bit tricky as they use internal objects which Windows doesn’t know about.  Another tricky scenario is trying to automate Terminal Server or Citrix sessions at the client level.  The client just gets a graphical representation of the server’s screen.  There is no access to the objects that make up the user interface within the session unless you are on the server itself.  So we used to have to install Macro Scheduler on the server if we wanted to automate applications inside the session.  This is fine if we have access to install stuff on the server.  There are times when we don’t.

Another issue that came up recently was a customer that wanted to test the network lag time between a user entering some data into a Windows Terminal Server client and the server serving up the following page.  The conundrum is that if you install Macro scheduler on the server and make it wait for a new window there is no lag time since all the automation is happening locally to the server.  But on the client there is no way to know about the new window object.  Until now.

Enter the Macro Scheduler Image Recognition Library.   This includes functions that compare images and find images within larger images.  In other words we can compare screens and find objects within screens by searching for their image.   We can find and click on buttons and other controls and wait for the screen or parts of the screen to change based on what they look like.  This lets us automate applications graphically rather than having to know about windows and GUI controls.  In fact this is more analogous to how a user uses a computer.  The user watches the screen for changes in appearance and finds objects by looking at them with his eyes.  He looks at what he sees.  He doesn’t worry about window handles, x and y coordinates.  So the Image Recognition Library means we can automate any application regardless of the technology it uses to expose it’s interface.  It works at the graphical level of the screen.  You can download the Image Recognition Library at http://www.mjtnet.com/imagerecognition.htm

Note: Image Recognition is now native within Macro Scheduler and the separate library is no longer required.