Selenium in Automation Testing

Let us start with some questions that Automated Testing environment should answer before delving into some serious  works.

1.What are the advantages of Selenium over QTP and Silk test?
Ans- The Greatest Advantage is that it is an Open Source free Tool. So cost wise it scores over other 2 tools. Other advantages I have explained in my third Answer.

2.Does it have any disadvantage?
Ans- One of the disadvantage which I felt is the lack of proper documentation. There are lots of features which we fail to utilize because of this. Also Support is limited compared to other paid tools and we have to  depend on forums and other people to solve our issues. Also Selenium can only be used for Web Based  Application.

3.How is it unique i.e, how does it stand out from the other automation tools?
Ans-Selenium testing suite is highly flexible. There are multiple ways to add functionality to Selenium framework to customize test automation. As compared to other test automation tools, it is
Selenium’s strongest characteristic. Selenium Remote Control support for multiple programming and scripting languages allows us to build any logic we need into our
automated testing and to use a preferred programming or scripting language of our choice. Also,  Selenium testing suite is an open source project where code can be modified and
enhancements can be submitted for contribution.

4.How flexible is the Selenium test suite?

Ans-Selenium Test Suite is highly flexible. For Java we may use Junit or  TestNG framework  for running suite. For C# we can use NUnit Framework.

5.And the last question would be why don't we use it in many project?
Ans- Lack of Experienced Resources with Selenium experience was one of the major concern. Quite a lot of application is not fully supported by Mozilla Browser writing of Test Scripts would have become difficult for few  scenarios.


 There are many Automation Testing Tools available, to name a few QTP, Silk Test, Selenium, Watir etc. Today I would like to share my experience with “Automation Testing Using Selenium”

About Selenium

Ø   Selenium is a OPEN SOURCE automation functional test tool developed by Thought Works.
Ø    Selenium is for web automation.
Ø    Selenium can be chosen to use its recording capabilities/you can edit the script .
Ø    Selenium tests run directly in any browser and supports any OS.
Ø    Selenium uses JavaScript to embed a test automation engine in browser
Ø    Selenium supports writing test in java,. NET, Perl, Python and Ruby.
Ø    Create regression tests to verify application functionality and user acceptance.

Components Of Selenium

Ø  Selenium IDE
Ø  Selenium RC
Ø  Selenium Core
Ø  Selenium Grid

Selenium IDE

Ø   Selenium IDE is implemented as Firefox extension.
Ø   Allows you to record, edit and debug test.
Ø   Test can be saved as HTML, Ruby scripts or any other format.
Ø   Options to assert the title of every page.
Ø    Debug and set breakpoint.
Ø   Easy record and playback.
Ø  Scripts written in SeIDE can be run in any Browser after creating a Suite for the Scripts


Installation of Selenium IDE

Ø   Install Mozilla Firefox browser
Ø   Download Selenium IDE 1.0.4 from the URL : http://www.openqa.org/selenium-ide/
Ø   Open the Mozilla Firefox browser
Ø   On the browser click on File - > Open File.. ->selenium-ide-1.0.4 (open the XPI file)
Ø    Go to tools option in the browser and click on  Selenium IDE and the tool gets invoked.

image005.jpg                                 image007.jpg


Record a Test

Ø   Once the Selenium IDE is invoked the tester can start navigating the AUT.
Ø   The flow is captured by selenium and be viewed under the table / source option.
Ø   The recorded script can be converted to java,. NET, Perl, Python and Ruby.
Ø   Test can be saved as per the tester’s requirements.

image008.jpg

Play back of a test

Ø   The recorded scripts can be played back by clicking on the ‘Play’ button

image013.jpg


Breakpoint

Ø   The tool offers the facility of breakpoint, where the script can be halted anywhere
Ø   After analyzing the script can be resumed
Ø   The speed of the scripts can be controlled by setting speed from fast to slow

image014.jpg
How Selenium Identifies Object
Ø  Actions
Ø  Accessors
Ø  Element Locators
Ø  Variables

Actions
Ø  Where the test actually “does something”.
Ø  Most actions typically take an element locator and possibly a value.
Ø  All actions have an additional “AndWait” sister-action.

Example:

Ø  check - check a checkbox
Ø  click - click a link, button, image, etc
Ø  open - opens a URL in the browser
Ø  select - selects a value from a drop-down
Ø  submit - submits a form
Ø  type - types a value in to a textfield/textarea

              Accessors
Ø Accessors are always “data related”
Ø  Accessors typically take only an element locator.
Ø  Accessors have seven permutations:
§  store (locator, variable*)
§  verify and verifyNot (locator, pattern)
§  assert and assertNot (locator, pattern)
§  waitFor and waitForNot (locator, pattern)

                Example
Ø  alert - the text of the most recent alert box
Ø  bodyText - the contents of the HTML body
Ø  eval - the return value of the JS expression
Ø  table - the contents of a specified row/col
Ø  text - the contents of the specified element
Ø  title - the title of the HTML page

             Element Locators
Ø  id=
Ø  name=
Ø  identifier=
Ø  dom=javascriptExpression
Ø  xpath=xpathExpression
Ø  link=text
Ø  css=cssSelectorSyntax
Ø  If no prefix is specified, the following strategies are used:
·         dom, if the locator starts with “document.”
·         xpath, if the locator starts with “//”
·         identifier, for all other

            Variables and Parameter

Ø Allow for basic logic in your scripts.
Ø  storeXxx comands take variables:
            Example:
Ø  storeValue nameField firstName
Ø  assertTextPresent ${title} ${firstName}

          Addons which helps Us in Identifying Locators:
Ø  Firebug for Mozilla Browser
Ø  IE Developer Tool Bar for IE

     Frequently used selenium commands

S.No
S.No Object/Property Command
S.No Object/Property Command
1
Text Box
getValue(), getText(), isEditable(), isVisible(), type()
2
List Box
getSelectedId(),getSelectedIndex(), ,
getSelectedLabel(),getSelectedValue(),
getSelectOptions(), select()
3
Multi Select / Element
getSelectedIds(),getSelectedIndexes(),
getSelectedLabels(),getSelectedValues(),isSomethin
gSelected()
4
Radio Button
check(), click(), isChecked()
5
Check Box
Check(), click(),isChecked(), uncheck()
6
Button
click()
7
Link
click(), getAllLinks()
8
Text
getText(),getBodyText()
9
Tables and Cells
getTable()

User Extensions


image017.jpg

Sample Extensions:
getVal extension – Helps to read the value from extension file
Flow control extension – Helps to incorporate the looping statements inside the script
UI element – Helps to create the object repository

@Note : Selenium IDE is generally used in Organizations where there is lack of Experienced Testers. For more programming Concepts to be implemented we would go for Selenium RC .

Limitations 0f SeIDE

Ø  Browser
      -Selenium IDE is only available for the Firefox. It cannot be used for different browsers.
Ø  Language
    –Selenium IDE can execute scripts created in Selenese only.
Ø  Complexity
   –It is difficult to use Selenium IDE for checking complex test cases involving dynamic contents, Parameterization, Loops.

So What Next ??
 We can use Selenium Remote Control

Selenium Remote Control

Ø  A server, written in Java and so available on all the platforms.
Ø  Acts as a proxy for web requests from them.
Ø  Client libraries for many popular languages.
Ø  Bundles Selenium Core and automatically loads into the browser

How RC Works
image020.jpg

Install And Start

Ø  Ensure that JDK is present on the machine and is in the class path.
Ø  Downloaded Selenium RC from http://www.openqa.org
Ø  Unzip to any directory on your file system.
Ø  Change directory to the Selenium Server on the command line or terminal.
Ø  Start Selenium Server.

cid:image021.png@01CAA660.3BAEE7B0

Selenium Client Drivers

Ø  Enables communication with Selenium Remote Control Server.
Ø  Functionality of Selenium is exposed via these drivers.
Ø  Available in Ruby, Python, Java, C-Sharp …and so on.
Ø  Give access to the rich features and libraries of the language, including their unit testing framework.
Ø  Makes it possible to develop automated scripts in the same language as product.
Ø  Which one you should use?
      –Whatever make sense in your context. I have been  running Test Scripts using Eclipse Java IDE using JUNIT and TestNG framework.

View of Eclipse: Script written using JUNIT Framework
image022.jpg

View of Selenium RC runner :



Reporting

Report is customizable. A typical TestNG framework report would like :
image031.jpg

Roadmap

Google is investing heavily on Selenium and they have come out with the latest version of Selenium RC 2.0.

Post a Comment

Previous Post Next Post