Tuesday, December 20, 2016

TestNG

Most of the Automation tester are using TestNG Framework just because of its advantages and more supported features. Its similar to JUnit framework but this Framework overcome the limitation of JUnit Framework.

NG Stands for "Next Generation" in TestNG.

Some of the TestNG Farmework features are listed below those are not exists in JUnit.

1. We can perfrom the Parallel Testing with TestNG Framewok.

2. We can perform data driven testing with the use of @DataProvider annotation.

3. We can see the HTML Results with TestNG Framework.

 Annotations of TestNG are :
@AfterSuite, @BeforeClass, @AfterClass, @BeforeTest, @AfterTest, @BeforeGroups, @AfterGroups, @BeforeMethod, @AfterMethod, @DataProvider, @Factory, @Listeners, @Parameters, @Test.

Installation of TestNG:
TestNG is not an in build framework in eclipse we have to download it.
Steps to Download: 
1. Open the Eclipse and select the Eclipse Marketplace option under the Help option of eclipse













2. It will show the list of various software that can be downloaded in eclipse























3. Search the TestNG option and Install it by clicking on the Next button
 






















4. Once you have been installed please verify its downloaded or not, just go to the other Option of ShowView
Window-->Show View-->Other...



















 5.TestNG option should be displayed under the Java Option.
























Practical Time:
Create the Project of TesNG in your eclipse and add the TestNG Library and write the first program.
1. If we want to execute the test case in TestNG then @Test annotation is used to do that, for example.

import org.testng.annotations.*;

public class TestNG1 {
 
 @Test()
 public void Test1()
 {
  System.out.println("This is the Test1");
 }
}
 
OutPut: 
 [TestNG] Running:
  C:\Users\zeeshan.khan\AppData\Local\Temp\testng-eclipse--603972738\testng-customsuite.xml

This is the Test1
PASSED: Test1

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

2. If we have more that one test cases and we want to execute those test cases as priority wise then code will be :
import org.testng.annotations.*;

public class TestNG1 {
 
 @Test(priority=2)
 public void Test1()
 {
  System.out.println("This is the Test1");
 }
 
 @Test(priority=1)
 public void Test2()
 {
  System.out.println("This is the Test2");
 }
}
 
Output: 
[TestNG] Running:
  C:\Users\zeeshan.khan\AppData\Local\Temp\testng-eclipse--651145255\testng-customsuite.xml

This is the Test2    //            Execute the Test 2 First because we have 
This is the Test1                  provided its priority as "1"
PASSED: Test2
PASSED: Test1

===============================================
    Default test
    Tests run: 2, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================

3. If we want to perform the Datadriven Testing then will 
have to use annotation@DataProvider.

import org.testng.annotations.*;

public class TestNG1 {
 
 
 @Test(priority =1,dataProvider="dataextract")
 public void setData(String userid, String pwd)
 {
  System.out.println("you have provided username as::"+userid);
  System.out.println("you have provided password as::"+pwd);
 }
 
 @DataProvider
 public Object[][] dataextract()
 {
 //Rows - Number of times your test has to be repeated.
 //Columns - Number of parameters in test data.
 Object[][] data = new Object[3][2];

 // 1st row
 data[0][0] ="Tester1";
 data[0][1] = "123456";

 // 2nd row
 data[1][0] ="Tester2";
 data[1][1] = "64665456";
 
 // 3rd row
 data[2][0] ="Tester3";
 data[2][1] = "655435345";

 return data;
 }
}
 
Output: 
[TestNG] Running:
  C:\Users\zeeshan.khan\AppData\Local\Temp\testng-eclipse-354263273\testng-customsuite.xml

you have provided username as::Tester1  // Extracts all the value from the DataProvider
you have provided password as::123456
you have provided username as::Tester2
you have provided password as::64665456
you have provided username as::Tester3
you have provided password as::655435345
PASSED: setData("Tester1", "123456")
PASSED: setData("Tester2", "64665456")
PASSED: setData("Tester3", "655435345")

===============================================
    Default test
    Tests run: 3, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
 
TestNG generated own results and its displayed as below:
 
 
 
 
 
 
 
 
 
 
 
 
4. HTML Result is generated after the TestNG Script under the 
test-output folder, look into the below screenshot.
 



























Navigate to this folder and open the "index.html" by getting actual path of this 
location(We can get this location from below shown window)












 
HTML Result look like as below shown picture.



Friday, August 19, 2016

Concept of Classes and Object in JAVA

A class is a model or blueprint for creating similar type of objects.Class contain the 
variable and methods. To understand a class ,take a pen and paper and write down all the 
properties and actions of any Person. So it is called a CLASS because its contain the 
properties and method or function of generic person.

Now we can create various objects with the use of similar kind of properties and methods of 
Class Person.

For example: SITA, DEV and KARAN are the objects of the Class Person that can have the same 
properties and functions which defined in Person Class.




















/* ##################  Person Class  #############################*/

// class keyword is used to declare a Class

public class Person {
 
 // Properties -instance Variables
 String Name;
 int Age;
 int PasspotNo;
 
 //actions -Methods
 void Dancing()
 {
 System.out.println("I am Dancing and My name is "+Name);
 }
 
 void Running()
 {
 System.out.println("I am Running and My Age is "+Age);
 }

}
So this is the way in JAVA we define the Class and you can say that this is the blueprint 
for Creating the Similar Kind of Objects.

To use a class, we should create an object to the class.Following syntax is used to create 
the Object in Java.

ClassName objectname = new ClassName()

So to Create the SITA object to Person Class, we can write as:

Person SITA = new Person();

Here "new" is an operator that created the object to Person class. Once we create the
Object of the Class a JVM provides the reference number or copy of the class to the object 
or variable for use.

Here SITA is object or variable that stores the reference number of the object returned by 
JVM.

Now below code will explain you how we create the object of Person class and How we use it.
Once you write object after creation and put the dot then you will see all the variables 
and Method list that has been define in Person Class.

Look into the below screenshot. Now you can use those


public class CreateObjectPersonClass {

 
 public static void main(String[] args) {
  
  //Creating object obj1 of Person Class with the use of new operator
  Person obj1 =new Person(); 
  
  //Assign the Value to instance Variables
  obj1.Name ="SITA";
  obj1.Age =24;
  obj1.PasspotNo= 123456;
  
  //Calling the Instance Methods
  obj1.Dancing();
  obj1.Running();
  
 }

}
Output:
I am Dancing and My name is SITA
I am Running and My Age is 24

Thanks...if you feel that this is fruitful information for you then please like 
this and give your feedback.


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