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.

Tuesday 8 September 2015

Selenium Implementation – A conceptual Overview



Selenium is one of the most trending tools currently in the market for automated cross browser testing of web applications. There is no specific guideline for implementing Selenium, however, there are several methodologies that can be followed to successfully leverage the features of Selenium.



Evaluate the Standards of the Organization:

For implementing a new software practice in an organization, the new software tool needs to be tested in terms economic and technical feasibility for the organization. 

Before implementing Selenium, its pros and cons should be well evaluated against the organization’s requirements. 

Selenium is only used to test web applications. The entire coverage provided by Selenium testing should be documented and well communicated to the team who will be using it. 

Selenium supports a large set of popular programming languages. However, if the implementation team uses a programming language that is not supported by Selenium, they will experience difficulties in the transition. 

Implementing a Framework 

The most naive way to use Selenium is to code a script for each test. This may seem as a very potential way of achieving full test coverage. But this same methodology may lead to future standstills due to a number of reasons.  Tests should stable, consistent, easily understandable and that which can be changed easily. This requires a framework to be in place. While implementing a framework can be time consuming, it will pay off enormously in the future.

Code Standardization

Conforming to an existing naming and documentation convention is an important aspect of any automation process. It is equally important to develop codes that can be reused. It can be a constructive initiative to train the automation developers on the fundamentals of software development techniques.

Externalization of the Configuration

The most common failure in software automation is when a new software build is released, the already developed automation scripts fail to test them successfully. To avoid such inconsistencies, the automated tests should be consistent and adaptable. This can be achieved in the following ways:

-          Making the automation self-aware by anticipating dynamic functionalities and accommodating them whenever possible.

-          Configurable values should be exposed whenever possible. A majority of the maintenance issues is caused by tweaking object identification. This is because Selenium provides no object identification strategy at all.

-          The naming conventions and the other coding standards should be strictly followed.  A failure to adhere to these conventions may lead to hours of debugging efforts.

-          Hard coding can seem easy and is mainly practiced by the ignorant or novice programmers. Specifying fixed values which are potentially configurable in the future, call for changes in the code for maintenance in the future.

Logging and Reporting

Logs and reports help to determine the pass or failure of tests, determine test coverage, debug test scripts, collect the debug report and access screen captures as well. Selenium lacks in logging and reporting. Without results and reports, test automation is of no use. 

While implementing these features, the best approach is to separate the concept of logging and reporting. Logging should be reserved for technical details while reports serve better as HTML or other portable readable format. Reports should also contain the execution details of the test cases and the environment in which they were run.

The client will always ask for the test report and it should be ensured that the test automation serves its purpose for which it was implemented in the first place.

Conclusion:

Which part of the application needs to be tested, the user expectations, project timeline, priorities determined by the project managers are contributing factors in determining the implementation practices. Thus, the best implementation practices for Selenium may be different for different projects and requires careful consideration of all the aspects.