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.



































Wednesday 30 September 2015

Challenges faced while executing Selenium Scripts



Selenium is an open source automated tool for testing web applications. It provides an extensive library of test functions. It interacts with web browsers using programming languages such as PHP, Java, .Net, C#, Ruby, Perl etc. Tests in Selenium can be scripted in HTML tables or using these programming languages. Selenium helps to locate UI elements. It defines the methods of comparing pre-calculated test results with the actual real time application functions. It supports almost all of the major web browsers and can be deployed on Linux, Windows and Macintosh. Selenium is mainly preferred for User Acceptance Testing.


Components of Selenium:

There are four components of Selenium. They can be used individually or combined with each other to create automated testing solutions for web applications. These four components can be defined as follows:

-      Selenium IDE: Selenium Integrated Development Environment is a plugin for Firefox that record the user interactions in the applications for formulating test cases.
-      Selenium Remote Control: Creates test cases using the supported programming languages.
-      Selenium WebDriver: It is an extension of Selenium RC. It executes the commands directly in the browser and generates results.
-      Selenium Grid: This tool helps to run test cases across multiple browsers and operating systems simultaneously minimizing the test execution time.

Challenges of Selenium Script Execution:

-      Selenium is unable to record the pop-ups which causes issues in executing Selenium scripts. This is handled by applying a getAlert() function. Before running a test script, a WebDriver script that can handle alerts needs to be imported. This script defines the following commands: 

void  accept(),
void dismiss(),
getText(),
void sendKeys(String stringToSend)

-      Events are not triggered when values change: Selenium is unable to trigger events automatically with changing values. Hence the command:
Selenium.FireEvent(cmbCategory, “onchange”);
is used where, cmbCategory is the object on which the event is fired; onchange is the event name.

-      Synchronization issues lead to timeouts: To solve this issue, a function needs to be created to check the presence of the element. This will need to take the object locator as the parameter and return true if the object is found. The following function can be used:
IsElementPresent(locator)
Thread.Sleep

-      SSL Issues: Selenium Tests may face issues with Secure Socket Layer(SSL). This issue can be solved by trustAllSSLCertificates.
For browsers excluding firefox:
C: > java -jar c:\Selenium\selenium-server2.14.0.jar. –trustAllSSLCertificates
For firefox:
C:> java -jar c:\Selenium\selenium-server2.14.0.jar. -firefoxProfileTemplate /C:\Selenium\ Profile

-      Flash App Testing: Flex Monkium can be used for automation of flash apps. The source code of the application is created by Flex Monkium and compiled with swc files. The app and the IDE are then connected and the tests are recorded with the IDE. 

-      Internet Explorer Launch Error: The zoom level in the browser should be 100% by default.

-      Error occurs when Selenium Webdriver is run on a new Windows machine. This can be solved by setting the following parameters:

DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(caps);

Some additional issues

1.    With change in the application design, the verification code also changes.
2.    Sometimes the application stops before the verification code is executed. When the verification code is rerun, the new verification code is rejected and the script fails to execute.
3.    Compatibility issues occur between Selenium and components of Java.
4.    The Element-ID of the data in the submitted application changes regularly.


The various components in designing Selenium test cases are as follows:

-      Page Object Model
-      Log4jLogging
-      Parameterizing using Excel
-      Exception Handling
-      Multi Browser testing
-      Capture videos
-      Capture Screenshots.

Conclusion:

The amount of test cases tend to grow with increasing complexity of the web application. Regression testing becomes more complex and requires longer testing time. This necessitates the development of test automation. Selenium reduces the cost of Functional Testing significantly over QTP.