Sunday, July 3, 2016

Software Testing Munch: Working with Selenium Grid

Software Testing Munch: Working with Selenium Grid: What is Grid: Selenium Grid  is a part of the  Selenium  Suite that specializes on running multiple tests across different browsers, oper...

Working with Selenium Grid

What is Grid:

Selenium Grid is a part of the Selenium Suite that specializes on running multiple tests across different browsers, operating systems, and machines in parallel.Selenium Grid has 2 versions - the older Grid 1 and the newer Grid 2

Selenium Grid allows the Selenium-RC/Web Driver solution to scale for test suites to be run in multiple environments.

Hub and Node Concept in Grid:

Selenium basically Provides the multiple instances of Selenium Web driver which are running on different OS with different browsers.

We have a common system which is known as a hub where Grid is running and all the Nodes are registered with this Hub.

Nodes which are basically other machine with same or different OS,Browsers. it means a machine with one OS and Browser is known as Node.

Whenever test is started they are basic send to the main HUB and hub check the capabilities that is what machine browser configuration and OS Requested. if that kind of machine or node is registered with hub then execution will start on that machine.




Lets do some exercise to create the Hub and Node:

1. We have to Create the First Hub for Grid
    Download the Server file first from the Location http://www.seleniumhq.org/download/

After downloading this save this file in a particular location , i have saved it in my E Folder.













Now open the Command Prompt and reach to that folder where this Server Jar file is placed 













and then run the below command (Note by default Hub will take 4444 Port)
java -jar selenium-server-standalone-2.53.1.jar -role hub



















Now check that Hub is configured or Not. Open the Browser and call the below URL: http://localhost:4444/grid/console ,Hub is always installed on local host at port 4444. we can change this port also if its not free.





















Click on View Config



















2. Now Next Step would be Registering the Nodes with that HUB.

Register the Node with Grid Hub with the use of below command :
java -jar selenium-server-standalone-2.4.0.jar -role node -hub http://localhost:4444/grid/register

Open the new window of command prompt and reach to that folder where server file is placed and then run the above command to register the nodes


















Now check whether node is register or not. again open the same URL in to the browser "http://localhost:4444/grid/console and you will get the below screen















In the above screen shot maximum 5 nodes has been created and execution could be done on 5 browsers parallel.

3. Configure Nodes-
Now Configure your browser with the Hub node for that you have to execute the below command and at code level you have to set the Capabilities.
Here i am going to configure FireFox Browser with Node.

Open another command window and run the below code

java -jar selenium-server-standalone-2.53.1.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox -port5566

Sometime you will get an error while running the above command and the error would be "Failed to Start SocketListener Port 5566".

To resolve this just change the Port Number and after running you will get the below screen

































To check that Browser is configure properly or not open the given URL in Browser http://localhost:4444/grid/console and you will see below screen.












Now open the eclipse and set the capabilities for firefox browser and test application is open on Grid or not.

import java.net.URL;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;


public class Grids {

 static WebDriver driver;
 static String baseUrl = "http://google.com";
 /**
  * @param args
  * @throws MalformedURLException 
  */
 public static void main(String[] args) throws MalformedURLException {
  // TODO Auto-generated method stub
  
  DesiredCapabilities capability = DesiredCapabilities.firefox();
  capability.setBrowserName("firefox");
  capability.setPlatform(Platform.VISTA);
  driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);
  driver.get(baseUrl);

 }

Execute the above code and you will see that Firefox browser will launch with google.com
Output:

















Saturday, July 2, 2016

Difference between Interface and Abstract Class

In many interviews you can face this basic question -What is the difference between the Interfaces and Abstract class and when we can use from both of them.

  
             Interface              Abstract Class

If we don't know any thing about implementation just we have requirement specification then we should with Interface concept.
If we are talking for Implementation not completely Partially implementation then we should go for Abstract Class.
Inside Interface every method is always Public and Abstract whether we are not declaring or not. Hence Interface is also considered  as 100% pure abstract class. Every Method in Abstract class need not be public and Abstract. In addition to abstract methods we can take concrete methods also.
We cannot declare interface method with the following modifiers.
Private ,Protected
final,static,synchronized,native and strictfp
There are no restrictions on Abstract class method modifiers.
Every variable present in interface is always Public , static and Final whether we are declaring or not. The variables present inside the Abstract class need not to be public,static and final.
We cannot create object of Interface and because of that we cannot declare  interface variable with the following modifiers:
private,protected,transient,volatile
There are no restrictions on Abstract class variable modifiers.
For Interface variable compulsory we should perform initialization at the time of declaration otherwise we will get the compile time error. For Abstract class variable it is not required to perform initialization at the time of declaration.
In Interface Constuctor is not applicable We can declare the Constructor in Abstract Class

Final,Finally and Finalize - Difference

Most of the time interviewer can ask difference between the Final, Finally and Finalize in Java. I will explain you each in detail.

Final(Modifier)

Final is a modifier applicable for classes ,methods and variables. 

If i declare a variable as Final then it will become constant we cannot perform reassignment for that variable.

If a method declared as Final in child class we cannot override that method in the child class.

If a Class declare as Final Class then we cannot extend that class it means we cannot create the child class for this Class.

Finally:

Finally is a block and always associated with Try Catch.
try
{

//Write Risky Code

}
Catch(X e)
{
// Handling code
}

Finally
{
// Clean up code
//for eg - Close the database
}

Finalize:(Method)
Finalize
{
//Clean up code
}


Lets try to explain this with example. when object is created then it has to be destroyed by garbage collector.But some object can have associated database connection etc so before destroying this object Garbage collector called the Finalize method to close the database connection.

Thanks...




Operators

Operators:

An operator is a symbol that performs an operation. An Operator acts on some variables, called operands to get the desired result





Arithmetic Operators ( Binary Operators because they act on two operands always)
 + , - ,* ,/ and %

Addition operator also use to join two strings,so its also called as String Concatenation operator.

For example:
String str1 ="Net";
String str2 = "Solutions";
String Joinstr = str1+str2;

Unary Operators 
This operator act on only one operand
 Increment Operator (++)
Decrement Operator(--)

Increment Operator –This operator increment the value of variable by 1
int x =1;
int y =x++; //Post Increment
int z =++x; // Pre Increment
System.out.println("Post Increment operator would be: "+y);
System.out.println("Pre Increment operator would be: "+z);

Output:
Post Increment operator would be: 1
Pre Increment operator would be: 3

Decrement Operator –This operator  decrement the value of variable by 1
int x =1;
int y =x--; (Post Decrement)
int z =--x; (Pre Decrement)
System.out.println("Post Decrement operator would be: "+y);
System.out.println("Pre Decrement operator would be: "+z);

Output
Post Decrement operator would be: 1
Pre Decrement operator would be: -1

Assignment Operator  (=)–This operator  is used to store some value into a variable.
for example:int x = 20;

Relational Operator: These operators are used to comparing the values.
  > greater than operator
  >= greater than or equal to
  < less than operator
  <= less than or equal to
  == equal to operator
  != not equal to operator


Mainly these relational operator is used in the conditional statement for example
int a=10;
int b=20;
if (b>a){
System.out.println("b is greater than a");
}

Logical Operator:
These operators are used to construct compound conditions.A compound condition is a combination of several simple conditions.
&& and operator
|| or operator
! not operator
for example :
int a=10;
int b=20;
if (a==10 || b==20);{
System.out.println("Value of a and b is :"+a+","+b);
}

Output:
Value of a and b is :10,20

Another example:
String str1 ="Net";
String str2 = "Solutions";
String Joinstr = str1+str2;
if (!str1.equals(str2)){
System.out.println("String 1 is not equal to string2");
}

Output:
String 1 is not equal to string2

Boolean Operators:
These operators act on boolean variables and produce boolean type result.
& boolean and operator
| boolean or operator
! boolean not operator

For example:
boolean d= true;
boolean e= false;
System.out.println("Value with and boolean operator is: "+(d&e));
System.out.println("Value with or boolean operator is: "+(d|e));
System.out.println("Value with not boolean operator is: "+(!e));

Output:
Value with and boolean operator is: false
Value with or boolean operator is: true
Value with not boolean operator is: true

New operator and Cast Operator will discuss  later

Thanks....

Variable and Datatypes

Variable:

A variable shows the memory location to store the data or values

For example:
    int x,y

 int is datatype (will discuss later)

 int x,y means that programmer telling to java compiler that we are going to store integer type data into x,y variable.

Now after that we can assign the values to these variable as

 x=10
 y=20

 ‘=‘ is the assignment operator and thus 10 is stored into x and 20 is stored into y.

Few Tips on Naming Convention in Java:

Java is a Case Sensitive Language, it recognize capital and small letters as different.We use below syntax to print the statement on console

System.out.println("Core Java Session");

If we use System as system (s is in lower case then java will not accept it).So we need to understand that where we need to use Capital and small letters.

1. Package name always start from small letter like java.awt,java.io etc

2. Class name and Interface name always start from Capital letter like System, ActionListener etc

3. Method fist word would be start from small letter but from 2nd word onwards letter would be start from Capital letter.
 Eg: println,readLine()

Datatypes:

In starting of this blog we  understood the variable and  with that variable we used the data type as int.
int y

Here we are declaring that y is a variable which can store integer type data, then it means y can store only integer number like 23,897 etc

 y =25

Datatype types are as :

1. Integer Datatypes
2. Float Datatypes
3. Character Datatypes
4. String Datatypes

5. Boolean Datatypes

Float data types:
These data types is used to represent the numbers with decimal point e.g.-  float num = 3.1
Float data types  into two categories

 Float (4 bytes Memory size) – Float can represent up to 7 digits accurately after decimal point
 Double (8 bytes Memory size) – Double can represent up to 15 digits accurately after decimal point

Question:
 Float fix =3.156 (What would be the memory size would be occupied by fix variable)
 Answer would be 8 bytes or 4 bytes?

Character data types:
This data types is used to represent a single character for example z,g,& $ etc.
  char ( 2 bytes Memory size)
  e.g – char ex ='Z';

String  data types:
This data type represent the group of characters like Salman Khan, so it means string will be create by grouping the characters.
String name ="KeenSmartz Solution“;

Boolean data types:
This data types represent only two values –true or false.
 e.g – boolean value = true;

Literals:
Literal represent a value that is stored into a variable directly in the program.
 boolean value = true;
 char ex ='Z';
 String name ="KeenSmartz Solution“;
 int i =20;

In Next Topic we will discuss about the Operators

Friday, July 1, 2016

Selenium - Demanded Open Source Tool

Selenium is a free open source Automated testing suite for web applications across different browsers and platforms.

Selenium has more advantages over various tools but here i will compare the advantages or disadvantages over QTP/UFT.

Selenium Features

1. Selenium is Open source - Its Free no License required

2. It Supports Multiple Languages - Java perl,PHP,Python,Rupy and C#

3. It Support Multiple Browser - FF,Google chrome,Safari and Opera

4. Its Supports Multiple OS - Windows ,Macintosh and Linux

5. It supports Web-based Application and Mobile App

6. Flexible and Extendable (More)

QTP/UFT Features

1. QTP is Commercial tool, its not a Open Source

2. It Support VB Script Only

3. Its main Compatible with IE but not its support FF and Chrome also.

4. Its supports Windows Only.

5. It Supports Windows.Web and Mobile Applications.

6. Its is also flexible and extentable. (Less)

History of Selenium

Selenium first introduce in 2004. After doing some enhancement in 2006 Selenium web driver introduced at Google.

In 2008, the whole selenium team decided to merge selenium web driver with RC in order to form more powerful tool Selenium 2.0

What are these versions in selenium, it will explain below:

Selenium 1
(Selenium IDE + Selenium RC  + Selenium Grid)

Selenium 2
(Selenium IDE + Selenium RC  + Selenium Web Driver + Selenium Grid)

Selenium Components:
1. Selenium IDE
2. Selenium RC
3. Selenium Web driver
4. Selenium Grid
5. Selendroid and Appium


In my coming tutorials my major concern is to teach you Selenium Web driver in more details.

Selenium IDE ( Integrated development Environment) - In this we can record the script and than we can run the same. Recording can be perform on FF browser only. We have to download Selenium IDE as add-on of FF. It will recorded the script in HTML Language.

We can convert these scripts in other language also.

Selenium RC 
RC is Selenium 1 , we will also called as Remote Control. in 2007 and 2008 we can automate the entire application.
Now a days selenium RC is not using by companies they are mostly using Web driver.

Selenium RC is a Server.so first of all we need to understand what is Server.

Server is a responsible to serves the request for example. If we have one web application on server and someone want to open that application through browser . it will send the request through browser to server by entering the URL and according that request web server will send the response to the browser and Page will Open.

Selenium RC acts as a mediator between Application and Test scripts.

Selenium Web Driver
Its a Selenium 2.  Its launches to remove the disadvantage of Selenium RC. And we are going to automate or study more on web driver in my coming lectures.

Disadvantages we will discuss in other blog.

Selenium Grid

Grid Provide the Parallel execution on various browser and it saves the time. please have a look into the below picture.

Without Grid:


With Grid:



Selendroid and Appium;

This is Selenium 3.

Selendroid is use to test web application on Android only but using Appium we can test webapplication on Android as well as iOS also.

Thanks...In Next Slide we will start Java Lectures because we are going to learn selenium webdriver with the use of Java

Automation Testing

Why Automation Testing is Important?
Manual Testing is performed by a Human sitting in front of a computer. Human carefully executing the test scripts.

And Automation testing means using a automation tool to execute the Test Case Suite.

The Automation software can also enter test data into the system under test compare actual and
expected results and generate detailed Test Reports.

Goal of Automation is to reduce number of test cases to be run manually and not manual testing all together.

Automated testing is important due to following Reasons:

 1. Manual Testing of all work flows all fields,all negative scenarios is Time and Cost Consuming.

2. It is difficult to test for Multilingual Sites Manually.

3. Automation does not require human intervention.You can run your test overnight.

4.Automation increases speed of test execution and Test Coverage.

5. Manual testing can become boring and hence Error Prone.

Which Test Case to Automate?
Select those parameters which increase the Automation ROI

1. Test Cases that are executed repeatedly.
2. Test Cases that are very tedious or difficult to execute manually.
3. Test cases which are time consuming.
4. High Risk- Business Critical Test Cases.

Which Test Cases not to be Automated?
1. Test cases that are newly designed and not executed manually at least once.
2. Test Cases for which the requirements are changing frequently.
3. Test Cases which are executed on Ad-HOC basis.

Automation Process:
1. Test tool Selection.
Test tool selection largely depends on the technology the Application Under test is built on.
For example:
QTP does not support Informatica so QTP cannot be used for testing Informatica applications.

Its a good idea to conduct Proof of Concept of tool on AUT.

2. Define Scope of Automation
Scope of Automation is the area of your application Under Test which will be automated.

3. Planning,Design and Development
During this phase you create the Automation strategy and Plan.

4.Test Execution
Automation scripts are executed during this phase.

5. Maintenance:
As new functionalities are added to the System Under Test with successive cycles,Automation Scripts need to be added ,reviewed and maintained for each release cycle.

Maintenance becomes necessary to improve effectiveness of Automation scripts.

Automation Tools: 
The more popular automation tools are:

QTP/UFT: Its is the Market leader in Functional Testing tool.

Rational Robot- Its an IBM Tool used to automate regression,functional and configuration tests.

Selenium- Its an open source web Automation tool.

How to Select the best tool?
 Use following attributes to select the best tool
1. Ease of use(SCRIPTING LANGUAGE USED)
2. Support various types of test including functional,Test management ,Mobile etc.
3. Support for multiple testing frameworks.

Tools selection is one of the biggest challenges to be tracked before going for automation.
1. First identify the requirements, Explore various tools and its capabilities
2. Set the expectation from the tool and go for the proof of concept.

Framework in Automation:
A framework is set of automation guidelines which help in
1. Maintaining consistency of testing.
2. Less Maintenance of code
3. Improves re-usability

There are four types of framework we are using in Automation
1. Data driven Automation Framework.
2. Keyword driven Framework.
3. Modular Automation Framework.
4. Hybrid Automation Framework.

Automation Best Practices:
To get Maximum ROI
1. Scope of Automation need to be determined in detail before the start of the project.
    This set the expectations from Automation right.

2. Select the right Automation tool
    A tool must not be selected based on its popularity but its fit to the Automation requirements.

3. Choose Appropriate Framework

4. Scripting standards
    Standards have to be followed while writing the scripts for Automation.

5. Measure Metrices
    Success of Automation cannot be determined by comparing the manual effort with the automation       effort but by also capturing the Metrices like
        - Percent of defect founds.
        - Productivity Improvement etc

The above guidelines will help to start your Automation. Thanks

Now in next slide i will give you brief details on Selenium.