Saturday 15 March 2014

Selenium WebDriver - Concepts & Architecture



Selenium - Introduction

Every possible automation scope is looking for the cost effective solution. As the word itself suggests “Cost”, people are very much inclined towards the open source automation tools and finally ending up with “Selenium”.

Why Selenium?
  • Open source
  • Easy to Use
  • Supports multiple languages, platforms & browsers
  • Faster execution
  • Reliable

Evolution of Selenium:

Developed by Jason Huggins at thoughtworks to perform the repeated tests and actions on his development project with different browsers and eventually creating a library of java scripts to interact with web browser.

Core components of Selenium

  • Selenium IDE – Is a Firefox add-on that records user actions performed on the browser to make a test, which can be played back again.
  • Selenium RC – Used to run the tests in multiple browsers and platforms by improving the test based on the language and test requirements.
  • Selenium GRID - Extends Selenium RC and WebDriver to distribute your tests across multiple machines/servers to attain quick test execution.


Selenium 2.0 - WebDriver architecture:

Let’s talk about the Selenium WebDriver and its architecture and some of the capabilities and extensions which can add to WebDriver object to address some of the important automation scenarios.


WebDriver makes direct calls to the browser using browser’s native support for automation.  It uses the approach of firing events at the OS level and is only possible where WebDriver can bind closely with the browser and how best to it can send native events without requiring the browser window to be focused.




WebDriver provides an object oriented API to use page object patterns of automation and is designed to accurately simulate the way that a user will interact with a web application. It emphasizes the exact manual user actions on the web application.

For example : Remote control server will be able to click on any element on the page even though the element or the object is not in the visible state, because RC relies completely on java script interpretations.

Assume there an element which is visible only after the mouse over happens on the main navigation bar. WebDriver will emphasize user to perform the mouse over and then click on the visible link below it.


Interesting capabilities of Selenium 2 - WebDriver

  • It has the ability to control elements on the page like a user would. Like dragging items around a page or even perform the mouse, or keyboard actions at very low-level to do some the good things  like drag and drop

    For example, moving the e-mails from inbox to sub-folders in yahoo or gmail.
Sample script for drag and drop

 Actions builder = new Actions(driver);

 Action dragAndDrop = builder.clickAndHold(<element to click >)
       .moveToElement(<target element to move>)
       .release(<target element to release>)
       .build();
  dragAndDrop.perform();

Even holding a key and performing some other actions likes typing

builder.keyDown(Keys.CONTROL)
   .click(<Element to click>)
   .click(<Other Element to click>)
   .keyUp(Keys.CONTROL);
  • Often we may end up in debugging our automation test scripts during the run time. In order to do so, we need have the addon ready and handy to pause the script execution and use external addons.

    We can bind the add-ons like Selenium
    IDE and firebug to browser while launching the browser using webdriver object with the help of profiling concept.

String IDEpath = "C:\\FF_Profile\\seleniumide.xpi";
FirefoxProfile profile = new FirefoxProfile();      
profile.addExtension(new File(IDEpath));

  • Interesting part in the above method will help us even changing the HTTP headers of the Firefox browser so that normal windows browser will be treated as simple mobile browser and as if the application is being tested on the mobile device/browser.

\
However this kind of situation we may come across when the automation engineer has to automate and test application as if the HTTP request coming from mobile browser.

In the below example, by changing the HTTP header information of the browser, any request sent from browser with modified headers will be considered as mobile browser request by the webserver.

File fl = new File("..\\Inputs\\modify_headers.xpi");
profile.addExtension(fl);
profile.setPreference("modifyheaders.config.active", true);
profile.setPreference("modifyheaders.config.alwaysOn", true);
profile.setPreference("modifyheaders.headers.count", 3);
profile.setPreference("modifyheaders.headers.action0", "Add");
profile.setPreference("modifyheaders.headers.name0", "X-Nokia-msisdn");
profile.setPreference("modifyheaders.headers.value0", "123456878901");
profile.setPreference("modifyheaders.headers.enabled0", true);
profile.setPreference("modifyheaders.headers.action1", "Add");
profile.setPreference("modifyheaders.headers.name1", "x-sec-pass");
profile.setPreference("modifyheaders.headers.value1", "msdp@2010");
profile.setPreference("modifyheaders.headers.enabled1", true);
profile.setPreference("modifyheaders.headers.action2", "Add");
profile.setPreference("modifyheaders.headers.name2", "User-Agent");
profile.setPreference("modifyheaders.headers.value2", "NokiaN95_8GB");
profile.setPreference("modifyheaders.headers.enabled2", true);


 By
Automation Mentor

We provide hands-on training on automation tools and frameworks

Thursday 6 March 2014

How to choose the right automation framework




Introduction

Automation framework is a set of guidelines / standards / programs / tools defined to improve the productivity of automation resources with better reusability of scripts and ease of use. Framework should also simplify the maintenance effort of the automated tests. If you build / use a strong automation framework, you don't need highly experienced automation resources to build automated tests. Even a junior automation resource with basic understanding on the tool can automate a product if the framework is built to address all the necessary features to automate given product.

Framework should also improve the reporting ability of automated scripts, with better visibility of failures with use of screenshots, logs and, videos in some cases.

The framework should help organizations get better ROI on automation projects.

Can I automate without a framework?

Yes! It is not mandatory to use a framework to implement automation.
However, the automation script will become cumbersome as more and more tests are automated without a strong framework. Maintenance of such scripts becomes huge overhead for the automation teams and may lead to abandonment of total automation initiatives.

Sometimes, automation without frameworks (mostly Record & Playback approach) may work for santiy tests with very few test cases (less than 30). Investing lot of time on frameworks for such smaller initiatives may not be feasible.

Automation frameworks

There are different automation frameworks available / used in the industry for different needs. While most of them are custom built, some of the frameworks for open source tools are are readily available for use with basic features.

Most commonly used frameworks in the industry include Data-driven, Modular, Keyword-driven and Hybrid. Each framework can be built with basic & advanced features.

Data-driven Framework:

  • Used when same tests are performed with different data sets
  • Tests & Test Data are represented by separate data sets for each feature
  • Easy to add/edit tests & test data
  • Test data maintained in external data source like excel, databases, flat files etc.

Modular Framework:

  • Used for small & stabilized applications with limited independent features
  • Each test is represented by separate module / function
  • Test data is passed as arguments to functions


Keyword-driven Framework:

  • Actions & transactions are represented by simple keywords
  • One or more records in Datasheet for each manual test step
  • Easy to understand / implement / maintain code

Hybrid Framework:

  • Combination of multiple frameworks
  • Usually it’s keyword-driven framework with data-driven features
  • Common data source is used for different types of tests


There is a lot of buzz in the market for script-less automation tools / frameworks these days. These frameworks allow non-technical manual testers and business users automate their own test/use cases without much understanding on the automation tools, programming and frameworks.

Why so many automation frameworks?

Each disease needs different medicine. Each of these frameworks solves different issues.
Here are the advantages & dis-advantages of different frameworks.

Advantages
Dis-advantages
Data-driven Framework
§  Easy to develop & maintain
§  Easy to automate using this framework
§  Takes less effort to develop
§  Suitable only for tests with repeated data sets
§  Need to build separate script & data sets for each functionality
Modular Framework
§  Not quite complex to build
§  Reusability of code to some extend
§  Well organized and easy to understand
§  Maintenance effort of scripts is very high
§  Difficult to automate large projects using this framework
Keyword-driven Framework
§  High reusability of code
§  Flexible and easy to use
§  Improves productivity significantly
§  Reduces the script maintenance effort
§  Takes lot of time to build
§  Need advanced automation engineers to develop the framework

Hybrid Framework
§  Comes with several features together
§  Flexible and easy to use
§  Improves productivity significantly
§  Reduces the script maintenance effort
§  Takes lot of time to build
§  Need advanced automation engineers to develop the framework



Which framework do I need?

Success of an automation project starts with the selection of right framework. Here are different framework recommendations based on the application nature, size and complexity.

Application Nature and Recommended Frameworks
Small Application with less than 100 test cases
Simple tests (with 1-5 test steps) & stable application
Record & Playback
Medium size tests (with 5-15 steps)
Modular Framework
Complex tests (beyond 50 steps) with database validations
Modular Framework - with advanced features
Tests with repeated data sets
Data-driven Framework (with combination of Modular based on above conditions)
Mid-size Application with 100 to 500 test cases
Simple tests (with 1-5 test steps)
Modular Framework
Medium size tests (with 5-15 steps)
Modular Framework
Complex tests (beyond 50 steps) with database validations
Keyword-driven Framework - with database capabilities
Tests have repeated data sets
Hybrid Framework with Modular/Keyword-driven & Data-driven combination
Large Application with 500 to 2000 test cases
Simple tests (with 1-5 test steps)
Keyword-driven Framework
Medium size tests (with 5-15 steps)
Keyword-driven Framework
Complex tests (beyond 50 steps) with database validations
Keyword-driven Framework - with database capabilities
Tests have repeated data sets
Hybrid Framework with Keyword-driven & Data-driven combination
Huge Application with above 2000 test cases
Simple / Medium / Complex tests
Advanced Keyword-driven Framework
Tests have repeated data sets
Hybrid Framework with Advanced Keyword-driven & Data-driven combination



By
Automation Mentor


We provide hands-on training on automation tools and frameworks