July 25, 2007

Watir Alternatives

An old-time Watir user has been using many of the Watir alternatives and reports on what he thinks of them.

I did a bit of work with WatiJ for a client a year ago, and I witnessed two .NET attempts at a Watir-like tool fail. WatiN is probably the only one left that I know of, but the syntax was pretty awful last time I checked. If I’m ever in a .NET-only shop again, I’ll probably try it out again. WatiJ is pretty good, but can suffer from memory leaks, and doesn’t have the maturity and support that Watir has, and hasn’t had much in the way of contributions. Watir far and away has the most support for HTML objects, has great syntax, and a great community. Now that Rails is becoming so popular, it is easier to introduce, and more programmers want to work with it. Using the same language as the programmers might be a bit less important now since a lot have seemed to have dabbled with Ruby or Rails.

I found WatiN to be a bit unreliable with page loads and the syntax is grating to me. (All those CamelCase capitals look like VB, and the methods lack the sophistication and ease of use Watir has.) I also found the WatiN community to be less friendly than Watir or WatiJ.

The WatiJ guys are really good, but the main programmers haven’t been able to contribute that much for quite some time. They have changed COM libraries (the source of the leaks) to one donated by a company which is better, but it still has the odd memory leak problem. The company that donated the library are working on fixing the memory leaks, and it is improving, but when they do appear, they can be nasty with larger scale automation efforts. I would probably only use WatiJ for tests on a smaller scale until this is addressed. The main developers have been really supportive and easy to work with, so I imagine they will get this sorted out eventually. I really like them - they are talented, supportive, easy to deal with, and get it. Even if I do something with testing needs that they don’t understand or agree with, they are supportive and helpful.
Posted by bret at 03:26 PM | Comments (0)

July 24, 2007

Learn Ruby

Many users new to Watir don’t realize that learning Watir really means learning Ruby. Maybe half of the questions we get on the Watir General list really amount to Ruby questions. This post recommends resources for learning Ruby.

Anyone wanting to learn Ruby really needs to take a look at Why’s Poignant Guide to Ruby (available online, in pdf or as a book). There is nothing like it in any language. It doesn’t assume you know programming and truly teaches you how to think in Ruby. Some people have called Ruby a poetic language. This is a poetic language manual. I gain a greater appreciation for how to think in Ruby every time I read it.

Why (yes, “Why” really is his name) also has created a Ruby programming tutorial and toolkit called Hackety Hack. It is a direct, patient tutorial, without much of the manic ideaphoria found in the Poignant Guide.

The Pickaxe Book is the standard Ruby reference. It includes a tutorial suitable for programmers who understand modern programming concepts such as exceptions, classes and regular expressions. And it has a reference section suitable for everyone. The first edition of this book is installed with the Ruby Windows Installer (Ruby → Ruby Documentation → RubyBook Help) and is also available online. If you like it, invest in getting the second edition, which has been updated to cover Ruby 1.8

Resources for Testers

If you understand the basics of programming, but are not familiar with these modern programming concepts—or simply prefer concrete explanations—then the resources in this section are for you.

Brian Marick and I wrote up a Ruby Cheat Sheet, a short description of basic Ruby commands for our one-day tutorial. Testers may find this a good place to start.

In Everyday Scripting with Ruby, Marick teaches the Ruby language by working through a series of practical scripts. These scripts accomplish everyday tasks that every tester can relate to: comparing file lists, monitoring code changes, scraping web pages, and using a notification framework. The book covers not only the Ruby language, including an excellent chapter on regular expressions, but also provides detailed advice on how to develop reusable libraries, something that Watir users are always asking for help with. If you are a serious Watir user, don’t hesitate to get this book.

Another practical Ruby book with concrete examples is the Ruby Cookbook by Carlson and Richardson. This is not an introduction to Ruby, but it is accessible to someone who has learned the basics. It consists of a series of examples, mostly about two pages long including both code and discussion. Its table of contents is organized by solution—so regular expressions are explained in section titled, “Getting the Parts of the String You Want.” Thus it is eminently browsable, allowing you to easily find the pages you need right now.

Other Ruby tutorials recommended by Watir users are:

Resources for Programmers

These resources are suitable for suitable for those of you who are already familiar with modern language concepts.

Thomas and Hunt wrote an article for Dr. Dobbs to introduce Ruby to the English-speaking world is the best short introduction to Ruby for programmers. It concludes with a demonstration of how to write a web server in Ruby. This article is the seed that eventually grew in to the Pickaxe Book, which, as mentioned above includes a good tutorial on Ruby.

The Ruby Way, by Hal Fulton, is a solid language manual. It has more breadth than the Pickaxe Book, covering more libraries and advanced topics. It also provides more detailed, accurate descriptions of language basics, like exactly how the “case” statement works. I’m still working my through it: it is deepening my knowledge of Ruby.

Posted by bret at 04:51 PM | Comments (2)

July 22, 2007

New Watir Website, Mailing List and Rspec Demo

We now have a new improved Watir website. This website includes up-to-date information on how to install the latest version of Watir and where to find our code repository, project wiki and other useful stuff. We are using several sites to host various aspects of the Watir project, which has caused some confusion. This website should now clear this up. We’ll be keeping it up to date going forward.

We’ve also recently moved the Watir General mailing list to Google Groups. We had trouble with the gateway connecting the old Rubyforge mailing list to the OpenQA forum and have therefore decided to move the whole thing over to Google Groups. We will be closing the old list and forum down shortly.

On Tuesday, I gave a presentation on Watir to the Austin on Rails user group. I’ve been using parts of Rspec for nearly a year and have recently decided that it’s time use all of it and stop using Test::Unit. I’m moving all my projects to use Rspec. Of course, I used it in Tuesday’s demo as well. Here’s the demo code from the presentation. It works with the Depot demo app (zip) from the Agile Rails book.

require 'watir' # requires 1.5.1.1202 or later

describe 'cart' do

  before(:all) do
    @browser = Watir::IE.find(:title, 'Pragprog Books Online Store') ||
      Watir::IE.new
  end

  before(:each) do
    @browser.goto 'http://localhost:3000/store/empty_cart'
    @browser.goto 'http://localhost:3000/store'
  end

  it 'should be empty' do
    @browser.link(:text, 'Show my cart').click
    @browser.div(:id, 'notice').text.should == 'Your cart is currently empty'
  end
  
  it 'should contain one book when added to cart' do
    title = @browser.h3(:text, 'Pragmatic Version Control') 
    catalog_entry = title.parent
    catalog_entry.link(:class, 'addtocart').click

    @browser.div(:id, 'banner').text.should == 'Your Pragmatic Cartx'
    @browser.cell(:id, 'totalcell').text.should == '$29.95'
  end
end
Posted by bret at 10:31 PM | Comments (0)