test automation using selenium

Upload: vamsi-mohan

Post on 08-Oct-2015

11 views

Category:

Documents


0 download

DESCRIPTION

Automation, Selenium

TRANSCRIPT

  • Test Automation using Selenium

    (A Guide for Beginners)

    1. Introduction

    Selenium is an open-source tool that is used for

    test automation. It is licensed under Apache

    License 2.0. Selenium is a suite of tools that

    helps in automating only web applications.

    The purpose of this document is to describe

    standards to be followed when designing and

    developing framework code. This document will

    help ensure consistency across the code,

    resulting in increased usability and

    maintainability of the developed code. This

    document provides test automation guidelines to

    leverage Selenium WebDriver features to foster

    a continuous, consistent and standard

    automation approach.

    Pre-Requisite:

    Ensure you have java installed in your

    system.

    Download Eclipse

    Download Test-NG Plug-in and install it.

    2. Scope

    This tutorial is designed for software testing

    professionals who would like to learn the basics

    of Selenium through practical examples. The

    tutorial contains enough ingredients to get you

    started with Selenium from where you can take

    yourself to higher levels of expertise.

    3. Selenium Suit

    Selenium IDE - Selenium Integrated

    Development Environment (IDE) is a Firefox

    plugin that lets testers to record their actions as

    they follow the workflow that they need to test.

    Selenium RC - Selenium Remote Control (RC)

    was the flagship testing framework that allowed

    more than simple browser actions and linear

    execution. It makes use of the full power of

    programming languages such as Java, C#, PHP,

    Python, Ruby and PERL to create more complex

    tests.

    Selenium WebDriver - Selenium WebDriver is

    the successor to Selenium RC which sends

    commands directly to the browser and retrieves

    results.

    Selenium Grid - Selenium Grid is a tool used to

    run parallel tests across different machines and

    different browsers simultaneously which results

    in minimized execution time.

    4. Framework Design and development

    Fig 1.0

    Driver: Driver block is responsible to initilise all the required objects to run the script. For example: WebDriver Object or Properties object. Pages: Pages are representation of functionalities presented in AUT pages in form of java classes.

    Test Scenario: Test scenarios are actual test cases written in TestNG framework.

    Configuration Files: Configuration files, or config files configure the initial settings for Automation like URL for Applicaiton under Test (AUT), User name, password etc.

    Recovery: While executing the Selenium scripts, we might get some Unexpected errors. In order to recover the test and continue executing the rest of the script from these unexpected errors,

    Recovery Scenarios are used.

    HTML reports: TestNG has the ability to generate reports in HTML format and by default; it generates a different type of report for its test execution. This includes an HTML and an XML report output. Without TestNG, Static HTML

  • report can also be created where the HTML tag with information can be written in a HTML page.

    5. Naming Conventions

    Data Type Prefix Example

    Boolean bln blnFlag

    Integer int intCount

    Long lng lngRowNumber

    Double dbl dblWeight

    Object obj objCurrent

    Single sng sngPosition

    String str strCurPage

    Array arr arrCellData

    Variant vnt vntPropValue

    User-Defined Type udt udtTransaction

    Scope Prefix Example

    Global g gStrAppPath

    Module-Level m mintRowCount

    Static s svntFlag

    Variable Passed by r rintValue

    Reference

    Variables Passed byv vintValue

    Values

    Local to the None strCurPage

    Function

    The constant names should be initial capped with

    underscores between words as shown in the

    following example : gstrApplication_Path

    6. Activities

    The following major activities in each phase of automation must be estimated.

    Automation Initiation

    Tool/Framework Feasibility Study

    Environment Setup

    POC

    Framework Design/Implement

    Design and Implement Various Framework Components

    Testing the Framework Components and End to End Testing

    Training Resources on the Framework/Tool

    Environment Setup

    Training

    Training Resources on the Framework/Tool

    Script Development Phase

    Script Creation

    Script Debugging

    Script Review

    Review Comments Incorporation

    Script Execution Phase

    Environment Setup

    Result Analysis

    7. Functions

    Names:

    The function name should start with def followed

    by the name of the function.

    When arguments are passed to the function, the

    variable naming standards should indicate

    whether it is passed by value or passed by

    reference.

    Example: def GetObject (strObjectname)

    Header:

    The function or procedure header should contain

    the following:

    Name of the project

    Name of the function

    Name of the author

    Description of the function/procedure

    Date of creation

    List of input parameters with their description

    Name of the person modifying it

    Date of modification

    Example:

    ************************************************** #Project Name : Test #Function Name : importdata.rb()

    #Author : Open Source

    #Description : This function handles the Suite Run, Object Repository, Keyword Driver and creating Reports.

  • #Date of creation :

    #Input Parameters:

    #Name of person modifying: Tester #Date of modification:

    **************************************************

    8. Function Complexity Framework code should be designed and developed with minimal possible loops and conditions for reduced complexity and enhanced maintainability.

    9. Function Structures The following tips provide guidance for creating easy-to-read and easy-to-maintain code.

    Modularize the code for increased reusability and reduced redundancy.

    Code should be well-indented with tabs. (Tab width should be 4).

    Values passed and returned to the functions should use simple variables.

    Reduce the use of global variables within the function. The scope of the variable should be decided based on the standards.

    10. Comment Standards

    6.1 Framework Code Header Comments

    The framework code header should contain the following:

    The copyright and proprietary information

    Name of the framework code

    Author of the code

    Name of the reviewer

    Date of creation

    Version number

    Every change to the framework code should be documented in the modification history. A modification history should contain the following:

    Name of the person who changed the code

    Date of change

    Version

    Changed function/event

    Change description

    6.2 Line Comments

    Significant lines in the code should be provided with inline comments to better explain the line of code's purpose and make it easier for subsequent developers to understand the code faster and more thoroughly.

    Example:

    #Open the Object Repository Excel sheet @@ObjBook= @@excel.workbooks.open(@@Object_Rep)

    11. General Guidelines

    a. Use an ampersand (&) for concatenating

    strings instead of +.

    b. Set the objects to nothing for cleaning

    the memory.

    c. Declare only one variable in a line.

    d. There should not be more than 80

    characters per line.

    e. The code should be properly indented.

    f. Declare variables using appropriate data

    types.

    g. Avoid using the variant data type.

    h. Use procedures instead of functions if

    there is no return value.

    References

    1. http://www.seleniumhq.org 2. http://www.qaautomation.net 3. http://mestachs.wordpress.com/2012/08/

    13/selenium-best-practices

    Vamsi Mohan is a research scholar in

    Scope management, India. He is an

    architect and consultant, managed end to

    end development of multinational

    projects. An extensive experience in full

    project lifecycle, software development,

    application design and architecture,

    documentation and project planning,

    database design, systems analysis and

    database optimization, conversion &

    integration, technical support; testing and

    implementation of various strategies in

    BFSI, CRM and Telecom domains.PH-

    919901261246. E-mail:

    [email protected]