Introduction to Selenium Automation Testing

Introduction to Selenium Automation Testing

Automation testing is mostly helpful when a small change is made to the source code of the software, the tester has to manually test each and every functionality of the application, which takes lot of time for the testers to test the complete functionality from scratch. If instead the tester automates the complete software using any automation tool, he can just run the automation tests using the automation tool every time when a change is made to the source code of the project or when a new build is given for testing frequently. Ultimately it saves the testing time of testers and relives the testers from the stress.

Out of all the open source and commercial tools available in the market, the following are the two most popular tools:
  1. QTP  ( Commercial Tool – Supports Desktop and Web Applications )
  2. Selenium ( Open Source Tool – Supports only Web Applications )
Selenium is one of the most popular open-source automated testing Tools available today.

Selenium automates web applications for testing purposes, but is certainly not limited to just that.

Introducing Selenium: Selenium is not a single tool, instead it is a set of different tools each with a different approach to support test automation. Learning all the tools will give you different options for approaching different test automation problems.These tools when used together give many options for locating the UI elements and comparing expected test results against actual application behavior. The following  are the four tools that comprise the Selenium’s Tools Suite:

  • Selenium IDE
  • Selenium 1 (or Selenium RC)
  • Selenium 2 (or Selenium WebDriver)
  • Selenium-Grid

Few Good things about the Selenium Automation Tools:

1. Selenium is an open source tool i.e. Unlike the proprietary tools its available free of cost.
2. This is the best tool available in the market for web application testing
3. One of the selenium’s key features is the support for executing one’s tests on multiple browser platforms like Internet Explorer, Firefox, Google Chrome, Opera, Safari etc.
4. Selenium allows you to control a browser from a language of your choice. You can choose any one of these Six languages to write automation scripts -> Java, C#, Ruby, Python, Perl and Php
5. Selenium is available for Operating Systems such as Windows, Linux and Mac
6. Selenium can be used for functional, compatibility, regression testings and User Acceptance Testing (Mainly used for Regression Testing).

  • Functional Testing refers to the test that verifies a specific action of the software (Example – Logging into the Gmail is an action)
  • Compatibility Testing is performed to verify whether a software works with all other supported software and hardware.
  • Regression Testing is the repetition of the earlier successful tests in order to make sure that changes to the software has not introduced any new side effects
  • User Acceptance Testing is testing an application prior to customer delivery for functionality and usability  using real world scenarios which resemble how the application will be used by the end users.

Drawbacks of using Selenium Automation Tools:

1. Selenium is a browser based testing tool. It cant be used for automating the desktop applications. (i.e. It can be used only for automating the web based applications)

Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.

Object Identification In Selenium

Object Identification In Selenium:

Object identification is a very crucial part of any automation effort be it in QTP, selenium or any other tool for that matter. So it makes it very important for each one of the automation folks around to be able to identify the objects used in the automation effort

Identifying Objects is Selenium (WebDriver) is pretty simple if you are working on an application built on Firefox, but it gets very tricky if you are working on IE application. So it would be best to master the object identification techniques.

If you have used the Selenium IDE for any recording you would have noticed that there are multiple ways of identifying an object. By default the Selenium IDE tries to recognize the object by the ID or name attribute. Selenium IDE identifies the objects by the attributes mentioned in the order below

Object identification is very important part of automation activity. So the automation people should be able to identify the objects for automation purpose.

For identifying these objects Selenium uses a concept of ‘Locators’. These locators are used to identify the objects which are mostly used while automating the test cases using Selenium.

Locators: There are number of locators present. These are among them.

  •  ID
  •  Name
  •  Link Text
  •  CSS Selector
    Tag and ID
    Tag and class
    Tag and attribute
    Tag, class, and attribute
    Inner text
  •   DOM (Document Object Model)
    dom: index
  •  XPath

For testing different applications i.e. Application Under Test (AUT), we need to identify the object it is made of. All applications either it is Web Application or Desktop Application; it is consisting of different objects like below:

  • Button
  • Text Box
  • Link
  • Drop Down
  • Radio Button
  • List Box
  • Slider

Finding an element and confirming the expected result requires locators. Through locator, In Document Object Mode (DOM) i.e. webpage, we uniquely identify the object. The ‘By‘ class is used in WebDriver to locate the elements.

o identify the objects such as Links, Buttons, Edit boxes, Drop downs, etc on the application Selenium uses a concept called “Locators”. There are around 8 different types of locators. Out of them, I will be explaining only four as they are widely used while automating the test cases using Selenium.

1. id = id – By default Selenium IDE takes “id” as Locator Every Web Page will be having some HTML Source code. This can be viewed using “View –> Page Source / View source” on the browser. In the following picture we can see “id” attribute of a HTML tag is used as a locator to identify an object.

2. name = name (Second locator) We will do the following steps to understand how exactly Selenium identifies the objects

3. xpath = xpathExpression. Xpath is used as a Locator to identify an object. This is an expression which is formed by combining various HTML tags. For example: //a[contains(text(),’VRL travels’)], //div[@id=’shortcuts’]/span/span[2]/a/span

4. link=link text (in HTML source we can located this using “href” tag)

Here XPath and CSS are the most widely used locators.

It is very easy to identify the object of the application which is built on Firefox but same on the other way if that application is made on IE browser then it is pretty difficult to identify the object.

There are different tools available to identify the objects on different browsers like Firefox/Chrome/IE etc.

If we are using Selenium IDE there are different ways to identifying the objects. By default Selenium identify the object using ‘ID’ or ‘Name’.

Here I have taken the example of ‘Flipkart’ home page. Here for search text box on Flipkart home page the recording is done through Selenium IDE. We can see here the order of identification of text box via different locators as above.

We can see the code of above recording. For each locator the code will look like as below:

1. driver.findElement(“fk-top-search-box”)).click();
2 driver.findElement(“q”)).click();
3. driver.findElement(By.cssSelector(“#fk-top-search-box”)).click();
4. driver.findElement(By.xpath(“//input[@id=’fk-top-search-box’]”)).click();
5. driver.findElement(By.xpath(“//form[@id=’fk-header-search-form’]/div/div/div/input”)).click();
6. driver.findElement(By.xpath(“//form/div/div/div/input”)).click();

6 Tools to Help You with Object Recognition

Using one the six tools

  1. Firefox – Selenium IDE
  2. Firefox – Firebug
  3. Firefox – Firepath
  4. Google Chrome Developer Tools
  5. IE Developer tool bar
  6. fire-ie-selenium
  7. XPath Checker
  8. Fire Finder