Category archive: watir

June 21, 2006

For the past couple months at work I’ve been using Watir, a Ruby library for controlling Internet Explorer, to automate some of the testing on our site. But the Snap site is a beast, with an enormous amount of Javascript and hundreds of dynamically-modified divs.

Since Watir can bog down while iterating through 100+ div objects, I’m working directly with WIN32OLE objects for certain things.

I’m very new to ruby. And WIN32OLE is weird. I had just been copying code from the watir library and modifying it to suit my needs, but today I had to do some more complicated stuff. In ruby, you can view the available methods of any object by doing this:

puts foo.methods

But if you do that with a WIN32OLE object it doesn’t give you jack. I finally managed to find a ruby-talk post from 3 years ago that shed some light on this. So here’s a method that can pull it off:

class WIN32OLE
  def list_ole_methods
    method_names = ole_methods.collect {|m| m.name}
    puts method_names.sort.uniq
  end
end

So doing:

foo.list_ole_methods

Will give you a long list of method names you can call with your object.

I realize this isn’t, uh, interesting, but hopefully the next tard trying to figure this stuff out will be able to find this post on Google.

And just for the record, Watir fucking rules. It easily outperformed every other automation tool we evaluated (many of which cost tens of thousands of dollars) and, not coincidentally, harnesses the power of an awesome language like Ruby. A lot of the other packages we looked at use strange proprietary languages that aren’t really documented (because then they can talk you into taking a weeklong $8k training course) and can’t pull off half the stuff we’ve already done using Watir.