Automated Web Testing with Selenium Pt. 1

Introduction to Selenium

If you are new to web application testing or are working on a project that is moving from an application UI to a web based UI, you may have never heard of Selenium.  You might not even think that you can perform reasonable automated testing against your new web UI.  Perhaps you don’t even know that UI testing can be automated. Gieven the sorry state of affairs from the large test tool vendors I would have to agree, but Selenium presents a whole new chapter in the war on defects.

There are quite a large number of tools and paradigms available which have contributed to failed UI automation efforts that resulted in wasted time and money.  Software vendors still advertise expensive, propreitary testing tools that are sure to solve all of your quality problems and cook dinner for you too.  The big players in the software testing world include HP’s Quick Test Pro and Borland’s SilkTest.  These tools are extremely expensive and promise the world.  But do they really deliver???  Of course, there are many other commercial UI test automation tools out there and they all have good and bad points.  In this series we will be focusing on Selenium and it’s place in the test tool box.

UI Automation has gotten a bad rap, for good reason

Let’s face it, automated testing of user interfaces has been around for a while now and does not have a good reputation.  From vendors who over-promise, over-charge and under-deliver; to well intentioned engineering efforts that go look great in Powerpoint but fail miserably in execution; failed test automation efforts are the road-kill of nearly every long-term software product.

Many experienced engineers and managers have seen enough automation road-kill throughout their careers to stay far away from any automation at the system or user level. On the other side of the spectrum are the new engineers and managers who think that any automation is good automation and will save their product!  Those of us who have lived through failed automation attempts and observed the wreckage of other teams failures have learned to view any automation solution with a bit skepticism and maybe, just a little hope for something better on the next go around.

In this series on automated web application testing, we will be walking through an implementation of Selenium and a number of other technologies that can enable your team to put together a reasonable test automation tool-chain without breaking your budget.

What is Selenium?

If we were talking chemicals, it would be element number 34 on the periodic table.  This element follows Arsenic and precedes Bromine and is used in making glass and various pigments.  Wait, this isn’t chemistry class…

In short, Selenium is a tool for automating functional regression tests of a web application.  Web applications of various complexity can be tested with Selenium.  This means that any website, or more generally, any HTTP 1.0+ compliant server that provides relevant responses to various HTTP requests are within the reach of the Selenium testing tool-chain.

Selenium can execute tests against all of the major browsers including Firefox, Chrome, Safari, Internet Explorer and Opera.  If this is not enough to satiate the most ravenous appetite of a tester, Selenium can also execute tests on any operating system that can run java.  This means Windows, Linux, Mac OSx, iOS (think iPod, iPad, iPhone) and Android.

From a very high level, Selenium has two modes of operation.  Under the original model, known and packaged as Selenium 1.0+, the Selenium tool inserts java-script into the browser which manipulates and checks various aspects of a pages DOM or Document Object Model.  The new model, known and packaged as Selenium 2.0+, utilizes native libraries to access and act upon page elements.

Selenium tests can be created via a user friendly Firefox plugin known as Selenium IDE, or for the more advanced testers and developers, selenium tests can be implemented in a number of programming languages including Java, C#, Ruby, Python, PHP, Perl and Groovy.  Tests created using the IDE can be exported directly into any of the supported languages.  In the case of Java, the IDE can also export directly to JUnit or TestNG unit test classes.

This is a lot of functionality, and we haven’t even touched the surface.  Stay tuned for the next article where we implement a selenium test and export it into several different formats.