Viva la RAutomation

Watir 1.9.0 got recently released. One of the biggest changes in that version, addition to the support for IE9, is a replacement of AutoIt with RAutomation! This means that the next time you’re installing Watir, you will lose all the functionality of AutoIt automatically. If you used it somewhere specifically to do something, then this post will try to help you to make the upgrade process less painful.

The Bad News About AutoIt

Let’s pretend you have something like this in your test:

Statement like this was pretty normal - you could use AutoIt directly from Watir. When you try to do the same with Watir 1.9.0 you will get an error like this:

This happens because there isn’t even anymore any method called autoit in Watir.

Quick & Dirty Fix

There are two ways to fix that problem. You could initialize your own AutoIt object and use that or you could use RAutomation’s AutoIt adapter. You can switch the adapter to AutoIt before loading Watir by setting the environment variable called RAUTOMATION_ADAPTER to “autoit” before loading Watir itself:

Of course this is not a good solution, after all AutoIt was replaced by RAutomation with having best intentions in mind. But it allows now to do something like this:

This makes it possible to use AutoIt’s methods directly through RAutomation’s AutoIt adapter.

Use AutoIt Only Where Really Needed

It would be ideal if you’d just convert all the existing AutoIt code to use RAutomation. Trust me, it would make sense to even you after you’ve changed your code - it’s cleaner, more readable and better in any way. Just refer to RAutomation’s README and this blog post and you’re set to go. If you’re familiar with the syntax of Watir itself then RAutomation’s syntax should be quite easy to follow also since it is inspired by Watir.

If there are still some places where you really-really need to use AutoIt due to some missing feature in RAutomation itself (don’t forget to tell me about it through GitHub issues!) then you can use AutoIt adapter also per RAutomation object and not globally by using environment variable like this:

This makes it possible for you to use AutoIt’s adapter in only places necessary.

Overview Of Upgrading Steps

If you don’t have any custom code using AutoIt then upgrading to Watir 1.9.0 shouldn’t cause you any problems - internally RAutomation is used and you shouldn’t even notice it. But if you have, then i recommend following the steps below to make the upgrade less painful:

  • set RAutomation to use AutoIt globally via environment variable
  • replace usages of Watir.autoit with browser.rautomation
  • replace in small steps your AutoIt code to use RAutomation
  • use :adapter => :autoit option for RAutomation to use AutoIt in very specific places where using RAutomation’s default adapter is impossible
  • remove the environment variable to use RAutomation’s default adapter
  • profit!

Conclusion

I think that using RAutomation instead of AutoIt is a good move. I’ve had that idea for a longer period of time and that’s one of the reasons i created RAutomation in the first place. Thanks to Hugh McGowan for implementing this idea. Viva la RAutomation!