Debugging With IRB

Debugging Watir WebDriver Automated Testing Scripts Using IRB

Debugging your automated testing scripts is probably one of the single most time consuming and resource intensive aspects of building & maintaining automation. As analysts embark on building out a suite of automated tests, it is imperative to have a well defined tool set and process for debugging their scripts especially in situations where the standard api usage doesn’t yield the desired results. Debugging also helps in enhancing the stability, reliability and consistency of the automated tests.

As part of our solution and delivery, we actively use (and promote the usage of) IRB to debug Ruby & Cucumber Automated Testing Scripts. IRB is an Interactive Ruby Shell. The program is launched from command line and allows the execution of Ruby commands with immediate response, experimenting in real-time. It features command history, line editing capabilities, and job control. It is able to communicate directly as a shell script over the Internet and interact with a live server. More information about IRB can be found at

Below are the simple steps to initiate an IRB session and launch a browser using standard Watir Webdriver commands in your command prompt in Windows (Terminal in OS X):

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'watir-webdriver'
=> true
=> #

At this point, a blank Firefox browser is launched.


The BIG advantage of using this process for debugging is that you don’t need the script to execute the x steps in order to get to the specific Test Step that you want to debug. The analyst can now manually navigate to the desired page and then execute specific Watir WebDriver commands in the IRB session and see the result directly in the browser that was launched when you executed the command earlier.

For this post, we will use the Zoho CRM application to highlight the IRB usage.

We will perform the below steps manually before getting to the specific step we want to debug:

• Click on the Sign In link and type in your id and password
• Hit Sign In and you are brought to the Home screen

While this seems like Automation 101 type of interaction, it is a little tricky since the text fields are housed within an iFrame which requires some special handling.

Screen Shot 2014-04-20 at 3.02.25 AM

As you can see from the above screenshot, this looks like a simple interaction where there are multiple identifiers defined for the input boxes – e.g.

browser.text_field(:id,'lid').set("sreya @ 3Qi Labs")

Unfortunately this returns an error that reads something like:

Watir::Exception::UnknownObjectException: unable to locate element, using {:type=>"(any text type)", :tag_name=>"input or textarea", :id=>"lid"}
from /Users/3qimbp2/awetest/gems/ruby/1.8/ruby/1.8/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:490:in `assert_exists'
from /Users/3qimbp2/awetest/gems/ruby/1.8/ruby/1.8/gems/watir-webdriver-0.6.4/lib/watir-webdriver/user_editable.rb:11:in `set'
from (irb):44

We try using some of the other DOM identifiers to try and validate its presence using Watir Webdriver:

>> browser.text_field(:class,"input usrbx").exists?
=> false

Upon further review, we identify the login section is being called in an iFrame

Screen Shot 2014-04-20 at 3.21.39 AM

Here’s where the debugging comes into play. We use the IRB session to execute a series of Watir WebDriver commands to identify the element and ultimately interact with it. Here’s what it boils down to:

Screen Shot 2014-04-20 at 3.26.49 AM

1. Can we validate the existence of the iFrame using Watir Webdriver:

>> browser.frame(:id,"zohoiam").exists?
=> true

2. Validate the specific input field (user id) iFrame:

>> browser.frame(:id,"zohoiam").text_field(:id,'lid').exists?
=> true

3. Interact with the specific element (to input data in this case)

>> browser.frame(:id,"zohoiam").text_field(:id,'lid').set("Sreya @ 3Qi Labs")
=> ""

VOILA! It worked!

Screen Shot 2014-04-20 at 3.27.03 AM

So here’s a good way to quickly interact with the application using the core Watir Webdriver API.  It helps by eliminating the need to execute the entire script in order to validate a specific change and allows you to inject modifications to your automated testing scripts with a high degree of confidence. We are also avid supporters of debugging with Pry, and you can get an overview of how to do this here:

A good resource to get the most commonly used methods in Watir-Webdriver is and you can always refer to for the latest updates and a comprehensive list of all commands broken out by the various categories

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk