Thursday, 26 February 2015

Automation Testing Parallelism-Different Approaches

Agenda:Achieving parallelism with different Approaches.

How:We can achieve parallelism using multiple ways:


1. Through TestNg: Using Testng.xml we can achieve parallelism.


<suite name="Parallel test runs" parallel="tests" thread-count="2">


<test name="TestOne">

    <classes>
        <class name="com.sample.TestOneExample" ></class>
    </classes>
</test>

<test name="TestTwo">

    <classes>
        <class name="com.sample.TestOneExample" ></class>
    </classes>
</test>
</suite>

2. Through Maven and JUnit/TestNg: Using Maven and JUnit 4.7 onwards / TestNg you can run your tests in parallel with the help of surefire Plugin.For achieving this you must set the parallel parameter, and change the threadCount attribute in pom.xml. 


<plugins>

    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <parallel>methods</parallel>
            <threadCount>10</threadCount>
          </configuration>
      </plugin>
    [...]

</plugins>


3. Using Gradle:


Once we apply the Java plugin we can run our tests with the test task,we can also run tests in parallel though by default it runs sequentially.


We need to configure "maxParallelForks" property to more a number more than 1,By default its "1".

The "forkEvery" property specifies the maximum number of test classes to execute in a test process,so that your test process will not be using a very large heap,and can be restarted after it has executed specific number of test classes.The default is to execute an unlimited number of tests in each test process.


4. using MbUnit for C#-Selenium:


For .net Application while working with C# and Selenium if We use NUnit then we can not achieve Parallel Testing,so we can achieve parallelism using MBunit,which provides a way to run the Automation Scripts parallely  in the following way:


In the Assembly file we need to mention the below lines:


[assembly: DegreeOfParallelism(2)]

[assembly: Parallelizable(TestScope.All)]

Here "2" is the number of instances of browser.


5. Using NOSE for Python-Selenium:


In Order to run Test Parallel for Python -Selenium we can use nose:


After installing NOSE we can write the following :



nosetests --processes=2

this means you are going to run 2 tests at the same time. If you get TimedOutException  then you can increase the TimeOut  for the Process as:



nosetests --processes=2 --process-timeout=10000


By this way We can achieve parallel testing using Selenium and with Multiple Unit Test Frameworks.





Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos




Saturday, 14 February 2015

WebDriverJS -Selenium Runner On Node with Promise Mechanism

Agenda Of the Blog: Introduction of  WebDriverJS (not WebDriver)-A Selenium Runner on Node

What is WebDriverJS: A selenium Runner on NODE,Highly extendible,compatible with all common JavaScript Testing Framework,hugely used for Angular JS application.

WebDriverJS & WebDriver are Same:NO.
The above two are related but not the same.

How both are related but not the same:
A. WebDriverJS is the JavaScript Language bindings for WebDriver,It runs on NODE,It uses an own chain API to execute and handle Asynchronous Calls in specific and in right order.

B.In Addition to NODE, WebDriverJS may also be used directly in the browser by JSonWire Protocol Communication as the Other Language binding of WebDriver(i.e Java,Python,Ruby etc. etc.).One of The Advantages for running WebDriverJS in the browser is that it can control the browser running the Script,as long as The URL for the server and Session ID for the browser are known.

C.Unlike other language bindings,which all provide blocking APIs,WebDriverJS is purely Asynchronous,In order to track handle exceptions WebDriverJS makes extensive use of "Promises."
While there are various promise implementations are there for JS,the WebDriverJS promise is based on the proposal from CommonJS,which defines a promise as any object with a "then" function property.

Asynchronous Computation:Its a concept of passing a callback function that is called when the result becomes available at some later time ,rather than a function returning a result value immediately.

Example:
Browser Offers a primarily single thread runtime environment,so if you request your browser to fetch some information which takes 3 seconds,then the browser will not be able to do anything else than to wait for HTTP call.

So, Asynchronous call came to the picture to overcome this kind of scenarios.

Concept of Promise:The promise object is used for deferred and Asynchronous computation.

A promise is in one of three different states:
1.Pending: Promise's initial state.
2.Fulfilled: Representing promise's state of successful operation.
3.Rejected: Represents promises's failed operation.

How WebDriverJS works with Asynchronous calls:
WebDriverJS uses a wrapper for Promise called ControlFlow Class

A.It maintains a list of scheduled actions
B.The exposed functions in WebDriverJS do not actually do their stuffs,they just push the required actions into ControlFlow Class.

Example:
With Simple WebDriver with Java we write :

driver.get("www.xyzabc.com");
driver.findElement(By.id("k1")).sendKeys("WebDriver");


Using Promise we need to write the same like:

driver.get("www.xyzabc.com").   then(function() {
     return driver.findElement(By.id("k1"));
   }).
   then(function(k1) {
     return k1.sendKeys("WebDriver");   }).


By this way WebDriverJS is related with WebDriver,uses Promise,JSON Wire Protocol and handles Asynchronous Calls very efficiently.



Visit for More Automation Related Discussion:


https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos



Sunday, 8 February 2015

GEB-Page Object Modelling with Power Of Selenium WebDriver and Groovy's expressiveness

                            
Agenda of this Blog: Introduction of GEB as a Solution of Browser Automation.

What is GEB: GEB is browser automation solution,which is a wrapper over Selenium WebDriver. It uses:


1. groovy's expressiveness to deal with the Browser Automation.
2. JQuery to deal with the WebElements.
3. Robust Page Object Modelling  Framework.

It can be Integrated with different Unit Test Framework such as JUnit,TestNg,Spock as well as different build tools like Maven,Gradle and CI tool like Jenkins.

Is it Really Useful when we have Selenium for Automation :
The answer to the above is YES, because it comes with few very good features along with it.

1. GEB uses Groovy language which itself is very powerful having features like Closure, GroovyMarkup and GPath support,dynamic and static typing is supported and many more.
2.As it is supported by Groovy,so less coding is required to write automation scripts compared to JAVA.
3. GEB supports JQuery to handle WebElements,so Scripts become more faster.
4.Asynchronous Content Lookup.
5.Selenium API can be used easily if need arises.

Structure of  Framework:

If we are using GEB then generally we follow 3 main building blocks of it:
1.Module:Where we keep our WebElements/Locators/JQuery Contents as static contents.
2.Pages:Place for the re-usable methods of Page/Module functionalities .
3.Specs: Where the Test Classes are kept.

Please refer the below screenshot for the Core framework structure.






Sample of Module given below:




Sample for Page :




GEB provides few methods like "at" which is used to verify whether we are on the stated page or not and "to" method to redirect the driver to the stated page.
If we are in certain page then to access the reusable methods of that page class i.e Page Functionalities we Don't need to create Object for that class,we can simple call the method.

Sample of a Test method :




Geb can be very effective and robust as a solution to the browser Automation.



Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos


Saturday, 7 February 2015

Use of Java Design Patterns In Selenium Framework

                                

Agenda for this blog: To design frameworks for Selenium by using Java Design Patterns.

Why use Design Patterns in Selenium Framework:

As selenium is an open source tool,so Its does not provide a framework along with it unlike other paid tool.So whoever is using Selenium has to write a framework for it.
Now,If you design your framework by using Java Design Patterns It can have multiple strengths:

1.Well structured code base
2.It will be generic and robust.
3.Framework re-usability and maintainability will be very high
4.Enhancements can be done with very little code changes without disturbing the existing Flows.
5.Debugging of Scripts/framework(if any) will be very easier.
6.Framework can be used with ease by the people who are new to Automation

What Type of Design Patterns will be useful for Selenium Framework:
First of all it depends on the requirement for the framework as it varies from Company to company and sometimes project to project,but then also there are some generic scenarios where we can use design patterns like Factory Design Pattern,Abstract Design Pattern,Singleton Design Pattern in the framework.

Which Area of a Generic Framework can be developed using Java Design Patterns:

Scenarios:
1.We are having a requirement to use Local WebDriver,Grid, ThreadDriver, HeadLess Driver,EventDriver,RemoteDriver with Sauce Labs Implementation etc.
so there we can use Factory Design Pattern and along with the above feature if you need multiple browsers like FireFox,Chrome,Safari,IE etc etc. then we can use Abstract Factory Design Pattern.

2.If you want to support Data Handling using xls file ,properties file,csv files etc etc there we can use the Factory Design Pattern.

3.We can configure the configuration Class using Singleton Design Pattern.

HOW:

Find the example for different driver implementation using Factory Design Pattern:

We are Creating an Interface ICurrentDriver which is Implemented by all type of Driver Classes such as ThreadDriver,LocalDriver,RemoteDriver because the implementations are different for each of them.











We can Design another Class Factory which will provide us the Object for the required Driver classes at runtime depending on the need.So we don't need to create and use separate Objects for each of the Driver classes,we will use only Factory class object and can access any of the Driver classes members and fields.




By this way we can use Design Patterns as per the requirement,we can use this concept in case of Handling Data in Selenium Framework.


Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos