MainMenu

Home Java Overview Maven Tutorials

Tuesday 26 December 2017

Difference between Final, Finally and Finalize in Java



Hello friends,

In this article we will learn what is the difference between Final, Finallyand Finalize with suitable examples.

In java, where we want restriction, we use Final Keyword.
We can use Final keyword with class, Method and variables.
Final Class can't be Inherited.
Final method can't be overridden.
Final variable can't be changed.

Finally is a block and the code written inside the Finally block will be executed whether exception is handled or not.

Finalize is a Method and it is used to perform clean up processing just before object is garbage collected.

Example of Final in java


public class Finalandfinally
{
public static void main(String args[])
{
final int x = 10;
int y = x+10;
x = y; //here you will get the error "Remove final modifier of x"
System.out.println("New value of x is :" + x);
Test2 obj = new Test2();
obj.sum();
}
}
final class Test1
{
final public void sum()
{
System.out.println("Hello i am inside method sum");
}
}
class Test2 extends Test1 //Remove final modifier of Test1
{
public void sum() //"Remove final Modifier of Test1.sum(....)"
{
System.out.println("Hello i am inside method sub");
}
}


Finally block

The finally block always executes when the try block exits.
This ensure that the finally block is executed even if an expected exception occurs.

public class Finalandfinally
{
public static void main(String args[])
{
try
{
System.out.println("Enter your no");
Scanner obj = new Scanner(System.in);
int x = obj.nextInt();
System.out.println("Enter your second number");
int y = obj.nextInt();
int z = x/y;
System.out.println("Your result is :" +z);
}
catch(ArithmeticException e)
{
System.out.println(e.getMessage());
}
finally
{
System.out.println("I will be executed whether exception occur or not");
}
}
}

finalize Method

1. Finalize is called before Garbage collector reclaim the object.
2.Its last chance for any object to perform cleanup activity i.e. releasing any system resources held , closing connection if open etc.
3.finalize() method is defined in java.lang.Object class
4.It's the responsibility of developer to call superclass finalize method when we override finalize method.
5.There is no gurantee that finalize method is called because finalize() method is called just before the garbage collection process happens and we are not sure when garbage collection process happens.
6.Exception propagated by finalize() method are not propogated and are ignore by garbage collector.
7.we can force jvm to call finalize method by calling
System.run.Finalization()
Runtime.getRuntime().runFinalization()
8.finalize() method gets called only once by garbage collector.

import java.util.Scanner;
import org.apache.poi.util.SystemOutLogger;
class A
{
int i = 50;
@Override
protected void finalize() throws Throwable
{
System.out.println("From Finalize Method");
}
}
public class Finalandfinally
{
public static void main(String[] args)
{
//Creating two instances of class A
A a1 = new A();
A a2 = new A();
//Assigning a2 to a1
a1 = a2; //Now both a1 and a2 will be pointing to same object
//An object earlier referred by a1 will become abandoned
//Making finalize() method to execute forcefully
Runtime.getRuntime().runFinalization();
System.out.println("done");
}
}

Friday 22 December 2017

Sort the array without using Java functions


Hello friends,

In this article we will learn how to sort the Array with java Collection and Without using java function



So first let's discuss by using java Method :
Sort the array by using java function.

public class Arraysort
{
public static void main(String args[])
{
int[] ary = {25, 32, 1, 6, 11, 9, 17, 100, 95};
Arrays.sort(ary);
System.out.println("Sorted array is : %s", Arrays.toString(ary));
}
}

Note : By default array will be sorted in ascending order.

Sort the array in descending order :

public class Arraysort
{
public static void main(String args[])
{
int[] ary = {25, 32, 1, 6, 11, 9, 17, 100, 95};
Arrays.sort(ary, Collections.reverseOrder());
System.out.println("Sorted array is : %s ", Arrays.toString(ary) );
}
}

Sort the String array in Ascending & descending array

public class Arraysort
{
public static void main(String args[])
{
int[] ary = {"way2testing.com", "datastop.in", "onlineifsccodebank.com"};
System.out.println("Sorted array is : %s \n\n", Arrays.toString(ary) );
}
}

Sort the string array in decending order
public class Arraysort
{
public static void main(String args[])
{
int[] ary = {"way2testing.com", "datastop.in", "onlineifsccodebank.com"};
Arrays.sort(ary, Collections.reverseOrder());
System.out.println("Sorted array in decending order is : %s ", Arrays.toString(ary) );
}
}

Sort the String without using Java API

Sort the String without using Java API
public class SortString
{
public static void main(String args[])
{
char temp;
String modifiedString = "";
Scanner userstring = new Scanner(System.in);
System.out.println("Enter your String");
String str = userstring.next();
}
char[] chrary = str.toCharArray();
for(int i = 0; i<chrary.length; i++)
{
for(int j = 0; j<chrary.length; j++)
{
if(chrary[i]<chrary[j])
{
temp = chrary[i];
chrary[i] = chrary[j];
chrary[j] = temp;
}
}
}
for(int k = 0; k<chrary.length; k++)
{
modifiedString = modifiedString + chrary[k];
}
System.out.println("Your sorted string is : " +modifiedString);
}



How to sort an array without using sort function in java.

public class sortme
{
public static void main(String args[])
{
int[] ary = {25, 3, 29, 9, 15, 40, 90, 75};
for(int i =0; i<ary.length; i++)
{
for(int j =0; j<ary.length; j++)
{
if(ary[i]<ary[j])
{
temp = ary[i];
ary[i] = ary[j];
ary[j] = temp;
}
}
}
for(int k = 0; k<ary.length; k++)
{
System.out.println("Your sorted array is : " +ary[k]);
}
}
}

reverse the string and number in java without using functions


For Video :- Click Here



Hello friends,

In this article we will learn Reverse a String with and without using Java Functions :-

import java.util.Scanner;
public class Stringplay
{
public static void main(String args[])
{
String rev = "";
Scanner sc = new Scanner(System.in);
System.out.println("Enter your first string");
String ys = sc.nextLine();
int length = ys.length();
for(int i =length-1; i>=0; i--)
{
rev = rev + ys.charAt(i);
}
System.out.println("Your String is: " +ys);
System.out.println("reverse String is: " +rev);
StringBuffer sb = new StringBuffer(ys);
rev = sb.reverse().toString();
System.out.println("simple reverse String is: " +rev);
}
}



And here is your output:

Enter your first string
chandan singh
Your String is: chandan singh
reverse String is: hgnis nadnahc
simple reverse String is: hgnis nadnahc

Reverse a number without using Java Functions :-

public class Jtestnew
{
@Test
public void g()
{
int x = 123%10;
System.out.println(x);
int y = 123/10;
System.out.println(y);
Scanner scn = new Scanner(System.in);
System.out.println("Enter the number");
int num = scn.nextInt();
int rnum = 0;
while(num!=0)
{
rnum = rnum*10 + num%10;
num = num/10;
System.out.println("Reversed number is: " +rnum);
}
}
}

Sunday 10 December 2017

How to Create WebDriver Instance for multiple class


Hello friends,

In this article we will learn how to create WebDriver Instance multiple classes:

So, we will create a WebDriver instance in one class & call it in multiple class
we have achieve this by 2 ways
1).By using extends
2).By using Singleton class

To know about singleton class Click Here

For Video :- Click Here



Method :1By extends Keyword

Step :1Create a class & initialize your driver

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MainDriver
{
public static WebDriver driver;
public static void createInstance()
{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
}


Step :2Create an another class & extend above driver class

public class Testcase1 extends MainDriver
{
public static void url()
{
MainDriver.createInstance();
driver.navigate().to("http://www.way2testing.com");
}
}


Step :3Create an another class & extend above driver class

public class TestCase2 extends MainDriver
{
public static void getTitle()
{
System.out.println(driver.getTitle());
}
}


Step :4Create an another class & extend above driver class

import org.testng.annotations.Test;

public class Excution
{
@Test(priority = 0)
public void getUrl()
{
Testcase1.url();
}
@Test(priority = 1)
public void getTitle()
{
TestCase2.getTitle();
}
}


If you will run this Exeution class , you can see that with one WebDriver Instance(driver), you are able to perform your all task.

Method :2By Singleton Class

Step :1Create a Singleton class & initialize your driver

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SingletonDriver
{
public static WebDriver driver = null;
public static void Initiallize()
{
if(driver == null)
{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
}
public static void close()
{
driver.close();
}
public static void quit()
{
driver.quit();
}
}



Step :2Create a class for your test cases & execute singleclass method

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Testcases
{
@BeforeTest
public void initializeDriver()
{
SingletonDriver.Initiallize();
}
@Test(priority = 0)
public void openurl()
{
SingletonDriver.driver.navigate().to("http://www.way2testing.com");
}
@Test(priority = 1)
public void getTitle()
{
System.out.println(SingletonDriver.driver.getTitle());
}
}



So, by using above methods, you can create a WebDriver Instanse(driver) and can use it in your multiple classes.
Thanks :)





Friday 24 November 2017

Selenium Integration with Jenkins Tutorials 1




For Video : CLICK HERE For Video Tutorials Playlist



Jenkins Introduction :


OPEN SOURCE AUTOMATION SERVER which can be used to automate all sorts of task such as Building, testing and deploying Software.
Jenkins is a powerful application that allows continuous integration and continuous delivery of projects, regardless of platform you are working on.
It is a free source so it an handle any kind of build integration.

Why Jenkins :


It is Easy to Install.
It has a lot of plugins which make task Easy.
It is build in java so it is Portable to all the major plateforms.
Jenkins is a software that allows continuous integration.

What is flow in jenkins :


Developers check their code & made changes as required
Jenkins will pick the changed source code and trigger a build and run any tests if required.
The build output will be available in the jenkins dashboards, automatic notifications can also be sent back to the developer.

What is continuous Integration :


Continuous Integration is a development practice in which the developers are required to commit changes to the source code in a shared repository several times in a day or with regular interval.
After that a job will get triggered by jenkins and create build.
This concept was meant to remove the problem of finding later occurrence of issues in the build lifecycle.

Here is the work flow of the CI :




What is continuous Integration ?

Continuous Integration is a development practice in which the developers are required to commit changes to the source code in a shared repository several times in a day or with regural interval.
After that a job will get triggered by jenkins and create build.
This concept was meant to remove the problem of finding later occurrence of issues in the build lifecycle.

on other hand you can say CI is just : Build & Test


Use of Continuous Integration

)1. : Automate the Build
)2. : Make the Build self Testing
)3. : Keep the Build Fast
)4. : Everyone can see what's happening.
)5. : This allow the team to detect the problems early.

Other Tools which support CI :


Jenkins
Teamcity
Go CD
Bamboo
Gitlab CI

Workflow in continuous integration




Before Continuous Integration :
The entire source code was built and then tested.
Developers have to wait for test results.
No Feedback

After Continuous Integration :
Every commit made in the source code is build and tested.
Developers know the best result of every commit made in the source code on the run.
Feedback is present.

Download Jenkins : Click here to go to Download Page

Download Jenkins for windows : Click here Download zip file

Download Jenkins : Click here to Download war file

Now download and install the jenkins in your machins task is done.

After that you will get below window



You need to enter the password present in appropriate location.

Jenkins will ask you, whether you want to create a user or continue with admin user
for admin user username & password will be admin
but in my case i will create a user so below window will appear



I will fill the required details & click on the next button after that below window will appear to install the plugins, your can select the plugins as per your need or you can select the default option which is install suggested plugins




It will take little bit time and after that your jenkins dashboard will appear at the location http://localhost:8080



Alternatively you can also install the jenkins in your machine using war file & cmd.
Open your command promt
navigate to jenins war file location using cd etc basic commands
not type commandjava -jar jenkins.war and hit enter key as below in image


congratulation jenkins is not installed in your machine.



How to Change port number in jenkins?


There is only one line commond to change the port number in jenkins :
java -jar jenkins.war --httpPort=8081

How to restart the Jenkins?


There is two ways to re-start the jenkins :
1): from browser :
write the below commond & hit enter
http://localhost:8080/restart

2): In windows machine :
Press win + r
type services.msc
find the jenkins & right click on it
There will be restart option , just press on it

Why do we need to change the home directory in jenkins?


1): Due to less space in user directory.
2): Due to project requirement.
3): Confliction with other app.

How to change home directory in Jenkins ?


You need to follow some couple of steps to change the home directory of jenkins :
1): Find the existing directory of jenkins
generally it is inside C , User directory & in my case it is :
C:\Users\chandan.singh\.jenkins
OR
from jenkins, you will also get Jenkins home directory
http://localhost:8080 >> manage jenkins >> Configure jenkins >> First option will be home directory

2): Create a new folder, where you want to have the home directory.
in my case
D:\Automation\Jenkins_Home

3):Now copy all the data from Old directory by pressing "Ctrl" + "A" and paste ("Ctrl" + "A") in new directory

4):Now change the Environment Variable

5): My computer , right click on it & select Properties
and select Advanced System setting
a pop will appear , click on Environment varable
under system variable find JENKINS_HOME & click on Edit button
Note : (if not available then click on Add button & add this as below image )
In path enter the new directory path, in my case it is
D:\Automation\Jenkins_Home
click on OK & OK
Now restart your jenkins & check the new directory.


Configure Email Smtp server details :

Outlook.com SMTP Server Settings

Outlook.com SMTP server address: smtp-mail.outlook.com
Outlook.com SMTP user name: Your full Outlook.com email address (e.g. myname@outlook.com, not an alias)
Outlook.com SMTP password: Your Outlook.com password
Outlook.com SMTP port: 587 (you can use port 25 as an alternative)
Outlook.com SMTP TLS/SSL encryption required: yes

Yahoo SMTP Server Settings

Yahoo! Mail SMTP server address: smtp.mail.yahoo.com
Yahoo! Mail SMTP user name: Your full Yahoo! Mail email address (including "@yahoo.com")
Yahoo! Mail SMTP password: Your Yahoo! Mail password
Yahoo! Mail SMTP port: 465
Yahoo! Mail SMTP TLS/SSL required: yes

Yahoo! Mail Plus SMTP Server Settings

The SMTP server settings for Yahoo! Mail Plus accounts (which no longer exist) were:
Yahoo! Mail SMTP server address: plus.smtp.mail.yahoo.com
Yahoo! Mail SMTP user name: Your Yahoo! Mail user name
Yahoo! Mail SMTP password: Your Yahoo! Mail password
Yahoo! Mail SMTP port: 465
Yahoo! Mail SMTP TLS/SSL required: yes

How to schedule the build in jenkins

Jenkins scheduler watch work on Cron Time Format.
What is Cron : a command to an operating system or server for a job that is to be executed at a specified time.



For Example : i want to run my build on 10:06 PM on 15 Jan then my command/time format will be :-
06 22 15 1 1 (Refer the below screen)
Explanation : in above time format 06is for Minute, 22 is for Hour, 15 for date of month,1 for month of year & 1 for day of week.

Jenkins Dashboard >> Click on your project >> Click on Configure >> Go to Source code Management Tab >> Under the build Triggers >> click on Build periodically checkbox >> In the Textbox input your schedule time in cron time format
Refer the below screen :







Tags :

How to change directory in jenkins

How to change port number in jenkins

How to restart jenkins

How to send emails from Jenkins

How to send emails when build is success

Send build success email from jenkins

What is Jenkins

Selenium Integration with jenkins

jenkins tutorial 2017

What is continuous Integration?

What is use of continuous Integration?

How to schedule test with jenkins

How to schedule test with jenkins in selenium

Monday 6 November 2017

Java 8 Stream Filter with Example


Hello friends,

In this article we will discuss about Stream Filter in Java:


For Video :- Click Here



we will provide java 8 Stream filter() example.
We filter a collection for a given Predicate instance. filter() method returns a Stream instance which consists only filtered element on the basis of given Predicate.

As the name says , Stream, means which is flowing continuously like data in list, and we want to filter some result from this list as per your need.
By below example this will get more clear.
Code :


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class Swap
{
public static void main(String args[])
{
List list = new ArrayList();
list.add("chandan");
list.add("adhiraj");
list.add("Akshat");
list.add("Anant");
List names = Arrays.asList("aviraj", "angraj", "devraj", "dananjay" );
list.stream().filter( u -> u.startsWith("ch")).forEach(System.out::println );
names.stream().filter( u -> u.endsWith("aj")).forEach(System.out::println );
names.stream().map(u -> u.equals("aviraj")).forEach(System.out::println);
}
}


OutPut:

chandan
aviraj
angraj
devraj
true
false
false
false


Code Explanation : First we create two list with name list & names then we will add some records in the both list.
then simply we will apply , Stream() method on the lists & filter() them as per our need.
finally we will print the required string.


for more deep knowledge :
Click here



Tags :
Java 8Stream
FilterStream filter with example

Saturday 4 November 2017

Scanner class in java with example


Hello friends,

In this article we will discuss about scanner class in Java:

Scanner class is used when we want Input from user.
In our example, we will take the name & age from user as input & will print these values.

For Video :- Click Here



import java.util.Scanner; public class Swap
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter Your Name");
String mystring = scan.next();
System.out.println("Enter Your Age");
int mynumber = scan.nextInt();
System.out.println("Your Name is :"+ mystring);
System.out.println("You are" + " "+ mynumber+ " " +"years old");
}
}

Output : Enter Your Name
Chandan
Enter Your Age
28
Your Name is Chandan
You are 28 years old.





Tags :

What is Scanner class in Java

Example of scanner class in java

How to take input from user in java

How To Swap Two variable without using third variable in java


Hello friends,

In this article we will discuss about swap variable without using third variable:

For Video :- Click Here



public class Swap
{
int x = 10;
int y = 15;
public static void main(String args[])
{
Swap object = new Swap();
object.g();
}
public void g()
{
x = x+y;
y = x-y;
x = x-y;
System.out.println("After Swap Value of y : " + y);
System.out.println("After Swap Value of x : " + x);
}
}


output :
After Swap Value of y : 10
After Swap Value of x : 15

Code Explanation : Suppose we have two variable x, y and they have value 10, 15 respectively and we want to swap these two variables value.
HOW IT WOULD BE DONE ?
1). First , i will join these two variables value & store it in variable x.
Now the value of x is 25.
2). Now, we will minus the value of y(15) from this x(25).
we will get 10 & will store in variable y
3). Now the value on y is 10 & value of x is 25.
again we will minus this y value from & store it in variable x so value of variable of x will become 15.

Congratulation You have swapped the value of two variable without using third variable. :)





Tags :

Swap two variable without using third variable in Java

how two swap two variable in java without using third variable

Monday 30 October 2017

First Script in Jmeter



Create First Script in Jmeter



Test plan : Test plan is just like a container which will contain all our test element that need to performe test.

Work bench : Work bench is a place where we can keep our element for temporary basis.

Thread Group : Contains the no. of user & their configuration with time.
Basically thread group is the users that will be used to create & run the test.
Each user will be treated as thread

Elements of Thread Group
Number of Threads(Users) : Simulates the no. of users on application under test.No of user application want to test.
Ramp-Up Period(in Seconds):In how many time all the user will hit the application
For Example : If value of "Number of Threads" is "10" and "Ramp-Up Period" is "20" seconds.
That its means each thread(User) will start 2 seconds later after the previous thread was started.
Formula : Ramp-Up Period/Number of Threads, in our case : 20/10 = 2 seconds.

Loop Count: Tell the Jmeter that how many times test will be executed,
For Example : If we have "loop" value is "5" then each user will hit the application 5 times.
means total : 10*5 = 50
Total 50 request will be send to the application with a 2 second gap.

Jmeter Overview , Download and Install Jmeter

Overview of Jmeter



Hello Friends,

In This article we are going to discuss about basic functionality of Jmeter.

For Video :- Click Here

Let's Have a little discussion on aspects releated to Jmeter

Performance testing : It is the type of testing which will ensure that how an application will behave with different kind of users, no of users , with different network & other environment.
It have Four main Aspects :
Scalibility
Stress
Load
Endurance

Scalibility Testing :The main Agenda is to check effectiveness of application under certain load.
Stress Testing:- To check the upper limit of extreme workloads to see how it handles high traffic and find the break point of application.
Load Testing :-How much Load(No. of User) applicatio can handle & whethere application performe well under specified Load or not.
Endurance testing :- Application can handle a cenrtain load for a long period of time.


The Apache JMeter is a Open Source Java based software and it was developved by Stefano Mazzocchi of Apache Software Foundation, mainly designed to test the load test behaviour and measure the performance.
Jmeter is designed to cover tests like Load, Functional, Performance, Regression etc.

Pre-Requisites :- One should have basic under standing of Java Programming language, text Editor and execution. And machine should have JDK installed.
To download & install JDK Click Here

JMeter Features :
It is free bacause it is Open source.

A good and User friendly GUI.

Can Perform load test on many different server types like HTTP, HTTPS, SOAP, JDBC etc.

Its Platform independent tool because it is a pure java application.

Automation functional, regression, performance etc testing can be done easily.




Download & Install Jmeter in Your Machine



How to Donwload Jmeter ?
Click here

How to Download Badboys?
Click here
How to Start Jmeter in Windows ?
Navigate to Windows -->Jmeter Folder --> bin --> Click on jmeter.bat file
Screen Shot :-



Commond to open Jmeter in Mac
Mac --> Open terminal --> Jmeter --> bin --> sh jmeter.sh

Wednesday 25 October 2017

HeadLess Browser testing in Selenium


Hello friends,

In this article we will discuss about headless or Ghost browser :

For Video :- Click Here



What is headless browser ?

Browser which is not visible to user is known as headless browser.
They are also know as Ghost browser.
in terms of selenium, Browser which will be controlled by selenium but will not be visible to user is known as headless browser testing.


Different kind of headless browser

In selenium we have following headless browser :

1).HtmlUnit
2).PhantomJS
3).Ghost
4).ZombieJS
5).Watir-webdriver
6).Jbrowser


Lets Talk about HtmlUnitDriver
1). The fastest browser among all the browsers
2). Excellent JavaScript support
3).Support for the HTTPS and HTTP protocols
4).Support for HTML responses
5).Support for cookies
5). Proxy server support
7). Support for basic and NTLM authentication
8).Support for submit methods GET and POST
9). Ability to customize the request headers being sent to the server
10). Ability to determine whether failing responses from the server should throw exceptions or should be returned as pages of the appropriate type


Cons of HtmlUnitDriver
1).It cannot emulate other browsers JavaScript behavior
2).Many times it get for complicated scripts

How to configure HtmlUnitDriver in Selenium Project

First of all download the jar files of HTMLUnitDriver by using below links :=

Download from website : Click here
download from google driver : Click here

Now create the Java Project & add this Jar file in your project 

 


Code

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class GhostDR
{
WebDriver driver;
@BeforeTest
public void g()
{
driver = new HtmlUnitDriver();
//System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\chromedriver.exe");
//driver = new ChromeDriver();
driver.navigate().to("http://www.way2testing.com");
}
@Test
public void h()
{
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println(driver.getTitle());
}
}




output :

Best Online Software Testing Tutorial: Software Testing
PASSED: h


Another good headless browser is phantomJS
PhantomJS is a headless browser with Javascript API.
It is also a favorite browser for most of Automation tester.
The main thing is that it is fast & able to handle large & complicated Script.
Download Phantom JS Browser below :
Download from Maven Website : Click Here to Download PhantomJS Driver
Click here to Download phantomJS Jar

Click here to download from Google Drive
Configure the project for PhantomJSDriver :-
You need to follow few steps :-
1). File file = new File("local system path/bin/phantomjs.exe")

2).set the path of PhantomJSDriver
System.setProperty("phantomjs.binary.path", file.getAbsolutePath())

3).WebDriver driver = new PhantomJSDriver();



Code

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
public class PISOFT
{
WebDriver driver;
@BeforeTest
public void g()
{
File file = new File("D:\\Selenium\\Complete selenium\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
driver = new PhantomJSDriver();
//driver = new HtmlUnitDriver();
//System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\chromedriver.exe");
//driver = new ChromeDriver();
driver.navigate().to("http://www.way2testing.com");
}
@Test
public void h()
{
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println(driver.getTitle());
}
}


output :

Best Online Software Testing Tutorial: Software Testing
PASSED: h







Tags :-


Headless browser testing in selenium


Selenium testing with PhantonJS browser


Selenium testing with Ghost browser


Selenium testing with HTMLUnitDriver


How to Download and Configure PhantomJSDriver


How to Download and configure HTMLUnitDriver




Wednesday 4 October 2017

Review and Bug Life Cycle

What is review?


Reviews are part of static testing, where tester are required to check/verify the documents like test case, RTM, test plan etc.


Kinds to review :


Walk Through : Not a formal process, led by author generally done for higher level document requirement Specification etc.

Inspection : Most formal review done by trained moderator

Informal Review : documents are prepared and checked thoroughly by the reviewers before the meeting & It involves peers to examine the product Formal/Technical Review : Done by the development team to technically verify the documents.



Roles & responsibility in a Review :

The Moderator : Review lead by moderator & his role is to determine the type of review, approach and the composition of review team. The Author : As the writer of the ‘document under review’, the author’s basic goal should be to learn as much as possible with regard to improving the quality of the document.
The Scribe/Recorder : he is responsible to record the bulletined points in review along with defect, feedback & suggestions. The reviewer : The role of the reviewers is to check defects and further improvements in accordance to the business specifications, standards and domain knowledge.

What are different phases of formal review?


Formal review process have below phases :


Planning
Kick-off
Preparation
Review meeting
Rework
Follow-up.

Note : In Some organization informal review is termed as Peer Review, where review is done inside the team by team member & generally it is done without any documentation.
Organization which follow review process also have checklist for review sheet with below point :

> Major functionalities are covered in test cases with high priority.

> GUI featured are covered properly.

> Test case document follow the organization approved document format & structure.

> Test steps are suitable to achieve the objective/Scenario.




Bug life cycle/Defect life cycle :

This cycle explain the life of a bug/defect which was found during testing.
As Diagram says it have different phases :

Defect Found : Potential defect that is raised and yet to be validated.
Verification : Now this bug will be inspected by lead & try to replicate it & it have two outcomes :
a: Rejected : If this is not a bug &; it is FAD (Functioning as designed) also it will be closed.
b: Open : Bug can be replicated successfully.
Assigned : If Bug is valid then it will be assigned to associative developer & status of bug will be assigned.
Fixed : Associated devfeloper will work on it & fix it and after that status will be fixed.
QA Verification/To Be verified : Here QA team/associated tester will RETEST the bug & again two out come will come
a : Verified/Closed : If bug is fixed then tester will pass it & status will become passed & bug will be closed.
b : RE-OPEN : If bug is still exist & test is able to replicate it then bug will be failed by tester & its status will become Assign.
END : Bug life cycle will end here and document will be updated with build number i.e Build x1.0 has four bugs & they are fixed.

There are some more status of bug :
Deffered : if bug is valid and it will be fixed in next further Iteration/Release then it will be marked with status deffered.
Deployed to QA : Bug has been fixed & deployed to QA environment & waiting for tester to Re-test it.
Ready to Release : Now bug is passed by tester & build is ready to release with fixed bug.



What is severity & priority ?

Bugs can be majored with two parameter :-
Severity : It defines the impact that a given defect has on system in other word "How much bug is serious with respect to the functionality."
Severity Types : Critical , Major, Moderate, Minor, Cosmetic
Priority : Priority defines the order in which bug/defect should be resolved. should we fix it now or can it wait?
Priority Types : Low, Medium & High.
Priority in Jira : High, Low & Medium
Severity in jira :
6-Blocker
5-Urgent
4-Very High
3- High
2- Medium
1- Low

Examples of high severity & high priority :


Master data can not be created when user click on "Create" button application get crashed.

OR
An error on basic functionality, which prevent user to use the application.

Example of high severity & low priority :


A job can be done by n number of ways but out of n , one is not working also this is not much more used by users.


(Email CRM : , User can send the email by method A, B, C....except C all are working & method C is very rarely used by user)



Example of low severity & High priority :


There is no validation message for wrong input although at last application will not submit the data.



Example of low severity & low priority :


Any cosmetic or spelling or grammatical error




What is Software Testing ???


What is manual testing ?


What is Smoke testing ?


What is Test Cases ?

How to write the test cases?


When to start test case execution ?


Test Management tools


How much negative test cases should write?


What is Retesting?


Exploratory Testing?


Regression Testing?


What is Ad-hoc Testing?


What is Unit testing?


What is Sanity Testing?

Difference between smoke and sanity testing


Types of Software Testing


What is review?


Kinds to review :


What is Formal review?


What is technical review :


Phases of review ?


What is peer review?


Bug life cycle in software testing?


what is severity & priority?


Example of high severity and high priority ?


Example of high severity and low priority?


Example of low severity and high priority


Example of low severity and low priority

Defect Clustering in Software Testing

What is Defect Clustering in Software Testing?

Defect Clustering :- As the Name says, a cluster of defect, which indicate that An area which have defect have more probability of existance of defect.

This below graph will elaborate more about defect custering.



Defect Clustering in Software Testing is one of the seven principles of Software Testing.

During software testing, as defects are found, analysis of defects can give surprising results!

Defect Clustering in Software Testing means that the majority of the defects are caused by a small number of modules, i.e. the distribution of defects are not across the application but rather centralized in limited sections of the application.

When a small number of modules contains most of the bugs detected or show the most operational failures.

This is particularly true for large systems where the complexity, size, change and developer mistakes can impact the quality of the system and affect particular modules.

Defect Clustering in Software Testing is based on the Pareto principle, also known as the 80-20 rule, where it is stated that approximately 80% of the problems are caused by 20% of the modules.

In this image the principle of defect clustering in software testing can be seen that most of the defects are clustered in particular sections of the application of an application e.g. Product Details, Reviews and Search Results Page for an e-commerce website and the remaining defects in other areas.

This can give a good indication that when a defect is found in one area of the application, chances are there are more defects in that particular area, so it is worth investing more time to test that particular area of the application to find as many defects as possible. However, testers should not ignore to test the rest of application as well as there may be other defects scattered around.

Defect aggregation or defect clustering in software testing can also indicate which area of the application needs more regression testing to ensure related features are not broken.

Analysis of test execution reports and grouping of the defects by features of the application produces a histogram which proves the principle of defect clustering in software testing. This helps with understanding of the defects better and also help with test case prioritization when there is not enough time to execute all the tests.

Advantages:
Tester can focus the same area in order to find the more number of defects.
Helps in reducing the time and cost of finding defects.

Tuesday 1 August 2017

Software Testing Selenium Webdrivere e-books



Download e_book for software manual testing



Download e_book for Selenium Ide



Download e_book for Selenium Webdriver

Download e_book for Soap UI



Download e_book for Appium

Basic Marketing Principle



Download e_book for PHP, Mysql, html5, Javascript

Basic English Grammer



Download e_book for WebDesign with HTML CSS

Download e_book for Ethical Hacker















Tags :-

pdf for software testing tutorials

PDF for selenium webdriver

ebook for software testing tutorials

ebook for selenium webdriver

pdf for SOAP UI tutorials

ebook for SOAP UI



Sunday 30 July 2017

How to scroll in appium



For Video Tutorial : Move on Youtube Channel


Note : Select the playlist as per your need & move with number sequence


Hello Friends,
In this tutorial, we will discuss how to scroll down the application in appium.
As we know that ScrollTo("") does not work in new release of appium, so here is new method
The method is simple just use the Dimension class.
Get the size of screen & define the start & end of scroll.
Below is sample code, which will open the whatsapp & scroll it.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
public class GetwhatsappContacts
{
AndroidDriver driver;
List list;
File src;
XSSFWorkbook wb;
XSSFSheet sheet;
XSSFRow row1;
String gn;
@BeforeTest
public void g() throws MalformedURLException, InterruptedException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "LYF");
capabilities.setCapability(MobileCapabilityType.VERSION, "6.0.1");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Andriod");
capabilities.setCapability("appPackage", "com.whatsapp");
capabilities.setCapability("appActivity", "com.whatsapp.Main");
File file = new File("C:\\Users\\cchauhan\\Downloads\\New Appium\\src\\apk file\\base.apk");
capabilities.setCapability("apk", file.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(2000);
}
@Test
public void j() throws InterruptedException
{
Thread.sleep(4000);
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.99;
int scrollStart = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int scrollEnd = screenHeightEnd.intValue();
driver.swipe(0,scrollStart,0,scrollEnd,5000);
Thread.sleep(1000);
}
}


Thanks :)

Wednesday 5 July 2017

Data Driven Framework in Appium for android



For Video Tutorial : Move on Youtube Channel


Note : Select the playlist as per your need & move with number sequence


Data Driven Framework in Appium:

For Video : CLICK HERE For Part1




Hello Friends,
In this tutorial we will discuss how to create Data Driven Framework in appium for Android.

It is very similar as we created in Selenium for any web application.

Click Here

for selenium data driven framework.

Suppose we have below scenarios/Task to automate on Android to add multiple contacts in android :-

Our Scenarios will be as below :
1).Open Android dialer
2).Click on contacts
3).Click on create contacts
4).Enter Name
5).Enter Mobile Number
6).Click save button
7).Click on home Button


We will write the code in eclipse to achieve the objective.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.apache.poi.ss.usermodel.DataFormatter;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.remote.MobileCapabilityType;
public class Newtest2
{
static AndroidDriver driver;
XSSFWorkbook wb;
static XSSFSheet sheet;
FileInputStream fis;
@BeforeTest
public void g() throws IOException
{
File src = new File("D:\\study material\\Selenium Final complete\\Appium software\\contactsdata\\contact_data.xlsx");
fis = new FileInputStream(src);
wb = new XSSFWorkbook(fis);
sheet = wb.getSheetAt(0);
}
@Test
public void main() throws MalformedURLException, InterruptedException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "LYF");
capabilities.setCapability(MobileCapabilityType.VERSION, "6.0.1");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Andriod");
capabilities.setCapability("appPackage", "com.android.dialer");
capabilities.setCapability("appActivity", "com.android.dialer.DialtactsActivity");
File file = new File("C:\\Users\\cchauhan\\Downloads\\New Appium\\src\\apk file\\.apk");
capabilities.setCapability("apk", file.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
for(int i =121 ; i<131; i++)
{
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("Contacts")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("Create new contact")).click();
List list = driver.findElementsByClassName("android.widget.EditText");
String data = sheet.getRow(i).getCell(0).getStringCellValue();
list.get(0).sendKeys(data);
//WebElement Name = driver.findElement(By.name("Name"));
//Name.sendKeys("csc");
driver.pressKeyCode(AndroidKeyCode.ENTER);
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
DataFormatter formatter = new DataFormatter();
String val = formatter.formatCellValue(sheet.getRow(i).getCell(1));
list.get(1).sendKeys(val);
//WebElement number = driver.findElement(By.name("Phone"));
//number.sendKeys("9718632008");
driver.findElement(By.id("Save")).click();
Thread.sleep(5000);
driver.pressKeyCode(AndroidKeyCode.HOME);
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS);
List list2 = driver.findElements(By.className("android.widget.TextView"));
list2.get(5).click();
}
}
}



Tags :-

Data driven framework in appium,

How to create data driven framework in appium

Code for data driven framework in appium,

Example of data driven framework in appium

Sunday 2 July 2017

Computer Technical Tips

Basic Technical Tips



How To Make Pendrive Bootable for Windows 7

How to Make Pendrive bootable for window 7



For Video :-

Click Here



Step. 1:English :Open your command promt with “Run as administration” option
Hindi :(विंडो स्टार्ट बटन पर क्लिक करे और सर्च बॉक्स मे cmd लिखे और फिर राइट क्लिक करे “run as administration” ऑप्षन को सेलेक्ट करे).

Step. 2:English :Write command Diskpat and hit enter
Hindi :(अब कमॅंड लिखे DISKPART और एंटर बटन दबाए)

Step. 3:English :Write command list disk and hit enter
Hindi :(कमॅंड लिखे list disk और एंटर बटन दबाए)

Step. 4:English :Now your usb device will appear with status size etc.
Hindi :(यहा पर आपकी Pendrive का स्टेटस और साइज़ दिखय देगा)

Step. 5:English :Write command select Disk 1 and hit enter
Hindi :(कमॅंड लिखे select disk 1 और एंटर बटन दबाए)

Step. 5.5:English :Write command Clean and hit enter
Hindi :(कमॅंड लिखे Clean और एंटर बटन दबाए)

Step. 6:English :write command Create partition primary and hit enter
Hindi :(कमॅंड लिखे Create partition primary और एंटर बटन दबाए)

Step. 7:English :Write command Select partition 1 and hit enter
Hindi :कमॅंड लिखे Select partition 1 और एंटर बटन दबाए

Step. 8:English : Write command Active and hit enter
Hindi :कमॅंड लिखे Active 1 और एंटर बटन दबाए

Step. 9:English :Write command Format fs = ntfs quick and hit enter and wait to get it 100 percent
Hindi :कमॅंड लिखे Format fs = ntfs और एंटर बटन दबाए और इसके 100 % तक होने का इंतज़ार करे.



Step. 10:English :Write command Assign and hit enter
Hindi :(कमॅंड लिखे Assign और एंटर बटन दबाए)

Step. 11:English :Write command Exit and hit enter and you will exit from diskpart
Hindi :(कमॅंड लिखे Exit और एंटर बटन दबाए, अब आप diskpart से बाहर अपनी C या D ड्राइव मे आ जाएँगे)

Step. 12:English :Now go to your local system drive where you have window 7 setup folder.
command to switch between drive Drive_Name: and hit enter i.e. D:
commmond to comeout from folder cd.. and hit enter
command to select folder cd folder’s name first later and press TAB and select your folder.
for example: if i am in C drive in command prompt and i wanna to go in D drive to select my folder Test
then my command will be :
D: and enter // to move in D drive
D T and Tab //to select the folder Test
Hindi : (अब अपने कंप्यूटर की उस drive मे जाए जहा पर window 7 का setup है)
drive मे switch करने के लिए command prompt पर DriveName: लिखे और एंटर बटन दबाए जैसे की D:
फोल्डर से बाहर आने के लिए cd.. command को टाइप करके एंटर बटन दबाए
फोल्डर मे जाने के लिए cd foldername का पहला letter लिख कर TAB बटन दबाए और अपना Folder सेलेक्ट करे.

Step. 13:English :After selecting your window 7 setup folder write command CD BOOT i.e. D:\windows 7\boot>
Hindi :Window 7 setup फोल्डर मे पहुचने के बाद command CD boot टाइप करे इससे आप window 7 ke boot को सेलेक्ट कर लेंगे


Step. 14:English : Now write the command BOOTSECT.EXE/NT60 D: if your drive is D
Hindi :कमॅंड लिखे BOOTSECT.EXE/NT60 D: जहा पेर D आपकी pendrive का नाम है यदि ड्राइव का नाम D नही है तो जो नाम है वो लिखे



Step. 15:English :Now copy all the files(by selecting CTRL+A) of window 7 folder into your pendrive
Hindi :अब अपनी कंप्यूटर की विंडो 7 के सेटप फोल्डर को ओपने करे, window 7 के फोल्डर मे ctrl+a कमॅंड को प्रेस करके सारी फाइल सेलेक्ट करे और इसे pendrive मे पेस्ट कर दे.

Congratulation your pendrive is bootable now…….
Step 16:-Now plugin the pendrive to you computer and restart your computer

Step 17 :As soon window start, press F12 button or Fn+F12 button together.

Step 18 : Select the USB Boot option

Step 19 :Windows loading will get started & then select the Install Now option.

Step 20 :Under Device option select the driver & click the format link/button, selected drive will be formatted

Note : Before complete windows installation if your computer restart then remove your pendrive & insert it when window start will glimpse.

Thanks :)

Tags :

How to make pendrive bootable for windows 7

pendrive ko bootable kaise banae

pendrive ke window 7 kkaise upload kare

prndrive se system kaise format kare

Monday 26 June 2017

How to test Date Fields & Login Fields/Page



How to test Date field/test Scenarios for date field



1. Ensure that calendar window is displayed and active, when the calendar is invoked by pressing the calendar icon. (Once we faced an issue, the calendar window is in minimized state when we invoked the calendar.)

2. Ensure that calendar date is defaulted to system date/Server date.

3. Ensure that when a date is selected in the calendar (double click, or some other method), the selected date is displayed in the text box.

4. Check for the format as per requirement i.e. mm-dd-yy or dd-mm-yy etc.

5. Check for day, month and year( day should not be > 31, similarily month should be<=12,feb month should have days 28/29, should accept 29 days of february in the leap year, and year as per requirement).

6. Also try characters and spcl. characters on date if textbox is editable.

7. Try dates 30-02-2004 i.e validation for month of feb.

8. Check as per requirement if all parts are separated with / or - or . sign

9. 1980-, -1980, 20/10/2006 etc. if given in requirement, this is usually given in search 1980- means search for records after 1980 and so on.

10. should not accept 000000 as a date.

11. start date < end date

12. Cannot be left blank generally.

13.Check if the field accepts the input as blank.

14.Check if the date as 32 is accepted or not.

15.Check if the year field accepts year entered 10 years backward or forward.



---------------------------------------------------------------------------------------------------------


How to test Login field/test Scenarios for login field




1.check whether the login works with correct credentials

2.check that it doesn't work with wrong credentials

3.check text field limits - whether the browser accepts more than the allowed database limits

4.check whether password text is hidden

5. Check if the page is loaded

6. If login is remembered, check if closing the browser and relogging doesnt take to login page

7. If login is not remembered check if cookies helps to remember the session within the period

8. Check if appropriate error-message is displayed when entered with incorrect input ie invalid user id or pwd

9. Check if appropriate error-message is displayed when password or user id is not entered

10. Check if after login, it doesn't take back to the login page when the website is opened in a new tab

11.Check if password restrictions are applied when entering password ie integer 0-9, characters and special characters etc

12.signon attempts limit

13. Availability of user id and password tab

14. Check if user id and password form field is long enough

15. If there is captcha, check if characters are visible and readable

16.If there is 'remember me' option, check if its a tick box

17.Check if everything works in different browsers

18. sign-on to the application with multiple user accounts at the same time and capture latency of authentication

How to test Login page,

How to Validate Login Page

Scenarios to test login page,

Manual test cases to test login page

How to test Date Fields,

How to Validate Date Fields

Scenarios to test Date Fields,

Manual test cases to test Date Fields