Running Watir reliably on a CI machine

I’ve found that Watir generally works well when running under Windows on a Continuous Integration machine (for example, Hudson or TeamCity) but if you use any of the autoit stuff to handle things like security authentication dialogs, it can fail when the machine is locked or not actively logged in.

I’ve found two ways to ensure Watir reliably runs tests without issues.

Run Caffeine to stop the machine locking or screensaver activating

Your Windows sys-admin might not like this one, but caffeine is a tiny executable that’s perfect for ensuring your Windows machine never locks or activates its screensaver, by simulating a keypress every 59 seconds. It’s a matter of installing it and a coffee cup appears in the tray to show you you’re machine is now on caffeine!

Use a command to release any remote desktop sessions to console

Caffeine works well, but if you use remote desktop to control the machine, when you disconnect, the machine will be locked and this will cause problems. What you need tp do is create a batch file, on your desktop say, that releases the RDP connection to console, so it’s ready to run any watir tests. The command you’ll need in the batch file is:

cmd.exe /Q /C "%windir%\System32\tscon.exe 0 /dest:console"

By using the combination of the above items, it’s easy to set up a reliable suite of Watir tests to run on a CI machine that you can easily remote into to see what is running when needed.

One thought on “Running Watir reliably on a CI machine

  1. NOTE: don’t read this post being from a Watir-hater as we still use Watir and find it quite useful for automated regression testing.

    While the above would work, I have found these workarounds to be cumbersome in an enterprise environment where many of these machines are managed by infra teams. Any reboots of these machines ends up breaking the test automation. Anytime, an infra team member has to take the console session, it breaks…

    In our environment, we have unsuccessfully tried to set-up Watir as a self-serve automated testing tool for multiple analysts/developers with a web front-end to initiate test executions but got stuck w/ AutoIT needing interactive session and there being no way to work it out with Watir or another alternative.

    I do wonder how the other (including commercial) tools don’t run into this problem

    It is frustrating that there is no solid solution for this situation.

Comments are closed.