The Issue 

Validating that an image works is just as important as validating text or a link; having something wrong in your UI is the most immediately noticeable error from a user standpoint. However, we can easily add image validation into our test automation. There are a variety of Watir Webdriver and Selenium commands that let us verify various image properties.

The Answer

These Watir Webdriver commands provide a variety of interaction for validating images, which can be utilized in a multitude of ways depending on your test cases.

The Code

Lets use these commands to take a look at an image on the 3Qi Labs website:

The Result

We can save the file (imageinfo.rb) and run it from the command line, with the following result:

  • Browser opens
  • Browser navigates to the 3Qi Labs homepage
  • Validates if image has loaded
  • Validates image width
  • Validates image height

The Takeaway

As you can see, there are a multitude of ways to validate an image using Watir Webdriver. Ensuring your size dimensions are consistent with expected results is key to validating the UI of your site; even one incorrectly formatted image can throw off the design of an entire page.