Saturday, 17 June 2006

But why use AutoIt?

There are many reasons why I am writing about AutoIt and not Perl or Ruby as a mechanism for free GUI test automation on windows. Here I have listed just 5 of them, and I know that some people are going to look at the list and think that what I am touting as a good reason is a bad one for them...



Because AutoIt...

  • is well documented

  • does not require an install so I can carry it around on a usb stick

  • has a good and standard editor/IDE

  • scripts can easily be converted to .exe

  • looks and feels like basic


AutoIt is well documented

AutoIt is supplied with good documentation, in the form of a .chm file and online. There are also a lot of examples provided with the install. This makes it very easy to learn and have a good source of easy to find examples to copy. The main AutoIt website has easily accessible forums and links to plenty of 3rd party tutorials to help get you up to speed

Works from a USB stick

This means that when I install it on my system I know that I'm not going to mess up my machine installation. It also means that I have an automation platform with me wherever I go. How handy is that?

Has a good and standard editor/IDE

I do not want to count the amount of time I have spent looking for a decent portable perl IDE, or ruby IDE or C++ IDE. AutoIt picked SciTe and then configured it to act as an easy to use, code folding highlighting, code completing IDE. The tools menu when editing an au3 file makes AutoIt much much easier than it used to be.

scripts can easily be converted to .exe

This makes it a great toolsmithing platform. I can use my automation functions to create small simple utilities for automating parts of the testers job . And since AutoIt has a whole series of GUI functions I can parcel them up with a simple GUI to make life easier. I will upload a logging tool written in AutoIt later, but you can take a look at applications other people have written in AutoIt

Looks and feels like basic

Yeah I know, for most people this is not a plus point, but I have done so much basic coding in the past that I find it very easy. And I do know that this makes AutoIt very easy to pass over to people who have not got much coding experience. It also means that I do not have to worry about forgetting syntax and nuances when I have gaps between my AutoIt usage. Every time I try to use Perl GUITest I have to relearn Perl, and I know it will be good for me to get a better grasp of Perl, but sometimes I just grab the nearest thing that will work and get on with the job.

For quick and easy automation with a small learning curve and the ability to create lasting solutions - AutoIt is very useful.

Tuesday, 13 June 2006

Simple Monkey Tester Annotated

I'm annotating the mokey tester code that I posted yesterday with even more comments for those people that are new to AutoIt and perhaps didn't understand what the code was doing.



The monkey tester code explained.

A comment in AutoIT starts with a semi colon and runs to the end of a line. You can also comment a block of code by using the #comments-start and #comments-end directives.

; monkey tester
; This monkey tester just randomly
; clicks on the window of the calculator


Now we create a few variables for the script . Variables are of type Variant so they can hold any value and they do not have to be declared before use. $parentWindowName is the text that will be searched for in the window name. i.e. when you start up Calculator then the Title of the window is "Calculator". If you start Notepad then the title of the window is "Untitled - Notepad".

; the title of the window
$parentWindowName="Calculator"
; the name of the application to run
$programRunName="calc"

Run is an AutoIt command to 'run' an application. Normally you would have to put the full path of the application in the argument e.g. "c:\apps\myapp.exe" but some applications like "calc" and "notepad" can be run directly.

; run the application
run($programRunName)

WinWaitActive is a command that you will probably end up using a lot in your scripts. It basically does what it says and pauses the script (waits) until a window is active. It tells if the window is active by looking for the value of $parentWindowName in the window title. The function WinWaitActive will return 0 if the window could not be found within the timeout period (in seconds, in this case defined as 3).

; wait until the window is showing, time out in 3 secs
WinWaitActive($parentWindowName,"",3)

This is the only really complicated part of the script. I get the Handle of the window using the window title. The Handle is the id that Windows recognises the window with and I'm using it because WinActive can be quite slow to find the window by using the title as it has to cycle around all the windows in the system matching the text. But by using the handle later on, all it has to match is the id and it can find this pretty quickly.

; get the handle of the window
$mainHwnd=WinGetHandle($parentWindowName)

We create a for loop to decide how long to monkey around for. AutoIt has several loop constructs: For...Next , While...WEnd, Do...Until

; monkey around 100 times
for$x=1to100

I use the WinGetHandle function here to check if the same window is still present as another window with the same title may have appeared and we may have accidentally switched to it. Synchronisation is a key part of automated testing when using tools like AutoIt and much of your automation code is going to be code to check if the preconditions for the action you are about to do are still true, and if not then either stop the script or do somthing to make them true. In the case of this script we are just going to stop if we cannot find the window we started with. AutoIt has a lot of GUI commands for interacting with the user but here we are using a simple MessageBox dialog by using the MsgBox function.

; check if the window is still available and if so activate it
ifWinGetHandle($parentWindowName)<>$mainHwndThen
; we lost the app
MsgBox(1,"App Gone","App is lost")
Exit
Else

winActivate($mainHwnd)
EndIf

The WinGetPos function returns an array. the array returned has 4 entries and is numbered starting at 0 so $array[0]-->

; get the position of the window
; - do it each time in the loop
; just in case it moved, or changed size

$pos=WinGetPos($mainHwnd)

So now we are going to generate 2 random numbers, one for the x value so between the x and x+width values. And one for the y value which is between y and y+height. This should give us a position inside the window.

; choose an x y value in the window
; (it might hit the close button)

$rndX=random($pos[0],$pos[0]+$pos[2])
$rndY=random($pos[1],$pos[1]+$pos[3])

We take the random values that we generated , move the mouse to the position and issue a "left" click of the mouse.

; move to the position and click it
mousemove($rndX,$rndY,0)
mouseclick("left")

Then we loop back around until we have done 100 monkey actions.

next

Now that was overly explained for the short example but since it is the first script I've shown you I thought it best to go through it in some detail.

The AutoIt help file is actually pretty good and if you look up each of the commands in the help file then you will learn a lot more than I have written up here.

The AutoIt language is pretty close to a dialect of basic which should make it pretty simple for anyone to pick up. One of the hardest things, as your scripts get larger are the lack of data structures for variables. You can get around that by using AutoIt in its dll form and using your favourite progamming language instead of AutoIt. But there are reasons why I like the AutoIt language itself and...I'll cover those later.

Monday, 12 June 2006

How to write a simple Monkey Tester in AutoIt

AutoIt is a simple windows automation language, and in this short code snippet I will give you the code for a very simple Monkey tester.



I'm tempted to talk a little bit about what AutoIt is, and what it does, but I'll save that for a later post. Right now I just want to dive into the action and show you a simple script that does a little monkey testing.
In this example we are using the built in Calculator for windows and all we are doing is randomly clicking on the application. It seems unlikely that this will expose any errors in Calculator but this code is here to demonstrate the principle and show how simple it all is.
In order to use the code you are going to have to go off to the AutoIt web site and download AutoIt v3 and I also recommend that you download the SciTE AutoIt Editor
  • Install the applications,
  • run SciTE,
  • paste the code below into the editor,
  • press F5 to run the code,
  • watch the monkey tester go to work.
See what you can learn from the code itself and by reading the AutoIt help files. It is extensively commented for such a little application.

; monkey tester

; This monkey tester just randomly
; clicks on the window of the calculator

; the title of the window
$parentWindowName = "Calculator"   
; the name of the application to run

$programRunName = "calc"   

; run the application
run($programRunName)   


; wait until the window is showing, time out in 3 secs
WinWaitActive($parentWindowName,"",3)   

; get the handle of the window
$mainHwnd = WinGetHandle($parentWindowName) 


; monkey around 100 times
for $x=1 to 100
       

    ; check if the window is still available and if so activate it
    if WinGetHandle($parentWindowName) <> $mainHwnd Then
        ; we lost the app

        MsgBox(1,"App Gone","App is lost")
        Exit

    Else
        winActivate ($mainHwnd)
    EndIf

   
    ; get the position of the window
    ; - do it each time in the loop
    ; just in case it moved, or changed size
    $pos = WinGetPos($mainHwnd)


    ; choose an x y value in the window
    ;   (it might hit the close button)
    $rndX = random($pos[0],$pos[0]+$pos[2])

    $rndY = random($pos[1],$pos[1]+$pos[3])

   
    ; move to the position and click it
    mousemove ($rndX,$rndY,0)

    mouseclick("left")
   
next

Saturday, 10 June 2006

If you install too much stuff then...

...these tools might help you out: Safarp,Startup Delayer, ShellExView



It may be obvious from the rest of the website that I install and try out a lot of different software. And yes... sometimes it doesn't work right, and I don't always install it under a virtual machine first, and my machine can get in a bit of a mess.

So there are a few tools that I use which have helped me get out of trouble in the past

Safarp is a simple little replacement for the add/remove control panel. The main benefit for me is that Safarp loads fast. In fact it loads faster than the time it takes me to even find the add/remove control panels applet. When I was having problems on one machine, Safarp was able to load the list of installed applications when the add/remove control panel applet was crashing every time I ran it. Safarp runs happily from a USB stick and so I carry it with me everywhere for those emergency uninstall moments.

Startup Delayer steps in when my machine is so clogged that I have to sit back and wait 5 minutes after boot up to get started - I guess I could uninstall stuff and figure out a way of setting up profiles so that only the apps I need are going to be running. Or I could just use R2's Startup Delayer to load the applications in the background in a time order that doesn't get in my way. I use Startup Delayer.

ShellExView helps when I have installed applications that use the context menu but don't play nice. When windows gives errors periodically after using the context menu, that often means that one of the context menu applications isn't working properly. By using ShellExView I can disable the various applications in the context menu until I work out which one is causing the problem. The good thing about being a tester is that I can, more often than not, make the periodic problems predictable and repeatable. The investigative skills I've learned when raising defects are a boon here. And that means that when I disable an application I know exactly what to do to check if the problem has gone away. ShellExView has been indispensable to me in the past, and it runs happily from a USB stick.

All of the above applications are free, so give them a try

Tuesday, 6 June 2006

Yorkspace tools list

Yorkspace.com has a small list of essential tools. I use many of these, and a few alternatives...



From the Yorkspace.com list have not used the torrent, podcast or mp3 tools, neither have I used Thunderbird.

I certainly recommend AutoIt, particularly with the SciTE4AutoIt editor. And I use VLC media player, as my default DVD viewing application.

I use the listed 7-zip and I use an alternative called PicoZip.

There are a couple of tools where I do not use the one listed, but I use something very similar and these alternatives are listed below.

I use Uniform Server instead of WAMPSERVER, but the two installs seem very similar. Take your pick and see which works best for you.

I use WinMerge and BeyondCompare instead of ExamDiff.

The Yorkspace.com list seems pretty good and if you don't have all the software listed, give some of them a try.

Sunday, 4 June 2006

Utils for a minor edge

A few useful utilities:


Switch Window provides a handy little popup window that lists all current windows and you can easily switch between them. I tend to use the [Start] context menu to trigger it.

Microsoft XP PowerToys has a few tools that I use regularly, I'm just going to draw your attention to 2 of them below

I have the Alt-Tab Replacement installed so that when I do use alt+tab, I get a thumbnail of the open window, which helps me identify exactly which window I'm looking for. This is also a great tool for testing people's powers of observation and seeing if they notice that your alt+tab is slightly more informative than theirs.

Command Prompt Here provides an extra context menu entry to open a command prompt set to the directory that you right clicked from in Explorer.

These tools give me a minor edge when I'm navigating Windows during the testing of Windows applications.

Wednesday, 26 April 2006

Can the words that we use affect our thinking

Can the words that we use affect our train of thought?

How do the different words we use to describe a system, change the way that we think about that system? Can we describe the Application Under Test differently and change the way that we think about it?



One exercise I tried recently was to think of different words to describe the software that I was testing and to see how that affected my thinking about that software.

I found that I was able to take different views of the software when I applied a different description. And different views allowed me to quickly identify different aspects of the software to test.

This was different from a heuristic approach as I was inferring, from the description, aspects of the software which I could then use to trigger thoughts about testing. It seems to me that this is one way to identify heuristics from first principles.

Example words I used : Application, System, Software, Solution, [Name], [Name Version X]

  • Try the words out for yourself and see what happens.

  • Identify more descriptive words and phrases for the software and see what happens

A classic piece of humorous writing on the use of words and language can be found in 'Through the Looking Glass', by Lewis Carroll. I find chapter 6, with Humpty Dumpty, to be particularly entertaining. There are plenty of editions online and I've linked to just one, purely arbitrarily, at literature.org [1]



`My name is Alice, but --'

`It's a stupid name enough!' Humpty Dumpty interrupted impatiently. `What does it mean?'

`Must a name mean something?' Alice asked doubtfully.

`Of course it must,' Humpty Dumpty said with a short laugh: `my name means the shape I am -- and a good handsome shape it is, too. With a name like yours, you might be any shape, almost.'

Through the Looking Glass, by Lewis Carroll, CHAPTER VI, HUMPTY DUMPTY [1]



'I'm Testing ...'Below are notes on what some of the descriptive words that I use to describe systems do for me. They may do a very different thing for you. And I guess that is to be expected, words are ambiguous.When I say that I'm Testing [Insert Name of Software Here], that may not mean very much. It may not mean much to other people if they don't know the name, and it certainly doesn't expose the level of knowledge that I have about the system. What it can do for me is get me thinking in terms of the superficialities, of the first things that come to mind:

  • the adverts,

  • the basic feature set,

  • what general kind of things need to be tested

  • basic requirements

If I extensionalise the name and give it some extra meta-tag information (in this case the version number): I'm testing [Name of Software] version A.B. Then I start to think about:

  • changes in this version,

  • what needs to be tested specifically in this version?

  • what the requirements were for this version?

  • have all the necessary changes been made?

  • Delivery dates and timescales.

When I call the Application a 'System' I start to think about

  • an integration of parts,

  • interfaces,

  • data syntax,

  • flow through the system

When I call the Application 'Software' I start to think of it as a thing:

  • which runs on an operating system (what versions),

  • interfaces with hardware (disk),

  • data semantics

  • common elements to software (instruction manual, box, help file,
    install routine).

When I call the Application a 'Solution', I think:

  • for whom?

  • for what problem?

And when I say 'Application' I'm thinking:

  • apply it to what?

  • Use it for what?

  • How can I apply it?

  • What functionality does it have?



`But "glory" doesn't mean "a nice knock-down argument",' Alice objected.

`When I use a word,' Humpty Dumpty said, in rather a scornful tone, `it means just what I choose it to mean -- neither more nor less.'

`The question is,' said Alice, `whether you can make words mean so many different things.'

`The question is,' said Humpty Dumpty, `which is to be master -- that's all.'

Alice was too much puzzled to say anything; so after a minute Humpty Dumpty began again. `They've a temper, some of them -- particularly verbs: they're the proudest -- adjectives you can do anything with, but not verbs -- however, I can manage the whole lot of them! Impenetrability! That's what I say!'

Through the Looking Glass, by Lewis Carroll, CHAPTER VI, HUMPTY DUMPTY[1]



No Answers, Just ExercisesAs an exercise for the reader... Now, what happens when you add some positive and negative phrases about the software to your descriptions?

  • Festering pile of bad code: are you positively motivated to test it yet?

  • Fantastic piece of software with just a few minor flaws: are you working hard to stress the software yet?

Answer the following questions and see what happens.

  • Can the state that you approach the thinking about software change the way that you think about the testing of it? I think that it can.

  • What words are you using to describe software?

  • What states are you in when you use those words?

  • How linked are the states and the words?

Enjoy.

References:

  •  [1] Through the Looking Glass, by Lewis Carroll, CHAPTER VI, HUMPTY DUMPTY @literature.org, [http://www.literature.org/authors/carroll-lewis/through-the-looking-glass/chapter-06.html]

  • [2] I summarised this blog post in a diagram called Descriptive Words and Software Testing

How to cope without MS Project

MS Project is the project schedule tool that I encounter more on site than any other tool, and the one that I personally prefer to use on sites.
But sometimes things don't go as planned and I recently found myself without MS Project on a site with many MS Project Plans.
Sadly Microsoft do not provide a viewer for MS Project files so I hastily tried to find a tool to help me view the plans.



Viewing:
I looked at a few but none were suitable, and then I found Afinion Project Viewer. The free viewer was adequate for my purpose, but at only 46 USD the full version seems reasonably priced, there is a lite version available for only 16 USD.
The free version allowed me to open .mpp files, and view the project plans in an outline with the associated gantt diagram on the right.
The Afinion website could be clearer in listing the differences between the versions but the free edition is a simple viewer without printing. (see the end of this article for a list of differences between versions).
So with Afinion viewer installed I can now comment on the plans.
Creation:
But I also had to create my own plan and I don't actually like doing that in a spreadsheet so I needed a free project planning tool that would give me the flexibility of moving back to project later, or of working with the files directly.
I've actually been looking for an excuse to try the opensource ganttProject in a production environment. 2 versions are available, both version 1.11.1 and 2.0-pre1 use the same file format.
2.0 looks much better and has a much better GUI, but still has bugs in the GUI that caused some hassles when creating milestones, and didn't have the full complement of exports that 1.11.1 has, so 1.11.1 should still be the version of choice used in prodution. But 2.0 is more comfortable for viewing your projects and is certainly worth watching to see how much more it improves.
v 1.11.1 has a handy export to mpx to allow me to move back to MS Project and the html export is very effective for sharing plans.
Because xml and xsl are used for the exports you can even plug in your own exports, but I didn't try that, the defaults served me perfectly well.
In summary:
Neither tool requires an install and I will add both to my System Tools folder and memory stick. Both run on Java, so with a local JRE installed in the tools folder I can avoid conflicts on any borrowed machine.
In an emergency I will happily turn to these tools again, and for simple plans GanntProject is perfectly adequate.
And the links again: ganttProject , Afinion Project Viewer

Afinion features between versions
Free
  • displays plans from MS Project (Project 2000, 2002, 2003)
  • No Install required - only copying the files into a folder.
  • Windows, Mac OSX, Linux, Solaris and Unix.
  • view the tasks in a daily, weekly, monthly, quarterly base.
In addition Lite:
  • .mpp versions (Project 2000, 2002 and 2003) simultaneously.
  • Printing
  • enable connections in the Gantt chart to get a clearly arranged view.
  • also available as server version.
  • language independent. Standard languages are English, Italian and German. Other languages on demand.
In addition full:
  • also displays plans from MS Project (version 98, Project Server).
  • displays also plans from SAP PS (network plans, wbs elements, tasks).
  • store all activities which are assigned to a resource directly into the Outlook task folder of the resource.
  • supports all currently MS Project versions in a database and as mpp file simultaneously. Thus you can support all sort of plans (old and new ones) with one version of Afinion Project-Viewer
  • can use the common databases (SQL-Server and MS Access Project Server)
  • shows different views used by the project manager.
  • has different filters and a standard view which the user can customise corresponding to their needs.
  • shows all activities of an employee over all projects in a database. So the employee can see immediately, where they are assigned to.

3 Useful Questions, GS

What do you mean? How do you know? What then? from driveyourselfsane.com

Articles on General Semantics from the European Society for General Semantics.