Selenium – Red Badgers use of the Open Source Web Testing Tool not the Chemical Element!

Selenium – Red Badgers use of the Open Source Web Testing Tool not the Chemical Element!


All software development companies have a requirement to continually ensure the quality of their product, this becomes more difficult as a product grows and the need for changes to the system evolve. Changes including; functional improvements, code patches or system configuration changes. This area of quality control is commonly maintained by the Test Team (QA Team) in the form of Regression Testing.

To complete the continuous task of regression testing of our functional deliverables, we here at Red Badger are avid fans of Selenium, the web application test tool. Selenium is an open source set of tools that allow a wide range of users, from the novice to the seasoned user to create automated test scripts. Selenium has grown over the years to form a huge international user base, which in turn has spawned a huge source of obtainable knowledge online and also in printed word form.

Selenium IDE code format selectionThe set of tools provided by Selenium include: Selenium IDE – Implemented as Firefox add-on, Selenium IDE allows the user to record each step as they manually navigate around a website, and then replay the actions, thus creating an automated script. More commonly used by beginners to Selenium as little or no coding experience is necessary to get started. The scripts are recorded in HTML and then using one of the best attributes of the tool, the user can select which software language to output the script. However, I would not recommend this method when designing test suites which may have any number of conceivable test cases - as the strength of a well designed framework and test suite requires a more manageable and configurable solution.

Selenium Server is the solution! Selenium Server has many names; Selenium Remote Control (RC) (also known as Selenium 1.0), Selenium 2.0 and Selenium WebDriver. Don’t be put off by the different naming conventions seen throughout the web. I’m not going to discuss where these different names have come from as I would rather tell you about the power of the component!

Selenium Server Overview DiagramAs can be seen in this diagram Selenium Server sits between the test scripts and the specified browsers. It automatically launches and kills browsers and acts as a HTTP proxy for web requests. In addition Selenium Server contains a magnitude of client libraries to support your favourite programming languages including; C#, Java, Perl, PHP, Python and Ruby.

At Red Badger we have a close relationship between the Development and Test teams, and hence chose to script the Selenium framework and test scripts in the same language that the development team are proficient in using; therefore C# forms the foundation of our robust NUnit framework using Microsoft Visual Studio as our dedicated IDE.

MS Visual Studio C Sharp FrameworkTo configure Visual Studio to use NUnit and Selenium client libraries the user must ‘Add Reference’ to the project solution. This is very simply done by pointing VS towards the .dll files of NUnit and Selenium.

Selenium Standalone Server is then initialised to interact with NUnit and the specified browser. Selenium Standalone Server is written in Java so Java must be installed on every machine that you wish to run the test scripts on.

Simply start Selenium Standalone Server with the following command in CMD:

C:\selenium>java -jar selenium-server-standalone-2.6.0.jar

Selenium Standalone Server

The Selenium official website documentation is impressively detailed and gives a great overview on each component and its abilities. The download section has all the latest stable releases and for each of the components out lined above and used daily here in Red Badgers automation framework. I would recommend keeping your Selenium Standalone Server and Selenium Client Server on the same version and updated regularly as the community works hard to improve this excellent tool set all the time.

Lessons Learned!

Shooting a moving target is never easy!

Writing automation scripts to test an ever changing data set always requires some serious thought and planning. As you will have learned by now, Xpaths are used to pin point elements within the website in order for Selenium to carry out the test actions. Building strong and efficient Xpaths are key to ensuring that your test scripts have a long lasting life, and in turn will reduce rework required overall on your test suite.

Firebug is an excellent Firfox add-on that lets you view the HTML of any element on your web page, these Xpaths may then be viewed and edited using a Firefox add-on called Xpath Checker.

Efficient Xpaths

In the above example we are selecting menus, they contain sub-menus and the sub-menu checkboxes. The titles of these menus constantly change depending on the users original query search. The solution was to design with specific Xpaths where we can pass in multiple variables to select an element. The variables passed are numerical and therefore select the menu etc. based on its location rather than its title!

Unique registered users for every run!

When testing a website that requires users to register and login to access additional content, we need to think about how these users will be unique every single time we run the same test script! The solution to this will depend on the structure of the database architecture and the method used to store each unique user’s details.

If you have access to a dedicated test environment and database you should be able to carry out a database backup and restore as part of each test script, with the added advantage of allowing user data to be pre-populated with each restore of the database. At Red Badger we have another method using a clever little C# trick creating a new user email using a date and time stamp, every time the test script is run.

For example giving: user_2011-10-19-17-52-20@gmail.com

Create Unique User

Imagine a Life without Selenium?

Automation regression testing certainly leads to a better use of resources. Skilled testers are freed up to concentrate on using their exploratory test methods on new functionality being delivered by the Development team. Virtual Machines may be set up and used as a dedicated resource for regression testing, with little or no maintenance when using the xUnit series.

As proved here with Selenium, cost is no longer an issue when considering developing an automated test suite. All one needs is a little determination and imagination!

Learning Material

In addition to the links above, I would like to point you towards this blog Evil Tester. This seasoned tester has worked hard to gather relevant learning material and has concluded it here in a manner that I am only too happy to recommend - How can I learn to automate my testing using Selenium?. Also if you prefer to have a good old fashioned book, this tester is the author of a great book for beginners Selenium Simplified.

XPath, CSS, DOM and Selenium: The Rosetta Stone contains printable wall charts comparing element section options. It outlines that Xpath, CSS, and DOM are a fairly diverse set of technologies yet they have quite a bit in common.

Similar posts

Are you looking to build a digital capability?