Monday 25 April 2016

Understanding Selenium Grid.



Selenium is a test automation tool that automates browsers.  Selenium grid is built on the traditional set up of Selenium. It takes advantage of the following properties.



-      The Selenium test, the application under test and the remote control/browser pair can communicate through HTTP, so they do not need to be collocated. 

-      The Selenium RC and the browser are never tied up to a specific application and hence, they can  be easily shared through multiple applications and multiple projects.

The Selenium Grid transparently distributes tests across multiple physical and virtual locations so that they can be run in parallel. This speeds up the testing process, giving back quick and accurate feedback. Through Selenium Grid, the existing computer infrastructure can be leveraged. It enables running multiple tests in parallel, on multiple nodes/clients in a heterogenous environment of OS and browser support.

The Selenium Grid allows running of multiple parallel instances of WebDriver or Selenium RC. It makes all nodes appear as a single instance and so the tests do not need to understand the actual infrastructure. To run the grid the Selenium Server Standalone package includes

-      The Hub
-      The Web Driver
-      The Selenium RC 

The Selenium exposes an external interface similar to the traditional Remote Control. It acts like a central point which receives the entire test request and distributes it to the right nodes. It is responsible for 

-      Allocating a selenium RC to a specific test

-      Limiting the number of concurrent test runs on each Remote Control

-      Shielding the tests from the actual grid infrastructure.

Testing Practices with Selenium Grid

-      Download the latest Selenium Server standalone JAR file. Here we are referring to version 2.25.0

-      Use the following command to launch the Selenium Server. It will start the Selenium Server Hub role. 

-      java -jar selenium-server-standalone-2.25.0.jar -port 4444 -role hub -nodeTimeout 600

-      On launching Selenium Standalone in the Hub role, it starts listening to nodes and Seleniumtesting. By default, the Hub provides 5 sessions on the server.

-      For running the tests with Selenium Grid, the Selenium WebDriver tests use the  class instances of RemoteWebDriver and DesiredCapabilites in order to define the browser, version and platform in which the tests will be executed on. Based on the preferences in the DesiredCapabilities, the Hub will redirect the test to the node matching the preferences. 

  These preferences are set using the methods of DesiredCapabilities class. They are 

-      setBrowserName()

-      setVersion()

-      setPlatform()

In order to refine the number of available browsers, an additional browser parameter can be specified. This can also be used for specifying more than one browser as well.

The command will look like this:

java -jar selenium-server-standalone-2.42.0.jar -role node -browser browserName=safari -browser browserName=chrome -browser browserName=firefox -hub http://localhost:4444/grid/register
For setting up Selenium Grid to work with Internet Explorer or Chrome, additional configuration may be required for each. It is recommended to check out the browser driver documentation for this. 

When using Selenium Grid, confusions can occur from time to time. Using Selenium Extras helps to clear these confusions and helps to fix issues which come up outside of the web browser. Some of its cleanup tasks are:

-      After a complete test run it kills any remaining or crashed instances of the browser used.

-      It modifies he browser settings on launch for a hassle free test execution.

-      It periodically starts grid nodes to clear up memory leaks.

-      It automatically records a video of the running test session at the OS level which helps to review the test failure more effectively.

Furthermore, restarting the whole OS after a certain amount of test runs allows to clear up any remaining crashed items. Restarting the entire machine after every 10 to 20 test runs gives a huge boost in stability.

Conclusion

The main advantage of Selenium Grid is to be able to run tests in parallel. It is to be noted that Selenium Grid does not by itself provide for parallelization.
 It can handle multiple connections, but the tester will need to find a way to set up and execute the tests in parallel. Some notable approaches include testing through a framework (TestNG in Java), testing through Continuous Integration or testing through third party library.

Wednesday 20 April 2016

Key Considerations before Adopting Selenium Framework



Organizations have become more aware of the crucial role of testing in software development life cycle and in delivering high quality software products. As the competition in the IT industry grows stiffer, the pressure to deliver high quality products with fewer resources and limited time is intensifying. 



Automation testing helps to overcome these criteria and also addresses the challenges presented by manual testing. Automated tests can be executed can be executed multiple times and much faster than manual tests. They help to find defects and issues which are more often overlooked in Manual testing. Automation helps in automating repetitive tasks and help to focus on high risk projects. 

Identifying the right automation tool is critical to ensure success of a testing project. A detailed analysis needs to be conducted before selecting a tool. The selection of a tool depends on: 

-      The application and its technology stack to be tested.
-      Detailed testing requirements.
-      Available skill sets in the organization.
-      The investment required.
-      Ease of adoption
-      Ease of scripting and reporting capabilities
-      Usage of tools

Selenium is for automating web browsers for testing purposes. It is  a free, open source tool with a different set of tools, which support test automation through different approaches. As it is an open source technology, it requires a development experience to make the automation tools available. Let us review the most important factors which affect the adoption of Selenium test automation tool.

-      Scope of the project: It is extremely important to have a very clear vision of the framework and the expectations. 

-      Complexity of the application: The size of the application needs to be determined based on the number of tests that has to be automated. This definition may differ from the perspective of a group or an individual. 

-      Supporting tools and technologies required: Once the automation framework is identified, based on the requirements, the required tools need to be identified. Further the dependencies and implications need to be understood. Selenium alone is not sufficient to complete test automation. There are other related tasks like reporting and log tracking, etc. For these separate tools are required, which need to be integrated with the framework.


-      Implementation of the Framework: In addition to just scripting, there are many other requirements like reading data, tracking and  reporting results, tracking logs, triggering scripts based on input conditions etc., which needs a framework in place. Web applications are not simple and involve a lot of tools and technology. Selenium may not be strong enough to build a strong framework based on the third party tools required for completing the testing requirements.

-      Learning and Training: Implementing any new software requires sufficient time for learning and training purposes. Selenium testing involves learning a programming language. The time involved, the resources available, the investment required in this phase is a deciding factor in the adoption of  Selenium 

-      Environment Setup: This deals with set up the code in the test environment and production environment, writing scripts and creating property files for tracking the environment and credentials.

Conclusion

The issues discussed above hold true for almost all automation frameworks under consideration. Selenium is mainly used for functional aspects of web based applications on a wide range of browsers and platforms. However, Selenium is not limited to testing only, it can emulate user actions and help to automate monotonous tasks in testing web applications. Considering the diverse composition and flexibility of the automating framework, after considering all the pros and cons, it is an investment worth making.

Thursday 17 December 2015

How does Selenium help with continuous delivery?



Continuous delivery is an approach which ensures that any version of the system is releasable at any given time without panic. It aims at frequently and  faster delivery. The concept of continuous delivery is tightly related to continuous integration. It is a software development practice by which the team members integrate their working modules more frequently, resulting into multiple integrations per day. The goal here is to put the customers in control of the software releases. 



Continuous delivery can be achieved by 

- establishing a collaborative work culture among all the people involved in the delivery process

- and by automating all the possible phases of the delivery process. 

One such important phase of a continuous delivery process is continuous testing. Continuous testing can be considered as the bottle neck for continuous delivery. It involves applying the methods and practices of agile development into the testing process. Automating this phase of testing has its own advantages, which improves the efficiency of the software in the long run. 

There are some major advantages of automated testing mainly related to continuous reuse of the test scripts. Selenium is one of the most widely used open source automated testing solution. It provides a suite of tools by which web browsers can be automated across many platforms. It can be used in conjunction with continuous integration for automated testing of the web application via test scripts. It provides the following features:

- Continuous regression testing
- Faster feedback to developers.
- Unlimited iterations of test case execution
- Supports Agile and other extreme development methodologies.
- Defect reporting

The entire Selenium testing suite is a rich set of test functions, which are highly flexible, providing the ability to compare expected test results with the actual behavior of the application. By integrating Selenium scripts for testing, development team can achieve end-to-end software testing.  As it supports a number of programming languages, it can be easily integrated into the existing IDEs for the continuous delivery process. Tests can be run in parallel, user activities can be recorded which can be played back later. They can also be saved as exportable files for later use. 

The implementation of Selenium in a development process can vary and follow different pathways to ensure that the best user experience is delivered. It starts within the development process where developers use it to test the functionality of their code. Once these codes are ready for pre production, dedicated teams for Quality Assurance use these test scripts and modify the parameters as required. In the production environment, the operations team can reuse these tests for acceptance testing and other post production monitoring. Thus, Selenium provides an effective test strategy incorporating all elements of test optimization further accelerating continuous integration, delivery and deployment.

Conclusion

Selenium components provide a very powerful mechanism for browser test automation. It allows multi-browser, multi OS Testing. Thus, it helps to achieve important improvements and enhancements in productivity.

Monday 30 November 2015

An Introduction to Selenium



Jason Huggins created Selenium in 2004. He was an engineer in Thoughtworks. There he was working on a web application which required regular testing. Realizing the inefficiency of repeated manual testing, he created 'JavaScriptTestRunner', a program in JavaScript which could control the browser actions. He made it open source considering that more web applications could be automated using this program. 



The Name:

Another framework for automated testing popular during those days was QTP, by the company Mercury Interactive. As Selenium is an antidote for Mercury, 'JavaScriptTestRunner' was hence renamed Selenium, as a competitor for Mercury Interactive, on pure grounds of wit.

Apart from being an open source tool, another factor that makes it popular is the multiple programming languages supported by it. It supports, Java, C#, PHP, Python, Perl and Ruby. Most of the popular browser vendors have also initiated processes to make their browsers compatible to it.

The Components:

Selenium is a combination of the following tools:

1.   Selenium IDE(Integrated Development Environment): Shinya Kasatani from Japan developed this IDE and donated it to the Selenium project on 2006. It is a Firefox Extension which automates the browser using a record and playback feature. It records user actions and then saves them as a reusable script in one of the programming languages. This exported file can be later on executed repeatedly.

2.  Selenium RC(Remote Control) also known as Selenium 1: Testers who were using Selenium Core required to install the whole application and the web server in their local setup.  To overcome this, Paul Hammant created Selenium RC, which acted as HTTP proxy which made the browser believe that the Selenium Core and the webserver come from the same domain.

3.  Selenium Web Driver: In 2006, the browsers and web applications were becoming more restrictive with running Javascript programs. Simon Stewart then created Selenium WebDriver which was the first cross platform testingframework. It could control the browser from the Operating System level. In 2008, Selenium RC was merged with Web Driver to form Selenium 2. WebDriver supports HTMLUnitbrowser which is generally used for functional testing.

4.  Selenium Grid: Patrick Lightbody developed Selenium Grid to minimize the time required for test execution. It captured browser screenshots and performed parallel tests on multiple browsers on multiple machines. It controlled multiple environment from a central location.  Thus, for a large test suite, or a slow running test suite, Selenium Grid divides the test suit and runs different tests on different machines at the same time. This parallel processing greatly minimizes the time required to execute the entire test suite.

Basic Concept:

Selenium works on a Page Object Model  which is an object oriented library that brings object oriented programming into test scripts. Here, web pages are the classes and its elements are assumed as  its variables. All the user interactions are treated as methods in this class. Page Factory in Selenium is an extension to  the Page Object Model. It initializes the web elements in the web page classes. The elements can be used only after their initialization.

Conclusion:

Selenium has been made to be very flexible. New functionalities can be added to both the test script and the framework to customize test automation. Also, as it is an open source software, its source code can be easily downloaded and modified as per requirement.