Watir, pronounced water, is an open-source (BSD) library for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.
Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.
A great use for Watir is to automate tedious form filling during development / developer testing. Let’s say you have a simple form like the following to submit a search query to Google:
<form id="search_form" action="http://google.com/search">
<input name="q" value="derekhat" />
<input type="submit" name="submit" />
The Ruby code to submit a form is pretty simply:
The only problem is that this won’t work in this case. The reason: there’s an input field called submit that hides the form’s submit method. The workaround is easy: