Automated testing of Magento with Watir

Few months ago I was attending this web conference where among various topic one covered the “Automated testing”. To be honest I never looked into any “automated testing” tools until then. This was the first time I heard about this tool called Watir. Shortly put, Watir (pronounced water), is an open-source (BSD) family of Ruby libraries for automating web browsers.

First thing some of you might notice is that Watir is written in Ruby, and your Magento is written in PHP so how does this relate? Actually it does not. Meaning Watir is not one of those include it in your script then use it tools. Basically it does not interact with your code whatsoever. Consider it as fully independent/separated app that runs desired browser and simulates real user sitting in front of the browser doing all sort of input text filling and form submitting, link clicking etc. Watir also checks results, such as whether expected text appears on the page.

All you need to do is to install Ruby language, then Watir, then… you are done. Watir website has great installation instructions so no need for me to write one here.

The guy whose lecture I listened on that conference is making his living as code tester. So, listening him giving praises to Watir got me thinking. My first impressions are extremely positive.

I myself am not a Ruby developer, as I code PHP most of the time and some Java on a side. However it took me less than hour to write this little Watir test class that when run starts the browser, goes to Magento demo site, goes to cellphones category, adds a cellphone to cart, then does a checkout as a “guest”.


require ‘rubygems’
require ‘watir’
require ‘test/unit’

class Magento_GuestAddToCart < Test::Unit::TestCase def test_GuestAddToCart browser = browser.goto("") browser.goto(""), "").click browser.text_field(:id, "qty").set("3") browser.button(:title, "Add to Cart").click browser.button(:title, "Proceed to Checkout").click, "login:guest").set browser.div(:id, "checkout-step-login").button(:text, "Continue").click browser.text_field(:id, "billing:firstname").set("John") browser.text_field(:id, "billing:lastname").set("Doe") browser.text_field(:id, "billing:company").set("My company name here") browser.text_field(:id, "billing:email").set("") browser.text_field(:id, "billing:street1").set("Sample street name1") browser.text_field(:id, "billing:street2").set("Please ignore this order, developer test") browser.select_list(:id, "billing:region_id").set("California") browser.text_field(:id, "billing:city").set("Alamo") browser.text_field(:id, "billing:postcode").set("94507") browser.select_list(:id, "billing:country_id").set("United States") browser.text_field(:id, "billing:telephone").set("0038531399222") browser.div(:id, "checkout-step-billing").radio(:id, "billing:use_for_shipping_yes").set browser.button(:title, "Continue").click sleep 4, "s_method_flatrate_flatrate").set browser.div(:id, "checkout-step-shipping_method").button(:text, "Continue").click sleep 4, "p_method_checkmo").set browser.div(:id, "checkout-step-payment").button(:text, "Continue").click sleep 4 browser.div(:id, "checkout-step-review").button(:text, "Place Order").click #browser.close end end [/sourcecode] Pretty nice, right?! So my question is, if this is something you can do in 15 min or less (when you get the hang of it), what else can you do? After tonight, I see Watir something as I will most likely be using in my projects from now on. Great thing about Magento is that it has this "specific functionalities" like "Cart page", "Register page", "My account page", "Checkout page" that you can write tests for and then simply run them on your new theme to see if anything got broken, etc. Especially the One Page Checkout with various payment and shipping gateways, etc. Not to mention entire Admin section of Magento when you are building your own custom admin modules. I would strongly encourage everyone interested who hasn't checked it out yet to spare some time and write a test or two.

You made it all the way down here so you must have enjoyed this post! You may also like:

Meet Magento Belarus features an Inchooer talking Magento 2 Checkout Ivona Namjesnik
Ivona Namjesnik, | 0

Meet Magento Belarus features an Inchooer talking Magento 2 Checkout

Tracking Onepage Checkout abandonment using Google Analytics Drazen Karacic-Soljic
, | 70

Tracking Onepage Checkout abandonment using Google Analytics

Magento EE, use reward points in X percent of total (subtotal) checkout value Branko Ajzele
Branko Ajzele, | 2

Magento EE, use reward points in X percent of total (subtotal) checkout value


  1. I used Watir in 2006 to automate all test cases (register, login, sell, review, my account, etc) in a site like ebay and it was very robust.

    I assume that seven years later it will be more usefull than in that time.

  2. Does waitr support test recording as well? and can I use the same testscript on different browsers ?

  3. Hi there Branko. Thanks for the tip!
    Please, Iยดm starting the study with Watir+Ruby on Magento after reading this article.
    I would like to know if the Inchoo team really adopted this software to test Magento features, and if you found any difficult to write automated test with it.
    Thank you so much.

  4. sorry i just read the above comment. im unable to resolve the same issue.

    getting a jssh runtime error with firefox.

  5. Im really so keen to use Watir but im immediately having issues. ive been through the docs quiet thoroughly but im struggling to get it working.

    a pity as i would really like to use it…


  6. Wow… Now, that’s what they have been talking about in Mallorca? ๐Ÿ˜‰

    Anyway, this sounds really great thing to know for the development of larger modules. I’m sure that especially you and your team will find it useful on your type of projects.

    Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.