Nowadays, most software development requires automation. Software solutions are getting more and more intricate in order to allow users to solve complex tasks. Thus, software testing changed its approach as it requires it to be efficient, accurate, and fast.
Keep in mind Watir is definitely not the most used tool while doing automation testing. Taking a look at their git repository, they only had three commits in 2022.
What is Watir?
Watir is an acronym for Web Application Testing in Ruby. It is an open-source testing framework for automating web testing built on Ruby. One of its libraries is connected to Selenium Webdriver, but it has a more user-friendly interface in comparison to Selenium.
Watir has many sub-projects, and the most known are:
- Watir – classic
- Watir WebDriver – provides cross-browser support as its a derivate of Selenium 2.0
Watir can run Windows, Mac, or Linux and supports browsers such as Chrome, Safari, Firefox, Internet Explorer, and Edge. It includes behavior-driven development tools such as RSpec, Cucumber, and Test/Unit, while it also supports data-driven testing.
It is a flexible and simple tool that integrates with almost every tool to help with failure identification and mitigate broken tests.
Features of Watir
- Locate Web Elements
One of Watir’s most essential features is its several ways to locate web elements. The Watir location API is created to be easily read and understood by users.
It has a built-in screenshot capability.
- Page Performance
The Watir Performance gem aims to provide a set of navigation timing metrics for Watir actions using a W3C page performance standard.
- Page Objects
This feature will help you reuse the code in the form of classes. We can automate our app without duplicating any code while also making it manageable.
- Headless Testing
With headless testing, the details are received in the command line without opening the browser.
It is easy to test file download in your UI or website.
It provides an easy-to-use API to test popups alerts in your website or UI.
Advantages of using Watir
- It is a free and open-source tool
- Fast and stable test execution
- Reduced automation testing cost
- Easy to maintain tests
- Can easily support different browsers on diverse platforms
- Supports page object design pattern
- Built-in library for taking screenshots, checking the page performance, and testing alerts
- Can easily integrate cloud testing tools such as SauceLabs, BrowserStack, etc.
- It uses Ruby to write scripts
- It does not support mobile-native applications.
- Only Ruby is supported and cannot be used with other testing frameworks.
- It doesn’t work with desktop applications.
Before diving in, you should be familiar with some software testing fundamentals. First of all, you should know the basics of automation and coding. More specifically, Ruby language, as Watir requires Ruby for scripting.
Environment set-up for Windows.
In order to perform cross-browser testing using Watir, you need to install the following:
- Ruby Mine (IDE).
The RubyInstaller is a must because Watir supports Ruby; therefore, this step is essential. In order to run a Ruby code, you need a Ruby interpreter. For Windows, installing the interpreter is more straightforward than for Mac and Linux.
Installing Watir is a very simple step. In order to install Watir, you have to install Ruby.
The RubyMine is an integrated development environment (IDE) that allows you to write, debug and test your application’s code.
Installing the drivers can be done two ways, manually or automatically.
First of all, a driver has to be present on the same machine as the browser you are automating. Watir recommends using the webdrivers gem to automatically ensure that the latest driver is downloaded and placed in a location where Selenium can access it.
If you want to set the drivers manually, you can download the drivers here. All browsers, except Safari, require you to add a path from your driver to the PATH Environment Variable.
If you want to avoid all this hassle, you can use a service provider such as BrowserStack or SauceLabs.
Once you have installed everything, you can hop on start a session.
As a bonus, if you want to use Watir with Python, you can take a look at Nerodia.