Articles in this series - Selenium- Automation Testing
- Selenium -Open Source Test Automation: An Overview
- Selenium-part II: Testing AJAX
- Selenium – Part III: Advanced Features of Selenium
Introduction
Within the software industry, once a product reaches the stable manual testing phase, every organization usually thinks of automated testing to save on the costs involved in manual testing. Since testing cost is an important factor for any project, organizations have started preferring open source test automation tools (which have reached a stage where they now rival the commercial ones) instead of investing in costly commercial testing tools. With no licensing costs, open source automation testing tools provide competitive features for automating the testing of software applications as well as Web portals.
A variety of open source automation testing tools is available for almost all types of testing such as functional, Web, UAT, regression, performance etc. Because of the extent to which these open source tools have matured, it’s time to think about them and have them in your QA automation kit. There are also various open source tools available to support the different testing types such as White Box Testing (Unit Testing, for e.g., using JUnit) and Black Box Testing (system/regression testing, for e.g., using Selenium, Sahi, Watir, TestMaker, LogiTest, TestGen4J, FitNesse etc).
The scope of this blog is to cover the basic flow for one of these open source Web testing automation tools – Selenium.
Why Selenium?
Selenium is probably the best option for automated testing of Websites today. It is becoming increasingly popular and it is the first choice of automation testers as well as organizations for automating the testing of Web-based applications for both the GUI as well as the functionality. Selenium can also be used as a unit testing tool for JavaScript. We at Xoriant have been working on Selenium for automating the testing of Web sites developed using AJAX for the pharmaceuticals and travel industries. The following graph shows the popularity of Selenium along with other open source automation testing tools.
Selenium Test Package
Selenium is a package of various test components which consists of the following three major tools. Each one has a specific role in aiding the development of test automation for a Web application.
- Selenium IDE – A Firefox extension to record test cases and suites.
- Selenium RC – Used to run tests on different browsers and systems.
- Selenium Grid – Runs multiple instances of Selenium RC at once.
- Qualitia and Tellurium – A wrapper for the Selenium engine.
Selenium Modes:
Bases on the components Selenium has following three modes for executing the test cases and test suites:
- Record-Playback mode (Selenium IDE):
In this mode only Selenium IDE is used to record the test scenarios in terms of test cases in firefox. This is a great way to get started to writing tests and group them together to form the test suite. The recorded tests can be exported to many programming languages so that we can tweak them and put them in the testing framework. The test cases and test suites can be replayed back to check the verifications and validations or sent to Selenium RC or Grid for further tweaking.
- Selenium Remote Control (RC) Mode
In this mode Selenium starts multiple browsers (one at a time) and then runs the recorded test-cases which are saved in your language of choice. This helps to enhance the test cases with looping and programming techniques to cover all the required test scenarios and checks.
- Test Runner Mode
In this mode the test cases are recorded ad replayed in the form of HTML tables. This is just one more facility to execute the Selenium IDE as well as RC test cases. This helps to check the test results reports in better manner if not formatted already.
Testing AJAX with Selenium
Selenium IDE – Recording and updating a script
Selenium IDE is the FireFox Add-on provided by the Selenium group. This is very simple and easy to use add-on so that non-programmers can record and create the test scripts for automating web components. These automated test scripts are used as Selenium RC test cases by choosing the language code. i.e. Selenium IDE makes easier to create Selenium RC test cases. (Install Selenium IDE and Selenium RC from Selenium download page).
Selenium IDE is used for:
- Recording and updating the test cases or write them manually in table tab.
- Creating Test Suite by grouping the test cases under one group
- Exporting Test Cases/Suites the supported language and save for Selenium RC to enhance them
- Finding reference of every API and Selense commands
- Debugging test cases by toggling breakpoints through the commands
How commands generated in IDE for AJAX pages:
- Almost all of the web pages are developed with AJAX technology since web2.0 evolution. While recording the page elements, Selenium IDE locates the page elements/objects using XPath/DOM/CSS. XPaths are found automatically, but you may have to update the specific elements in Xpath manually by looking into the source of the page to make them unique. Firebug is the helpful firefox Add-on for this purpose.
- Every command has maximum two arguments. The first is usually target element pointed by its ID, name, link, DOM, CSS or XPath and the second is the value to that target element if exists. The selenium IDE commands when saved in the programming language of our choice for selenium RC purpose are called as Selenese.
- The common commands are open, click, type, assert, verify. Commands beginning with ‘assert’ or ‘verify’ are for checks and verifications. If verify command is used and it fails, it fails the test case and continue to run the remaining tests. If assert command is used and it fails, the test case is aborted and stops to run the remaining tests.
- For synchronizing the flow of test execution Selenium has commands ending with ‘AndWait’, it tells Selenium to wait for the page to load after the action has been done. However, it fails when using AJAX calls. In this case you have to use ‘WaitFor’ commands.
Selenium IDE – Most commonly used commands
The following are the most commonly used commands in the Selenium IDE:
open: Opens a page using a URL.
click: Clicks the element/object on the page.
clickAndWait: Performs a click operation, and optionally waits for a new page to load.
verifyTitle: Verifies the expected title and continues to run if it fails.
assertTitle: Verifies an expected page title and stops the execution if it fails.
verifyTextPresent: Verifies that the expected text is present somewhere on the page.
verifyElementPresent: Verifies an expected UI element, as defined by its HTML tag.
verifyText: Verifies that the expected text and its corresponding HTML tag are present on the page.
waitForPageToLoad: Pauses execution until an expected new page loads.
waitForElementPresent: Pauses execution until an expected UI element, as defined by its HTML tag, is present on the page. Used with AJAX calls.
Get more details about Selenium IDE here: Selenium IDE documentation.
If you need a full reference of all Selenium commands, read the Selenium commands.
Conclusion
In the first part of this blog, we have covered the basics of a typical test setup required for Selenium for automated testing of a Web-based application.
In the next part, we shall see automated testing in action – i.e., a practical example of how to actually use the Selenium IDE and RC to execute the tests. The reader is advised to check out the links highlighted in this blog to build the foundation needed for part two.
Related posts:
- Selenium for Test Automation Selenium is a suite of tools used to automate web application testing across many platforms. It is an open source tool developed in Java Script and browser technologies and hence...
- Selenium – Part III: Advanced Features of Selenium Introduction This is the third and concluding part of a three-part blog on Selenium – a free and open source automated software testing tool. In part one of this blog,...




Is Java knowledge required using Selenium tool?
Yes, for automating the complex test scenarios for functional and database testing, java knowledge is required. As the test engineer is required to update/create code with looping and methods and also for covering additional test scenarios and generalizing the test suites. This is applicable to all programming languages supported by Selenium RC like PHP, C#, Python….
But if you are using Selenium-IDE only then you will be using only the HTML code-base, which does not require knowledge of any programming language.
I hope this answers your question.
Thanks,
Dada
hi,
i would like to know is there any books available in market for selenium like a complete reference guide.I am new to this tool, so i wish to learn both coding in html and also about the tool.
Sandhya,
There are following books available on selenium in the market as below:
- Selenium 1.0 Testing Tools: Beginner’s Guide- PACKT publishing
- Selenium simplified: Paperback publishing
Not sure whether these books are available in the book shops in India.
I would suggest to follow the free documentation available on Selenium’s home website first:
- http://seleniumhq.org/docs/book/Selenium_Documentation.pdf
All the required info related to selenium installation as well as coding for IDE, RC is available on this site.
Thanks,
Dada
I need to know, How to download the open source selenium tool
Hi Narendra,
Please go to the selenium home page at http://seleniumhq.org/ and download Selenium IDE, Selenium RC and other components too. Installation information is also available on the given site.
Thanks,
Dada
Can SharePoint bases web apps be tested using Selenium? AS many SharePoint based features are only conpatiple with IE?
Hi,
I want to use this tool on .NET/Java based desktop tool.Could we use this tool?
Hi Somendra/Anirban,
The entire suite of tools results in a rich set of testing functions specifically geared to the needs of testing of web applications of all types.
As long as it is web app Selenium should support the automation. May be Selenium2.0 have included the Sharepoint based web Apps in its list.
Anirban,
May be Selenium Org will include the desktop applications/tools soon in its target applications.
Hope this helps.
Thanks,
Dada
Hi,
I wanted to know if I could make you of Selenium to automate some of my tasks. My tasks can be briefed as follows.
1)Open browser and go to a particular webpage. (some buttons need to be clicked)
2)Copy a value from a column in an excel sheet on a specific textbox in the website and click a tab in the page.
3)Copy the value generated in a textbox of the webpage to excel.
4)Continue steps 2,3 for all values in excel sheet.
I need to know if a process like this can be automated with Selenium alone?
Hi Thomas,
These type of scenarios are quite difficult to automate in simple straight forward scripts in Selenium.
But nothing is impossible if you make use of the Junit/Nunit/Python Frameworks and create code for handling File communication in java/.net/python scripts.
You need to study the Junit/nunit/python frameworks supported by Selenium suite to get a clear idea.
Hope this helps.
Thanks,
Dada
Can we use Selenium for mobile applications? I am working on Mobile applications especially Windows mobile.
Hi,
Thanks for referring our blogs.
Version 2.0 of the application testing suite will support iPhone and Android apps, with BlackBerry and Windows Phone 7 capabilities.
Please refer the link for more details:
http://www.infoworld.com/d/application-development/selenium-test-suite-add-mobile-apps-011
hope this helps.
Regards,
Dada