Friday, January 15, 2016

How to Design Automation Framework using Page Object Model using Selenium With Java

How To add Reference in IntelliJ IDE

1. Open the Project in Intellij IDE.
2. Add a lib directory in project structure.
3. Add Selenium jar file in lib folder.
4. Right click on lib folder and click on "Add as library".
5. It will be reflected into External libraries.


If we don't have jar files in our local drive we can download from below maven web sites .

So I am going to add few dependency of cucumber .

1. Go to http://mvnrepository.com/ and search your jar files.
    i.e. cucumber-java and cucumber-junit.
2. Select version and click on .
3. Download the jar. If you are using any build tool like maven/gradle then click on tab "Gradle"
4. Copy the whole text and paste in dependencies section of build.gradle file.
5. Add Jar files in lib folder ,right click and add as a library.


Next topic is to choose pattern to design the Automation Framework . There are so many pattern are available bur we are supposed to select wisely. Here I am just listing down all the available pattern in other post I will go to the details of each pattern and where its applicable.

1. Page Object pattern.
2. Advanced Page Object pattern.
3. Façade Design Pattern in Automation Testing
4. Singleton Design Pattern in Automation Testing.
5.Fluent Page Object Pattern in Automation Testing.
6. Strategy design pattern in Automation Testing
.....


 

How to Design Automation Framework using Page Object Model using Selenium With C#

WIP..

How to identify and design a Class

This is an art; each designer uses different techniques to identify classes. However according to Object Oriented Design Principles, there are five principles that you must follow when design a class,

SRP - The Single Responsibility Principle -
A class should have one, and only one, reason to change.

OCP - The Open Closed Principle -
You should be able to extend a classes behavior, without modifying it.

LSP - The Liskov Substitution Principle-
Derived classes must be substitutable for their base classes.

DIP - The Dependency Inversion Principle-
Depend on abstractions, not on concretions.

ISP - The Interface Segregation Principle-
Make fine grained interfaces that are client specific.

For more information on design principles, please refer to Object Mentor.
Additionally to identify a class correctly, you need to identify the full list of leaf level functions/ operations of the system (granular level use cases of the system). Then you can proceed to group each function to form classes (classes will group same types of functions/ operations). However a well defined class must be a meaningful grouping of a set of functions and should support the re-usability while increasing expandability/ maintainability of the overall system.
In software world the concept of dividing and conquering is always recommended, if you start analyzing a full system at the start, you will find it harder to manage. So the better approach is to identify the module of the system first and then dig deep in to each module separately to seek out classes.

A software system may consist of many classes. But in any case, when you have many, it needs to be managed. Think of a big organization, with its work force exceeding several thousand employees (let’s take one employee as a one class). In order to manage such a work force, you need to have proper management policies in place. Same technique can be applies to manage classes of your software system as well. In order to manage the classes of a software system, and to reduce the complexity, the system designers use several techniques, which can be grouped under four main concepts named Encapsulation, Abstraction, Inheritance, and Polymorphism. These concepts are the four main gods of OOP world and in software term, they are called four main Object Oriented Programming (OOP) Concepts. 



Association is a (*a*) relationship between two classes, where one class use another. But aggregation describes a special type of an association. Aggregation is the (*the*) relationship between two classes. When object of one class has an (*has*) object of another, if second is a part of first (containment relationship) then we called that there is an aggregation between two classes. Unlike association, aggregation always insists a direction.


In this case I can say that University aggregate Chancellor or University has an (*has-a*) Chancellor. But even without a Chancellor a University can exists. But the Faculties cannot exist without the University, the life time of a Faculty (or Faculties) attached with the life time of the University . If University is disposed the Faculties will not exist. In that case we called that University is composed of Faculties. So that composition can be recognized as a special type of an aggregation. 











So in summary, we can say that aggregation is a special kind of an association and composition is a special kind of an aggregation. (Association->Aggregation->Composition)


Thursday, January 14, 2016

How to Implement Selenium Grid

       •Execute multiple tests in parallel.      
 •Faster verification process.
 •The selenium-server-standalone package includes the Hub, WebDriver, and legacy RC needed to run the grid.



                  Setup

Step 1: Start the hub.

Step 2: Start the nodes.
Step 3: Execute tests.

Step 1: Start the hub


HUB:The Hub is the central point that will receive all the test request and distribute them the right nodes.

Open a command prompt and navigate to the directory where you copied the selenium-server-standalone file. Type the following command:
java -jar selenium-server-standalone-2.14.0.jar -role hub

The hub will automatically start-up using port 4444 by default. To change the default port, you can add the optional parameter –port

When you run the command. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Step 2: Start the Node


Regardless on whether you want to run a grid with new WebDriver functionality, or a grid with Selenium 1 RC functionality, or both at the same time, you use the same selenium-server-standalone jar file to start the nodes.


java -jar selenium-server-standalone-2.14.0.jar -role node  -hub http://localhost:4444/grid/register


Note: The port defaults to 5555 if not specified whenever the "-role" option is provided and is not hub.


java -jar selenium-server-standalone-2.14.0.jar -role node  -hub http://localhost:4444/grid/register -port 5556

Creating Batch Files:



 Grid Setup :
start LaunchHub.bat
ping -n 10 localhost
start IENode.bat
ping -n 10 localhost
start LaunchChromeNode.bat
ping -n 10 localhost
start LaunchFireFoxNode.bat
ping -n 10 localhost



launch Hub :

cd C:\
cd javaserver
set HUB_URL=http://172.16.148.29:4444/grid/register
set SELENIUM_VERSION=2.42.2
set browsertimeouttime=800000
Set newsessiontimeout=10000

start java -jar selenium-server-standalone-%SELENIUM_VERSION%.jar -role hub

For Chrome: 

cd C:\
cd JavaServer
set HUB_URL=http://172.16.148.29:4444/grid/register
set SELENIUM_VERSION=2.42.2
set portNumber=5567
set CHROME_DRIVER_LOC="C:\Drivers\chromedriver.exe"
java -jar selenium-server-standalone-%SELENIUM_VERSION%.jar -role webdriver -hub http://172.16.148.29:4444/grid/register -port 6257 -browser browserName=chrome,platform=WINDOWS,maxInstances=5  -Dwebdriver.chrome.driver=%CHROME_DRIVER_LOC%

IE Node:

cd C:\
cd JavaServer
set HUB_URL=http://172.16.148.29:4444/grid/register
set SELENIUM_VERSION=2.42.2
set portNumber=5565
set IE_DRIVER_LOC="C:\Drivers\IEDriverServer.exe"
java -jar selenium-server-standalone-%SELENIUM_VERSION%.jar -role webdriver -hub http://172.16.148.29:4444/grid/register -port 6256 -browser browserName=iexplorer,platform=WINDOWS,maxInstances=5 -Dwebdriver.ie.driver=%IE_DRIVER_LOC%

C# Code to intialize the Remote web Driver 


            switch ("Chrome")
            {

                case "firefox":

                    capabilities = DesiredCapabilities.Firefox();
                    webDriver = new RemoteWebDriver(new Uri(" http://localhost:4444/wd/hub"), capabilities);

                    break;

                case "iexplore":
                    capabilities = DesiredCapabilities.InternetExplorer();
                    capabilities.SetCapability("platform", "WINDOWS");
                    capabilities.SetCapability("browserName", "iexplorer");
                    //  capabilities.(
                    webDriver = new RemoteWebDriver(new Uri(" http://localhost:4444/wd/hub"), capabilities);
                    webDriver.Navigate().GoToUrl("www.google.com");
                    break;

                case "Chrome":
                     capabilities = DesiredCapabilities.Chrome();
                   capabilities.SetCapability("platform", "WINDOWS");
                    capabilities.SetCapability("browserName", "chrome");
                    capabilities.SetCapability("Dwebdriver.chrome.driver", @"C:\Drivers\chromedriver.exe");
                    webDriver = new RemoteWebDriver(new Uri(" http://localhost:4444/wd/hub"), capabilities);
                    webDriver.Navigate().GoToUrl("http://www.seeques.com/25202262/chrome-on-remote-webdriver-via-grid-failed-to-start.html");

                    webDriver.Navigate().GoToUrl("www.google.com");
                    break;
            }

            return webDriver;
Note:
1.        Driver version should be based on your OS bit(32 or 64 bit machine)
2.       Node configuration and C# code configuration should match.( Otherwise  new session exception will come)

Testing Types,Test Design Techniques and other Manual Testing Concepts

What is severity and priority of bug? Give some example.

Priority: concern with application from the business point of view.
It answers: How quickly we need to fix the bug? Or How soon the bug should get fixed?
Severity: concern with functionality of application. It deals with the impact of the bug on the application.
How much the bug is affecting the functionality of the application?
Ex.
  • High Priority and Low Severity:
    Company logo is not properly displayed on their website.
  • High Priority and High Severity:
    Suppose you are doing online shopping and filled payment information, but after submitting the form, you get a message like "Order has been cancelled."
  • Low Priority and High Severity:
    If we have a typical scenario in which the application get crashed, but that scenario exists rarely.
Low Priority and Low Severity:
  • There is a mistake like "You have registered success" instead of successfully, success is written.


 What is difference between Smoke testing and Sanity Testing?

The difference between smoke and sanity testing is described below:
  • Sanity testing is performed when new build is released after fixing bugs where as smoke testing is performed to check the major functionalities of the application.
  • Sanity is performed by the tester or the developer but smoke testing can be performed by the tester or developer.
  • Smoke testing is performed earlier where as sanity is performed after the smoke testing.
  • Sanity testing is narrow and deep approach of testing and smoke testing is focused testing based on major functionalities.
What is difference between Retesting and Regression testing?

The difference between Retesting and Regression testing are below:
  • Retesting is done to verify defects fixes where as regression is perform to check if the defect fix have not impacted other functionality that was working fine before doing changes in the code.
  • Retesting is planned testing based on the defect fixes listed where as regression is not be always specific to any defect fix. Also regression can be executed for some modules or all modules.
  • Retesting concern with executing those test cases that are failed earlier whereas regression concern with executing test cases that was passed in earlier builds.
  • Retesting has higher priority over regression, but in some case retesting and regression testing are carried out in parallel.
Explain bug life cycle.

Bug Life Cycle:

  • When a tester finds a bug .The bug is assigned with NEW or OPEN status.
  • The bug is assigned to development project manager who will analyze the bug .He will check whether it is a valid defect. If it is not valid bug is rejected, now status is REJECTED.
  • If not, next the defect is checked whether it is in scope. When bug is not part of the current release .Such defects are POSTPONED
  • Now, Tester checks whether similar defect was raised earlier. If yes defect is assigned a status DUPLICATE
  • When bug is assigned to developer. During this stage bug is assigned a status IN-PROGRESS
  • Once code is fixed. Defect is assigned with FIXED status.
  • Next the tester will re-test the code. In case the test case passes the defect is CLOSED
  • If the test case fails again the bug is RE-OPENED and assigned to the developer. That’s all to Bug Life Cycle.

What is alpha and beta testing?

Alpha testing: is performed by the IN-House developers. After alpha testing the software is handed over to software QA team, for additional testing in an environment that is similar to the client environment.
Beta testing: It is performed by end user. So that they can make sure that the product is bug free or working as per the requirement. IN-house developers and software QA team perform alpha testing. The public, a few select prospective customers or the general public performs beta testing.

What are test driver and test stub and why we need them?
  • The Stub is called from the software component to be tested. It is used in top down approach.
  • The driver calls a component to be tested. It is used in bottom up approach.
  • Both test stub and test driver are dummy software components.
We need test stub and test driver because of following reason:
  • Suppose we want to test the interface between modules A and B and we have developed only module A. So we cannot test module A but if a dummy module is prepare, using that we can test module A.
  • Now module B cannot send or receive data from module A directly so, in these cases we have to transfer data from one module to another module by some external features. This external feature used is called Driver. 
What is difference between QA, QC and Software Testing?

Quality Assurance (QA): QA refers to the planned and systematic way of monitoring the quality of process which is followed to produce a quality product. QA tracks the outcomes and adjusts the process to meet the expectation.

Quality Control (QC): Concern with the quality of the product. QC finds the defects and suggests improvements. The process set by QA is implemented by QC. The QC is the responsibility of the tester.

Software Testing: is the process of ensuring that product which is developed by the developer meets the user requirement. The motive to perform testing is to find the bugs and make sure that they get fixed.


What are verification and validation and difference between these two?
Verification: process of evaluating steps which is followed up to development phase to determine whether they meet the specified requirements for that stage.

Validation: process of evaluating product during or at the end of the development process to determine whether product meets specified requirements.
Difference between Verification and Validation:

  • Verification is Static Testing where as Validations is Dynamic Testing.
  • Verification takes place before validation.
  • Verification evaluates plans, documents, requirements and specifications, where as Validation evaluates product.
  • Verification inputs are checklist, issues list, walkthroughs and inspection, where as in Validation testing of actual product.
  • Verification output is set of documents, plans, specifications and requirement documents where as in Validation actual product is output.

                                        Test Design Techniques

1) Boundary value analysis: is software testing technique in which test cases are designed to include representatives of boundary values in and out of a given range.

Example:When ever the engineers need to develop test cases for a range kind of input then they will go for boundary value analysis .Which describes to concentrate on the boundary of the range.


LB-1  LB LB+1   MV UB-1 UB+1


2) Equivalence partitioning: also, called Equivalence Class Partitioning is a software testing technique that divides the given condition into partitions and one input data from each partition can be chosen for testing.


Example:When the test engineers need to develop test cases for a feature which has more number of validation then one will go for equableness class partition.Which describe first divide the class of inputs and then prepare the test cases.


Develop the test cases for Email test Box whose validations are as follows.


Requirements:

1. It should accept Minimum 4 characters maximum 20 characters.
2. it Should accept only small character.
3. It should accept @ and _ special symbols only.

Boundary Value Analysis:


LB-1 LB LB+1  MV      UB-1    UB     UB+1

3ch 4ch   5ch    12ch    19ch    20ch   21ch

Equavlance Class :


valid                                       Invalid


4char                                       3char

5char                                       21char
12char                                      A-Z
19char                                      0-9
20 char                                      All the special character apart from @ and _
a-z                                             Alpha numeric
@                                              Blank space
_                                                dismal number            


3) State transition testing: is a black box testing technique, which can be used to design test cases for a system that acquires finite number of states and can transit from one state to another upon specific events.

4) Error Guessing: is a technique where experience of a tester is used to find the errors or part of application with highest possibility of finding errors. This is skill-based technique without any rules.
5) Use case testing: In this technique, use cases/scenarios are used to write the test cases. Interaction of users and system is described in a use case.
Some more test design techniques:
6) Statement coverage
7) Condition Coverage
8) Exploratory testing

9) Decision Table : Use for logical coverage and we uses data flow diagram.









How to Kill all the Open Browser

We can use using System.Diagnostics namespace using C#.


public static void CloseAllBrowsers()
        {
            List<string> browserList = new List<string>() { "iexplore", "chrome", "firefox" };
            Process[] process = Process.GetProcesses().Where(x => browserList.Contains(x.ProcessName))
                .ToArray();
                

            foreach (Process proc in process)
            {
                proc.Kill();
                while (!proc.HasExited) { }
            }
        }

How to Set Up Jenkins CI Server with TestNG and Gradle plugin

Download and installation

  1. Download Java .war file from Jenkins-ci.org








  1.   Open command prompt as administrator
  2.   Run the following command to start Jenkins service                                                                      Java –jar Jenkins.war                                                                                                                   Note:  You have to be in the same path as where the .war file was downloaded to run the command
  3. By default, Jenkins runs on port 8080.
  4.            Once the service is started, open a browser and hit localhost:8080
  5.  . .     If there is any other service, using the 8080 port already then Jenkins will not run or open.
  6.      .    In that case, change the port for Jenkins in command prompt by running the following command.
  7.         Java -jar Jenkins.war –httpPort=909
  8.          After this launch browser and hit localhost:<portNo.> where <portNo> is the port given by you in the command                                                                                                                                   The Jenkins interface should load in the browser as shown below:

Plugin installation

1.       Click on Manage Jenkins link
2.       Click on Manage Plugins in the following page:











1.       Navigate to ‘Available’ tab
2.       Search for ‘TestNG , Gradle , GitHub  in the search bar or scroll down to ‘External Site/Tool Integrations’ section
3.       Select the All the required Plugin checkbox and click on ‘Download now and install after restart’
4.       Once you get a success message, close the browser and .cmd prompt
5.       Repeat steps 2-8 to restart Jenkins for the plugin to be activated
6.       To verify if the plugin is installed correctly, navigate to Manage Jenkins > Manage Plugins > Installed tab and check if TestNG, Gradle , GitHub plugin is displayed and ‘Enabled’ checkbox is ticked




     Creating Job

1.       On the main dashboard, click on ‘create new jobs’
2.       The following options are displayed:











·         Provide a name for the job and select appropriate job.
·         To run a Java Selenium based project, a freestyle project should suffice.
·         We can also select ‘Build multi-configuration project’ if we are configuring the job to run for multiple configurations, environments etc.
1.       In the configuration window that gets displayed, provide a meaningful description
2.       Scroll down to ‘Build’ section
3.       Setting GIT repository and branch.













S   Setting Build trigger Time:

     



    Invoking Gradle Section:












            In the ‘Post-build Actions’, click on ‘Add post-build action’ button to add several actions to be done after triggering the job
·         Add ‘Archive the artifacts’. Provide the location of the TestNG report HTML and XML files.
·         Add ‘Incorporate TestNG Results’. Select both the check box options to display trend graphs of average response time and error rate %.











1.       Save the job
2.       Run:  Go to Jenkins home page. Search created job open it and click on “Build Now” link.

     

   Running Jenkins slave on different machine

By default, Jenkins will trigger the job on the same machine as the installation. So when a job is triggered, it will use the same machine’s CPU and memory. This can lead to choking when multiple jobs are triggered for different configurations/environments.
In order to avoid this, we can configure Jenkins Slaves. In other words, we can program Jenkins to run the jobs on other machines (which would become ‘slaves’ to the ‘master’ system). There is no need to install Jenkins on the slave machines.
Steps can be found here.

   Viewing results

Navigate to the job created and click on Build Now.
Once the build has completed successfully, navigate to the build number and click on it.

Configuration Transform

Configuration Transformation gives the ability to run our project with multiple configuration for different build environment which have different connection string i.e. databases credentials .....  Multiple configuration files for different environments (e.g. dev/staging/production). 

We can use different tools to create configuration files.
 1. Slow Cheetah.
 2. Configuration Transform Extension

Step to Create Configuration Files.

1. Add App.config file to project
2. Right click App.config file in solution explorer and select Add Config Transforms
http://visualstudiogallery.msdn.microsoft.com/site/view/file/73848/1/package_preview.png
Notice that you have new App.$$$.config files under App.config
http://visualstudiogallery.msdn.microsoft.com/site/view/file/73849/1/app_configs.png
corresponding to build configurations
http://visualstudiogallery.msdn.microsoft.com/site/view/file/73850/1/configuration_manager.png
3. Set the source App.config
XML
<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
  <appSettings> 
    <add key="Environment" value=""/> 
  </appSettings> 
</configuration>
4. Set the target App.Debug.config
XML
<?xml version="1.0"?> 
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> 
  <appSettings> 
    <add key="Environment" value="Debug" xdt:Transform="Replace" xdt:Locator="Match(key)"/> 
  </appSettings> 
</configuration>
5. Build project.

Linked Configs Step by Step Instructions:
1. Add link(Existing Item...) App.config file to project
2. Right click link App.config file in solution explorer and select Add Config Transforms
http://visualstudiogallery.msdn.microsoft.com/site/view/file/73848/1/package_preview.png
Click Yes button, if you select No button concrete(not linked) config files will be created which suits certain use case
http://i1.visualstudiogallery.msdn.s-msft.com/579d3a78-3bdd-497c-bc21-aa6e6abbc859/image/file/113321/1/add_as_linked_configs_message_box.png
Notice that you have new App.$$$.config files under App.config
http://visualstudiogallery.msdn.microsoft.com/site/view/file/73849/1/app_configs.png
corresponding to source App.config files
3. Continue with step 3 above... 


Trouble Shooting: After doing this code will not debug . For This we are supposed to unload .csproj file and need to remove  is Transform File  tag. And  below (4th one heading code in .cs 


. Bind App.*.config files to main App.config
Find the project file section that contains all App.config and App.*.config references. You'll notice their build actions are set to None:
<None Include="App.config" />
<None Include="App.Debug.config" />
<None Include="App.Release.config" />
First, set build action for all of them to Content.
Next, make all configuration-specific files dependant on the main App.config so Visual Studio groups them like it does designer and codebehind files.

Replace XML above with the one below:
<Content Include="App.config" />
<Content Include="App.Debug.config" >
  <DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config" >
  <DependentUpon>App.config</DependentUpon>
</Content>
4. Activate transformations magic
In the end of file after
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
and before final
</Project>
insert the following XML:
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
    <!-- Generate transformed app config in the intermediate directory -->
    <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
    <!-- Force build process to use the transformed configuration file from now on. -->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="app.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

Now you can reload the project, build it and enjoy App.config transformations!