Professional Documents
Culture Documents
Introduction
Selenium is set of different software tools each with a different approach to supporting test automation. Selenium is an open source tool. Selenium supports as many as 8 programming languages such as HTML , Ruby , PHP, Python, C#, Java, Perl etc. Latest side of Selenium is Grid, which allows the running of multiple Selenium tests on different browsers and different platforms.
www.seleniumhq.org Software's: All the selenium software's can be downloaded by using the below link http://seleniumhq.org/download/ Documentation: Documentation can be downloaded by using the below link http://seleniumhq.org/docs/
Scripting Language:
QTP allow users to write script in VB script only. Silk test has proprietary scripting language 4TL. ( 4 Test Language ) But Selenium allows writing script in Java, Ruby, Perl, PHP, C# and Python.
Price :
Selenium is an open source tool. Silk and QTP are not free tools QTP license cost is around $7500 , Silk test license cost is around $8500 USD
Limitations
Desktop applications:
We cant automate desktop applications using Selenium. We can automate using QTP and Silk test.
Object Repository:
Capturing objects properties is a tough task as we need to prepare the object repository.
Features of Selenium
It has support for multiple operating systems like Windows, Linux and
Mac
Cross browser testing can be done easily on browsers like IE, Firefox,
Python .. etc
It can be used for automating Ajax and swift web pages. It is easy to use, if are familiar with any one of supported programming
language
It is easy to learn It is free-open source tool It has matured community forums to get clarifications
Components
Selenium is majorly divided into four components Selenium CORE Selenium IDE Selenium RC(Remote Control) Selenium Grid
Selenium CORE
Selenium Core is a test tool for web applications. Selenium Core tests run directly in a browser. And they run in Internet Explorer, Mozilla Firefox on Windows, Linux, and Macintosh. This is deprecated with the advent of Selenium IDE and Selenium RC. Initially IDE has capability for recording test cases only. In earlier stages executed recorded script using Test runner. Later IDE introduced with the execution facility. Disadvantages: We cannot record scripts using this. We can run scripts in only HTML format using Test runner.html
We need to enter the test suite path in Test Suite edit box on the left hand side . Click on Go and then the screen window changes with the commands.
Now click on Run option on the right hand side of the window
Selenium IDE
IDE means integrated development environment, which is used for record and run the scripts. Selenium IDE is add-on for Mozilla Firefox. The recorded scripts in Selenium IDE can be viewed in the following supported languages: 1) HTML 2) Java 3) C# 4) PERL 5) Python 6) Ruby 7) PHP The recorded scripts in Selenium IDE can be run against other browsers like IE, Safari, Google, Chrome and Opera by using Selenium RC. By default the script that is recorded should be saved with the .html extension. back. It supports only for Firefox. Using Selenium IDE we can record, save, execute and debug the scripts It cant support for Database verifications Error handling and Customize reporting.
It will keep the user actions as they are performed and store them as a reusable script to play
Selenium IDE
The script is saved as .html file so the run options are active Observations: Table is active here because the extension is .html Run Options are active and we can run the test case now.
Selenium RC
Selenium RC comes in two parts i.e. Server and Client libraries Selenium-RC software comes with seven folders and we need to use
Selenium RC (Contd)
Selenium RC is an Open Source platform and supports only webapplications for automation. We can develop scripts using any popular programming languages Using Selenium RC with a high-level programming language allows us to query database, email test results and use iteration statements to navigate through the result set Using RC we can execute scripts in different browsers and platforms
With the server running, we may now use a client also. Selenium selenium = new DefaultSelenium( String seleniumServerHost, int seleniumServerPort, String browserType, String baseURL); selenium.open("http://www.somesite.com/somePage.html"); selenium.stop();
baseURL is the base URL for the site you are testing.
Now, just opening a page isnt all that useful. We need to interact with the page. To
do this, we use our selenium clients methods with locators. For example:
selnium.click("link=Text For Some Link"); The string link=Text For Some Link is a locator.
Locators
In Selenium, the objects are called as locators and they can be identified using Xpath, DOM or CSS.
Locators take the form of
locatorType=argument
A locator type can be an element id, an element name, an xpath expression, link text, and more. A few examples: selenium.click( id=idOfThing ); selenium.click( name=nameOfThing ); selenium.click( xpath=//img[@alt='The image alt text'] ); slenium.click( dom=document.images[56] ); selenium.click( link=Test Page For Selenium ); //a css locator //an id locator //a name locator //an xpath locators //a DOM locator //a link locator selenium.click( css=span#firstChild );
Sample Script
import com.thoughtworks.selenium.*; // This is a package need to be include for using Selenium API public class SampleScript // This is Class name { public static void main( String args[] ) throws Exception // This is main function { // This is the statement for Creating Browser Object DefaultSelenium Brw= new DefaultSelenium ("localhost",4444,"*chrome", "http://"); Brw.start(); // This statement starts the Browser Brw.open("www.google.com"); // This statement loads google.com url Brw.waitForPageToLoad("30000"); // This stmt waits till loading complete web page Brw.windowMaximize(); // This stmt maximizes browser window Brw.type("//input[@name='q']", "valuelabs"); // This stmt enters Valuelabs text in search field Brw.click("//input[@name='btnG']"); // This stmt clicks on google search button } }
//input[@name='q] Object Identifier for Search Field //input[@name='btnG'] Object locator for Search Btn
Configuration
Open the Eclipse by double clicking on eclipse.exe, Click on OK for workspace launcher. Click on workbench, it will allow you to move inside the eclipse. Click on File->New->Select Java Project. Enter the Project name and then click on Configure JRE s
Configuration (Contd)
Click on Add and give the path upto the jdk directory so that all the JRE files will be added and click on Finish.
Configuration (Contd)
Now the JRE is successfully configured with our project root directory Right click on JRE System Library-> Build Path>Configure Build Path
Configuration (Contd)
Click on Add External JAR s and then select the four jar files and add them to our project.
Configuration (Contd)
Now the jar files are also successfully configured with our project. Click on Run from the Menu--> External Tools-->Select External Tools Configuration--> Double Click on Program and then enter the following details as shown in the screen. Click on Apply and then click on Run .
Configuration (Contd)
Now the Selenium RC is successfully configured with Eclipse and you are ready to write the scripts and execute them successfully. On successful running of Selenium server, the eclipse IDE gives an message that the server started successfully on port number 4444(default)
Configuration(Contd)
Objects Identification
For identifying the properties in Selenium, we use the below tools: Debug bar for Internet Explorer. Firebug for Mozilla Firefox. Debug bar Installation: Download the debug bar software by using the below link: http://www.debugbar.com/ Click on the exe file and then install the software. Once the software is installed, you will find the debug bar on the left side of the window.
Debug bar
Drag the circle and place it on the object which we want to identify the object.
Debug bar
The properties will be identified in the Attrs field. Using these fields, we can identify the objects.
Firebug
Firebug Installation: Download the debug bar software by using the below link: https://addons.mozilla.org/en-US/firefox/addon/1843/ Click on the exe file and then install the software. Once the software is installed, you will find the firebug on the bottom of the window.
Firebug(Contd)
Once we select the object, automatically the objects properties will be displayed in the bottom:
Firebug(Contd)
Selenium Grid
Selenium Grid is used for launching the multiple browsers with supported operating system in parallel. We can run the scripts on different browsers in parallel. Selenium Grid is a tool that dramatically speeds up functional testing of web-apps. It allows you to easily run multiple tests in parallel, on multiple machines, in a heterogeneous environment. Selenium Grid consists of a component called Selenium Hub which is the unique entry point for all the tests running by using Selenium Grid.
Heartbeat Mechanism
To ease the maintenance of a Selenium-Grid deployment: Selenium Grid Hub sends periodic heartbeat messages to all registered Remote Controls to make sure that they are still up and running. Selenium Grid Remote Controls send periodic heartbeat messages to the Hub to check that it still considers them as registered.
Selenium Grid-Setup
Questions
Mail me @ satish.tirumani@valuelabs.net