Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
329 views

Selenium Java Training

The document provides instructions for downloading and installing Java JDK 8 on your local system. It explains how to download the Java JDK 8 file from Oracle's website, run the installer, and complete the installation process. It also describes how to verify that Java has been successfully installed by opening the command prompt and entering the "java -version" command.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
329 views

Selenium Java Training

The document provides instructions for downloading and installing Java JDK 8 on your local system. It explains how to download the Java JDK 8 file from Oracle's website, run the installer, and complete the installation process. It also describes how to verify that Java has been successfully installed by opening the command prompt and entering the "java -version" command.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 994

[SELENIUM TRAINING BY HANUMANTH]

Selenium Automation Tool Handbook


A basic referential guide to Selenium
2021

Download and install JDK(Java Development Kit) into your local System :
If you want to access the Java and Selenium then we need to install JDK first (Java
Development Kit).
Step 1- Download Java JDK 8
You can download Java 8 from the Oracle’s Java official website.

Java Download Page – JDK 8


Scroll down and you will see various download options for various platforms.
You will see two option, 32 and 64 bit versions for download. You can choose either
of them based on your system. Since the world is moving towards 64 bit
architecture, I use the 64 bit version. File ending with i586.exe is the 32 bit
version where as the file ending with x64 is the 64 bit version.

Java JDK 8 download page


Click on the version you want to download which is 64 bit version which in my case
is jdk-8u241-windows-x64.exe Go ahead, accept the licence agreement and download
the file.
Oracle does not allow you to download older versions of Java such as Java 8 without
registering with Oracle. That is you will have to create an account and login to be
able to download.
Its better to have an Oracle account because for a lot of downloads, Oracle has
stated asking users to login to download the files

Java JDK 8 – download – Licence Agreement


You will be asked to login to start the download. If you don’t have an Oracle
account, you can create here.

Oracle Login Page


Step 2- Run the Installer
To start the installation process, run the installer (.exe file)by double clicking
it. You will see the installation wizard.

Java SE JDK 8 Installation Wizard


Click Next to continue
Step 3- Custom Setup
In this screen you can change certain installation defaults. I accept this as it
is. You can change the installation directory if you want by clicking on change.
Click next to continue.

Java SE JDK 8 Installation Wizard – Custom Setup


Step 4 – Installation begins
You will see the installation begins

Java SE JDK 8 Installation Progress


You will be asked to specify the default installation folder for JRE. I accept the
default and click next.

Java SE JDK 8 Installation – Specify JRE destination folder


After this the installation will continue. Wait for sometime for the installation
process to complete.
Java Installation Progress
Once the installation completes, you will see the Installation complete message.
Java SE JDK 8 – Installation Complete
Click on close to complete the installation.
That’s it, now you have Java JDK installed on your system.
How to verify java successfully installed or not into your local system
 Open the command prompt.
 Run command java -version

It should show your installed java version detail as shown in above image.
That means java is installed successfully into your local system and you are ready
to use it.

Download and launch Eclipse IDE


1. IDE stands for Intigrated Development Environment.Eclipse Ide is useful to
write our test scripts in java or java based tools like selenium.
2. We need to follow below URL to download and launch Eclipse Ide
https://www.eclipse.org/downloads/packages/release/oxygen/3a

Download the Eclipse Oxygen, you can choose version Windows 32 bit or 64 bit based
on your OS

Wait until complete download.


copy downloaded file and paste into personal folder and extract
click on Eclipse folder
Associate Java and selenium webdriver with eclipse Ide.
 Here click on 'eclipse.exe' file directly.Here no need to install eclipse
into your local system.
 First time when you start eclipse software application, it will ask you to
select your workspace where your work will be stored as shown in bellow image.

Choose a workspace folder name as D:\workspace and click on ok button .Here You can
change the workspace location by clicking on Browse button>select the workspace
location where you have to save the working file.
Create new project
 Go to File
 New
 Java Project and give your project name 'JavaProject' > Click on finish
button.
Create new package
 Right click on source folder(src)
 New
 Package
 give the package name ‘JavaPack’
 Click on finish button.
Create New Class
 Right click on package ‘JavaPack’
 New
 Class
 give the class name 'Javademoclass'
 click on Finish button.

Java Comments :
>The java comments are statements that are not executed by the compiler and
interpreter. The comments can be used to provide information or explanation about
the variable, method, class or any statement. It can also be used to hide program
code for specific time.
Types of Java Comments :
There are 2 types of comments in java.
1. Single Line Comment
2. Multi Line Comment

Single Line Comment :


The single line comment is used to comment only one line.
Syntax:
//This is single line comment
Example:
public class SingleLineComment {
public static void main(String[] args) {
int i=10;//Here, i is a variable
System.out.println(i);
}
}
Multi Line Comment :
The multi line comment is used to comment multiple lines of code.
Syntax:
/*
This
is
multi line
comment
*/
Example:
public class MultiLineComment {
public static void main(String[] args) {
/* Let's declare and
print variable in java. */
int i=10;
System.out.println(i);
}
}
Data types in Java
>What is a variable in java ?
Ans :Variable is a memory location,here variable x can store some data based on
data type this is called variable.
>In java Every variable and every expression variable should have a dataType

>We can use DataTypes in our selenium webdriver to prepare the selenium automation
test script.
>In java or other programming languages,we know we need variables to store some
data based on data type.
>When we want to use a variable-in a program, we should first declare it as:
For example :

‘a’ can store an integer number like 10 as:

int x=10;
Types of dataTypes
1.Primitive dataTypes
2.Non-Primitive dataTypes
>What are primitive dataTypes in java?
Ans : boolean,char,byte,short,int,long,float and double
>What are non-primitive dataTypes in java ?
Ans : String ,array,class etc.

1.byte datatype
>This will be used to store positive and negative no’s
>Byte can store in the range of values min -128 to max 127
Example1 :
byte b=125; //valid
System.out.println(b);
Code Explanation:
>Here Providing value is 125( byte type value).
>Here Expected value is byte type.
>Here Variable b can store in the range of the values min -128 to max 127
>You are providing value is 125(By default java compiler can be considered as a
byte type)
>So we can assign byte type value into byte type variable b then this
statement(byte b=125;) is valid.
Found : byte
Required : byte
>In this case JVM will execute successfully.
Java Program:
>Run the java code from the Eclipse IDE?

package JavaPack;

public class Javademoclass {

public static void main(String[] args) {

byte b=125;// valid

System.out.println(b);

}
Example2 :
byte b=-128; //valid
System.out.println(b);
Code Explanation:
>Here Providing value is -128( byte type)
>Here Expected value is byte type.
>Here Variable b can store in the range the values min -128 to max 127
>You are providing value is -128(By default java compiler can be considered as a
byte type)
>So We can assign byte type value into byte type variable b then this statement is
valid.
Found : byte
Required : byte
>In this case JVM will execute successfully.
Example3 :
byte b=127; //valid
System.out.println(b);
Code Explanation:
>Here Providing value is 127( byte type)
>Here Expected value is byte type.
>Here Variable b can store in the range the values min -128 to max 127
>You are providing value is 127(By default java compiler can be considered as a
byte type)
>So We can assign byte type value into byte type variable b then this statement is
valid.
Found : byte
Required : byte
>In this case JVM will execute successfully.
Example 4
byte b="Kosmik";//invalid "HYD" or "123" or "HYD123" or "^%&^&^&**(("
System.out.println(b);
Code Explanation
>Here providing value is Kosmik
>Here Expected value is byte type
>Here variable b can store in the range of values min -128 to max 127.
>But you are providing value is Kosmik(by default java compiler can be considered
as a String type)
Note :
>We can say this("Kosmik") is a String type value
>Here String mean collection of characterss
>Here String always must be in double quotes
>Here everything in double quotes it's a string
>So we can't assign String type value into byte type variable b then this statement
is invalid
Found : String
Requird : byte
>In this case java compiler will through an error
Example5 :
byte b=true; //invalid
System.out.println(b);
Code Explanation
>Here providing value is true
>Here Expected value is byte type
>Here byte type variable b can store in the range of values min -128 to max 127.
>But you are providing value is true(by default java compiler can be considered as
a boolean type)
Note :
>We can say this(true) is a boolean type value
>Here boolean mean true / false
>So we can't assign boolean value into byte type variable b then this statement is
invalid
Found : boolean
Required : byte
>So in this case java compiler will through an error.
Example 6
byte b=127L; //invalid
System.out.println(b);
Code Explanation :
>Here providing value is 127L(long type value)
>Here Expected value is byte type
>Here byte type variable b can store in the range of values min -128 to max 127.
>But you are providing value is 127L(by default java compiler can be considered as
a long type value )
Note :
>We can say this(127L) is long type value or long literal value by suffixed with
'l' or 'L'
>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
Ans : Yes
>So we can't assign long type value into byte type variable b then this statement
is invalid

Datatype rules

byte(least) < short < int < long < float < double(highest)

>We can assign left-side datatype value into right-side datatype variable
>We can't assign right-side datatype value into left-side datatype variable
>If you are trying to assign right-side datatype value into left-side datatype
variable then we required TypeCasting.
Found : long type value
Required : byte type value
>So in this case java compiler will through an error.

Example 7
**********
byte b=10.5F; //invalid
System.out.println(b);
Code Explanation :
*******************
>Here providing value is 10.5F(float type value)
>Here Expected value is byte type
>Here byte type variable b can store in the range of values min -128 to max 127.
>>But you are providing value is 10.5F(by default java compiler can be considered
as a float type value )
Note :
>We can say this(10.5F) is a float type value by suffixed with 'f' or 'F'
Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
Ans : Yes
>So we can't assign float type value into byte type variable b then this statement
is invalid

Found : float type value


Required : byte type value
>So in this case java compiler will through an error.
Example 8
**********
byte b=5.8; //invalid
System.out.println(b);
Code Explanation :
*******************
>Here providing value is 5.8(double type value)
>Here Expected value is byte type
>Here byte type variable b can store in the range of values min -128 to max 127.
>>But you are providing value is 5.8 (by default java compiler can be considered
as a double type value )
Note :
>We can say this(5.8) is a double type value '
>By default every floating-point literal value is double type

>So we can't assign double type value into byte type variable b then this statement
is invalid
Found : double type value
Required : byte type value
>So in this case java compiler will through an error.
Example 9
**********
byte b=128; //invalid
System.out.println(b);
Code Explanation :
*******************
>Here providing value is 128 (int type value)
>Here Expected value is byte type
>Here byte type variable b can store in the range of values min -128 to max 127.
>>But you are providing value is 128 (by default java compiler can be considered
as a int type value )
Note :
>We can say this(int) is a int type value '
>By default every integral literal value is int type

>So we can't assign int type value into byte type variable b then this statement is
invalid

Found : int type value


Required : byte type value
>So in this case java compiler will through an error.
Sample Program :
package JavaPrograms;
public class ByteDataTypes {
public static void main(String[] args) {
byte a=-128; //currect
byte b=127; //currect
byte c=128; //compile time error
byte d=1.27; //compile time error
byte e="kosmik"; //compile time error
byte f=125; //currect
byte g=true; //compile time error

System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
}
}
short DataType
>This will be used to store positive and negative nos
>short data type can store in the range of values min -32768 to max 32767
short Example1
short s=-32768; //valid
System.out.println(b);

Code Explanation
>Here providing value is -32768
>Here Expected value is short type
>Here variable s can store in the range of values min -32768 to max 32767
>You are providing value is -32768 (by default java compiler can be considered as a
short type)
>So we can assign short type value into short type variable s then this statement
is valid
Found : short
Required : short
>So in this case JVM will execute successfully
short Example2
short s=32767; //valid
System.out.println(s);
Code Explanation
>Here providing value is 32767
>Here Expected value is short type
>Here variable s can store in the range of values min -32768 to max 32767
>You are providing value is 32767 (by default java compiler can be considered as a
short type)
>So we can assign short type value into short type variable then this statement is
valid
Found : short
Required : short
>So in this case JVM will execute successfully
short Example3
short s=32768; //invalid
System.out.println(s);
Code Explanation
>Here providing value is 32768(int type)
>Here Expected value is short type
>Here variable s can store in the range of values min -32768 to max 32767
>But you are providing value is 32768(By default java compiler can be considered as
a int type)
Note :
>What are the integral integer dataType in java ?
Ans :byte,short,int,long
>By default every literal literal value is int type.
>What are the integral floating-point dataTypes ?
Ans :float and double
>By default every floating-point literal value is double type.
>So we can't assign int type value into short type variable s then this statement
is invalid
Found : int
Required : short
>So in this case java compiler will through an error
short Example4
short s=3.2768; //invalid
System.out.println(s);
Code Explanation
>Here providing value is 3.2768(double type)
>Here Expected value is short type
>Here variable s can store in the range of values min -32768 to max 32767
>But you are providing value is 3.2768(By default java compiler can be considered
as a double type)
>So we can't assign double type value into short type variable s then this
statement is invalid
Found : double
Required : short
>So in this case java compiler will through an error
short Example5
short s=true; //invalid
System.out.println(s);
Code Explanation
>Here providing value is true
>Here Expected value is short type
>Here variable s can store in the range of values min -32768 to max 32767
>But you are providing value is true(By default java compiler can be considered as
a boolean type)
>So we can't assign boolean value into short type variable s then this statement is
invalid
Found : boolean
Required : short
>So in this case java compiler will through an error
short Example6
short s="Kosmik";
System.out.println(s);
>Here Providing value is Kosmik
>Here Expected value is short type
>Here variable s can store in the range of values min -32768 to max 32767
>But your Providing value is Kosmik(By default java compiler can be considered as a
String type).
Note :
1.String mean collection of charecters.
2.String always should be within double code.
>So we can't store String type value into short type variable s then this statement
is invalid.
Found :String
Required :short
>So in this case java compiler will through an error.
Sample Program :
package JavaPrograms;
public class ShortDataTypes {
public static void main(String[] args) {
short a = -32768; // Currect
System.out.println(a);
short b = 32767;// Currect
System.out.println(b);
short d = 3.2767; // compile time error
System.out.println(d);
short e = true;// compile time error
System.out.println(e);
short f = "Kosmik";// compile time error
System.out.println(f);

}
}
int dataType
>int dataType the most commonly used in java and selenium.
>This will be used to store positive and negative no's
>Int datatype can store in the range of values min -2147483648 to max 2147483647
int Example 1
int i=-2147483648; //valid
System.out.println(s);
Code Explanation
>Here Providing value is -2147483648( int type)
>Here Expected value is int type
>Here Variable i can store in the range the values min -2147483648 to max
2147483647
>Your Providing value is -2147483648 (By default java compiler can be considered as
a int type).
>So we can assign int type value into int type variable i then this statement is
valid.
Found: int
Required: int
>In this case JVM will execute successfully.
int Example2
int i=2147483647; //valid
System.out.println(i);
Code Explanation
>Here Providing value is 2147483647(int type)
>Here Expected value is int type
>Here Variable i can store in the range the values min -2147483648 to max
2147483647
>Your Providing value is 2147483647 (By default java compiler can be considered as
a int type).
>So we can assign int type value into int type variable i then this statement is
valid.
Found : int
Required : int
>In this case JVM will execute successfully.
int Example3
int i=21.47483647; //invalid
System.out.println(i);
Code Explanation
>Here Providing value is 21.47483647
>Here Expected value is int type
>Here variable i can store in the range of values min -2147483648 to max 2147483647
>But you are Providing value is 3.2767((By default java compiler can be considered
as a double type)
Note :
1.By default every integral literal value is int type.
2.By default every floating-point literal value is double type.
>So we can't assign double type value into int type variable i then this statement
is invalid.
Found : double
Required : int
>In this case java compiler will through an error.
int Example4
int i=true; //invalid
System.out.println(i);
Code Explanation
>Here Providing value is true
>Here Expected value is int type
>Here variable i can store in the range of values min -2147483648 to max 2147483647
>But you are Providing value is true(By default java compiler can be considered as
a boolean type)
>So we can't store boolean value into int type variable i then this statement is
invalid.
Found : boolean
Required : int
>So in this case java compiler will throug an error.
int Example5
int i=2147483647L; //invalid
System.out.println(i);
Code Explanation
>Here Providing value is 2147483647L
>Here Expected value is int type
>Here variable i can store in the range of values min -2147483648 to max 2147483647
>But you are Providing value is 2147483647L(By default java compiler can be
considered as a long type value)
Note :
1.We can say explicitly this is a long literal value by suffixed with 'l' or
'L'
>So we can't assign long type value into int type variable i then this statement
is invalid.
Found : long
Required : int
>In this case java compiler will through an error.
int Example6
int i="Kosmik"; //invalid
System.out.println(i);
Code Explanation
>Here Providing value is Kosmik
>Here Expected value is int type
>Here variable i can store in the range of values min -2147483648 to max 2147483647
>But you are Providing value is "Kosmik" (By default java compiler can be
considered as a String type).
Note :
1.String mean collection of charecters.
2.String always should be within double code.
>So we can't assign String type value into int type variable i then this statement
is invalid.
Found :String
Required :int
>So in this case java compiler will through an error.
Sample Program :
package JavaPrograms;
public class IntDataTypes {
public static void main(String[] args) {
int a=-2147483647;
System.out.println(a);
int b=2147483647;
System.out.println(b);
int d=21.47483647;//compile time error
System.out.println(d);
int e=true;//compile time error
System.out.println(e);
int g=2147483647L;//compile time error
System.out.println(g);
int h="Kosmik";//compile time error
System.out.println(h);
}
}
long DataType
>This will be used to store positive and negative no's
>Long data type can store in the range of values min -9223372036854775808 to max
9223372036854775807
long Example 1
long l=-9223372036854775808L;
System.out.println(l);
Code Explanation
>Here providing value is -9223372036854775808L
>Here Expected value is long type.
>Here variable l can store in the range of values min -9223372036854775808 to max
9223372036854775807
Note :
>We can say explicitly this is a long literal value by suffixed with 'l' or
'L'
>So we can assign long type value into long type variable l then this statement is
valid.
Found : long
Required : long
>In this case JVM will execute successfully.
long Example 2
long l=9223372036854775807L;
System.out.println(l);
Code Explanation
>Here providing value is 9223372036854775807L
>Here Expected value is long type.
>Here variable l can store in the range of values min -9223372036854775808 to max
9223372036854775807
>But you are Providing value is 9223372036854775807L(i.e long type value)
Note :
>We can say explicitly this is a long literal value by suffixed with 'l' or
'L'
>So we can assign long type value into long type variable l then this statement is
valid.
Found : long
Required : long
>In this case JVM will execute successfully.

long Example 3
long l=92.23372036854775807;
System.out.println(l);
Code Explanation
>Here providing value is 92.23372036854775807
>Here Expected value is long type.
>Here variable l can store in the range of values min -9223372036854775808 to max
9223372036854775807
>But you are Providing value is 92.23372036854775807(By default java compiler can
be considered as a double type)
Note :
1.By default every integral literal value is int type.
2.By default every floating-point literal value is double type.
>So we can't store double type value into long type variable l then this statement
is invalid.
Found : double
Required : long
>In this case java compiler will through an error.
long Example 4
long l=true;
System.out.println(l);
Code Explanation
>Here providing value is true
>Here Expected value is long type.
>Here variable l can store in the range of values min -9223372036854775808 to max
9223372036854775807
>But you are Providing value is true(By default java compiler can be considered as
a boolean type)
>So we can't store boolean value into long type variable l then this statement is
invalid.
Found : boolean
Required : long
>So in this case java compiler will throug an error.
Long Example 5
long l="Kosmik";
System.out.println(l);//invalid
Code Explanation
>Here providing value is Kosmik(String type)
>Here Expected value is long type
>Here variable l can store in the range of values min -9223372036854775808 to max
9223372036854775807
>But you are providing value is Kosmik(By default java compiler can be considered
as a String type)
>So we can't assign String type value into long type variable l then this statement
is invalid
Found : String
Required : long
>So in this case java compiler will through an error.
Sample Program :
package JavaPrograms;
public class LongDataTypes {
public static void main(String[] args) {
long a=-9223372036854775808L ;
System.out.println(a);
long b=9223372036854775807L;
System.out.println(c);
long d=92.23372036854775807L;//compile time error
System.out.println(d);
long e=true;// compile time error
System.out.println(e);
long f="Kosmik";// compile time error
System.out.println(f);
}
}
Boolean Datatype
>This will be used to store only boolean values such as true/false
>Here range not appicable(not valid) to boolean dataType
Example 1
boolean b= 0 ;
System.out.println(b);//invalid
Code Explanation
>Here providing value is 0(int type)
>Here Expected value is boolean type
>But you are providing value is 0
Note :
>By default every integral literal value is int type
>So we can't assign int type value into boolean type variable b then this statement
is invalid
Found : int
REquired : boolean
>So in this case java compiler will through an error
Example 2
boolean b= "true" ;
System.out.println(b);//invalid
Code Explanation
>Here providing value is "true"(By default java compiler can be considered as a
String type)
>Here Expected value is boolean type
>But you are providing value is "true"(String type value)
Note :
>String mean collection of charecters
>String always should be in double quotes
>boolean b can store only boolean values not string type value
>So we can't assign String type value into boolean type variable b then this
statement is invalid
Found : String
Required : boolean
>So in this case java compiler will through an error
Example 3
boolean b= true ;
System.out.println(b);//valid
Code Explanation
>Here providing value is true(By default java compiler can be considered as a
boolean type)
>Here Expected value is boolean type
>So we can assign boolean type value into boolean type variable b then this
statement is valid
Found : boolean
Required : boolean
>So in this case JVM will execute successfully
Example 4
boolean b= True ;
System.out.println(b);//invalid
Code Explanation
>Here providing value is True(variable True)
>Here Expected value is boolean type
>But you are providing value is True(By default java compiler can be considered as
a variable True)
Note :
>boolean value must be prefixed with 't' not 'T'
>This(True) is not appicable(not valid) for any data type
>So we can't assign variable True into boolean type variable b then this statement
is invalid
Found : variable True
Required : boolean
>So in this case java compiler will through an error
Sample Program :

package JavaPrograms;

public class BooleanDataTypes {

public static void main(String[] args) {


boolean a = 0;
System.out.println(a);

boolean b = "true";
System.out.println(b);

boolean c = True;
System.out.println(c);

boolean d = true;
System.out.println(d);

}
}

There are many non-primitive data types in java

String DataType
>This will be used to store group of charecters such "HYD" or "Kosmik123"
or”123456”
Or “!@#$%^1234”
>Here Everything in double quotes it's a String
>Here range not appicable for String data type
Example 1
String s= "Kosmik" ;
System.out.println(s);//valid
Code Explanation
>Here providing value is "Kosmik"(By default java compiler can be considered as a
String type)
>Here Expected value is String type
Note :
>Here String variable s can store group of charecters or single charecter
>String mean collection of charecters
>String always must be in double quotes
>Here we can use small letters or capital letters
>So we can assign string type value into String type variable s then this statement
is valid
Found : String
Required : String
>So in this case JVM will execute successfully
Example 2
String S= Kosmik; //invalid
System.out.println(S);
Code Explanation :
>Here providing value is Kosmik(variable Kosmik)
>Here Expected value is String type
>Here range not applicable for string data type
>But you are providing value is Kosmik(By default java compiler can be considered
as variable Kosmik)
Note :
>String mean collection of characters
>String always must be in double quotes
>This(Kosmik) is not applicable for any data type
>So we can't assign variable Kosmik into String type variable s then this statement
is invalid.
Found : variable Kosmik
Required : String
>So in this case java compiler will through an error
Example 3
String S= 10; //invalid
System.out.println(S);

Code Explanation :
>Here providing value is 10( int type value)
>Here Expected value is String type
>Here range not applicable for string data type
>But you are providing value is 10(By default java compiler can be considered as
int type value)
Note :
>By default ,every integral literal value is int type.
>So we can't assign int type value into string type variable s then this statement
is invalid.
Found : int
Required : String
>So in this case java compiler will through an error.
Example 4
String S= true; //invalid
System.out.println(S);
Code Explanation :
>Here providing value is true(boolean type value)
>Here Expected value is String type
>But you are providing value is true(By default java compiler can be considered as
a boolean type value)
Note :
>Here Boolean mean true / false
>So we can't assign boolean type value into String type variable s then this
statement is invalid.
Found : boolean
Required : String

>So in this case java compiler will through an error


What are valid and invalid statements?--IQ
String str1 = "kosmiktech"; //valid
String str2 = "KOSMIKTECH"; //valid
String str3 = kosmiktech ; // invalid
String str4 = 10; // invalid
String str5 = true; //invalid
Float data type
>This will be used to stored positive and negative decimal values
>Here Float datatype can store in the range of the values min -3.4028235e38F to max
3.4028235e38F
Note : Here e mean exponential form
>Here We can specify floating-point literal value(float value or double value) only
in decimal form.
Example 1
float f= 2.356f; //valid
System.out.println(f);
Code Explanation :
>Here providing value is 2.356f(float type value)
>Here Expected value is float type
>Here float type variable f can store in the range of the values min -
3.4028235e38F to max 3.4028235e38F
>Here providing value is 2.356f(By default java compiler can be considered as a
float type value)
Note :
*********
>We can say this(2.356f) is a float literal value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float literal value ?
***********************************************************************
Ans : Yes
>So we can assign float type value into float type variable f then this statement
is valid.
Found : float
Required : float
>So in this case JVM will execute successfully
Example 2
float f= -125.563f; //valid
System.out.println(f);
Code Explanation :
>Here providing value is -125.563f(float type value)
>Here Expected value is float type
>You are providing value is -125.563f(By default java compiler can be considered as
a float type value)
>So we can assign float type value into float type variable f then this statement
is valid.
Found : float
Required : float
>So in this case JVM will execute successfully
Example 3
float f= -101.23; //invalid
System.out.println(f);
Code Explanation :
>Here providing value is -101.23(double type value)
>Here Expected value is float type
>Here float type variable f can store in the range of the values min -
3.4028235e38F to max 3.4028235e38F
>Here providing value is -101.23(By default java compiler can be considered as a
double type value)
>So we can't assign double type value into float type variable f then this
statement is invalid.
Found : double
Required : float
>So in this case java compiler will through an error
float Example 4
float f=10.111111111f; //9 1's 10.111111
System.out.println(f);//valid
Code Explanation
>Here providing value is 10.111111111f(float type value)
>Here Expected value is float type
>Here variable f can store in the range of values min -3.4028235e38F to max
3.4028235e38F
>You are providing value is 10.111111111f (By default java compiler can be
considered as a float type)

Note :
>Float type variable f can store only decimal value upto 6 digits after decimal
>So we can assign float type value into float type variable f then this statement
is valid
Found : float
Required : float
>So in this case JVM will execute successfully
float Example 5
float f=25f;//25.0f
System.out.println(f);//valid
Code Explanation
>Here providing value is 25f(float type value)
>Here Expected value is float type
>Here variable f can store in the range of values min -3.4028235e38F to max
3.4028235e38F
>But you are providing value is 25f (By default java compiler can be considered as
a float type)

Note :
>When i run this program by default java compiler will provide 25.0(in decimal
form)
instead of 25 while assigning the value into float variable f.
>Here suffixed with ‘f’ or ‘F’ is a mandatory for float type value ?
Ans : Yes
> float f= 25f; //25.0f we can say explicitly this is a float type value by
suffixed with 'f' or 'F'
>So we can assign float type value into float type variable f then this statement
is valid
Found : float
Required : float
>So in this case JVM will execute successfully
float Example 6
float f=25; //25.0 valid
System.out.println(f);
Code Explanation
>Here providing value is 25(int type value)
>Here Expected value is float type
>Here variable f can store in the range of values min -3.4028235e38F to max
3.4028235e38F
>But you are providing value is 25(By default java compiler can be considered as a
int type)
Note :
>When i run this program by default java compiler will provide 25.0(in decimal
form)
instead of 25 while assigning the value into float variable f.
>So we can assign int type value into float type variable f then this statement is
valid
Found : int
Required : float
>So in this case JVM will execute successfully
Sample program

package JavaPrograms;

public class FloatDataTypes {

public static void main(String[] args) {

float a = 2.356f; //currect


System.out.println(a);

float b = -125.563f;//currect
System.out.println(b);

float d = -101.23;//compile time error


System.out.println(d);

float f=10.111111111f; //9 1's 10.111111


System.out.println(f);//valid
float f = 25f;//currect
System.out.println(f);

float g = 25;//currect
System.out.println(g);

}
}
Double DataType
>This will be used to store positive and negative decimal values
>Double dataType can store in the range of values min -1.7976931348623157e308d to
max 1.7976931348623157e308D
>We can specify floating-point literal value(float value or double value) only in
decimal form
Example 1
double d=2.356; //valid
System.out.println(d);

Code Explanation
>Here Providing value is 2.356(double type value)
>Here Expected value is double type
>Here Double variable d can store in the range of values min -
1.7976931348623157e308d to max 1.7976931348623157e308D
>You are providing value is 2.356(By default java compiler can be considered as a
double type)
>So we can assign double type value into double type variable d then this statement
is valid
Found : double
Required : double
>So in this case JVM will execute successfully
Example2
double d=-125.56; //valid
System.out.println(d);
Code Explanation
>Here providing value is -125.56(double type value)
>Here Expected value is double type
>Here Double variable d can store in the range of values min -
1.7976931348623157e308d to max 1.7976931348623157e308D
>But you are providing value is -125.56 (By default java compiler can be
considered as a double type)
>So we can assign double type value into double type variable d then this statement
is valid
Found : double
Required : double
>So in this case JVM will execute successfully
Example 3
double d=10.1111d;// valid
System.out.println(d);
Code Explanation
>Here providing value is 10.1111d(double type value)
>Here Expected value is double type
>Here Double variable d can store in the range of values min -
1.7976931348623157e308d to max 1.7976931348623157e308D
>You are providing value is 10.1111d(By default java compiler can be considered as
a double type)
Note :
>We can say explicitly this is a double literal value by suffixed with 'd' or 'D'
>Here suffixed with 'd' or 'D' is a mandatory for that double type value?
Ans : No
>So we can assign double type value into double type variable d then this statement
is valid
Found : double
REquired : double
>So in this case JVm will execute successfully
Example4
double d=10.1111111111111111;//16 1's
System.out.println(d);//valid
Code Explanation
>Here providing value is 10.1111111111111111(double type value)
>Here Expected value is double type
>Here Double variable d can store in the range of values min -
1.7976931348623157e308d to max 1.7976931348623157e308D
>You are providing value is 10.1111111111111111(By default java compiler can be
considered as a double type)
Note :
>Double variable d can store only decimal values upto 14 digits after decimal
>So we can assign double type value into double type variable d then this statement
is valid
Found : double
Required : double
>So in this case JVM will execute successfully
Example 5
double d= true;
System.out.println(d);
Code Explanation
>Here providing value is true(boolean type value)
>Here Expected value is double type
>Here Double variable d can store in the range of values min -
1.7976931348623157e308d to max 1.7976931348623157e308D
>But your Providing value is true(By default java compiler can be considered as a
boolean type)
>So we can't assign boolean value into double type variable d then this statement
is invalid.
Found : boolean
Required : double
>So in this case java compiler will through an error.
Sample Program

package JavaPrograms;

public class DoubleDataTypes {

public static void main(String[] args) {

double a = 2.356; //currect


System.out.println(a);

double b = -125.563;//currect
System.out.println(b);

double d=10.1111111111111111;//16 1's


System.out.println(d);//valid
double d=10.1111d;//
System.out.println(d);//valid
double h = true;//compile time error
System.out.println(h);

double i= 10.234f;
System.out.println(i);

}
}
Char data type
>This will be used to store single character such as 'r' or 'R' or '@' or '8' etc.
>Here everything in single quotes it's a character
>Here Char data type can store in the range of the values min 0 to max 65535
Example 1
char ch= 'c'; // valid
System.out.println(ch);

Code Explanation :
>Here providing value is 'c'(char type value)
>Here Expected value is char type
>Here char type variable ch can store in the range of the values min 0 to max 65535
>You are providing value is 'c'(By default java compiler can be considered as a
char type value)
Note :
>We can say this('c') is a char type value
>Here char value must be in single quotes
>Here char type variable ch can store single character not a group of characters.
>So we can assign char type value into char type variable ch then this statement is
valid.
Found: char
Required: char
>So, in this case, JVM will execute successfully
Example 2
char ch= "c"; // invalid
System.out.println(ch);
Code Explanation :
>Here providing value is "c"(String type value)
>Here Expected value is char type
>Here char type variable ch can store in the range of the values min 0 to max 65535
>But you are providing value is "c"(By default java compiler can be considered as a
String type value)
Note :
>We can say this("c") is a string type value
>Here string means a collection of characters
>Here String always must be in double-quotes.
>So we can't assign string type value into char type variable ch then this
statement is invalid.
Found: String
Required: char
>So, in this case, Java compiler will through an error
Example 3
char ch= c; // invalid
System.out.println(ch);
Code Explanation :
>Here providing value is c(variable c)
>Here Expected value is char type
>Here char type variable ch can store in the range of the values min 0 to max 65535
>But you are providing value is c(By default java compiler can be considered as
variable c)
Note :
>This(c) is not appicable for any datatype
>So we can't assign variable c into char type variable ch then this statement is
invalid.
Found: variable c
Required: char
>So in this case java compiler will through an error
Example 4
char ch= 'dd'; // invalid
System.out.println(ch);
Code Explanation :
>Here providing value is 'dd'(unclosed character literal value)
>Here Expected value is char type
>Here char type variable ch can store in the range of the values min 0 to max 65535
>But you are providing value is 'dd'(By default java compiler can be considered as
an unclosed character literal value)
>So we can't assign unclosed character literal value into char type variable ch
then this statement is invalid.
Found: unclosed character literal value
Required: char
>So, in this case, java compiler will through an error

Follow ASCII table in java


https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
Example 5
char ch= 66; //ASCII value(66) of a character --B(B is a char literal value)
System.out.println(ch);//valid
Code Explanation
>Here providing value is 66
>Here Expected value is char type
>Here char variable ch can store in the range of values min 0 to max 65535
Note :
>When i run this program by default java compiler will provide ASCII value of a
character while assigning the value into char type variable ch.
>So we can assign char literal value into char type variable ch then this statement
is valid
>So in this case JVM will execute successfully
More Examples
> char ch= 66;
System.out.println(ch);//valid
> char ch= 97;
System.out.println(ch);//valid
> char ch= 65;
System.out.println(ch);//valid
> char ch= 65535;
System.out.println(ch);//valid
Note : You can try more examples in the range of values min 0 to max 65535

Example 6
int i= 'a'; //the character of ASCII value ---97(This is int literal value)
System.out.println(i);//valid
Code Explanation
>Here providing value is 'a'
>Here Expected value is int type
>Here int type variable i can store in the range of values min 0 to max 65535
>You are providing value is 'a'
Note :
>When i run this program by default java compiler will provide the character of
ASCII value while assigning the value into int type variable i.
>So we can assign int literal value into int type variable i then this statement is
valid
>So in this case JVM will execute successfully.
More Examples :
> int i= 's';
System.out.println(i);//valid
> int i= 'd';
System.out.println(i);//valid
> int i= 'D';
System.out.println(i);//valid
Note : You can try more examples in the range of values min 0 to max 65535
Sample Program :

package JavaPrograms;

public class CharDataTypes {

public static void main(String[] args) {

char a = 'd'; //currect


System.out.println(a);

char b = d; //compile time error


System.out.println(b);

char c = "d"; //compile time error


System.out.println(c);
char d = 'dd'; // compile time error
System.out.println(d);

}
}

Interview Questions -byte datatype


What are Integral integer datatypes ?
1.byte
2.short
3.int
4.long

1.By default every integral literal value is what type ?


Ans : int type
3.What is the minimum and maximum values for byte datatype ?
Ans : min -128 to max 127
4.Can we assign int type value into byte type variable?
Ans : No
5.Can we assign negative values into byte type variable ?
Ans : Yes
6.Can we assign large no into byte type variable ?
Ans : No(We can't store more than 127)
7.Can we assign double type value into byte type variable?
Ans : No
8.Can we assign String type value into byte type variable?
Ans : No
9.Can we assign boolean type value into byte type variable?
Ans : No
Interview Questions -short datatype
1.By default every integral literal value is what type ?
Ans : int type
3.What is the minimum and maximum values for short datatype ?
Ans : min -32768 to max 32767.
4.Can we assign int type value into short type variable?
Ans : No
5.Can we assign negative values into short type variable ?
Ans : Yes
6.Can we assign large no into short type variable ?
Ans : No(We can't store more than 32767)
7.Can we assign double type value into short type variable?
Ans : No
8.Can we assign String type value into short type variable?
Ans : No
9.Can we assign boolean type value into short type variable?
Ans : No
10.Can we assign byte type value into short type variable?
Ans : Yes
Interview Questions -int datatype
1.By default every integral literal value is what type ?
Ans : int type
3.What is the minimum and maximum values for int datatype ?
Ans : min -2147483648 to max 2147483647
4.Can we assign int type value into Int type variable?
Ans : Yes
5.Can we assign negative values into int type variable ?
Ans : Yes
6.Can we assign large no into int type variable ?
Ans : No(We can't store more than 2147483647)
7.Can we assign double type value into int type variable?
Ans : No
8.Can we assign String type value into int type variable?
Ans : No
9.Can we assign boolean type value into int type variable?
Ans : No

10.Can we assign byte type value into int type variable?


Ans : Yes
11.Can we assign short type value into int type variable?
Ans : Yes
Interview Questions -long datatype
1.By default every integral literal value is what type ?
Ans : int type
3.What is the minimum and maximum values for long datatype ?
Ans : min -9223372036854775808 to max 9223372036854775807
4.Can we assign int type value into long type variable?
Ans : Yes
5.Can we assign negative values into long type variable ?
Ans : Yes
6.Can we assign large no into long type variable ?
Ans : No(We can't store more than 9223372036854775807)
7.Can we assign double type value into long type variable?
Ans : No
8.Can we assign String type value into long type variable?
Ans : No
9.Can we assign boolean type value into long type variable?
Ans : No
10.Can we assign byte type value into long type variable?
Ans : Yes
11.Can we assign short type value into long type variable?
Ans : Yes
12.Can we assign int type value into long type variable?
Ans : Yes
Interview Questions -float datatype
What are Integral Floating point data types
Ans :float , double
1.By default every integral literal value is what type ?
Ans : int type
2.By default every integral Floating point literal value is what type ?
Ans : double type
3.What is the minimum and maximum values for float datatype ?
Ans : min -1.7e38 to max 1.7e3
4.Can we assign int type value into float type variable?
Ans : Yes
5.Can we assign negative values into float type variable ?
Ans : Yes
6.Can we assign large no into float type variable ?
Ans : No(We can't store more than 1.7e38)
7.Can we assign double type value into float type variable?
Ans : No
8.Can we assign String type value into float type variable?
Ans : No
9.Can we assign boolean type value into float type variable?
Ans : No
10.Can we assign byte type value into float type variable?
Ans : Yes
11.Can we assign short type value into float type variable?
Ans : Yes
12.Can we assign int type value into float type variable?
Ans : Yes
13.Can we assign long type value into float type variable?
Ans : Yes
Interview Questions -double datatype

What are Integral Floating point data types


Ans :float , double
1.By default every integral literal value is what type ?
Ans : int type
2.By default every integral Floating point literal value is what type ?
Ans : double type
3.What is the minimum and maximum values for double datatype ?
Ans : min -3.4e308 to max 3.4e308
4.Can we assign int type value into double type variable?
Ans : Yes
5.Can we assign negative values into double type variable ?
Ans : Yes
6.Can we assign large no into double type variable ?
Ans : No(We can't store more than 3.4e308)
7.Can we assign double type value into double type variable?
Ans : Yes
8.Can we assign String type value into double type variable?
Ans : No
9.Can we assign boolean type value into double type variable?
Ans : No
10.Can we assign byte type value into double type variable?
Ans : Yes
11.Can we assign short type value into double type variable?
Ans : Yes
12.Can we assign int type value into double type variable?
Ans : Yes
13.Can we assign long type value into double type variable?
Ans : Yes
14.Can we assign float type value into double type variable?
Ans : Yes
Interview Questions -String datatype
1.Can we assign int type value into String type variable?
Ans : No
2.Can we assign negative values into String type variable ?
Ans : No
3.Can we assign double type value into String type variable?
Ans : No
4.Can we assign String type value into String type variable?
Ans : Yes
5.Can we assign boolean type value into String type variable?
Ans : No
6.Can we assign byte type value into String type variable?
Ans : No
7.Can we assign short type value into String type variable?
Ans : No
8.Can we assign int type value into String type variable?
Ans : No
9.Can we assign long type value into String type variable?
Ans : No
10.Can we assign float type value into String type variable?
Ans : No
Interview Questions -boolean datatype
3.What is the minimum and maximum values for boolean datatype ?
Ans : Range not applicable for boolean datatype(But allowed boolean values are
true/false)
4.Can we assign int type value into boolean type variable?
Ans : No
5.Can we assign negative values into boolean type variable ?
Ans : No
7.Can we assign double type value into boolean type variable?
Ans : No
8.Can we assign String type value into boolean type variable?
Ans : No
9.Can we assign boolean type value into boolean type variable?
Ans : Yes
10.Can we assign byte type value into boolean type variable?
Ans : No
11.Can we assign short type value into boolean type variable?
Ans : No
12.Can we assign int type value into boolean type variable?
Ans : No
13.Can we assign long type value into boolean type variable?
Ans : No
14.Can we assign float type value into boolean type variable?
Ans : No
Interview Questions -char datatype
3.What is the minimum and maximum values for char datatype ?
Ans : min 0 to max 65535
4.Can we assign int type value into char type variable?
Ans : No
5.Can we assign negative values into char type variable ?
Ans : No
7.Can we assign double type value into char type variable?
Ans : No
8.Can we assign String type value into char type variable?
Ans : No
9.Can we assign boolean type value into char type variable?
Ans : Yes
10.Can we assign byte type value into char type variable?
Ans : No
11.Can we assign short type value into char type variable?
Ans : No
12.Can we assign int type value into char type variable?
Ans : No
13.Can we assign long type value into char type variable?
Ans : No
14.Can we assign float type value into char type variable?
Ans : No
Important key points :
>In java Every variable and every expression should have dataType
>We can use DataTypes in our selenium webdriver to prepare the selenium automation
test script.
>In java or other programming languages,we know we need variables to store some
data.
>By default every integral literal value is int type.
>By default every floating-point literal value is double type.
>String mean collection of charecters.
>String always should be within double quotes.
>We can say explicitly this is a long literal value by suffixed with 'l' or 'L'
>We can say explicitly this is a float literal value by suffixed with 'f' or 'F'
>float this will be used to store decimal values upto 6 digits after decimal
Data types Rules:
(least) byte –> short –> int –> long –> float –> double(highest)
(least) char –> int –> long –> float –> double(highest)

1.We can assign left-side value to any right-side value


2.But we can't assign right-side value to any left-side value.
3.If you are trying to assign right-side value to any left-side value then we
requires typecasting explicitly.
>We can say explicitly this is a double type value by suffixed with ‘d’ or ‘D’
>We can specify explicitly double literal value only in decimal form
>Double data type can store only decimal values upto 14 digits after decimal
>Here boolean b can store only boolean values such as true/false
>char ch can store single character but the character must be in single quotes not
double quotes
>Here String s can store group of characters or single character.
>Here String must be in double quotes.
>char literal value must be in single quote
>Here String variable s can store group of charecters not boolean value
>Here String variable s can store group of charecters or single charecter
>String mean collection of charecters
>if(a)==>if(10)==>Here java compiler will expecting boolean value not integral
literal value
>if(a)==>if(10)==>Here if you are trying to use integral literal value then
immediately java compiler will through an error.
>boolean value must be prefixed with 't' not 'T'
>boolean b can store only boolean values not string type value
>Here suffixed with ‘f’ or ‘F’ is a mandatory for float type value ?
Ans : Yes
>Here suffixed with ‘d’ or ‘D’ is a mandatory for double type value ?
Ans : No
>Here suffixed with ‘l’ or ‘L’ is a mandatory for long type value ?
Ans : Yes
>What are the integral floating-point data types ?
Ans : float,double
Variable in java
>Variable is a memory location and here variable x can store some data based on
data type then it is called variable..
Example : int x=10;

Object Syntax :
//Create a Student class object
Student S = new Student();
Syntax Explanation :
>new Student();==>This is called Student class object
>Student()==>This is called Student constructor
>new==>Here new is called keyword
>Why we are using new keyword ?
Ans : By using this,we can create the object(new Student();)
>Here S is called object reference variable
>Here Student is called a class.

Variable types
1.Instance variables
2.Local variables
3.Static variables
1.Instance variables in java

> For Example I am taking a student class,where every student must be required name
and rollno.
>Here i am taking 1st stud class object,2nd stud class object-----nth stud class
object.
>Create stud1 reference variable this(stud1) refer to 1st stud class object,Create
stud2 reference variable this(stud2) refer to 2nd stud class object-----Create
studn reference variable this(studn) refer to nth stud class object.
>Here 1st stud name and roll no is name : Akki,rollno :101
>Here 2nd stud name and roll no is name : Sai,rollno :102
...........
>Here nth stud name and roll no is name : Hanu,rollno :103

Definition :
>The values of the name and rollno are different from student to student such type
of variables are called instance variables.
>The values of the name and rollno are different from object to object such type
of variables are called instance variables.
Example 1

public class Student {


int x=10;//instance variable
public static void main(String[] args) {
System.out.println(x);//error
}
}

>Where we can declare instance variables ?


Ans :We can declare instance variables inside the class or outside the method or
outside the constructor or outside the block(if,if-else,ladder if-
else,forloop,while,do-while,switch,static block)
>Static method can be declared with static keyword.
>Can we access the instance variable into static area directly?
Ans : No
>If you are trying to access the instance variable to the static area then
immediately java the compiler will through an error.
Example 2

public class Student {

String name ="Sai";//instance variable


int rollno=101;//instance variable

public static void main(String[] args) {

//create student class object

Student s=new Student();//here s is called object reference variable

System.out.println(s.name);//Sai

System.out.println(s.rollno);//101

}
>How to create the object for that student class?
Ans : Student s=new Student();
>Can we access the instance variable into static area ?
Ans : No,but we can access through object reference
Example 3

public class Student {


String name ="Sai";//instance variable
int rollno=101;//instance variable

//instance method
void m1()
{
System.out.println("Instance area "+name);//Sai
}

public static void main(String[] args) {

//create Student class object

Student s=new Student();


s.m1();//call the m1() through object reference variable s

System.out.println("static area : "+s.rollno);//101

}
}

>Can we access the instance variable into static area directly ?


Ans :No,but we can access through object reference
>Can we access the instance variable into instance area directly ?
Ans : Yes,we can access
Example 4
public class Student {

//instance variables

int i;
String str;
boolean b;
double d;

public static void main(String[] args) {

//create student class object

Student s=new Student();//here s is called object reference variable

System.out.println(s.i);//0
System.out.println(s.str);//null
System.out.println(s.b);//false
System.out.println(s.d);//0.0

}
>Here I am not initializing the values for that instance variables, When I run this
program by default java compiler will provide default values for that instance
variables.
Example 5
public class Student {
//instance variables

private String str;


public double d;
protected int i;

public static void main(String[] args) {

//create student class object

Student s=new Student();//here s is called object reference variable


System.out.println(s.i);//0
System.out.println(s.str);//null
System.out.println(s.d);//0.0

}
>What are the access modifiers in java?
Ans :
1.private
2.public
3.protected
4.default
Can we assign access modifiers for that instance variables?
Ans: Yes, we can assign
>CAn we access instance variable anywhere?
Ans: Yes we can access anywhere through an object reference.
>When instance variables will be accessible anywhere?
Ans: At the time of object creation.

>How many ways to access the instance variable to anywhere?


Ans: Only one way through an object reference
>Instance variables it's a part of object
2.Local variables in java
Exampl 1

public class Student {

//create method

void m1()
{

int x=10;//local variable


}

//create constructor

Student()
{
int y=20;//local variable

//create if block
If(){

int z=30;//local variable

}
>Where we can create local variables ?
Ans : inside the method or inside the constructor or inside the block such type of
variables are called local variable.
Example 2
public class Student {

public static void main(String[] args) {

int i=0;//local variable

for(int j=0;j<3;j++)
{
System.out.println(i);// valid
System.out.println(j);// valid

System.out.println(i);// valid
System.out.println(j);// error

>Here local variable(int i=0;) ,we can access any where inside the main method(For
Ex : We can access Inside the for loop or outside the for loop)
>int j=0;==>This is a local variable for that for loop
>Here local variable(int j=0;) we can access inside the forloop only and we can't
access the outside of the forloop.
>If you are trying to access the local variable(int j=0;)outside of the forloop
then immediately java compiler will through an error.
Example 3
public class Student {

public static void main(String[] args) {

int a;//local variable


int b;//local variable

System.out.println(a);//error
System.out.println(b);//error

}
>When i run this program by default java compiler will not provide default values
for that local variables,here compulsory we have to initilize the values for that
local variables.
>But java compiler will provide default values for that instance variables and
static variables.
Local variables Examples
int a; //invalid
int a=10;//valid
int a=0;//valid
Instance variables Examples
int a; //valid
int a=10;//valid
int a=0;//valid
Static variables Examples
static int a; //valid
static int a=10;//valid
static int a=0;//valid
Example 4
public class Student {

public static void main(String[] args) {

//local variables

private double d=2.5;//invalid

public byte b=10;//invalid

protected float=4.6f;//invalid

int x=10;//valid

final int y=20;//valid

}
>Can we assign access modifiers for that local variables ?
Ans :No
>Can we assign access modifiers for that instance variables and static variables ?
Ans :Yes,we can assign
>Here final is called modifier
>final int y=20;==>Here final means constant
>final int y=20;==>Here constant variable value never be changed ,that means no
increment or no decrement.So always y is 20.
>Can we assign any access modifiers for that local variable ?
Ans: No,but allowed final modifier
>Here local variable it's a part of methods or constructors or block
>Can we access the local variable anywhere ?
Ans :No
>Can we access the instance variable anywhere ?
Ans : Yes,we can access through object reference.
>When local variables will be accessible ?
Ans : While executing the methods or constructor or block.
3.Static variable in java

>For Exampl i am taking student class,where every student must be required


name,rollno and collegeName
>Here i am taking 1st stud1 class object,2nd stud2 class object....nth studn class
object
>Create 1st stud1 reference variable,2nd stud2 reference variable....nth studn
reference variable
>Here 1st stud1 refer to 1st stud1 class object,2nd stud2 refer to 2nd stud2 class
object....nth studn refer to nth studn class object.
>Here i am taking 1st stud1 name=Akki;,rollno=101;,collegeName=Kosmik;
>Here i am taking 2nd stud2 name=Sai;,rollno=102;,collegeName=Kosmik;
------
>Here i am taking nth studn name=Hanu;,rollno=103;,collegeName=Kosmik;
Defination :
>The values of the name and rollno are different from student to student such type
of variables are called instance variables
>The values of the name and rollno are different from object to object such type of
variables are called instance variables
Defination :
>The name of the college is same from student to student such type of variable is
called static variable
>The name of the college is same from object to student such type of variable is
called static variable
>Static varible can be declared with static keyword
Example 1

public class Student {

static String name="Sai"; // static variable

public static void main(String[] args)


{

System.out.println(name);//valid--Sai

}
>Static methods can be declared with static keyword such type of methods are called
static methods
>Static variable can be declared with static keyword such type of variable is
called static variable
>Can we access the static variable directly into static area ?
Ans : Yes,we can access
>Where we can declare the static variable ?
Ans : We can declare the static variable inside the class or outside the method or
outside the constructor or outside the block.

Example 2
public class Student {

static String name="Sai"; // static variable

public static void main(String[] args)


{
//create student class object

Student s=new Student();

System.out.println(s.name);//Sai

}
>Can we access the static variable into static area through object reference ?
Ans : Yes,we can access
Example 3
public class Student {

static String name="Sai"; // static variable

public static void main(String[] args)


{

System.out.println(Student.name);//Sai

}
>Can we access the static variable into static area through class name ?
Ans : Yes,we can access
Example 4

public class Student {

static String name="Sai"; // static variable

//instance method

void m1()
{
System.out.println("Instance area-->print student name through class
name :"+Student.name);//Sai

System.out.println("Instance area-->print student name directly :


"+name);//Sai

public static void main(String[] args)


{
//create student class object

Student s=new Student();//here s is called object reference variable s

s.m1();//call the m1() method through object reference variable s

System.out.println("static area-->print student name through object


reference :"+s.name);//Sai

System.out.println("static area-->print student name


directly :"+name);//Sai

>Can we access the static variable into instance area directly ?


Ans :Yes, we can access
>Can we access the static variable into instance area through class name ?
Ans : Yes,we can access
>CAn we access the static variable into static area directly ?
Ans : Yes,we an access
>CAn we access the static variable into static area through object reference ?
Ans : Yes,we can access
>How many ways to access the static variable ?
Ans :Three ways

1.Directly we can access anywhere


2.Through object reference
3.Through class name
Example 5

>If you want access the static variable like as instance variable through an object
reference, then java compiler will show you warning message and it won’t stop the
program because java compiler will replace object name to class name automatically
when i run this program.
>Where we can create static variables ?
Ans :Inside the class or outside the method or outside the constructor or outside
the block
Note :
>We can access the static variables into static area and instance area without
creating an object.
We need to know below points :
>Instance variables its a part of object
>Local variables it's a part methods or constructor or block.
>Static variables it's a part of class
Instance variables points:
>For every object a separate copy of name,rollno,marks will be created.
>For every object a separate copy of instance variables will be created.
>For every student a separate copy of name,rollno,marks will be created.
>How to print all the students name ,rollNo and marks ?

part 1
********
1.Print 1st student details
2.Print 2nd student details
-----
3.Print nth student details
part 2
*********
1.if u want to print the 1st student details then we need to create the object for
that 1st student
2.if u want to print the 2nd student details then we need to create the object for
that 2nd student
------
3.if u want to print the nth student details then we need to create the object for
that nth student
part 3
**********
Print 1st student details
********************************
1.First,initialize the values for that instance variables
2.Print 1st student details
Print 2nd student details
***************************
1.First,initialize the values for that instance variables
2.Print 1st student details
Print nth student details
*****************************
1.First,initialize the values for that instance variables
2.Print 1st student details
>If I change the 1st student marks then there are any effect of that 2nd student
marks,3rd student marks -----nth student marks ?
**********************************************************************************
Ans : No effect
When Function will be called ?
Ans : Whenever you create an object after function will be called

Example 1
public class Student {

//instance variables

String name;
int rollno;
int marks;

//instance method

void m1()
{

System.out.println("Student name : "+name);


System.out.println("Student rollno : "+rollno);
System.out.println("Student marks : "+marks);

public static void main(String[] args) {

//create object for that 1st stud

Student s1=new Student();//here s1 is called object reference variable


System.out.println("1st stud details");
// Initialize the values for that instance variable
s1.name="Akki";
s1.rollno=101;
s1.marks=520;
s1.m1();//call the m1() method through object reference variable s1

//create object for that 2nd stud

Student s2=new Student();//here s2 is called object reference variable


System.out.println("2nd stud details");
// Initialize the values for that instance variable
s2.name="Sai";
s2.rollno=102;
s2.marks=420;
s2.m1();//call the m1() method through object reference variable s2

//create object for that 3rd stud

Student s3=new Student();//here s3 is called object reference variable


System.out.println("3rd stud details");
// Initialize the values for that instance variable
s3.name="Hanu";
s3.rollno=103;
s3.marks=320;
s3.m1();//call the m1() method through object reference variable s3

>Can we change the 1st stud1 marks ?


Ans : Yes,we can change no problem

>If i change the 1st student marks then there are any effect for that 2nd student
marks ,3rd student marks -----nth student marks
Ans : No effect
Example 2
public class Student {

//instance variables

String name;
int rollno;
int marks;

//instance method

void m1()
{

System.out.println("name : "+name);
System.out.println("rollno : "+rollno);
System.out.println("marks : "+marks);

public static void main(String[] args) {

//create object for that 1st stud

Student s1=new Student();//here s1 is called object reference variable


System.out.println("1st stud details");
//Assign the values for that instance variables
s1.name="Akki";
s1.rollno=101;
s1.marks=520;
s1.marks=550;
s1.m1();//call the m1() method through object reference variable s1

//create object for that 2nd stud


Student s2=new Student();//here s2 is called object reference variable
System.out.println("2nd stud details");
//Assign the values for that instance variables
s2.name="Sai";
s2.rollno=102;
s2.marks=420;
s2.m1();//call the m1() method through object reference variable s2

//create object for that 3rd stud


Student s3=new Student();//here s3 is called object reference variable
System.out.println("3rd stud details");
//Assign the values for that instance variables
s3.name="Hanu";
s3.rollno=103;
s3.marks=320;
s3.m1();//call the m1() method through object reference variable s3

}
>Can we access the static variable directly into static area ?
Ans : Yes, we can access
>Can we access the static variable into static area through object reference?
Ans : Yes,we can access
>Can we access the static variable into static area through class name?
Ans : Yes,we can access
Static variables part 2:
>Create college name and share the college name for all the students of that class.
>Create single copy and share this copy for all the objects of that class

>How to print all the students name,rollno and collegeName ?

part 1
********
1.Print 1st student details
2.Print 2nd student details
-----
3.Print nth student details
part 2
*********
1.if u want to print the 1st student details then we need to create the object for
that 1st student
2.if u want to print the 2nd student details then we need to create the object for
that 2nd student
------
3.if u want to print the nth student details then we need to create the object for
that nth student
part 3
**********
Print 1st student details
********************************
1.First,initialize the values for that instance variables
2.Print 1st student details
Print 2nd student details
***************************
1.First,initialize the values for that instance variables
2.Print 1st student details
Print nth student details
*****************************
1.First,initialize the values for that instance variables
2.Print 1st student details

Example 1
public class Student {

//instance variables
String name;
int rollno;
static String collegeName;

//instance method

void m1()
{

System.out.println("name : "+name);//Hanu
System.out.println("rollno : "+rollno);//103
System.out.println("collegeName : "+collegeName);//320

public static void main(String[] args) {

//Assign the value for that static variable collegeName

Student.collegeName="Kosmik";

//create object for that 1st stud

Student s1=new Student();//here s1 is called object reference variable


System.out.println("1st stud details");
//Assign the values for that instance variables
s1.name="Akki";
s1.rollno=101;
s1.m1();//call the m1() method through object reference variable
s1

//create object for that 2nd stud

Student s2=new Student();//here s2 is called object reference variable


System.out.println("2nd stud details");
//Assign the values for that instance variables
s2.name="Sai";
s2.rollno=102;
s2.m1();//call the m1() method through object reference variable s2

//create object for that 3rd stud

Student s3=new Student();//here s3 is called object reference variable


System.out.println("3rd stud details");
//Assign the values for that instance variables
s3.name="Hanu";
s3.rollno=103;
s3.m1();//call the m1() method through object reference variable s3

}
>If i change the 3rd student college name then there are any effect for that 1st
stud collegeName,2nd stud collegeName -----nth studn collegeName?
Ans : Yes effect
Example 2
public class Student {

//instance variables

String name;
int rollno;
static String collegeName;

//instance method

void m1()
{

System.out.println("name : "+name);//Hanu
System.out.println("rollno : "+rollno);//103
System.out.println("collegeName : "+collegeName);//320

public static void main(String[] args) {

//Assign the value for that static variable collegeName

Student.collegeName="Kosmik";

//create object for that 1st stud

Student s1=new Student();//here s1 is called object reference variable


System.out.println("1st stud details");
//Assign the values for that instance variables
s1.name="Akki";
s1.rollno=101;
s1.m1();//call the m1() method through object reference variable s1

//create object for that 2nd stud

Student s2=new Student();//here s2 is called object reference variable


System.out.println("2nd stud details");
//Assign the values for that instance variables
s2.name="Sai";
s2.rollno=102;
s2.m1();//call the m1() method through object reference variable s2

//create object for that 3rd stud

Student s3=new Student();//here s3 is called object reference variable


System.out.println("3rd stud details");
//Assign the values for that instance variables
s3.name="Hanu";
s3.rollno=103;
s3.m1();//call the m1() method through object reference variable s3

//After change the 3rd stud collegename


s3.collegeName="New India";
System.out.println("1st stud collegeName : "+collegeName);

System.out.println("2nd stud collegeName : "+collegeName);

System.out.println("3d stud collegeName : "+collegeName);

Conclusion :
Instance variable:
>For every object a separate copy of instance variables will be created.
>If i change the 3rd student marks then there are any effect for that 1st stud
marks,2nd stud marks -----nth studn marks?
Ans : No effect.
Static variable :
>Create single copy and share this copy for all the objects of that class
>If i change the 3rd student collegeName then there are any effect for that 1st
stud collegeName,2nd stud collegeName -----nth studn collegeName?
Ans : Yes effect.
>When instance variables will be accessible ?
Ans: At the time of object creation
>When local variables will be accessible ?
Ans: While executing the methods or constructor or block
>When static variables will be accessible?
Ans: Suppose If you want to share the copy for all the objects then we need to use
a static variable

>Instance variable is a global variable


>Static variable is a class variable
>Instance variable access to any where through object reference
>Static variable access to any where through class name
>Local variable declare inside the method or constructor or block
Can we declare the variables like this?
int x=10,y=20; // valid

int x=10,String y="Kosmik"; //invalid

int x=10,int y=20; //invalid

int x=10;int y=20; //valid


*******************Variables Topic End******************
What is a method or function in java
>Method is a group of statements which is created to perform some actions and
operations.
>Inside a method you can’t be execute by itself.
>To execute that method you need to create object first then after function will be
called.
Syntax :

Note :
Here always method name start with small letter and then next word start with
capital letter
Ex's : add(),addFunction(),addfunction(),test(),testFunction().
Write a program for a method Without return statement and without parameters:-
************************************************************************

Example 1
package MethodOnlineClassesExamples;

public class WithoutReturnAndPrameters {

void add() {
int a = 10;
int b = 20;
int c = a + b;
System.out.println(c);

public static void main(String[] args) {

// Create the object for that class

WithoutReturnAndPrameters objectRef = new WithoutReturnAndPrameters();

objectRef.add();// call the add() function from objectRef

When function will be called?


Ans : Whenever you create an object after function will be called
Write a program for a method With return statement and without parameters:-
*******************************************************************************

Example 2

package MethodOnlineClassesExamples;

public class WithtReturnAndWithoutPrameters {

int add() {
int a = 10;
int b = 20;
int c = a + b;

return c;// 30

public static void main(String[] args) {

WithtReturnAndWithoutPrameters objectRef = new


WithtReturnAndWithoutPrameters();

int result = objectRef.add();// call the add() function from objectRef

System.out.println(result);// 30

}
}

When return statement will be used?


Ans :
>Suppose If you want to return method variable value,then compulsory we have to
write return statement within the body of method.
>If you are using return statement in this method, then compulsory c
value to be returned.Here c value is 30.30 is an int type value.So you have to
return int type.

Write a program for a method Without return statement and with parameters:-
*******************************************************************************

Note :
Here class name and method name may be the same(But this is not recommended as per
coding standard in java) or not.
Example 3
package MethodOnlineClassesExamples;

public class WithoutUsingReturnAndWithParameters {

void add(int a,int b)


{
int c=a+b;

System.out.println(c);//30

public static void main(String[] args) {

WithoutUsingReturnAndWithParameters objectRef=new
WithoutUsingReturnAndWithParameters();

objectRef.add(10,20);//call the add()

}
Write a program for a method With return statement and with parameters:-
******************************************************************************

Example 4

package MethodOnlineClassesExamples;

public class WithReturnAndWithPrameters {

int add(int a, int b) {


int c = a + b;

return c;// 30

public static void main(String[] args) {


WithReturnAndWithPrameters objectRef = new
WithReturnAndWithPrameters();

int result = objectRef.add(10, 20);// call the add()

System.out.println(result);

}
Why we are using parameters ?
Ans : By using these parameters,we can receive the data from outside into method
Note :
>Here Method can never return more than one value

Examples :
1.return c;//valid statement
2.return a,b;//invalid statement
3.return a,return b;//invalid statement
Example 5
With using return statement and with parameters:-
*****************************************************

Flow-control statements

1.if statement

If statement is used for checking condition, if the condition will satisfy then
compiler will execute if block.

Syntax :

if(boolean condition or Testing part)


{
//statement;
}

Example 1

int dog_age=5;

int cat_age=5;

if(dog_age==cat_age)
{
System.out.println("Animals age matched");
}

Note : If the condition is true then JVM will execute if block

Example 2

int dog_age=7;

int cat_age=5;

if(dog_age==cat_age)
{
System.out.println("Animals age matched");
}

Note :

>If the condition is true then JVM will execute if block.


>If the condition is false then JVM will print nothing output.
>But my requirement if the condition is true then JVM will execute if block.
If the condition is false then JVM has to print something in the console in this
case we are going to use else block.

2.if-else statement

If-else is used for checking condition, if the condition will satisfy then compiler
will execute if block. if the condition will not satisfy then compiler will
execute else block.
Figure :

Syntax :

Example 3

int dog_age=7;

int cat_age=5;

if(dog_age==cat_age)
{
System.out.println("Animals age matched");
}else
{
System.out.println("Animals age not matched");
}
Note :

>Now if the condition is true then JVM will execute if block.


if the condition is false then JVM will execute else block.

Conclusion :

>If you want to check only true condition then you have to go if statement

>If you want to check true or false condition then you have to go if-else
statement

Example 4

package Control_Flow;

public class IF_Else {

public static void main(String[] args) {


int A=100;

if(A>50)
{
System.out.println("Hello");//output--Hello
}else
{
System.out.println("Kosmik");
}

}
}

Code Explanation :
>int A=100;
>if(A>50)===>if(100>50)here java compiler will return true.
>If condition is true then JVM will execute if block

Found : boolean
Required : boolean

>In this case JVM will execute successfully

Example 5

package Control_Flow;

public class IF_Else {

public static void main(String[] args) {

int A=10;

if(A)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");
}

Code Explanation :

>Here int A=10;


> if(A);if(10); here java compiler will expecting boolean value not integral
literal value
>If you are trying to use any other type except boolean value then immediately java
compile will through an error.

Found : int
Required : boolean

>in this case java compiler will through an error

Example 6
package Control_Flow;

public class IF_Else {

public static void main(String[] args) {

int x=10;

if(x=20)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");
}
}
}

Code Explanation :

>int x=10; now onwards x value will become 20.


>if(x) here x means what 20
>if(20) here java compiler will expecting boolean value not integral literal value
>If you are trying to use any other type except boolean value then immediately java
compile will through an error.

Found : int
Required : boolean

>In this case java compiler will through an error.

Example 7

package Control_Flow;

public class IF_Else {

public static void main(String[] args) {

int x=10;

if(x==20)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");
}
}
}

Code Explanation :

>Here int x=10;


>if(x==20)===>if(10==20)here both are not matched then java compiler will return
false.
>If condition is false then JVM will execute the else block.

Found : boolean
Required : boolean

>In this case JVM will execute successfully

Note :

>java compiler compile the code (whether the code is correct or not).
>JVM will execute the code .

Example 8

package Control_Flow;

public class IF_Else {

public static void main(String[] args) {

boolean b=true;

if(b=false)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");//Output--Kosmik
}

}
}

Code Explanation :

>Here boolean b=true;Now onwards b value will become false


>if(b); here b means what false
>if(false)===>here java compiler will return false .
>If condition is false then JVM will execute else block.

Found : boolean
Required : boolean

>In this case JVM will execute successfully

Example 9

package Control_Flow;

public class IF_Else {

public static void main(String[] args) {

boolean b=false;

if(b==false)
{
System.out.println("Hello");//Output--Hello
}else
{
System.out.println("Kosmik");
}

}
}

Code Explanation :

>Here boolean b=false;


>if(b==false)===>if(false==false)both are same then java compiler will return
true.
>If condition is true then JVM will execute if block

Found : boolean
Required : boolean

>In this case JVM will execute successfully

Note :
== -------->By using this ,we can compare the values
= ------->By using this,we can assigning the value into variable
******************If,If-else Topics End*******************
Switch statement
If you want to check one or more conditions then we will go for a switch statement.
Flow diagram :

Syntax :
switch(Expression value){
case value1 :statement1-->Code to be executed;
break;
case value2 :statement2-->Code to be executed;
break;
case value3 :statement3-->Code to be executed;
break;
default :statement4-->Code to be executed if all the case values are not
matched with expression value;
}
>Here curly brackets are mandatory for switch statement.
>Here curly brackets are optional for if,else if,ladder if else,for loop,while,do-
while

Syntax Explanation
>If Expression value and case value1 both are matched then JVM will execute
statement1 and exit from switch statement by using a break statement without
checking the case value2 and case value3.
>If Expression value and case value1 both are not matched then JVM will jump into
case value2.
>If Expression value and case value2 both are matched then JVM will execute
statement2 and exit from switch statement by using a break without checking the
case value3.
>If Expression value and case value2 both are not matched then JVM will jump into
case value3.
>If Expression value and case value3 both are matched then JVM will execute
statement3 and exit from the switch statement by using a break.
>If Expression value and case value3 both are not matched then JVM will jump into
default and execute the statement4.
Example 1

public class switch_stat {

public static void main(String[] args) {

int x=10;

switch(x){

System.out.println("Kosmik");

}
>Here curly brackets are mandatory?
Ans: Yes, here curly brackets are mandatory
>In a switch statement, every statement should be under case value or case label
and default
>Here independent statements are not allowed
Example 2

public class switch_stat {

public static void main(String[] args) {

int x=10;
int y=20;

switch(x){

case 10 : System.out.println("Kosmik");//valid
case y : System.out.println("Kosmik");//invalid

}
>Here every case value should be constant, not variable
Example 3

public class switch_stat {

public static void main(String[] args) {

int x=10;//local

final int y=20;//here y is constant variable

switch(x){

case 10 : System.out.println("Hello");//valid
case y : System.out.println("Kosmik");//valid

}
>Here final is called as a modifier
>Can we assign final modifier for that local variable, instance variable, and
static variable?
Ans: yes, we can assign
>What are the access modifiers in java?
Ans :
1.private
2.public
3.protected
4.default
>Can we assign access modifiers for local variables?
Ans: No,
>Can we assign access modifiers for instance variables and static variables?
Ans: Yes, we can assign
>Here final means what constant,so here y is constant variable.constant variable y
never be changed that means no increment and no decrement.So always y is 20.
Example 4

package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{
byte x=10;

switch(x)
{
case 10 : System.out.println(10);//valid
break;

case 100: System.out.println(20);//valid


break;

case 1000: System.out.println(30);//invalid


break;
}
}
}
>Here byte data type this will be used to store in the range of values min -128 to
max 127
>Here every case value must be in the range of values min -128 to max 127
> Here case 10 is allowed in the range of values min -128 to max 127
> Here case 100 is allowed in the range of values min -128 to max 127
> Here case 1000 is not allowed in the range of values min -128 to max 127
>If you are trying to use(case 1000) more than 127 then immediately java compiler
will through an error
Found: int // case 1000
Required: byte
>In this case, java compiler will through an error
Example 5
package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{
byte x=10;

switch(x)
{
case 10 : System.out.println(10);
break;

case 11: System.out.println(11);


break;

case 11: System.out.println(12);


break;
}
}
}

>Duplicate case value not required


>If you trying to use Duplicate case value then immediately java compiler will
through an error.
Case value rules :

Fall-through (fall-down)inside the switch


**********************************************

Ans : Here expression value is matched with any case value from that case onwards

all the statements will be executed automatically until break statement then this

concept is called fall-through concept.

Example 6
***************
package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{

int b=0;

switch(b){

case 0: System.out.println("Sai");

case 1: System.out.println("Akki");
break;
case 2: System.out.println("Hanu");
default: System.out.println("NewIndia");
}
}
}

Note :
**********

>Here default case will be executed when expression value is not matched with any
case value.

Example 7
***************
package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{

char ch='r';

switch(ch){

case 'g': System.out.println("green");

case 'r': System.out.println("Red");


break;
case 'y': System.out.println("Yellow");

default: System.out.println("no color");


}
}
}

Default case rules


********************
1.Here default case will be executed when expression value is not matched with any
case value.

2.In switch block,we can write default case only once

3.In switch block,we can write default case anywhere

Example 7
***************
package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{

int furniture=0;
switch(furniture){

default: System.out.println("no color");

case 0: System.out.println("table");

case 1: System.out.println("chair");
break;
case 2: System.out.println("cot");

}
}
}

Loops in java ?
********************

Why we are using loops in java ?


************************************
Ans : Here loops are used to execute a group of statements repeatedly

as long as the condition is true

Example 1
************
public class Loops_Statement {

public static void main(String[] args) {

System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");

}
}

types of loops
*******************

3.forloop

Where exactly we can use forloop in java ?


**************************************
Ans : Sometimes we need to perform same action with multiple times so at that time

we need to fallow forloop.

Syntax :
*********

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
//loop body

>
>

Example 1
*************

How to print 1(starting)-10(ending) nos ?


*********************************************
1
2
3
4
5
.........10

Example 2
************
public class Loops_Statement {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{

System.out.println(i);

}
}

i++

i=i+1
i=1+1
i=2
------------

i++

i=i+1
i=2+1
i=3
Example 7
How to print car color using switch ?
package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{
char car_color ='r';

switch(car_color)
{
case 'g': System.out.println("green");
break;
case 'r': System.out.println("red");//red
break;
case 'y': System.out.println("yellow");
break;

default: System.out.println("Car color not matched");


}

}
}
>Here char value must be in single quotes
>Here char can store single character not a group of characters
Default case
Example 9
package Control_Flow;

public class Switch_stat {

public static void main(String[] args)


{
//int furniture=0;
//int furniture =1;
//int furniture =2;
int furniture =3;

switch(furniture)
{
default:

System.out.println("no furniture");

case 0:

System.out.println("table");

break;
case 1:

System.out.println("chair");

case 2:

System.out.println("cot");
}

}
}

More Examples :
What are the valid and invalid statements?

Switch statement Rules:


1. The default case will be executed when there is no case matched.
2. Inside a switch statement, we can take only one default case
3. Inside a switch statement, we can write default case anywhere but the switch is
recommended to write as the last case
4. Duplicate case value not required
5. Every case value must be constant value, not variable.
6. Within a switch statement, every statement should be under case and default
7. Inside a switch statement, Independent statements are not allowed.
8.Curly brackets are mandatory for the switch statement.
9.Curly brackets are optional for if,else if,ladder if-else,for loop,while,do-
while.
14.Here break statement is mandatory ?
Ans : No,here break statement is optional
15.Here default case is mandatory ?
Ans : No,here default case is optional
*****************Switch Topic End*****************
Iterative statements

Why we are using loops?

Ans: Loops are used to execute a group of statements repeatedly as long as the
condition is true.
For Example, Suppose if you want to print Kosmik 100 times then no need to write
like below. If you write like as below then your code size increased,development
time increased,duplicate code increased. So to avoid this situation you are going
to use the Loops Concept.
Example 1

public class WhileLoop {

public static void main(String[] args) {

System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");
System.out.println("Kosmik");

For Loop in java


Syntax :

for(initialization-part; boolean conditional-part/testing-part;


increment/decrement-part)
{

//loop body--- code to be executed ;


}
Syntax Explanation

>for(initialization-part; conditional-part/testing-part; increment/decrement-


part)==>Here code to be executed repeatedly if the condition-part is true.
>for(initialization-part; conditional-part/testing-part; increment/decrement-
part)==>Here if the condition is false then JVM will come of the For Loop and
execute the statements that appear after the For Loop.
When forloop will be accessible ?
Ans : Some times we need to perform same action with multiple times so at that time
we need to follow forloop.
Example 1
How to print Hanumanth (Starting value)1-100(ending value) times in java ?
public class ForLoop {

public static void main(String[] args) {

for (int i = 1; i <= 100; i++) {

System.out.println("Hanumanth");

Example 2
public class ForLoop {

public static void main(String[] args) {


int j = 1;

for (int i = 1; i <= 10; i++) {

System.out.println("Print i value :" + i);//valid


System.out.println("Print i value :" + j);//valid

}
System.out.println("Print i value :" +
i);//invalid
System.out.println("Print i value :" +
j);//valid

}
How to work with Nested For Loop(For loop inside another for loop)
Syntax :

for(initialization-part ; conditional-part ; Increment/Decrement-part)


{

for(initialization-part ; conditional-part ; Increment/Decrement-part)


{

//Inner for loop body---Code to be executed

}//Inner for loop end

//Outer for loop body---Code to be executed

}//Outer for loop end


Example 5
public class ForLoop {

public static void main(String[] args) {

int k = 0;

// Read the multiple rows


for (int i = 0; i < 3; i++) {

// Read the multiple columns

for (int j = 0; j < 3; j++) {


System.out.print(k + " ");

k++;

} // Inner loop ending

System.out.println();

} // Outer loop ending

}
Output :
0 1 2
3 4 5
6 7 8
Outer loop execute ---3 times
Inner loop execute ---9 times
Difference betweeen print() and println() in java ?
Ans :
print():
System.out.print("Kosmik")==>This will be used to print the Kosmik and the curser
waits on the same line to print the next text.
Examples :
System.out.print("Hello... ");
System.out.println("Hi");
System.out.println (“Kosmik");
Output :
Hello... Hi
Kosmik

println():
System.out.println("Kosmik")==>This will be used to print the Kosmik and move to
the next line to print the next text.
Examples :
System.out.println("Hello");
System.out.println("Hi");
System.out.println("Kosmik");
Output :
Hello
Hi
Kosmik
Transfer statement
This will be used to transfer from one place to another place nothing but transfer.
How to use break statement ?
Example 1
public class IfClass {

public static void main(String[] args) {

int x = 10;

if (x == 10) {
break;

System.out.println("Kosmik");

}
>Here if you are trying to use break statement outside of the switch and Loops then
immediately java compiler will through an error.

Note :
We can use break statement inside switch and Loop only
Without break statement inside switch :
Example 2
public class SwitchClass{

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println(0);//0
case 1 : System.out.println(1);//1
case 2 : System.out.println(2);//2
default : System.out.println("Kosmik");//Kosmik
}

}
With break statement inside switch :
Example 3

public class SwitchClass {

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println(0);//0
case 1 : System.out.println(1);//1
break;

case 2 : System.out.println(2);
default : System.out.println("Kosmik");

}
}

}
>Why we are using a break statement inside the switch ?
Ans: To stop the fall-through
Without break statement inside For Loop
How to print (starting value)1-10(ending value) numbers Without using break
statement inside For loop ?
Example 1
public class ForLoop {

public static void main(String[] args) {

for (int x = 1; x <= 10; x++) {

System.out.println(x);//

}
With break statement inside For loop
How to print (starting value)1-4(ending value) numbers With using break statement
inside do-while loop ?
Syntax :
for(initialization-part ; condition-part / Testing-part ; increment/decrement-part)
{
if(condition to break)
{
break;

}
}
Syntax Explanation :
>for(initialization-part ; condition-part / Testing-part ; increment/decrement-
part)==>Here if the condition is true then JVM will execute For Loop block.
>for(initialization-part ; condition-part / Testing-part ; increment/decrement-
part)==>Here if the condition is false then JVM will come of the For Loop and
execute the statements that appear after the For Loop.
>if(condition to break)==>Here if the condition is false then JVM will come of the
if block and execute the statements that appear after the if block.
>if(condition to break)==>Here if the condition is true then JVM will come inside
and break the statement,here break statement that mean an exit from For Loop and
execute the statements that appear after the For Loop.
Example 2
package SeleniumTests;

public class SampleProgram {

public static void main(String[] args) {

for (int x = 1; x <= 10; x++) {

if (x == 5) {
break;
}

System.out.println(x);//

}
>Why we are using a break statement inside the loops ?
Ans : To break the loop based on condition
Continue statement
Example 1
package SeleniumTests;

public class SampleProgram {

public static void main(String[] args) {

int x = 10;

if (x == 10) {
continue;

System.out.println(x);//

>If you are trying to use continue statement outside of the loops then immediately
java compiler will through an error.
>Where we can use continue statement ?
Ans : We can use inside Loops only.

Without continue statement inside For loop?


How to print (starting value)1-10(ending value) numbers Without using continue
statement inside For loop?
Example 2
package SeleniumTests;

public class SampleProgram {

public static void main(String[] args) {

for (int x = 1; x <= 10; x++) {

System.out.println(x);//

With continue statement inside For loop?


How to print (starting value)1-10(ending value) except 3 number With continue
statement inside For loop?
Syntax :
for(initialization-part ; condition-part / Testing-part ; increment/decrement-part)
{
if(condition to continue)
{

continue ;

}
Statement1;
Statement2;

Syntax Explanation :
>for(initialization-part ; condition-part / Testing-part ; increment/decrement-
part)==>Here if the condition is true then JVM will execute For loop block.
>for(initialization-part ; condition-part / Testing-part ; increment/decrement-
part)==>Here if the condition is false then JVM will come of the For loop and
execute the statements that appears after the For loop block.
>if(condition to continue)==>Here if the condition is false then JVM will come of
the if block and execute the statements that appear after the if block.
>if(condition to continue)==>Here if the condition is true then JVM will come
inside and execute the statements and then continue, here continue statement means
to continue for the next iteration without executing the remaining statements(That
means remaining statements are skipped)
Example 3
package SeleniumTests;

public class SampleProgram {

public static void main(String[] args) {


for (int x = 1; x <= 10; x++) {

if (x == 3) {

continue;

System.out.println(x);//

}
Constructor
>This is similar to method concept
Why we are using constructors?
Ans:
Types of constructor
There are two types of constructors in java:

1.Default constructor
Syntax :
Student()
{

}
2.Parametarized constructor
Syntax :
Student(para1,para2)
{

}
>Student(para1,para2)===>By using these parameters, we can receive the data from
outside into constructor.
>Here constructor doesn't return any value, not even void
>In the method, the return type is mandatory?
Ans: Yes
1.In default constructor,how to initialize the values to an instance variable

Example
package ConstructorPack;

public class Student1 {

// instance variables

String name;
int rollno;

// here default constructor is called and executed automatically

Student1() {
name = "Sai";
rollno = 100;
}

// here method is called and executed when we call it

void stud_Details() {
System.out.println("Hi this is :" + name);
System.out.println("My rollno :" + rollno);

public static void main(String[] args) {

// Create Student class object : Sai

Student1 Sai = new Student1();

Sai.stud_Details();// call the stud_Details() from Sai

// Create another Student class object :Akki

Student1 Akki = new Student1();

Akki.stud_Details();// call the stud_Details() from Akki

Note : Both Sai and Akki get the same data.But my requirement Sai will get
different data and Akki will get different data So at that time we need to follow
parameterized constructor.

When default constructor will be called?


Ans: Whenever you create an object by default default constructor will be called
When function will be called?
Ans: Whenever you create an object after function will be called
2.In parameterized constructor,how to initialize the values to a variable
Example
package ConstructorPack;

public class Student2 {


// instance variables

String name;
int rollno;

// here default constructor is called and executed

Student2() {
name = "Sai";
rollno = 100;

// here parameterized constructor is called and executed


Student2(String Name, int Rollno) {

name = Name;
rollno = Rollno;

// here method is called and executed

void stud_Details() {
System.out.println("Hi this is :" + name);
System.out.println("My rollno :" + rollno);

public static void main(String[] args) {

// Create Student class object : Sai

Student Sai = new Student();

Sai.stud_Details();// call the stud_Details() from Sai

// Create another Student class object :Akki

Student Akki = new Student("Akki", 200);

Akki.stud_Details();// call the stud_Details() from Akki

}
}

When parameterized constructor will be called?


Ans: Whenever you create an object and passing the values then parameterized
constructor will be called
Note :
>A Constructor is called and executed automatically
>A method is called and executed when we call it
>In Constructor, class name and constructor name must be same
>In the method, class name and method name may be the same or not
In java, Constructor overloading is possible?
Ans: Yes
What is a constructor overloading ?
Ans : Here constructor name same but with different argument types then it is
called constructor overloading.

Example :

Program :

package ConstructorPack;

public class Student {

// instance variables

String name;
int rollno;
// here default constructor is called and executed

Student() {
name = "Sai";
rollno = 100;

// here parameterized constructor is called and executed

Student(String Name, int Rollno) {

name = Name;
rollno = Rollno;

// here method is called and executed

void stud_Details() {
System.out.println("Hi this is :" + name);
System.out.println("My rollno :" + rollno);

public static void main(String[] args) {

// Create Student class object : Sai

Student Sai = new Student();

Sai.stud_Details();// call the stud_Details() from Sai

// Create another Student class object :Akki

Student Akki = new Student("Akki", 200);

Akki.stud_Details();// call the stud_Details() from Akki

}
1.A method is called and executed multiple times per single object
Example :
package ConstructorExamples;

public class Student {

// instance variables
String name;
int rollno;

// here method is called and executed when we call it

void stud_Details(String name, int rollno) {


System.out.println("Hi this is :" + name);//
System.out.println("My rollno :" + rollno);//
}

public static void main(String[] args) {

// Create the student class object : Sai

Student stud = new Student();

stud.stud_Details("Sai", 100);// call the stud_Details() from stud


stud.stud_Details("Akki", 200);
stud.stud_Details("Hanu", 300);

}
2.A constructor is called and executed only once per single object
3.We can write one or more constructors in the same class but with
different parameters.
Example
package ConstructorExamples;

package ConstructorExamples;

public class Student3 {

// here parameterized constructor is called and executed automatically

Student3(String name) {

System.out.println("Student name :" + name);

// here parameterized constructor is called and executed automatically

Student3(String name, int rollno) {

System.out.println("Student name :" + name);


System.out.println("Student rollno :" + rollno);

// here parameterized constructor is called and executed automatically

Student3(int id) {

System.out.println("Student id :" + id);

public static void main(String[] args) {

Student3 stud1 = new Student3("Sai");

Student3 stud2 = new Student3("Akki", 200);

Student3 stud3 = new Student3(123);

}
}

4.If instance variable and local variable both are not same then in this case this
keyword an optional.
Example
package ConstructorExamples;
package ConstructorExamples;

public class Student4 {

// Instance variable

int a = 10;

// here method is called and executed when we call it

void stud_Details() {

// local variable

int b = 20;

System.out.println(b);

public static void main(String[] args) {

Student4 stud = new Student4();

stud.stud_Details();// call the stud_Details() from stud

5. If the instance variable and local variable both are same then in this case we
have to give this keyword mandatory.
this keyword in java

>This keyword refers to an instance of the current class object


>By using this keyword you can access instance variables, constructors, and
methods.
>Specifying this keyword is some times optional and some times mandatory.
>Whenever you create an object by default this keyword is also created internally,
here this keyword refers to student class object.
How to call the instance variable from this keyword?
Syntax : this.variable
How to call the default constructor from this keyword?
Syntax : this()
How to call the parameterized constructor from this keyword?
Syntax :this(value)
How to call the method from this keyword?
Syntax : this.methodname()
Example
package ConstructorExamples;
public class Student4 {

//Instance variable

int a=10;

//here method is called and executed when we call it

void stud_Details()
{
//local variable

int a=20;

System.out.println("local variable : "+a);//20

System.out.println("Instance variable :"+this.a);//10

public static void main(String[] args) {

Student4 stud = new Student4();

stud.stud_Details();//call the stud_Details() from stud

Example 2
package ConstructorExamples;

public class Student5 {

// instance variable

int a = 10;

// here parameterized constructor is called and executed automatically

Student5(int a) { //local variable

this.a = a;

// here method is called and executed when we call it

void stud_Details() {

System.out.println(a);// 10

public static void main(String[] args) {

Student5 stud = new Student5(10);


stud.stud_Details();// call the stud_Details() from stud

}
Calling parameterized constructor and method from default constructor
Example
package ThisKeywordExamples;

public class Student1 {

// instance variable

int a;

// here default constructor is called and executed automatically

Student1() {
this(10);// call the parameterized constructor and send 10
this.stud_Details();

Student1(int a) {
this.a = a;

}
// here method is called and executed when we call it
void stud_Details() {
System.out.println(a);// 10

public static void main(String[] args) {


Student1 stud = new Student1();

Calling default constructor from parameterized constructor


Example
package ThisKeywordExamples;

public class Student2 {

Student2() {
System.out.println("Hello Hanumanth");
}

// here parameterized constructor is called and executed automatically

Student2(int a) {
this();// call the default constructor
System.out.println(a);// 10

public static void main(String[] args) {


Student2 stud = new Student2(10);

Calling parameterized constructor from parameterized constructor


Example 1
package ThisKeywordExamples;

public class Student3 {

// here default constructor is called and executed automatically

Student3() {
this(10);// call the parameterized constructor

Student3(int a) {
this(10, 20);// call the parameterized constructor
}

Student3(int a, int b) {
this(10, 20, 30);// call the parameterized constructor
}

Student3(int a, int b, int c) {


System.out.println("Total values : " + (a + b + c));// 60
}

public static void main(String[] args) {

Student3 stud = new Student3();

Class and Object in java?

Here Class and objects Examples


Class :Vehicles Objects :car,bus,auto etc.
Class :Animals Objects :cat,dog,elephant etc.
Class :Furniture Objects :chair,table,cot etc.
Class :Fruits Objects :mango,orange,apple etc.

What is an Object in java?


Ans: It exists really / physically
Examples : car,cat,apple,table etc.
In real-world objects have two things
1.State / Properties
2.Behavior / Action
Diagram
>Here Student must be required Properties and Actions

What is a class in java?


Ans: It doesn't exist really / physically
Examples: vehicles, Animals, Furniture, Fruits, etc.
>Here class is a blueprint / Template / Structure / design from which
individual objects are created.

>Here always created from class to object, not object to class

In real world car is an object, it has two things


1.State / Properties
2.Behavior / Action
Diagram
>Here Car must be required Properties and Actions

Object Syntax
Student S= new Student();
Syntax Explanation :
>Student()==>This is a constructor
>new==>This is a keyword
>Why we are using a new Keyword?
Ans : By using new keyword ,we can create the object(new Student();)
>Here S is called object reference variable
>Here Student ==>This is a class
Class Syntax :
class <Class-name>
{
//State / Properties------Variables

<Datatype> variable1;
<Datatype> variable2;

//Behaviour / Actions-----Methods / Functions

return-type method_name1()
{

}
return-type method_name2()
{

main()
{

}
Example
package Method_Function;

public class Student {

void stud_details(String name,int rollno)


{
System.out.println("Student name :"+name);//Hanu

System.out.println("Student rollno :"+rollno);//103


}
public static void main(String[] args)
{

//create the object for that Student class

Student S = new Student();

S.stud_details("Sai",101);//call the stud_details() and pass


"Sai",101

S.stud_details("Akki",102);//call the stud_details() and pass


"Akki",102

S.stud_details("Hanu",103);//call the stud_details() and pass


"Hanu",103
}
}

Difference betweeen Class and Object in java?


Class
>It doesn't exist really / physically
Examples: vehicles, Animals, Furniture, Fruits, etc.
>In the program, We can create class only once
>We can create the class without using object
>Memory space is not allowed when class is created
>Here class contain variables and methods
>Why we are using class keyword?
Ans: By using the class keyword, we can create the class
Object
>It exists really / physically
Examples : car,cat,apple,table etc.
>We can create no of objects in the same class
>We can't create the object without a class
>Memory space is allowed when the object is created
>And also object can contain variables and methods
>Why we are using a new keyword?
Ans: By using the new keyword, we can create the object
Java Oops Concepts

When will you go for inheritance in java?


Without inheritance :
Example:
Teacher class code
package JavaExamples;

public class Teacher {


//instance variable

int id;
String name;
String address;
int sal;

//to store Id
void setId(int id)
{
this.id=id;
}
//to retrieve Id
int getId()
{
return id;
}
//to store name
void setName(String name)
{
this.name=name;
}
//to retrieve name
String getName()
{
return name;
}
//to store address
void setAddress(String address)
{
this.address=address;
}
//to retrieve address
String getAddress()
{
return address;
}
//to store Sal
void setSal(int sal)
{
this.sal=sal;
}
//to retrieve sal
int getSal()
{
return sal;
}

Student class code


package JavaExamples;

public class Student {

//instance variable

int id;
String name;
String address;
int marks;

void setId(int id)


{
this.id=id;
}
int getId()
{
return id;
}
void setName(String name)
{
this.name=name;
}
String getName()
{
return name;
}
void setAddress(String address)
{
this.address=address;
}
String getAddress()
{
return address;
}
void setMarks(int marks)
{
this.marks=marks;
}
int getMarks()
{
return marks;
}
}

Main class code


package JavaExamples;

public class MainClass {

public static void main(String[] args) {


System.out.println("*******Teacher details******");

Teacher T=new Teacher();

T.setId(101); //call the setId and send 101


T.setName("Akki"); //call the setName and send Akki
T.setAddress("Kukatpally");//call the setAddress and send Kukatpally
T.setSal(20000);//call the setSal and send 20000

System.out.println("Id : "+T.getId());//call the getId


System.out.println("Name : "+T.getName());//call the getName
System.out.println("Address : "+T.getAddress());//call the getAddress
System.out.println("Sal : "+T.getSal());//call the getSal

>In this program,an object to Teacher class is created by JVM ,as shown below

System.out.println("*******Student details******");

Student S=new Student();

S.setId(102); //call the setId and send 102


S.setName("Sai"); //call the setName and send Sai
S.setAddress("KPHB");//call the setAddress and send KPHB
S.setMarks(926);//call the setSal and send 926

System.out.println("Id : "+S.getId());//call the getId


System.out.println("Name : "+S.getName());//call the getName
System.out.println("Address : "+S.getAddress());//call the getAddress
System.out.println("Marks : "+S.getMarks());//call the getMarks

>In this program,an object to Student class is created by JVM ,as shown below

Just compare the Teacher class and Student class. You can find 75% of the
similarities in both the classes. While developing the Student class, if the
programmer has thought of reusing Teacher class code, developing the Student class
would have been very easy.With this idea, let us rewrite Student class
again.Whatever code is available in the Teacher class will be omitted in writing
the Student class as that code will be automatically available to the Student
class.
For this purpose,simple use the keyword ‘extends’ as :
class Student extends Teacher
The preceding statement means all the members(variables and methods)of Teacher
class are available to Student class without rewriting them in Student class .Only
additional members should be written in Student class.
So,developing the Student class will become easy as shown below :
public class Student extends Teacher{

//instance variable

int marks;

void setMarks(int marks)


{
this.marks=marks;
}
int getMarks()
{
return marks;
}
}
Inheritance in Java ?
>Inheritance is also known as IS-A Relationship
Definition

>Create new class from the existing class, the subclass acquired all
the features of the superclass by using extends keyword then it is called
Inheritance.
What are the advantages of Inheritance ?
*****************************************
Ans : By using Inheritance,we can

1.Reduce the code size


2.Reduce the development time
3.Avoid the duplicate code

What is the main advantage of inheritance ?


********************************************
Ans : Code reusability
Syntax :
class Superclass
{

}
class Subclass extends Superclass
{

}
MainClass
{
}
Syntax Explanation :
***********************
>class SubClass extends SuperClass===>Create SubClass from SuperClass by using
extends keyword(that means Superclass code is available
to Subclass automatically by using extends keyword)

>Here extends is called keyword


>Why we are using extends keyword ?
***********************************************
Ans : By using this, we can inherit the Subclass from SuperClass
Note :
>Inheritance created always parent to a child, not a child to parent

In superclass(Teacher class)

In superclass, we have to create Common code and Additional code(optional)

//Common code

>setId()
>setName()
>setAddress()
>getId()
>getName()
>getAddress()

// Additional code(optional)

>setSal()
>getSal()

In subclass(Student class)

In Subclass, we have to create only additional code, not superclass code

//Additional code(Mandatory)

>setMarks()
>getMarks()

Example 1

Manual steps
************
1.Create the superclass(Teacher class)
2.Create the subclass(Student class) from superclass(Teacher class)
3.Create Mainclass

Java code:

1.Create the superclass(Teacher class)

package JavaExamples;

public class Teacher {

//Common code from both the classes

//instance variable

int id;
String name;
String address;
int sal;

//to store Id
void setId(int id)
{
this.id=id;
}
//to retrieve Id
int getId()
{
return id;
}
//to store name
void setName(String name)
{
this.name=name;
}
//to retrieve name
String getName()
{
return name;
}
//to store address
void setAddress(String address)
{
this.address=address;
}
//to retrieve address
String getAddress()
{
return address;
}

//additional code(optional)
//to store Sal
void setSal(int sal)
{
this.sal=sal;
}
//to retrieve sal
int getSal()
{
return sal;
}

2.Create the subclass(Student class) from superclass(Teacher class)

package JavaExamples;

public class Student extends Teacher{

//instance variable

int marks;

void setMarks(int marks)


{
this.marks=marks;
}
int getMarks()
{
return marks;
}
}

In Student class,
>Here you don't write super class code
>Here only additional members(variables and methods) should be written in the
student class

3.Create Mainclass

package JavaExamples;

public class MainClass {

public static void main(String[] args) {


System.out.println("*******Teacher details******");

Teacher T=new Teacher();

T.setId(101); //call the setId and send 101


T.setName("Akki"); //call the setName and send Akki
T.setAddress("Kukatpally");//call the setAddress and send Kukatpally
T.setSal(20000);//call the setSal and send 20000

System.out.println("Id : "+T.getId());//call the getId


System.out.println("Name : "+T.getName());//call the getName
System.out.println("Address : "+T.getAddress());//call the getAddress
System.out.println("Sal : "+T.getSal());//call the getSal

System.out.println("*******Student details******");

Student S=new Student();

S.setId(102); //call the setId and send 102


S.setName("Sai"); //call the setName and send Sai
S.setAddress("KPHB");//call the setAddress and send KPHB
S.setMarks(926);//call the setSal and send 926

System.out.println("Id : "+S.getId());//call the getId


System.out.println("Name : "+S.getName());//call the getName
System.out.println("Address : "+S.getAddress());//call the getAddress
System.out.println("Marks : "+S.getMarks());//call the getMarks
}

}
Types of Inheritance
1.Single Inheritance
2.Multi-Level Inheritance
3.Hierarchical Inheritance

1.Single Inheritance

Example
Follow the Steps
1.Create Superclass(Parent class)
2.Create Subclass(Child class) from Superclass(Parent class)
3.Create MainClass

Java code
Parent (Superclass) :

package Inheritance_Example2;

public class Parent { // super class

void m1()
{
System.out.println("Parent");//parent
}

Child(Subclass):

package Inheritance_Example2;

public class Child extends Parent {

void m2()
{
System.out.println("Child");//child

MainClass

package Inheritance_Example2;

public class MainClass {


public static void main(String[] args) {

//Create the object for that Child class

Parent S = new Child();

S.m1();//call the m1()----valid


S.m2();//call the m2()----Invalid

}
Case 1

with child reference,we can call the parent class method


with child reference,we can call the child class method

Child C = new Child();


C.m1();//call the m1()----valid
C.m2();//call the m2()----valid
Case 2

With Parent reference,we can call the Parent class method


With Parent reference,we can't call the Child class method
Parent C = new Child();
C.m1();//call the m1()----valid
C.m2();//call the m2()----invalid
Case 3

With Parent reference,we can call the Parent class method


With Parent reference,we can't call the Child class method
Parent P = new Parent();
P.m1();//call the m1()----valid
P.m2();//call the m2()----invalid
Case 4

With Parent object,we can't call the Parent class method using child reference.
With Parent object,we can't call the Child class method using child reference.
Child P = new Parent();
P.m1();//call the m1()----invalid
P.m2();//call the m2()----invalid
Imp points
>By using the class keyword, we can create the class
>By using the new keyword, we can create the object
>Memory space is not allowed when class is created
>Memory space is allowed when the object is created
>Here always created from class to object, not object to class

>Here always created from Parent to Child, not Child to Parent

>Here class can contain members(variables + Methods)


>And object also can contain members(variables + Methods)
2.Multi-level Inheritance

>Here Father class acquired all the features of GrandFather class code and
Son class acquired all the features of Father class code by using extends keyword
then it is called Multi-Level Inheritance.
Syntax
class GrandFather //superclass
{

}
class Father extends GrandFather
{

}
class Son extends Father
{

}
Example 1

Follow the Steps


1.Create a GrandFather class(Superclass)
2.Create Father class(Subclass1) from GrandFather class(Superclass)
3.Create Son (Subclass2) class from Father class(Subclass1)
Java code
Superclass(GrandFather)
package MultiLevelInheritance;

public class GrandFather { // superclass

void rest() {
System.out.println("rest");
}

}
Subclass1(Father)
package MultiLevelInheritance;

public class Father extends GrandFather {

void work() {

System.out.println("work");
}

}
Subclass2(Son)
package MultiLevelInheritance;

public class Son extends Father {

void study() {
System.out.println("study");// study
}

MainClass
package MultiLevelInheritance;

public class MainClass {

public static void main(String[] args) {


// Create object for that son class

Son S = new Son();

S.rest();// call the rest method---valid


S.work();// call the work method---valid
S.study();// call the study method---valid

Note :
>In Child class(Father),You don't write parent class code internally
superclass code is available to child class automatically by using extends
keyword.
>In Son class, you don't write parent class code internally parent class(Father)
code is available to Child class(Son) automatically by using extends keyword.
Example 2

Syntax :
class Calculation //superclass
{

}
class Sum extends Calculation
{

}
class Subtraction extends Sum
{

}
Example

Follow the Steps


1.Create Calculation class(Superclass)
2.Create Sum class (Subclass1)from Calculation class(Superclass)
3.Create Subtraction(Subclass2) class from Sum class(Subclass1)
Java code
Superclass(Calculation)
package MultiLevelInheritance3;

public class Calculation {

// Instance variables

int x;
int y;

public void getData() {


x = 10;
y = 20;

}
Subclass1(Sum)
package MultiLevelInheritance3;

public class Sum extends Calculation {

// instance variable

int sum;

public void sum() {


sum = x + y;
System.out.println("Sum value : " + sum);
}

}
Subclass2(Subtraction)

package MultiLevelInheritance3;

public class Subtraction extends Sum {

// Instance varible

int sub;

public void sub() {


sub = y - x;// 10
System.out.println("Subtraction value : " + sub);// 10
}

}
Mainclass

package MultiLevelInheritance3;

public class MainClass {

public static void main(String[] args) {

// Create object for that Calculation class

Calculation S = new Calculation();

S.getData();// call the getData()---valid


S.sum();// call the sum()---Invalid
S.sub();// call the sub()---Invalid

Case 1

Subtraction S = new Subtraction();


S.getData();//call the getData()---valid
S.sum();//call the sum()---valid
S.sub();//call the sub()---valid

>With child(Subtraction) reference,we can call the parent class(Calculation class)


method
>With child(Subtraction) reference,we can call the Subclass1(Sum class) method
>With child(Subtraction) reference,we can call the Subclass2(Subtraction class)
method
Case 2

Sum S = new Subtraction();


S.getData();//call the getData()---valid
S.sum();//call the sum()---valid
S.sub();//call the sub()---invalid

>With child(Sum) reference,we can call the parent class(Calculation class) method
>With child(Sum) reference,we can call the Subclass1(Sum class) method
>With child(Sum) reference,we can't call the Subclass2(Subtraction class) method
Case 3

Calculation S = new Calculation();


S.getData();//call the getData()---valid
S.sum();//call the sum()---invalid
S.sub();//call the sub()---invalid

>With Parent(Calculation) reference,we can call the parent class(Calculation class)


method
>With Parent(Calculation) reference,we can't call the Subclass1(Sum class) method
>With Parent(Calculation) reference,we can't call the Subclass2(Subtraction class)
method
Case 4

Sub S = new Calculation();


S.getData();//call the getData()---valid
S.sum();//call the sum()---invalid
S.sub();//call the sub()---invalid

>With parent object(Calculation),we can't call the parent class


method(Calculation class method) by using child reference(Subtraction class
reference).
>With parent object(Calculation),we can't call the Subclass1
method(Sum class method) by using child reference(Subtraction class reference).
>With parent object(Calculation),we can't call the Subclass2
method(Sub class method) by using child reference(Subtraction class reference).
Hierarchical Level Inheritance

>Here multiple subclasses acquired all the features of one super


class by using extends keyword then is called Hierarchical Level Inheritance.

Syntax :
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Superclass
{

}
class Subclass3 extends Superclass
{

}
Example 1

Follow the Steps


1.Create Superclass(Animal)
2.Create subclass1(Dog) from Superclass(Animal)
3.Create Subclass2(Cat) from Superclass(Animal)
4.Create Subclass3(Cow) from Superclass(Animal)
5.Create Mainclass
Java code
Superclass(Animal)
package HierarchicalInheritance1;

public class Animal { //superclass

void eat()
{
System.out.println("Eating");
}

Subclass1(Dog)
package HierarchicalInheritance1;

public class Dog extends Animal {

void bark() {
System.out.println("Barking");
}

Subclass2(Cat)
package HierarchicalInheritance1;

public class Cat extends Animal {

void meow() {
System.out.println("Meowing");
}

Subclass3(Cow)
package HierarchicalInheritance1;

public class Cow extends Animal {

void moo() {
System.out.println("Mooing");
}

Mainclass
package HierarchicalInheritance1;
public class MainClass {

public static void main(String[] args) {

// Create the object for that Cow class

Animal D = new Cow();


D.eat();// call the eat()---Valid
D.moo();// call the bark()---Valid

In Dog class
>You don't write superclass code internally Super
class code is available to subclass automatically by using extends keyword.
>Here Only additional code should be written
In Cat class
>You don't write superclass code internally Super
class code is available to subclass automatically by using extends keyword.
>Here Only additional code should be written
In Cow class
>You don't write superclass code internally Super
class code is available to subclass automatically by using extends keyword.
>Here Only additional code should be written
Case 1
//Create the object for that Dog class
Dog D = new Dog();
D.eat();//call the eat()---Valid
D.bark();//call the bark()---Valid

>With child reference, you can call the parent class method
>With child reference, you can call the child class method
Case 2
//Create the object for that Dog class
Animal D = new Dog();
D.eat();//call the eat()---Valid
D.bark();//call the bark()---InValid

>With parent reference, you can call the parent class method
>With parent reference, you can't call the child class method
Case 3
//Create the object for that Cat class
Cat D = new Cat();
D.eat();//call the eat()---Valid
D.meow();//call the bark()---Valid

>With child reference, you can call the parent class method
>With child reference, you can call the child class method
Case 4
//Create the object for that Cat class
Animal D = new Cat();
D.eat();//call the eat()---Valid
D.meow();//call the bark()---InValid

>With parent reference, you can call the parent class method
>With parent reference, you can't call the child class method
Case 5
//Create the object for that Cow class
Cow D = new Cow();
D.eat();//call the eat()---Valid
D.moo();//call the bark()---Valid

>With child reference, you can call the parent class method
>With child reference, you can call the child class method
Case 6
//Create the object for that Cow class
Animal D = new Cow();
D.eat();//call the eat()---Valid
D.moo();//call the bark()---InValid

>With parent reference, you can call the parent class method
>With parent reference, you can't call the child class method
Example 2

Follow the Steps


1.Create Superclass(College)
2.Create subclass1(Principal) from Superclass(College)
3.Create Subclass2(Teacher) from Superclass(College)
4.Create Subclass3(Student) from Superclass(College)
5.Create Mainclass
Java code
Superclass(College)
package HierarchicalInheritanceExample3;

public class College {

// Instance variables

int id;
String name;
String address;

void setId(int id) {


this.id = id;
}

void setName(String name) {


this.name = name;
}

void setAddress(String address) {


this.address = address;
}

int getId() {
return id;
}

String getName() {
return name;
}

String getAddress() {
return address;
}

Subclass1(Principal1)
package HierarchicalInheritanceExample3;

public class Principal1 extends College {

void evaluate() {
System.out.println("Evaluating");
}

Subclass2(Teacher1)
package HierarchicalInheritanceExample3;

public class Teacher1 extends College {

// instance variable

int sal;

void setSal(int sal) {


this.sal = sal;
}

int getSal() {
return sal;
}

Subclass3(Student1)
package HierarchicalInheritanceExample3;

public class Student1 extends College {

// Instance variable

int marks;

void setMarks(int marks) {


this.marks = 500;
}

int getMarks() {
return marks;// 500
}

Mainclass
package HierarchicalInheritanceExample3;

public class MainClass {


public static void main(String[] args) {

// Create the object for that Principal1 class

Principal1 P = new Principal1();

P.setId(101);// call the setId() and send 101


P.setName("SitaRam");// call the setName() and SitaRam
P.setAddress("Kukatpally");// call the setAddress() and send Kukatpally
P.evaluate();//call the evaluate()

System.out.println("Principal1 ID : " + P.getId());// call the getId()


System.out.println("Principal1 Name: " + P.getName());// call the
getName()
System.out.println("Principal1 Address : " + P.getAddress());// call the
getAddress()

// Create the object for that Teacher1 class

Teacher1 T = new Teacher1();

T.setId(102);// call the setId() and send 101


T.setName("Sai");// call the setName() and SitaRam
T.setAddress("KPHB");// call the setAddress() and send Kukatpally
T.setSal(20000);// call the setSal() and send 20000

System.out.println("Teacher1 ID : " + T.getId());// call the getId()


System.out.println("Teacher1 Name: " + T.getName());// call the
getName()
System.out.println("Teacher1 Address : " + T.getAddress());// call the
getAddress()
System.out.println("Teacher1 Sal : " + T.getSal());// call the getSal()

// Create the object for that Student1 class

Student1 S = new Student1();

S.setId(103);// call the setId() and send 101


S.setName("Akki");// call the setName() and SitaRam
S.setAddress("Hyd");// call the setAddress() and send Kukatpally
S.setMarks(500);// call the setSal() and send 20000

System.out.println("Student1 ID : " + S.getId());// call the getId()


System.out.println("Student1 Name: " + S.getName());// call the
getName()
System.out.println("Student1 Address : " + S.getAddress());// call the
getAddress()
System.out.println("Student1 marks : " + S.getMarks());// call the
getMarks()

In Principal class
>You don't write superclass code ,internally superclass code is available to
subclass by using extends keyword
>Here Only additional code should be written
>Create evaluate method
In Teacher class
>You don't write superclass code, internally superclass code is available to
subclass by using extends keyword
>Here Only additional code should be written
>Here Set the sal
>Here Get the sal
In Student class
>You don't write superclass code ,internally superclass code is available to
subclass by using extends keyword
>Here Only additional code should be written
>Here Set the marks
>Here get the marks
Steps,
Print principal detail
>If you want to print the principal details then we need to create
the object for that Principal class
>Next set the id, name, and address
>Next, get the id, name, and address
Print Teacher detail
>If you want to print the Teacher details then we need to create
the object for that Teacher class
>Next set the id, name, address, and sal
>Next, get the id, name, address, and sal
Print Student detail
>If you want to print the Student details then we need to create
the object for that Student class
>Next set the id, name, address, and marks
>Next, get the id, name, address, and marks
What is the super() and this() ?
Example 1
class Test{

Test()
{

System.out.println("Hanumanth");
super();//Invalid

}
>Here super() must be in the first line in the constructor.

Example 2
class Test{

Test()
{
super();//valid
System.out.println("Hanumanth");

}
>Here always super() must be in the first line in the constructor.
Example 3
class Test{

Test()
{

System.out.println("Hanumanth");
this();//Invalid

}
>Here this() must be in the first line in the constructor.
Example 4
class Test{

Test()
{
this();//valid
System.out.println("Hanumanth");

}
>Here always this() must be in the first line in the constructor.
Example 5
class Test{

Test()
{
this();//valid---1st place
super();//Invalid----2nd place

System.out.println("Hanumanth");

}
>Within the constructor,we can write either super() or this() but
both are not required simultaneously.
Example 6
class Test{

void Test()
{

super();//Invalid

System.out.println("Hanumanth");

}
>Here always super() and this() must be inside the constructor.
>If you are trying to use outside of the constructor then immediately java
compiler will through an error.
> How to call the superclass default constructor using super()?
Follow the steps
>Create superclass(Animal)
>Create subclass(Dog2) from superclass (Animal)
>Create Mainclass
Example 7
Superclass(Animal)
package SuperThisExample;

public class Animal {

Animal()
{
System.out.println("Animal is created");//Animal is created
}

Subclass(Dog2)
package SuperThisExample;

public class Dog2 extends Animal {

Dog2() {
super();// call the super class default constructor.

System.out.println("Dog2 is created");// Dog2 is created

Mainclass
package SuperThisExample;

public class Mainclass {

public static void main(String[] args) {

// Create the object for that Dog2 class

new Dog2();// call the subclass default constructor

In Dog2 class
**************
>You don't write superclass code internally superclass code is available to
subclass by using extends keyword.
>Here only additional code should be written
Why we are using super keyword?
*********************************
Ans: By using the super keyword, we can call the superclass default constructor.
>new Dog2();==>By using this, we can call the subclass default constructor
How to call the superclass parameterized constructor using super()?
Follow the steps
******************
>Create superclass(Shape)
>Create subclass(Rectangel) from superclass (Shape)
>Create Mainclass
Example 8
Superclass(Shape1)
package SuperThisExample2;

public class Shape1 {

// Instance variables

int l;
int b;

// here parameterized constructor is called and executed automatically

Shape1(int l, int b) {
this.l = l;
this.b = b;

Subclass(Rectangle2)
package SuperThisExample2;

public class Rectangle2 extends Shape1 {

Rectangle2() {

super(10, 20);// call the super class parameterized constructor

System.out.println("Print Area of the rectangle : " + (l * b));// 200

Mainclass
package SuperThisExample2;

public class Mainclass {

public static void main(String[] args) {

// Create the object for that Rectangle2 class

new Rectangle2();// call the subclass default constructor

In Rectangle2 class
*********************
>You don't write superclass code, internally superclass code is available to
subclass by using extends keyword.
>Here only additional code should be written
Conclusion :

super() and this() conclusion

Why we are using super()?

Ans: By using this, we can call the superclass default constructor

Why we are using super(value)?

Ans: By using this, we can call the superclass parameterized constructor

Why we are using this()?

Ans: By using this, we can call the current class default constructor

Why we are using this(value)?

Ans: By using this, we can call the current class parameterized constructor

What is the super, this keywords?

Why we are using super keyword ?


Ans : By using this, we can call the superclass members(variables + methods)
How to call the superclass variable ?
Ans : super.variablename

How to call the superclass method ?


Ans : super.methodname();
Why we are using this keyword ?
Ans : By using this, we can call the current class members(variables + methods)
How to call the current class variable ?
Ans : this.variablename
How to call the currentclass method ?
Ans : this.methodname();
Example 1

Follow the Steps

1.Create superclass(Animal)
2.Create subclass(Cat6) from superclass(Animal)
3.Create Mainclass

Superclass(Animal)
package ThisSuperExample1;

public class Animal {

// Instance variable

int cat_age = 5;

Subclass(Cat6)
package ThisSuperExample1;
public class Cat6 extends Animal {

//Instance variable

int cat_age=7;

void display()
{
System.out.println("Print super class cat age : "+super.cat_age);// To
call the super class cat_age

System.out.println("Print current class cat age : "+this.cat_age);// To


call the current class cat_age

MainClass
package ThisSuperExample1;

public class Mainclass {

public static void main(String[] args) {

//Create the object for that subclass(Cat6)

Cat6 C = new Cat6();

C.display();//call the display()

Why we are using super.variable?

Ans: To call the superclass variable

Why we are using this.variable?

Ans: To call the current class variable

Example 2

Follow the Steps

1.Create superclass(Animal1)
2.Create subclass(Cat7) from superclass(Animal1)
3.Create Mainclass
Superclass(Animal1)
package ThisSuperExample2;

public class Animal1 {

void meow()
{
System.out.println("This is a Animal class");
}

Subclass(Cat7)
package ThisSuperExample2;

public class Cat7 extends Animal1 {

void meow()
{

System.out.println("This is a Cat class");

void display()
{
super.meow();//To call the super class meow()

this.meow();//To call the current class meow()

Mainclass
package ThisSuperExample2;

public class MainClass {

public static void main(String[] args) {

//Create the object for that cat class

Cat7 C = new Cat7();

C.display();//call the display()


}

Can we override the parent class method into the Childclass?

Ans: Yes

Where we can use this() and super()?

Ans: In constructor only


Where we can use this and super keywords?

Ans: We can use anywhere except the static area

Super(),this() Super,this
1.These are constructor calls,
Super();---to call the super class constructor
This();---to call the current class constructor
1.These are keywords,
Super---to call the super class instance members(variables and methods)
This---to call the current class instance members(variables and methods)
2.We can use inside the constructor only,and we should use first line only 2.We
can use(super,this) any where but except static area
3.We can use only one,but not both simultaniously 3.We can use any number of
times
Polymorphism in java
Poly means ------many
morphs mean--------forms
Polymorphism means ------many forms
In real-world examples of polymorphism
Ex1: Here one form represents many forms then it is called polymorphism
Ex2: Here Same name(Animal) but with different sounds then it is called
polymorphism

Ex3: A person behaves like in different ways then it is called polymorphism.


A person behaves like in different ways
****************************************

Types of polymorphism

1.static / compile-time / early binding


>Method overloading
>Method hiding
2.Dynamic / runtime / late binding
>Method overriding
Method overloading
Definition 1
************
>Here Same method name but with different argument types then it is
called method overloading.

Example 1
************

package Methodoverloading3;

public class MethodoverloadingExample3 {

//here method is called and executed when we call it

void m1()
{
System.out.println("no-arg");//no-arg
}
void m1(int i)
{
System.out.println(i);//
}

void m1(double d)
{
System.out.println(d);//
}

public static void main(String[] args) {

//Create the object for that MethodoverloadingExample3 class

MethodoverloadingExample3 MO = new MethodoverloadingExample3();

MO.m1();//call the m1()

MO.m1(10);//call the m1() and pass 10

MO.m1(10.5);//call the m1() and pass 10.5

}
}

Definition 2
************
>Here method name same but with different method signature then it is called method
overloading

Example 2

package Methodoverloading3;

public class MethodoverloadingExample4 {

//here method is called and executed when we call it

void add(int a,int b)


{
System.out.println("Add a+b : "+(a+b));//30
}

void add(int a,int b,int c)


{
System.out.println("Add a+b+c : "+(a+b+c));//60
}

public static void main(String[] args) {

MethodoverloadingExample4 MO = new MethodoverloadingExample4();

MO.add(10,20);//call the add() and pass 10,20

MO.add(10,20,30);//call the add() and pass 10,20,30

}
}

Method overriding
Defination 1:
>Here I am not satisfied with parent class method implementation so that in a
child, I am rewriting that method but with different method implementation then it
is called method overriding.
Example
Manual Steps
>Create parent class
>Create childclass from parentclass
>Create Mainclass
Java code

Superclass(Parent5)
package MethodOverridingExamples2;

public class Parent5 {

void vehicle()
{
System.out.println("Parent class method : size / model");
}

void car_color()
{
System.out.println("Parent class method : Car color is blue");
}

}
Subclass(Child5)
package MethodOverridingExamples2;

public class Child5 extends Parent5 {

void car_color()
{
System.out.println("Child class method : Car color is Red");//Car color
is Red
}

}
Mainclass
package MethodOverridingExamples2;

public class Mainclass {

public static void main(String[] args) {

//create the object for that Parent5 class

Parent5 C = new Parent5();

C.vehicle();//call the vehicle()

C.car_color();//call the car_color()


}

>Here automatically parent class code is available to child class by using extends
keyword.
>Here parent class method which is overridden then it is called overridden method.
>Here Child class method which is overriding then it is called overriding method.
>When I run this program, by default JVM will always call to method overriding of
child class, not the method overridden of the parent class.
Case 1
*******
//create the object for that child class
Child5 C = new Child5();
C.car_color();//call the car color
C.vehicle();//call the vehicle
Case 2
*******
//create the object for that child class
Parent5 C = new Child5();
C.car_color();//call the car color
C.vehicle();//call the vehicle
Case 3
********
//create the object for that Parent5 class
Parent5 C = new Parent5();
C.car_color();//call the car color
C.vehicle();//call the vehicle
Method overriding in java ?
Definition 2:
Ans : Here method name same and method signature same then it is called method
overriding
Example
Manual steps
>Create Parent class
>Create child class from Parent class
>Create Main class
Java code
Parent class code
public class Parent {

void calculate(double a)
{

System.out.println("Print Square value : "+(a*a));

}
Child class code
public class Child extends Parent {

void calculate(double a) //child


{

System.out.println("Print Square root value : "+Math.sqrt(25.0));//5.0


}
}
Mainclass code
public class Mainclass {

public static void main(String[] args) {

Child C = new Child();

C.calculate(25.0);//call the calculate() and pass 25.0

}
Note :
>When i run this program by default JVM will always call to Child class
method(Method overriding),not parent class method(Method overridden)
Case 1
Child C = new Child();
C.calculate(25.0);//call the calculate() and pass 25.0
Case 2
Parent C = new Child();
C.calculate(25.0);//call the calculate() and pass 25.0
Case 3
Parent C = new Parent();
C.calculate(25.0);//call the calculate() and pass 25.0
Method overriding Rules :

private(least) < protected < public(highest)


Case 1:

>Can we override parent class private method into child class as a private method ?
****************************************************************************
Ans : NO
>Can we override parent class private method into child class as a protected method
?
****************************************************************************
Ans : Yes
>Can we override parent class private method into child class as a public method ?
****************************************************************************
Ans : Yes

Examples

Case 2

>Can we override parent class protected method into child class as a protected
method ?
****************************************************************************
Ans : Yes
>Can we override parent class protected method into child class as a private method
?
****************************************************************************
Ans : No
>Can we override parent class protected method into child class as a public
method ?
****************************************************************************
Ans : Yes
Examples

Case 3

>Can we override parent class public method into child class as a protected
method ?
****************************************************************************
Ans : NO
>Can we override parent class public method into child class as a private method ?
****************************************************************************
Ans : No
>Can we override parent class public method into child class as a public method ?
****************************************************************************
Ans : Yes

Examples

Case 4

>Can we override parent class final method into child class as a protected method ?
****************************************************************************
Ans : NO
>Can we override parent class final method into child class as a private method ?
****************************************************************************
Ans : No
>Can we override parent class final method into child class as a public method ?
****************************************************************************
Ans : No
>Can we override parent class final method into child class as a final method ?
****************************************************************************
Ans : No
Examples

Case 5

>Can we override parent class private method into child class as a final method ?
****************************************************************************
Ans : Yes
>Can we override parent class protected method into child class as a final method ?
****************************************************************************
Ans : No
>Can we override parent class public method into child class as a final method ?
****************************************************************************
Ans : No

Examples

Method overloading Rules :

private(least) < protected < public(highest)


>Can we overloading private / protected / public /final /static methods ?
Yes, we can overload private / protected / public /final /static methods in Java
but, you can access these from the same class.
Example 1

Example 2

Example 3

More Examples :

Abstract class in java ?


abstract keyword in java?
****************************

>Here abstract keyword is applicable only for classes and methods but not for
variables.
>In general words abstract mean not clear, not complete, incomplete method,
incomplete class, the partial implementation just like that.
>Here we need to learn 4 things
1.concrete method
2.concrete class
3.abstract method
4.abstract class
What is a concrete method (regular method)in java?
Definition :
>Here A method has declaration part and implementation part such type of method is
called a concrete method.

Example
class Test
{
//concrete method
void m1(int i)
{

}
//concrete method
void m2()
{

}
//concrete method
public static void main(String[] args)
{

}
What is a concrete class(regular class) in java?
Definition :
>A class can contain only concreate methods such type of class is called concreate
class.
Example
//concrete class
class Test
{
//concrete method
void m1(int i)
{

}
//concrete method
void m2()
{

}
//concrete method
public static void main(String[] args)
{
}

}
What is an abstract method in java?
Definition :
> A method has a declaration part but not the implementation part such type of
method is called abstract method.

Example
abstract class Test //Unimplemented class
{
//abstract method
abstract void m1(); //Unimplemented method

//concrete method
void m2() //implemented method
{

}
>Here abstract method can be declared with abstract keyword
>Here abstract method should end with a semicolon.
>Here who is the responsibility to provide the implementation(body) for that
abstract method?
**********************************************************************************
Ans: Child class
>Here abstract method must be override in child class.
What is an abstract class in java?
Definition :
A class can contain concreate methods and abstract methods such type of class is
called abstract class.
Example
abstract class Test //Unimplemented class
{
//abstract method
abstract void m1(); //Unimplemented method

//concrete method
void m2() //implemented method
{
}

}
Note :
>Here we can't create the object for that abstract class(Unimplemented class)
Abstract class in java ?
Follow the steps
1.Create Superclass(Abstract class(Car))
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))
3.Create Subclass2(Santro) from superclass(Abstract class(Car))
4.Create Mainclass

>In superclass(Abstract class(Car))


common code + Additional code(optional)
>In subclass
Additional code(mandatory)

Here common things or common code


1.regino
2.FuelTank
3.Steering
4.Brakes

School project
//Concreate methods
1.Teacher-------100%------complete knowledge (void teacher(){})
2.Student-------100%------complete knowledge (void student(){})
3.Chort board------100%----complete knowledge (voidchordboard(){})

//abstract method
4.Fee------50%------incomplete knowledge(abstract void fee();)
//abstract method
abstract void atm();

Who is the responsible to provide the implementation(body) for that abstract method
?
Ans : Child class
Note :

>Here we can't create the object for that abstract class(Unimplemented class)
>Here we can create the object for that child class
Example
1.Create Superclass(Abstract class(Car))

package AbstractExample;

public abstract class Car { // Unimplemented abstract class

int regino; // instance variable

Car(int r) {

regino = r;
}

// Here every car will have Fuel tank and same mechanism to open the Fuel
// tank and fill the Tank
void openFuelTank() // implemented method
{
System.out.println("open the Fuel tank and fill the Tank");
}

// Here every car will have steering mechanism but different cars will have
// different steering mechanism

abstract void steering(); // Unimplemented method

// Here every car will have brakes but different cars will have different
// breaking mechanism

abstract void brakes(); // Unimplemented method

}
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))

package AbstractExample;

public class Maruti extends Car {

Maruti(int regino) {

super(regino);// call the superclass parameterized constructor

// Here Maruti car will have ordinary steering mechanism

public void steering(int direction, int angle) {

System.out.println("Here Maruti car will have ordinary steering


mechanism");
}

// Here Maruti car will have hydraulic brakes

public void brakes(int force) {


System.out.println("Here Maruti car will have hydraulic brakes");

}
3.Create Subclass2(Santro) from superclass(Abstract class(Car))

package AbstractExample;

public class Santro extends Car {

Santro(int regino) {
super(regino);
}

// Here Santro car will have power steering mechanism

void steering(int direction, int angle) {

System.out.println("Here Santro car will have power steering


mechanism");
}

// Here Santro car will have gas brakes

void brakes(int force) {


System.out.println("Here Santro car will have gas brakes");

}
4.Create Mainclass

package AbstractExample;

public class Mainclass {

public static void main(String[] args) {

//Create Maruti class object

Maruti M = new Maruti(10);

System.out.println(M.regino);//10

M.openFuelTank();//call the openFuelTank()

M.steering(1,90);//call the steering(1,90)

M.brakes(500);//call the brakes pass 500

//Create Santro class object

Santro S = new Santro(20);

System.out.println(S.regino);//20

S.openFuelTank();//call the openFuelTank()

S.steering(2,80);//call the steering(1,90)

S.brakes(400);//call the brakes pass 500

}
Interface in java?
Follow the steps
1.Create Interface(Animal)
2.Create subclass(Cat) from inteface(Animal)
3.Create Mainclass
Example
1.Create Interface(Animal)

package InterfaceExample;

public interface Animal { // Unimplemented interface


int x = 15;

// Here every Animal make a sound but different animals make different
// sounds

// abstract method

public abstract void sound(); // Unimplemented method

}
2.Create subclass(Cat) from inteface(Animal)

package InterfaceExample;

public class Cat implements Animal {

// Here Cat animal will make a sound : Meow

public void sound() // implemented method


{

System.out.println("Meow");// Meow
}

}
3.Create Mainclass

package InterfaceExample;

public class Mainclass {

public static void main(String[] args) {

// Create the object for that Cat class

Cat C = new Cat();

System.out.println(C.x);// 15

C.sound();// call the sound()

Imp points
>When I run this program by default JVM will provide public static final for that
variable x.
>Can we change the variable value of the interface?
*********************************************************
Ans: No
>In the interface, all the variables are public static final
>In the Interface, every variable and every method should be public
>Can we create an interface without creating an abstract method?
*************************************************************
Ans: Yes
>Here interface is called Unimplemented interface
>Here abstract class is called Unimplemented abstract class
Note :
>Here we can't create the object for that Unimplemented interface and Unimplemented
abstract class
>Here we can create the object for that child class

>Difference between extends keyword and implements keyword?


****************************************************************
extends: By using this, we can inherit the subclass from a superclass
implements: To implement an interface in the child class, you must use the
implements keyword
>Here abstract method must be override in the child class
Here who is the responsibility to provide the implementation(body) for that
abstract method?
***********************************************************************************
****
Ans: Child class
>An interface can contain variables and abstract methods but not create concrete
methods and constructors.
School project
>Here abstract class can contain concreate methods and abstract methods
When we will go to the abstract class?
*****************************************
Ans: If u want to work with concrete and abstract methods then we use an abstract
class
Ex :
*****
1.Teacher--------100%-------complete knowledge (void teacher(){})
2.Student--------100%-------complete knowledge (void student(){})
3.Chort board----100%-------complete knowledge (void chortboard(){})

4.Fee-------50%---------incomplete knowledge (abstract void fee();)

>Here interface can contain only abstract methods


When we will go for the interface concept?
********************************
Ans: If u want to work with only abstract methods then we use the interface
concept
Ex :
*****
1.Teacher--------50%-------incomplete knowledge (abstract void teacher();)
2.Student--------50%-------incomplete knowledge (abstract void student();)
3.Chort board----50%-------incomplete knowledge (abstract void chortboard();)
4.Fee-------50%---------incomplete knowledge (abstract void fee();)
Some more Examples
**********************

1.A class can extend another class


2.A class can't extend multiple classes
3.An interface can extend another interface
4.An interface can extend multiple interfaces(interface1,interface2)
5.An interface can't implement another interface
6.A class can implement another interface
7.A class can implement multiple interfaces(interface1,interface2)
Multiple inheritances in java?

>Here java does not support Multiple inheritances (A class can not extend multiple
classes)
diagram :
Syntax :
class Superclass1
{
}
class Superclass2
{

}
class Subclass extends Superclass1,Superclass2
{

}
Example
class Father
{

}
class Mother
{

}
class Son extends Father, Mother
{

}
How to handle multiple inheritances in the interface concept?
>A class can implement multiple interfaces
diagram :

Syntax :
interface interface1
{

}
interface interface2
{

}
class Child implements interface1,interface2
{

}
Example
interface Father
{

}
interface Mother
{

}
class Child implements Father, Mother
{

}
Program
Follow the Steps
1.Create Interface1(Father)
2.Create Interface2(Mother)
3.Create Childclass(Son) from multiple interfaces(Father,Mother)
4.Create Mainclass
Java code:
1.Create Interface1(Father)

package MultipleInheritance;

public interface Father { // Unimplemented interface

float HT = 6.2f;

public abstract void method(); // Unimplemented method

}
2.Create Interface2(Mother)

package MultipleInheritance;

public interface Mother {

float HT = 5.8f;// valid

abstract void method();

}
3.Create Childclass(Son) from multiple interfaces(Father,Mother)

package MultipleInheritance;

public class Son implements Father, Mother {

public void method() {


// Child got average height of it's parents

float H = (Father.HT + Mother.HT) / 2;

System.out.println("Child got average height of it's parents :" + H);


}

}
4.Create Mainclass

package MultipleInheritance;

public class Mainclass {

public static void main(String[] args) {

// Create the Son class object

Son S = new Son();

S.method();// call the method()

Father F = new Son(); // valid

System.out.println("Print Father height : " + Father.HT);// 6.2

Mother M = new Son(); // valid


System.out.println("Print Mother height : " + Mother.HT);// 5.8

Can we call the variable from the interface?


Ans: Yes
Syntax : InterfaceName.variableName
Can we call the variable from class?
Ans: Yes
Syntax : ClassName.variableName
Note :
>Here we can't create the object for that interface but we can create a reference
for that interface.
Son S = new Son(); // valid
Father S = new Son(); //valid
Mother S = new Son();//valid
Father S = new Father();//invalid
Mother S = new Mother();//invalid
ArrayList in java(it's a part of Collection Topic)
>ArrayList is an array.
>By creating an ArrayList object we can store the number of values dynamically.
>Dynamically we can increase the memory size when new value stores into ArrayList
object.
>A program must import the java.util package to use ArrayList calss.

Example 1
import java.util.ArrayList;

public class ArrayListClass {

public static void main(String[] args) {

ArrayList<Integer> array_list = new ArrayList<Integer>();//here


array_list is called object reference variable

array_list.add(10); //store 10 into array_list object through add


function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function

System.out.println("ArrayList size : "+array_list.size());//4

/*
>Here i want to print 10,20,30,40 present in the array_list
>How to print 10,20,30,40 present in the array_list?
Ans : At that time we need to use for loop.

>For loop : Sometimes we need to perform same action with


multiple times so at that time we need to use for loop.
*/
//Print all the values present in the array_list

for(int i=0;i<array_list.size();i++)
{
System.out.println("Array_List value :
"+array_list.get(i));//here get()method to retrieving values from array_list
}

}
Example 2
>For example, If you want to store only integer values in an array_list then follow
below syntax.
Ans : ArrayList<Integer> array_list = new ArrayList<Integer>();
Here <Integer> represents a type of values to be stored into the array_list
array_list.add(10); //store 10 into array_list object through add
function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function
Note :
> Integer dataType the most commonly used in java and selenium.
> Integer dataType can store positive and negative no's
> Integer datatype can store in the range of values min -2147483648 to max
2147483647
Example 3
>For example, If you want to store String type values in an array_list then follow
below syntax.
Ans : ArrayList<String> array_list = new ArrayList<String>();
>Here <String> represents a type of values to be stored into the array_list
array_list.add("Akki"); //store Akki into array_list object through add
function
array_list.add("Sai"); //store Sai into array_list object through add
function
array_list.add("hanu"); //store hanu into array_list object through add
function
array_list.add("Kosmik"); //store Kosmik into array_list object through add
function
Figure :

Note :
>Here String must be in double quotes
>Here String mean collection of characters
>String data type can store group of charecters such "HYD" or "Kosmik123"
or”123456” Or “!@#$%^1234”
>Here range not appicable for String data type
Example 4
>For example, If you want to store double type values in an array_list then follow
below syntax.
Ans : ArrayList<Double> array_list = new ArrayList<Double>();
Here <Double> represents a type of values to be stored into the array_list
array_list.add(10.2); //store 10.2 into array_list object through add
function
array_list.add(11.3); //store 11.3 into array_list object through add
function
array_list.add(21.5); //store 21.5 into array_list object through add
function
array_list.add(34.4); //store 34.4 into array_list object through add
function
Figure :

Note :
>This will be used to store positive and negative decimal values
>Double dataType can store in the range of values min -1.7976931348623157e308d to
max 1.7976931348623157e308D
>We can specify floating-point literal value(float value or double value) only in
decimal form
>Double data type can store only decimal values upto 14 digits after decimal
Example 5
>For example, If you want to store float type values in an array_list then follow
below syntax.
Ans : ArrayList<Float> array_list = new ArrayList<Float>();
Here <Float> represents a type of values to be stored into the array_list
array_list.add(10.2f); //store 10.2 into array_list object through add
function
array_list.add(11.3f); //store 11.3 into array_list object through add
function
array_list.add(21.5f); //store 21.5 into array_list object through add
function
array_list.add(34.4f); //store 34.4 into array_list object through add
function
Figure :

Note :
>Here Float type value should be suffixed with 'f' or 'F'
>This will be used to store positive and negative decimal values
>Float datatype can store in the range of the values min -3.4028235e38F to max
3.4028235e38F
> Here e mean exponential form
>We can specify floating-point literal value(float value or double value) only in
decimal form
>Float data type can store only decimal values upto 6 digits after decimal
Example 6
>For example, If you want to store boolean type values in an array_list then follow
below syntax.
Ans : ArrayList<Boolean> array_list = new ArrayList<Boolean>();
Here <Boolean> represents a type of values to be stored into the array_list
array_list.add(true);
array_list.add(true);
array_list.add(false);
Figure :

Note :
>This will be used to store only boolean values such as true/false
>Here range not appicable(not valid) to boolean dataType
Example 7
>For example, If you want to store Character type values in an array_list then
follow below syntax.
Ans : ArrayList<Character> array_list = new ArrayList<Character>();
Here <Character> represents a type of values to be stored into the array_list
array_list.add('a');
array_list.add('b');
array_list.add('c');
Figure :

Note :
>This will be used to store single character such as 'c' or 'D'or '@' or '7' or
'?'...
>Everything in a single quote it's a character
>Here char data type can store in the range of values 0 to 65535
Example 8
>For example, If you want to store Long type values in an array_list then follow
below syntax.
Ans :ArrayList<Long> array_list = new ArrayList<Long>();
Here <Long> represents a type of values to be stored into the array_list
array_list.add(12345L);
array_list.add(12346L);
array_list.add(12347l);
Figure :

Note :
>Here long type value should be suffixed with 'l' or 'L'
>This will be used to store positive and negative no's
>Long data type can store in the range of values min -9223372036854775808 to max
9223372036854775807
Example 9
>ArrayList<Integer> array_list = new ArrayList<Integer>();//here array_list is
called object reference variable
Here <Integer> represents a type of values to be stored into the array_list
array_list.add(10); //store 10 into array_list object through add
function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add("kosmik");//Invalid----Here Integer type values are
allowed not string type.
>If you are trying to store String type value into array_list then immediately java
compiler will through an error.
Figure :

>Can we store duplicate values in an array_list object?


Ans : Yes,we can store
Example 10
ArrayList<Integer> array_list = new ArrayList<Integer>();//here array_list is
called object reference variable
array_list.add(10); //valid
array_list.add(20); //valid
array_list.add(30); //valid
array_list.add(30); //valid

Figure :

Example 11
>For example, If you want to store Interger,Double,Float,Long,String,boolean,
Character value then follow below steps
ArrayList array_list = new ArrayList();//here array_list is called object
reference variable
array_list.add(10);
array_list.add(20.2);
array_list.add(10.3f);
array_list.add("Kosmik");
array_list.add(true);
array_list.add('s');
>Here no need to mention type (That means Interger,Double,Float,Long,String,
Boolean,character)
>In this case we can store any type of values.
Figure :

Can we remove 20 in an arrayList?


Ans : Yes,we can remove
Syntax :
arrayList.remove(index);
Example
arrayList.remove(1); //removed 20 in an arrayList
Figure :

Example :
import java.util.ArrayList;

public class ArrayListClass2 {

public static void main(String[] args) {

ArrayList<Integer> array_list = new ArrayList<Integer>();//here


array_list is called object reference variable

array_list.add(10); //store 10 into array_list object through add


function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function

System.out.println("ArrayList size : "+array_list.size());//4

//Print all the values from array_list

for(int i=0;i<array_list.size();i++)
{
System.out.println("Array_List value :
"+array_list.get(i));//here get()method to retrieving values from array_list
}

System.out.println("*******After removed 20 from array_list*******");

array_list.remove(1);//removed 20 from array_list

//Print all the values present in an array_list

for(int i=0;i<array_list.size();i++)
{
System.out.println("Array_List value :
"+array_list.get(i));//here get()method to retrieving values from array_list
}

Can we replace 20 with 50 in an arrayList ?


Ans : Yes,we can replace by using set(int index,Object obj);

Syntax :
array_list.set(int index,Object obj);
Example

array_list.set(1,50); //replace 20 with 50 in the position of 1


Figure :

Example :
import java.util.ArrayList;

public class ArrayListClass2 {

public static void main(String[] args) {


ArrayList<Integer> array_list = new ArrayList<Integer>();//here
array_list is called object reference variable

array_list.add(10); //store 10 into array_list object through add


function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function

System.out.println("ArrayList size : "+array_list.size());//4

//Print all the values from array_list

for(int i=0;i<array_list.size();i++)
{
System.out.println("Array_List value :
"+array_list.get(i));//here get()method to retrieving values from array_list
}

System.out.println("After Replace 20 with 50");

array_list.set(1,50);//here replace 20 with 50 in the position of 1

for(int i=0;i<array_list.size();i++)
{

System.out.println("ArrayList value :" +array_list.get(i)


);//here get() method to retrieving the values from Array_list

}
}

}
can we insert 50 in the position of 1 ?
Ans : Yes,we can insert by using add(int index,Object obj);
Syntax :
array_list.add(int index,Object obj);

Example
array_list.add(1,50);//insert 50 in the position of 1
Figure :

Example :
import java.util.ArrayList;

public class ArrayListClass2 {

public static void main(String[] args) {


ArrayList<Integer> array_list = new ArrayList<Integer>();//here
array_list is called object reference variable

array_list.add(10); //store 10 into array_list object through add


function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function

System.out.println("ArrayList size : "+array_list.size());//4

//Print all the values from array_list

for(int i=0;i<array_list.size();i++)
{
System.out.println("Array_List value :
"+array_list.get(i));//here get()method to retrieving values from array_list
}

System.out.println("After insert 50 in the position of 1");

array_list.add(1,50);//here insert 50 in the position of 1

System.out.println("ArrayList size : "+array_list.size());//5

for(int i=0;i<array_list.size();i++)
{

System.out.println("ArrayList value :" +array_list.get(i)


);//here get() method to retrieving the values from Array_list

}
}
}
Can we remove all the values present the arrayList ?
Ans : yes,we can remove by using clear()
Syntax :
array_list.clear();// remove all the values present in the arrayList
Example
array_list.clear();// remove all the values present in the arrayList
Figure :

Example
import java.util.ArrayList;

public class ArrayListClass2 {

public static void main(String[] args) {


ArrayList<Integer> array_list = new ArrayList<Integer>();//here
array_list is called object reference variable

array_list.add(10); //store 10 into array_list object through add


function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function

System.out.println("ArrayList size : "+array_list.size());//4

System.out.println("After remove all the objects at a time present in


the array_list");

array_list.clear();//here remove all the objects at a time present in


the array_list

System.out.println("ArrayList size : "+array_list.size());//0

How to verify arratList has empty or not ?


Ans : By using isEmpty()
Syntax :
array_list.isEmpty();//verify arratList has empty or not

>If arrayList has empty then it returns true


>If arrayList has not empty then it returns false

Example
array_list.isEmpty();//verify arratList has empty or not
Figure :

Example
import java.util.ArrayList;

public class ArrayListClass2 {


public static void main(String[] args) {
ArrayList<Integer> array_list = new ArrayList<Integer>();//here
array_list is called object reference variable

array_list.add(10); //store 10 into array_list object through add


function
array_list.add(20); //store 20 into array_list object through add
function
array_list.add(30); //store 30 into array_list object through add
function
array_list.add(40); //store 40 into array_list object through add
function

System.out.println("ArrayList size : "+array_list.size());//4

System.out.println("After remove all the objects at a time present in


the array_list");

array_list.clear();//here remove all the objects at a time present in


the array_list

System.out.println("ArrayList size : "+array_list.size());//0

System.out.println(array_list.isEmpty());//verify whether the


array_list has empty or not

/*

>If ArrayList is empty then returns true


>If ArrayList is not empty then returns false
*/

}
>Can we add empty data in an array_list?
Ans : Yes, we can add
Example :
import java.util.ArrayList;

public class ArrayListClass2 {

public static void main(String[] args) {

ArrayList<String> array_list = new ArrayList<String>();

array_list.add("Akki"); //store Akki into array_list object through add


function
array_list.add("Sai"); //store Sai into array_list object through add
function
array_list.add("hanu"); //store hanu into array_list object through add
function
array_list.add("Kosmik"); //store Kosmik into array_list object through add
function

array_list.add("");//store empty data in an array_list through add function


System.out.println("ArrayList size : "+array_list.size());//5

for(int i=0;i<array_list.size();i++)
{

System.out.println("ArrayList value :" +array_list.get(i)


);//here get() method to retrieving the values from Array_list

}
}

}
*******************Selenium 1st class****************************
What are the prerequisites to run the selenium web driver ?--IQ
1.JDK
2.Eclipse IDE / Oxygen
3.Selenium Jar files
4.Testing Application
5.Browser(FF or IE or Chrome or opera or safari and Edge)
Here,
1. Download JDK and install it into your local system.(Follow the Steps : Go to
page 2 )
2.Download Eclipse IDE and open the Eclipse directly, and here no need to install
Eclipse.(Follow the Steps : Go to page 9 )

Steps, (Follow the Steps :Go to page 10 )


1.Create a new Selenium project
2.Create a new Package
3.Create a new class
4. Download and Add selenium jar files for that project
Download selenium jar files :
After completion of eclipse Ide launching with the creation of project,package and
class with main(),we need to download selenium webdriver jar file.
Follow the below steps :
 Go to google search
 Enter selenium then search it
 Click on first link(https://www.selenium.dev/)
 Scroll to Selenium WebDriver Download option
 Click on download

 Scroll to Selenium Client & WebDriver Language Bindings


 Click on download for java based selenium webdriver

 wait until complete download.


 copy downloaded jar file and paste into personal folder and extract
Add selenium jar files for that project:
 Right click on project 'HrmsSeleniumProject'
 go to Java build path
 configure build path
 select Libraries
 Click on add external JARs button
 Then go your jar file folder path location
 select both .jar files from D:\selenium-java 3.12.0.
 click on open button
 Again Click on add external JARs button
 Then go your jar file folder path location
 Click on libs folder
 select all .jar files from D:\selenium-java 3.11.0\libs
 click on open button
 click on ok button

Why we are using selenium java jar files?


Ans: Suppose if you want to work with selenium web driver then we need to download
the jar file and configure the jar file for that project.
Where we can get the selenium java jar files?
Ans :Follow the Steps :Go to page 119
Java Comments :
Ans : Follow the Steps :Go to page 10

Manual TestSteps:
 Open the firefox browser
 Navigate the application url
 Get the Title of the WebPage
 Print the title of the webpage
 Verify Title of the WebPage
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Welcome Selenium Text
 Print the Welcome Selenium Text
 To verify whether the welcome page successfully opened or not
 Clicking On Logout Button
 Close the current Firefox Browser

Example :
package SeleniumPack;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstProgram {

//Instance variable

WebDriver driver;

//here method is called and executed when we call it

//Instance method

void openBrowser()
{
//Open the firefox browser

driver = new FirefoxDriver();//Here driver is called object reference


variable

//Navigate the application url

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

//Get the Title of the WebPage

String title = driver.getTitle();


System.out.println(title);//OrangeHRM - New Level of HR Management

//Verify Title of the WebPage

if(title.equals("OrangeHRM - New Level of HR Management"))


{
System.out.println("title verified successfully");
}else
{
System.out.println("title not verified successfully");
}

//here method is called and executed when we call it

//Instance method

void loginTest()
{
//Identify the username and enter username

driver.findElement(By.name("txtUserName")).sendKeys("selenium");

//Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

//Clicking On Login Button

driver.findElement(By.name("Submit")).click();

//Identify and get the Welcome Selenium Text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

System.out.println(text);//Welcome selenium

//To verify whether the welcome page

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified successfully");
}

//Clicking On Logout Button

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

}
//Instance method

void closeBrowser()
{
driver.close();//close the current browser window

//Static method

public static void main(String[] args) {

//Create the object for that FirstProgram class

FirstProgram F = new FirstProgram();

F.openBrowser();//call the openBrowser()

F.loginTest();//call the loginTest()

F.closeBrowser();//call the closeBrowser

Interview Questions:
Note: Here driver instance of the web driver
What is a web driver?
Ans: Webdriver it's an interface in between selenium automation
test script and Testing Application.
Why we will import the packages?
Ans: We will import the packages, which contains some specific classes to use their
functions in the test script
What is the default package of selenium ?--IQ
Ans : org.openqa.selenium
get()
*********
>This will be used to navigate the application URL in the current browser window.
getTitle()
**********
>This will be used to get the current page Title
Verify Title of the webpage Syntax :

If(Actual_value.equals(Expected_value))
{

//Execute the code if condition is true

}else
{
//Execute the code if condition is false
}

Actual_value : Take the text from Testing Application.


Expected_value : client requirement

Handling Frames
1.How to handle single frame
2.How to handle multiple frames
3.How to handle Nested frames(frame inside a frame)
How to handle single frame ?
What is a frame?
Frame is just like as a container where few elements can be grouped.
How to identify frame inside a webpage?
There are different ways to identify frame inside a webpage
Way 1:
 Open webpage in a browser.

 Right click on webelement in a webpage

Way 2:
 Open webpage in a browser.
 Right click on webelement in a webpage
 Open source code(Html Code) of the webpage by clicking inspect element see
below image.

How many ways to switch to frame?


There are 4 ways to switch to the frame.
Switch to frame by using index :
Method 1 :
Suppose if there is single frame in a webpage then we can switch to the iframe by
using index.
Here is the sample code:
Syntax : driver.switchTo().frame(int index);
Ex : driver.switchTo().frame(0);

Note : By default single frame index value ‘ 0’.That means when webpage has only
one frame then the index will be zero.
Method 2 :
Suppose if there are 3 frames in a webpage then we can switch to the iframe by
using index.
Here is the sample code:
Syntax :
List<WebElement> framelist=driver.findElements(By.tagName("iframe"));

driver.switchTo().frame(framelist.get(int index));

Ex :
List<WebElement> framelist=driver.findElements(By.tagName("iframe"));

//switchTo 1st frame by using index

driver.switchTo().frame(framelist.get(0));

//switchTo 2nd frame by using index

driver.switchTo().frame(framelist.get(1));

//switchTo 3rd frame by using index


driver.switchTo().frame(framelist.get(2));

Switch to frame by using Id or Name :


We can also use Name and Id attributes of iframe through which we can switch to
iframes.
Here is the sample code:
Syntax 1:
driver.switchTo().frame(String id);

Html code :

Ex : driver.switchTo().frame(“rightMenu”);
Syntax 2:
driver.switchTo().frame(String name);

Html code :

Ex: driver.switchTo().frame(“rightMenu”);

Switch to frame by using WebElement :


We can also switch to the frame using webelement.
Here is the sample code:
Syntax :
driver.switchTo().frame(WebElement element);

Html code :

Ex : driver.switchTo().frame(driver.findElement(By.name(“rightMenu”)));
Selenium Program :

TestSteps:
 Open Firefox Browser
 Open AppURL In Browser
 Get the Title of WebPage
 Verify Title of WebPage
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Welcome selenium text
 Verify Welcome selenium text
 Switch to frame
 Handle DropDown in Selenium
******************************
a) How to print all the dropdown values
>First,get the dropdown size or count dropdown values
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown
>print all the dropdown values
b) How to Select the dropdown value inside a frame
>Switch to frame
>Identify dropdown
>Select the dropdown value
c) verify selected value from dropdown
>get the selected value
>Verify selected value
d) How to Verify dropdown values
 Again switch back to main window from frame
 Clicking On Logout Button
 Close the Firefox Browser
Example
package SeleniumPack;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class FirstProgram {

//Instance variable

WebDriver driver;

//here method is called and executed when we call it

//Instance method

void openBrowser()
{
//Open the firefox browser

driver = new FirefoxDriver();//Here driver is called object reference


variable

//Navigate the application url

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

//Get the Title of the WebPage

String title = driver.getTitle();

System.out.println(title);//OrangeHRM - New Level of HR Management

//Verify Title of the WebPage

if(title.equals("OrangeHRM - New Level of HR Management"))


{
System.out.println("title verified successfully");
}else
{
System.out.println("title not verified successfully");
}

//here method is called and executed when we call it

//Instance method

void loginTest()
{
//Identify the username and enter username

driver.findElement(By.name("txtUserName")).sendKeys("selenium");

//Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

//Clicking On Login Button

driver.findElement(By.name("Submit")).click();

//Identify and get the Welcome Selenium Text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

System.out.println(text);//Welcome selenium

//To verify whether the welcome page

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified successfully");
}

//Switch to frame

driver.switchTo().frame(0);

//First,Identify dropdown

WebElement dropdown = driver.findElement(By.id("loc_code"));

//Next,Identify all the values from this dropdown

List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));

System.out.println(droplist.size());//3
System.out.println("****Print all the dropdown values inside a frame****");

//print all the dropdown values

for(int i=0;i<droplist.size();i++)
{

System.out.println(droplist.get(i).getText());

//Select the dropdown value

Select S = new Select(dropdown);

//S.selectByIndex(1);
S.selectByVisibleText("Emp. ID");

//S.selectByValue("6");

//get the selected value

String selected_value= S.getFirstSelectedOption().getText();

System.out.println(selected_value);

//Verify selected value

if(selected_value.equals("Emp. ID"))
{
System.out.println("Selected value verified successfully");

}else
{
System.out.println("Selected value not verified successfully");
}

//Clicking On Logout Button

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

//Instance method

void closeBrowser()
{
driver.close();//close the current browser window

//Static method

public static void main(String[] args) {

//Create the object for that FirstProgram class

FirstProgram F = new FirstProgram();

F.openBrowser();//call the openBrowser()

F.loginTest();//call the loginTest()

F.closeBrowser();//call the closeBrowser

}
Interview Questions :
Where we can use for loop ?
Ans : Some times we need to perform same action with multiple times so at that time
we need to follow for loop
Can we declare class as a datatype in java ?
Ans : Yes
How many ways to switch to frame ?
Ans : 4 ways,What are these

How to verify single checkbox in a webpage using selenium?

TestSteps

 Open the Firefox browser


 Navigate the AppUrl
 Identify Checkbox1
 Click Checkbox1
 Verify Checkbox1
 Close the current Browser window

Selenium Code :

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SingleCheckbox {


public static void main(String[] args) {
//open the firefox browser
WebDriver Driver = new FirefoxDriver();
//navigate the AppUrl
Driver.get("http://demo.guru99.com/test/radio.html");
// Identify Checkbox1
WebElement CheckBox1= Driver.findElement(By.id("vfb-6-0"));
//Select Checkbox1
CheckBox1.click();
//Verify Checkbox1
if (CheckBox1.isSelected())
{
System.out.println("Checkbox1 Selected");
} else
{
System.out.println("Checkbox1 not Selected");
}
//Close the current Browser window
Driver.close();
}
}

How to Verify multiple checkboxes ?

Manual Steps :
 open the firefox browser
 navigate the AppUrl
 Identify all Checkboxes
 Count total checkboxes in a webpage
 Verify multiple checkboxes one by one
 Close the browser
Selenium Code
package SeleniumPack;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class VerifyMultipleCheckboxes {
public static void main(String[] args) {
// open the firefox browser
WebDriver driver = new FirefoxDriver();
// navigate the AppUrl
driver.get("http://demo.guru99.com/test/radio.html");
// Identify all Checkboxes
List<WebElement> allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));
//Count total checkboxes
System.out.println("Total checkboxes : " + allchk.size());// 3
// Verify multiple checkboxes one by one
for (int i = 0; i < allchk.size(); i++) {
allchk.get(i).click(); //click on particular checkbox
//verify particular checkbox
if (allchk.get(i).isSelected()) {
System.out.println("checkbox selected successfully");
} else {
System.out.println("checkbox not selected successfully");
}
}
//Close the browser

}
}
1.How to select multiple options from listbox?

2.Verify Multiple selections are allowed or Not from a list box.

TestSteps :
1.Launch the web browser
2.Navigate the url
3.Identify the Lisbox
4.select multiple options from a list box.
5.Verify Multiple selections are allowed or Not from a list box.

Selenium Code :
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class IsMultiple {

public static void main(String[] args) {


//1. Launch the Firefox browser
WebDriver driver=new FirefoxDriver();
//3. Navigate the url
driver.get("https://apps.fas.usda.gov/esrquery/esrq.aspx");

//identify the listbox


WebElement
listbox=driver.findElement(By.xpath("//*[@id='MainContent_lbCountry']"));

//create select object for that listbox


Select Countries=new Select(listbox);
//select multiple options from a list box.

// Selecting an option using ‘selectByVisibleText’


Countries.selectByVisibleText("AFGHANISTAN");

// Selecting an option using ‘selectByVisibleText’


Countries.selectByVisibleText("ARGENTINA");

// Verify Multiple selections are allowed or Not from a list box.


if(Countries.isMultiple())
{
System.out.println("Multiple selections allowed");
}
else{
System.out.println("Multiple selections not allowed");
}

}
Working with popups :

In this chapter, we will cover:


1. How to Handling Web-Based alert Popup/Javascript Alert Popup.
2. How to Handling modal popup window.
3. How to Handling multiple windows.

Introduction:
Javascript Alerts Popup, Confirmation Popup and Prompt Popup are very regularly
used elements of any software webpage and you must know how to handle all these
kind of popups In selenium webdriver software automation testing tool.First of
all, Let me show you all three different popup types to remove confusion from your
mind and then we will see how to handle them In selenium webdriver.
It is nothing but a small box .Here alert box speaks about error message or some
information.
How to Handling Web-Based alert Popup/Javascript Alert Popup.

TestSteps :

 open the firefox browser


 Navigate the url
 Enter the Username
 Enter the password
 click on login button
 click on logout button
 switchTo alert ,get the alert text and store the alert text into alert_text
variable
 verify alert text
 click on ok button
 close the browser

Selenium code :

package PopupExamples;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AlertExample {

public static void main(String[] args) throws InterruptedException {

// open the firefox browser

WebDriver driver = new FirefoxDriver();

// Navigate the url

driver.get("http://demo.guru99.com/v4/");

// Enter the Username

driver.findElement(By.xpath("html/body/form/table/tbody/tr[1]/td[2]/
input")).sendKeys("mngr279617");

// Enter the password

driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td[2]/
input")).sendKeys("gYpyqur");

// click on login button

driver.findElement(By.xpath("html/body/form/table/tbody/tr[3]/td[2]/
input[1]")).click();

// Wait 5sec

Thread.sleep(5000);

// click on logout button

driver.findElement(By.xpath("html/body/div[3]/div/ul/li[15]/a")).click();

// Wait 5sec

Thread.sleep(5000);

// switchTo alert ,get the alert text and store the the alert text in
alert_text
// variable
Alert alt = driver.switchTo().alert();

String alert_text = alt.getText();

System.out.println("Print alert text :" + alert_text);

// verify alert text

if (alert_text.equals("You Have Succesfully Logged Out!!")) {


System.out.println("alert text verified successfully");
} else {
System.out.println("alert text not verified successfully");
}

// click on ok button

alt.accept();

// click on cancel button

// alt.dismiss();

// close the browser

// Wait 5sec

Thread.sleep(5000);

// close the browser window

driver.close();

Note :
1.Until you do not handle alert you cannot perform any action in the parent
window.
2. Web-Based alert and Java Script alerts are same so do not get confused.
Interview Question :

How to Handling Web-Based alert Popup/Javascript Alert Popup.

Manual steps

1.switch to alert box


2.get the alert text
3.click on ok button from alert box

Example

//switch to alert box

Alert alert = driver.switchTo().alert();

String alet_text = alert.getText();


System.out.println(alet_text);//alert text verified successfully

//verify alert text

if(alet_text.equals("alert text verified successfully"))


{
System.out.println("Alert text vcerified successfully");
}else
{
System.out.println("Alert text not vcerified successfully");
}

//click on ok button

alert.accept();

//click on cancel button


//alert.dismiss();
How to handle single popup window or Modal popup window ?

TestSteps :
 Open the firefox browser
 Navigate the Application Url
 Click on Sign in
 1.Switch to model popup window
 2.Do some action
 3 .click on model popup window
 close the current browser window
Selenium Program :
package SeleniumJavaTests;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class VerifyMultipleCheckboxes {
public static void main(String[] args) throws InterruptedException {
// open the firefox browser
WebDriver driver = new FirefoxDriver();
// navigate the AppUrl
driver.get("https://www.kayak.co.in/flights");
Thread.sleep(3000);
driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div[2]/
div/div[1]/div/div[2]/div[1]/div/div[2]/span/div/div[2]/span/button/div[1]/div/
div[2]/strong")).click();
//1.switch to model popup window
driver.switchTo().window(driver.getWindowHandle());
//2.Do some action
Thread.sleep(5000);
//3.Click on model popup window
driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();

}
}
How to handle multiple windows in Selenium WebDriver?
Practice site :
https://www.cleartrip.com/trains
Point to Note : -
1. We can handle multiple windows in selenium webdriver using Switch To methods
which will allow us to switch control from one window to another window.
2. If you are working with web applications then you must have faced this
scenario where you have to deal with multiple windows.
3. If you have to switch between tabs then also you have to use the same
approach. Using switch To method we can also handle frames and alerts with easy
methods. I will focus on multiple windows as of now.
Before starting this section I will recommend you watch ArrayList in Java which
will help you to understand this concept in details.

ArrayList : -
1.By creating ArrayList,we can store no of windows at dynamically.
2. By creating ArrayList,dynamically we can increase the memory size when new
window store into ArrayList (Java Collection Object).
3. ArrayList is type of Java Collection Object useful to store duplicate objects.
4. ArrayList Elements are stored in index based.
5. ArrayList allow duplicate elements.

There are two methods in Selenium WebDriver to handle multiple windows -

 driver.getWindowHandle() – This method is used to get the current opened


window.

Syntax : -

//Get the current opened window

String currentWindow = driver.getWindowHandle();

Return type – String

 driver.getWindowHandles() - This method is used to get all the opened windows


in a Set.

Syntax : -

//Get all the opened windows in a Set

Set<String> all_openedwindows = driver.getWindowHandles();

Return Type - Set<String>

If there are multiple windows opened then follow below syntax.


1. The user wants to go to main window, Follow below syntax.

Syntax : - driver.switchTo().window(parentWindow);

Ex : - driver.switchTo().window(AllWindowHandles.get(0));

Note – By default main window index value ‘0’

2. The user wants to go to child1 window, Follow below syntax.

Syntax : - driver.switchTo().window(child1 Window);

Ex : - driver.switchTo().window(AllWindowHandles.get(1));
3. The user wants to go to child2 window, Follow below syntax.

Syntax : - driver.switchTo().window(child2 Window);

Ex : - driver.switchTo().window(AllWindowHandles.get(2));
Diagram:

In some applications, you will get some Popups that is nothing but separate
windows.

Manual Steps :
TestCase_ID Test Steps Step Description
TC_09 Step 1 Launch firefox Browser

TC_ Step 2 Navigate the Application Url

TC_ Step 3 Enter the username

TC_ Step 4 Enter the password

TC_ Step 5 Click on login button

TC_ Step 6 click on feedback

TC_ Step 7 Get total windows and store into windows variable

TC_ Step 8 print total windows

TC_ Step 9 By creating ArrayList object u can store no of window based


popups dynamically

TC_ Step 10 Switch to new child window

TC_ Step 12 print the child window title

TC_ Step 13 Do some action on child window based on your requirement

TC_ Step 14 close the child window

TC_ Step 15 Wait for 3sec

TC_ Step 16 Switch to main or parent window

TC_ Step 17 print the parent window title

TC_ Step 18 Do some action on main window based on your requirement


TC_ Step 19 close the Parent window

Complete program to handle multiple windows in selenium webdriver ?


First, we will switch to child window (pop up window) then we will close it and
then we will switch to the parent window.
Selenium Code:
package seleniumProject;
import java.util.ArrayList;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Handle_Multiple_Windows {

public static void main(String[] args) throws InterruptedException {

//Open the firefox browser


WebDriver driver = new FirefoxDriver();

//Navigate the Application Url


driver.get("http://kosmiktechnologies.com/seleniumLiveProject/kosmik-
hms/");

//Enter the username


driver.findElement(By.name("username")).sendKeys("kosmik");

//Enter the password


driver.findElement(By.name("password")).sendKeys("kosmik");

//Click on login button


driver.findElement(By.name("submit")).click();

//click on feedback
driver.findElement(By.xpath(".//*[@id='navigation']/li[3]/a")).click();

//Get total windows and store into windows variable


Set<String> windows=driver.getWindowHandles();

//print total windows


System.out.println(windows.size());

//By creating ArrayList object u can store no of window based popups


dynamically
ArrayList<String> AllWindowHandles = new ArrayList<String> (windows);

1. new ArrayList<String> ();

2. new ArrayList<String> (windows);

3. ArrayList<String> AllWindowHandles = new ArrayList<String> (windows);

//Switch to new child window


driver.switchTo().window(AllWindowHandles.get(1));

//print the child window title


System.out.println(driver.getTitle());

// Do some action on child window based on your requirement

//close the child window


driver.close();

//Wait for 3sec


Thread.sleep(3000);

//Switch to main or parent window


driver.switchTo().window(AllWindowHandles.get(0));

//print the parent window title


System.out.println(driver.getTitle());

// Do some action on main window based on your requirement

//close the Parent window


driver.close();
}
}
How to Handle multiple windows in selenium?
1.How to count total windows ?
Set<String> totalWindows = driver.getWindowHandles();
System.out.println("Total windows : "+totalWindows.size());//
2.How to handle Child window ?

Manual Steps :
>switch to child window
>Do some action
>close the child window
Code :
******
Set<String> totalWindows = driver.getWindowHandles();
System.out.println("Total windows : "+totalWindows.size());//

ArrayList<String> AllWindowHandles = new ArrayList<String> (windows);

//switch to child window


driver.switchTo().window(allwindows.get(1));
//Do some action
System.out.println(driver.getTitle());
//close the child window
driver.close();

3.How to Handle the Main window ?


Manual Steps :
>Again switch to the main window
>Do some action
>Close the main window
Code :
*******
Set<String> totalWindows = driver.getWindowHandles();
System.out.println("Total windows : "+totalWindows.size());//

ArrayList<String> AllWindowHandles = new ArrayList<String> (windows);


//Again switch to the main window
driver.switchTo().window(allwindows.get(0));
//Do some action
System.out.println(driver.getTitle());
//Close the main window
driver.close();
Action Class :

By using Action Class, You can perform all actions on a web page.
To handle the mouse movements and keyboard events then we use Actions class
in selenium.
To use Actions class in our code, First we need to create the Actions class
object for that driver.
Where exactly we can use action class?

For Ex :Suppose If u want to perform mouse hover ,drag and drop,Rihgt click and
doubleClick etc..in this kind of situation we need to use Action class.

perform() :Execute the action on that webelement

Note : For each action we need to perform()


Mouse Actions:

How to perform dragAndDrop operation in selenium ?


Ans : By using dragAndDrop()

How to perform MouseHover operation in selenium ?


Ans : By using moveToElement()

How to perform doubleClick operation in selenium ?


Ans : By using doubleClick()

How to perform rightClick operation in selenium ?


Ans : By using contextClick()
1.How to perform Drop & Drag operation in Selenium ?
Many times, We have the web application where we need to drag an element from one
location to another location. To handle this kind of actions we need Action class
in selenium

Test steps :
 Open the firefox browser
 Navigate the AppUrl
 Identify the drag element
 Identify the drop element
 Create action class object for that driver
 Performing Drag and Drop operation
 Identify and get the Dropped! text and store into dropped_text variable
 To verify whether the dragAndDrop operation successfully performed or not
 Close the current browser window

Selenium code :

package ActionClassExamples;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class DragAndDrop {

public static void main(String[] args) {

// instance variable

WebDriver driver = new FirefoxDriver();

//  Navigate the AppUrl

driver.get("https://jqueryui.com/resources/demos/droppable/default.html");
WebElement drag = driver.findElement(By.id("draggable"));

WebElement drop = driver.findElement(By.id("droppable"));

Actions act = new Actions(driver);

act.dragAndDrop(drag, drop).perform();

String dropped_text =
driver.findElement(By.xpath("//*[@id='droppable']/p")).getText();

System.out.println(dropped_text);

// To verify whether the dragAndDrop operation successfully performed


or
// not

if (dropped_text.equals("Dropped!")) {
System.out.println("dragAndDrop operation verified
successfully");

} else {
System.out.println("dragAndDrop operation not verified
successfully");
}

}
2.How to perform Mouse hover in selenium?
Test steps :
 Open the firefox browser
 Navigate the AppUrl
 Get the Title of WebPage
 Print the title of the webpage
 Print the title of the webpage
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Welcome selenium text and store into text variable
 Print the welcome selenium text
 To verify whether the welcome page successfully opened or not
 Create action class object for that driver
 Mouse hover on PIM main module
 Click on Add Employee submenu
 Wait 5sec
 Switch to frame by using Id
 Identify and get the Add Employee text and store into addEmp variable
 Print the Add Employee text
 To verify whether the Add Employee page successfully opened or not
 Switch back to main window
 Click on Logout
 Wait 5sec
 Close the current browser window

Selenium Code :

package ActionClassPack;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class MouseMovement {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();
// navigate the AppUrl

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

// Get the Title of WebPage

String title = driver.getTitle();

// print the title of the webpage

System.out.println(title);

// Verify Title of the WebPage

if (title.equals("OrangeHRM - New Level of HR Management")) {


System.out.println("title is verified successfully");
} else {
System.out.println("title is not verified successfully");
}

// Enter the username

driver.findElement(By.name("txtUserName")).sendKeys("selenium");

// Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

// Clicking On Login Button

driver.findElement(By.name("Submit")).click();

// Identify and get the Welcome selenium text and store into text
variable
String text =
driver.findElement(By.xpath("//*[@id='option-menu']/li[1]")).getText();

// Print the welcome selenium text

System.out.println(text);

// To verify whether the welcome page successfully opened or not


if (text.equals("Welcome selenium")) {

System.out.println("Welcome selenium is verified successfully");

} else {
System.out.println("Welcome selenium is not verified
successfully");
}

//create action class object for that driver

Actions act = new Actions(driver);

//mouse hover on PIM main module

act.moveToElement(driver.findElement(By.id("pim"))).perform();

// click on Add Employee submenu

driver.findElement(By.xpath("//*[@id='pim']/ul/li[2]/a")).click();

//wait 5sec
Thread.sleep(5000);

//Switch to frame by using Id

driver.switchTo().frame("rightMenu");

// Identify and get the Add Employee text and store into addEmp
variable

String addEmp =
driver.findElement(By.xpath("/html/body/form/div/div[1]/div[2]/div[1]/
h2")).getText();

// Print the Add Employee text

System.out.println(addEmp);

// To verify whether the Add Employee page successfully opened or not

if (addEmp.equals("PIM : Add Employee")) {


System.out.println("Add Employee page verified successfully");
} else {
System.out.println("Add Employee page not verified
successfully");
}

//switch back to main window

driver.switchTo().defaultContent();

//Click on Logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

//wait 5sec
Thread.sleep(5000);

//close the current browser window

driver.close();

3.To verify whether the DoubleClick operation successfully performed or Not?

TestSteps :
 Open the firefox browser
 Navigate the AppUrl
 Identify copyText button element
 Create action class object for that driver
 Double click on copyText button
 Identify and get the text from input field2 and store into entered_text
variable
 To verify whether the double click operation successfully performed or not
 Close the current browser window

Selenium Code :

package SeleniumPack;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class DoubleClick {

public static void main(String[] args) throws InterruptedException {


// Open the firefox browser
WebDriver driver = new FirefoxDriver();
// Navigate the AppUrl
driver.get("file:///E:/Selenium%20Software%20dump%20files/Browser
%20Elements/doubleClickMe.html");

// identify copyText button element


WebElement element =
driver.findElement(By.xpath("html/body/button"));

// Create action class object for that driver

Actions action = new Actions(driver);

// double click on copyText button

action.doubleClick(element).perform();

//wait 5 sec
Thread.sleep(5000);
System.out.println("double click operation
successfully performed");

/*
Note :

We can retrieve value which we have typed or


already typed in text box/text area. It will be useful when we want to verify if
correct value is typed or to know existing value in text box/text area.
To retrieve value from text box/textarea, we need to
use getAttribute() method.

*/

// Identify and get the text from input field2 and


store into entered_text variable
String entered_text =
driver.findElement(By.id("field2")).getAttribute("value");

// to verify whether the double click operation


successfully performed or not

if (entered_text.equals("Hello World!")) {
System.out.println("Entered text verified
successfully");
} else {
System.out.println("Entered text not verified
successfully");
}

// Close the current browser window

driver.close();
}
}
getText();
>If u want to get the particular text in a webpage then we use getText()
getAttribute()
>If u want to get the value from input field(textbox,text area) then we use
getAttribute()

4.How to perform rightClick operation in selenium?


Example 1
TestSteps :

 Open the firefox browser


 Navigate the AppUrl
 Identify about element
 Create action class object for that driver
 Perform Rightclick on about element

Selenium Code :

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Context_Click {

public static void main(String[] args) {

//Open the firefox browser

WebDriver driver = new FirefoxDriver();

//Navigate the AppUrl

driver.get("https://www.google.co.in/");

//Identify about element

WebElement about = driver.findElement(By.linkText("About"));


//Create action class object for that driver

Actions action = new Actions(driver);

// Right click on about element

action.contextClick(about).perform();

//Close the current browser window

driver.close();
}
}

Example 2

TestSteps :

 Open the firefox browser


 Navigate the AppUrl
 Identify about element
 Create action class object for that driver
 Rightclick on about element
 Wait 5sec
 Click on Open Link In New Window
 Close the current browser window

Selenium Code :

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Context_Click {


public static void main(String[] args) {

//Open the firefox browser

WebDriver driver = new FirefoxDriver();

//Navigate the AppUrl

driver.get("https://www.google.co.in/");

//Identify about element

WebElement about = driver.findElement(By.linkText("About"));

//Create action class object for that driver

Actions action = new Actions(driver);

// Right click on about element

action.contextClick(about).perform();

System.out.println("Sucessfully Right clicked on the About


element");

// Click on Open Link In New Window

action.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).click().perform();

//wait 5sec

Thread.sleep(5000);

//Close the current browser window

driver.close();
}
}
Keyboard Actions:
1.How to give the input value from the keyboard ?or How to perform single action in
a webpage using selenium?
Ans)By using sendKeys()
Examples
>sendKeys(Keys.ARROW_DOWN)
>sendKeys(Keys.ARROW_UP)
>sendKeys(Keys.DELETE)
>sendKeys(Keys.F12)
>sendKeys(Keys.ENTER)
>sendKeys("a")
2.How to perform multiple Actions at a time in a webpage using selenium?
Ans : By using keyDown() and keyUp()
>keyDown()===>Perform the key press
>keyUp()===>Perform the key release
Examples
Ctrl + a,Ctrl + c ,Ctrl +v,Shift + a,Alt+ F ,Ctrl + N, Ctrl + T, Ctrl + w---------
Ctrl + a = Ctrl press + press a + Ctrl release
Ctrl + a = keyDown(Keys.CONTROL) +sendKeys("a") + keyUp(Keys.CONTROL)
Ctrl +v = keyDown(Keys.CONTROL) +sendKeys("v") + keyUp(Keys.CONTROL)

Shift + a = Shift press + press a + Shift release


Shift + a = keyDown(Keys.SHIFT) + sendKeys("a") + keyUp(Keys.SHIFT)
Shortcut Keys

Keyboard’s Key Keys enum’s value


Arrow Key – Down Keys.ARROW_DOWN
Arrow Key – Up Keys.ARROW_UP
Arrow Key – Left Keys.ARROW_LEFT
Arrow Key – Right Keys.ARROW_RIGHT
Backspace Keys.BACK_SPACE
Ctrl Key Keys.CONTROL
Alt key Keys.ALT
DELETE Keys.DELETE
Enter Key Keys.ENTER
Shift Key Keys.SHIFT
Spacebar Keys.SPACE
Tab Key Keys.TAB
Equals Key Keys.EQUALS
Esc Key Keys.ESCAPE
Home Key Keys.HOME
Insert Key Keys.INSERT
PgUp Key Keys.PAGE_UP
PgDn Key Keys.PAGE_DOWN
Function Key F1 Keys.F1
Function Key F2 Keys.F2
Function Key F3 Keys.F3
Function Key F4 Keys.F4
Function Key F5 Keys.F5
Function Key F6 Keys.F6
Function Key F7 Keys.F7
Function Key F8 Keys.F8
Function Key F9 Keys.F9
Function Key F10 Keys.F10
Function Key F11 Keys.F11
Function Key F12 Keys.F12

1.How to perform Ctrl+a using Action class in selenium?


TestSteps :

 Open the firefox browser


 Navigate the AppUrl
 Enter webdriver text into search box
 Create action class object for that driver
 Select webdriver text(perform ctrl+a)
 Close the current browser window

Selenium Code :

package SeleniumTests;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Ctrl_a {
public static void main(String[] args) {

//Open the firefox browser

System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver = new FirefoxDriver();

//Navigate the AppUrl

driver.get("https://www.google.com/");

//Enter webdriver text into search box

driver.findElement(By.name("q")).sendKeys("webdriver");

//Create action class object for that driver

Actions action = new Actions(driver);

//Select webdriver text(perform ctrl+a)

action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).perform();

2.How to perform Ctrl+a and DELETE using Action class in selenium?


TestSteps :

 Open the firefox browser


 Navigate the AppUrl
 Enter webdriver text into search box
 Create action class object for that driver
 Select webdriver text and DELETE(perform ctrl+a and DELETE)
 Close the current browser window

Selenium Code :

package SeleniumTests;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Ctrl_a {


public static void main(String[] args) {

//Open the firefox browser

System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver = new FirefoxDriver();

//Navigate the AppUrl


driver.get("https://www.google.com/");

//Enter webdriver text into search box

driver.findElement(By.name("q")).sendKeys("webdriver");

//Create action class object for that driver

Actions action = new Actions(driver);

// Select webdriver text and DELETE(perform ctrl+a and DELETE)

action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).sendKeys(Keys.DELETE
).perform();

3.How to Enter the Text Into InputField(textbox,textarea) Using ActionClass in


selenium?
TestSteps :

 Launch the Firefox browser


 Navigate to AppUrl
 Identify Enter Keyword text box
 create action class object for that driver
 Enter the Keyword(i.e Enter Kosmik Technologies Keyword)
 Closing current driver window
Selenium Code :
package ActionClassPack;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class EnterText_Into_InputField_Using_ActionClass {

public static void main(String[] args) {


// Launch the Firefox browser
WebDriver driver = new FirefoxDriver();
// Navigate to AppUrl
driver.get("https://www.kosmiktechnologies.com/jobs/");
// Identify Enter Keyword text box
WebElement EnterKeyword = driver.findElement(By.id("keyword"));
// create action class object for that driver
Actions act = new Actions(driver);
// Enter the Keyword(i.e Enter Kosmik Technologies Keyword)
act.sendKeys(EnterKeyword,"kosmik Technologies").perform();

// Closing current driver window


driver.close();
}
}
4.How to Enter the Text Into InputField(textbox,textarea)and click on GO Button
Using ActionClass in selenium?
TestSteps :

 Launch the Firefox browser


 Navigate to AppUrl
 Identify Enter Keyword text box
 create action class object for that driver
 Enter the Keyword(i.e Enter Kosmik Technologies Keyword)
 identify Go button
 Click on Go button
 Closing current driver window
Selenium Code :
package SeleniumTests;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class ActionClassprogram {


public static void main(String[] args) {

// Launch the Firefox browser

WebDriver driver = new FirefoxDriver();

// Navigate to AppUrl

driver.get("https://www.kosmiktechnologies.com/jobs/");

// Identify Enter Keyword text box

WebElement EnterKeyword = driver.findElement(By.id("keyword"));

// create action class object for that driver

Actions act = new Actions(driver);

// Enter the Keyword(i.e Enter Kosmik Technologies Keyword)

act.sendKeys(EnterKeyword,"kosmik Technologies").perform();

// identify Go button

WebElement GO_button = driver.findElement(By.className("form-control"));

//Click on Go button

act.moveToElement(GO_button).sendKeys(Keys.ENTER).perform();

// Closing current driver window

// driver.close();
}
}
How to Upload a file ?
Practice Website :

There are different ways to handle file upload with Selenium Webdriver.

1.sendkeys() :If u want to upload the file then we need to use sendkeys().
2.AutoIt tool :Some times selenium did not find the window based elements then
we need to use AutoIt.

1.By using sendkeys()

The First and the Easy way is simple case of just finding the element and typing
the absolute path of the image file into it.

NOTE: This works only when the textbox is enabled. So please make sure that the
input element is visible.

The OTHER WAY to Handle File Upload

Some times sendkeys() it doesn ‘t work at that time u need to follow AutoIt tool.
If there is no text box / input tag to send the file path using Sendkeys method at
that time u need to follow Autoit tool.

You will have only a button (Customized button) and when click on browse button,
browser opens a window popup and to select the file from windows, And as we know
selenium will not support window based applications.
Why we are using AutoIT in Selenium?
1-While automating web-application many times you will get window based activity
like- file upload, file download pop up, window authentication for secure sites
etc.
In this case Selenium fails and will not be able to handle desktop elements to
avoid this we will use AutoIT script that will handle desktop or windows elements
and will combine AutoIT script with our Selenium code.
Introduction to AutoIT tool
1-AutoIt is freeware automation tool that can work with desktop application too.
2-It uses a combination of keystrokes, mouse movement and window/control
manipulation in order to automate tasks in a way not possible or reliable with
other languages (e.g. VBScript and SendKeys).
For more info about AutoIT, you can visit their Official Website AutoIt Official
Website

How to write script in AutoIT?


For AutoIt scripting you should have three things ready.
1-AutoIt Editor- Editor help us to write AutoIt scripts.
2-Tool Finder (Same as firebug on Firefox) – It will help us to identify the
element and check their Attributes.
3- AutoIt Help section- This help you to understand about AutoIt functions and what
are the parameter it accepts.
Let’s start with Downloading first
Step 1– Navigate to AutoIt official
website https://www.autoitscript.com/site/autoit/downloads/ and go to download
section or Click here Download AutoIt
Step 2– Click on Download AutoIt and Install
Step 3– Click on Download Editor and Install.

Step 4– Once both installed in your machine check all is installed correctly.
Note- Generally it goes to C:\Program Files\AutoItv3 location if you do not change
it

Step5– Open SCiTE folder and Click on SciTE this will open AutoIt Editor

Once all Installed Let’s see how we can write script


Upload File in Selenium Webdriver using Autoit

To upload a file in Selenium Webdriver we will create AutoIT script, which will
handle file-uploaded window, and then we will combine Selenium script with AutoIt
scripts.
Click on Upload button you will get file uploader we will handle the same using
AutoIt.
Step 1– Open Editor and Finder Tool

Step 2– We need to write script to upload file so we will use some methods of
AutoIt.

Each method will have some own functionality.

ControlFocus-This will give focus on the window.


ControlSetText-This will set the file path.
ControlClick-This will click on open button.

Step 1-
Click on Browse button , new window will open now open finder tool and Click on
Finder tool and drag to the file name as I shown in below screenshot.

This will give all the detail about that window and file name Section info : we
will use only some attribute like window title, class and instance.
Open AutoIt Editor and Write Script

In ControlClick method we will give control id of open button


Step 2-
Save the script to a particular location with some unique name.
Note- By default script will be saved as .au3 extension
Step 3– Now Compile the script so for compiling right click on file and Select
compile script this will generate .exe file of the file.

Step 4- Now write Selenium program and add this .exe file and run your program.
TestSteps :
 Open the firefox browser
 Navigate the AppUrl
 Get the Title of WebPage
 Print the title of the webpage
 Print the title of the webpage
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Welcome selenium text and store into text variable
 Print the welcome selenium text
 To verify whether the welcome page successfully opened or not
 Create action class object for that driver
 Mouse hover on PIM main module
 Click on Add Employee submenu
 Wait 5sec
 Switch to frame by using Id
 Identify and get the Add Employee text and store into addEmp variable
 Print the Add Employee text
 To verify whether the Add Employee page successfully opened or not
 Upload the file
 Switch back to main window
 Click on Logout
 Wait 5sec
 Close the current browser window

Selenium Code :

package ActionClassExamples;

import java.io.IOException;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class AutoIt {

public static void main(String[] args) throws InterruptedException,


IOException {
// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the AppUrl

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

// Get the Title of WebPage

String title = driver.getTitle();

// print the title of the webpage

System.out.println(title);

// Verify Title of the WebPage

if (title.equals("OrangeHRM - New Level of HR Management")) {


System.out.println("title is verified successfully");
} else {
System.out.println("title is not verified successfully");
}

// Enter the username


driver.findElement(By.name("txtUserName")).sendKeys("selenium");

// Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

// Clicking On Login Button

driver.findElement(By.name("Submit")).click();

// Identify and get the Welcome selenium text and store into text
// variable
String text =
driver.findElement(By.xpath("//*[@id='option-menu']/li[1]")).getText();

// Print the welcome selenium text

System.out.println(text);

// To verify whether the welcome page successfully opened or not

if (text.equals("Welcome selenium")) {

System.out.println("Welcome selenium is verified successfully");

} else {
System.out.println("Welcome selenium is not verified
successfully");
}

// create action class object for that driver

Actions act = new Actions(driver);

// mouse hover on PIM main module

act.moveToElement(driver.findElement(By.id("pim"))).perform();

// click on Add Employee submenu

driver.findElement(By.xpath("//*[@id='pim']/ul/li[2]/a")).click();

// wait 5sec
Thread.sleep(5000);

// Switch to frame by using Id

driver.switchTo().frame("rightMenu");

// Identify and get the Add Employee text and store into addEmp
variable

String addEmp =
driver.findElement(By.xpath("/html/body/form/div/div[1]/div[2]/div[1]/
h2")).getText();

// Print the Add Employee text

System.out.println(addEmp);
// To verify whether the Add Employee page successfully opened or not

if (addEmp.equals("PIM : Add Employee")) {


System.out.println("Add Employee page verified successfully");
} else {
System.out.println("Add Employee page not verified
successfully");
}

// wait 5sec
Thread.sleep(5000);

// driver.findElement(By.id("photofile")).sendKeys("E:\\Selenium.png");

act.moveToElement(driver.findElement(By.id("photofile"))).click().perform();

// driver.findElement(By.id("photofile")).click();

// wait 5sec
Thread.sleep(3000);

// Upload file

Runtime.getRuntime().exec("E:\\Autoit\\FileUpload.exe");

// wait 5sec
Thread.sleep(5000);

// switch back to main window

driver.switchTo().defaultContent();

// Click on Logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

// wait 5sec

Thread.sleep(5000);

// close the current browser window

driver.close();

Xpath(is defined as xmlPath) in Selenium


________________________________________
If there is no alternative way like id, class, name, etc. then XPath is used
to find an element on the web page.
Xpath is the complete address of the Element.
By using XPath we can identify the normal elements and dynamic elements.
Xpath-types
1. Absolute XPath
2. Relative Xpath
Diff erence between Absolute XPath and Relative Xpath ?
Absolute XPath Relative Xpath
1.It takes the xpath from(/)tag or html tag to identify WebElement. 1.It takes
the xpath from(//) to identify WebElement insteady of writing from root tag(/).
2.This is a long length xpath 2.This is a short length xpath
3.Below is the example of an absolute XPath expression of the element shown below.
Syntax :
/html/body/input
Htmlcode :

Example : /html/body/input
3.Below is the example of a Relative XPath expression of the same element
shown below.
Syntax:
//tagName[@Attributename='value']
Htmlcode :

Example :
// input [@name=’username’]

4.Here absolute xpath ,It identifies the element very fast.4.Here Relative xpath,It
will take more time in identifying the element but in real time we should follow
relative xpath not absolute xpath ,some times we need to follow absolute xpath.

Note:
________________________________________
Here disadvantage of the absolute XPath is that if there are any changes
made in the application or in the XPath of the element then that absolute XPath
gets failed. So in this case Relative XPath, it's better.
If there are any changes made in the application or in the XPath of the
element then we should go for Relative XPath.
If there are no changes made in the application or in the XPath of the
element then we should go for Absolute XPath.
In future any of the webelement when added/Removed then Absolute Xpath
changes. So Always use Relative Xpaths in your Automation.
How to get the Absolute XPath and Relative XPath in Firefox?
Ans: By using SelectorsHub
How to install SelectorsHub in Firefox?
-To install SelectosHub in Firefox
 Open Firefox browser.
 Go to google search
 Enter SelectorsHub for firefox then search it
 Click on SelectorsHub – Get this Extension for Firefox (en-US)
 Open Firefox Browser Add-Ons page and search for SelectorsHub add-on.
 You will get the SelectorsHub add-on in the search result.
 Click on Add to Firefox button.

 It will ask for confirmation to add an addon in firefox.


 Click on Add button.

 On successful installation, It will show SelectorsHub icon on top-right


corner of Firefox browser.
 Click on Okay ,Got it button

How to get the Absolute XPath and Relative XPath in Chrome?


Ans: By using SelectorsHub
How to install SelectorsHub in Chrome?
- Click on below link to install Selectors hub in your Chrome browser.
https://chrome.google.com/webstore/detail/selectorshub/
ndgimibanhlabgdgjcpbbndiehljcpfh/
Click on add to chrome

Click on Add Extension

Once it is installed, SelectorsHub icon will display on top-right corner of google


chrome browser.

How to get the Absolute XPath and Relative XPath in IE?


________________________________________
Ans: By using Fire-IEBrowser tool
Download Fire-IEBrowser tool Tool For IE Browser
1) Go to https://code.google.com/p/fire-ie-selenium/downloads/list

2) Download Fire-IEBrowser1.4.zip file.

3) The downloaded file by default save in to the Download folder but still it
depends on your system settings.

How to Use Fire IE Browser Tool for Selenium Browser


1) Double click on the Fire-IEBrowser1.4.xlsm file, this will open Microsoft Excel
file.

Note: Tool Is being crashed with some websites and there Is not any online support
for this tool. So use It If works with your website.

2) This may display the security pop up with in the excel file, Click on
EnableEditing.

3) One more security warning can appear with in the excel, for this click on Enable
Content button.

4) Now It will open FIRE – IE BROWSER – WEB ELEMENT DETAILS dialog with Proceed
button as shown In below Image. Click on Proceed button.

5) It will open Fire IE Selenium tool as shown In below Image.

To start using it, type https://www.google.com/ in the URL box and click on Load
button.

6) This might produce script error depend on the application, but do not worry
about this and simply click on Yes button.

7)Mouse hover on Object/element then Right click on Google Search button .


8)Click On Insert_details button then This will Open Object Description dialog.

8) Enter the name of the HTML element/object name in text box and click on OK
button as shown In above Image.

10 ) This will display the Excel file with the saved information against the
selected HTML element Information contains XPath, CSS Path and other details of the
Google Search button element in Fire-IEBrowser1.4.xlsm file’s sheet.

Same way you can get all these details of any element and use In Selenium WebDriver
test script for IE only or any WebSite

How to check xpath is valid or not in firefox ?


________________________________________
- In Firefox you can use the web developer tools console for xpath validation like
this:
1.Open Web Developer tools.
2.Click on Console
3.Type $x("path")
Ex : $x("//input[@username='txtUserName']")
This should let you validate that your path is valid.

How to check xpath is valid or not in Chrome ?


________________________________________
1.Press F12 to open Chrome Developer Tool
2.Then press Ctrl+F
3.In the search box, type in XPath , if elements are found, they will be
highlighted in yellow.
see below image

Note :
But in IE browser there is no chance to verify whether the xpath is valid or not.

How to handle Dynamic Element/Object in selenium ?


________________________________________
 Many web sites create dynamic elements on their web pages where Ids of the
elements gets generated dynamically. Every reload id gets generated differently. So
to handle this situation we use some JavaScript functions like starts-with ends-
with,and contains .

starts-with
________________________________________
We can use this function when ID in starting is constant then dynamic.
if your (Loginbutton)dynamic element ids have the format where button
id="continue-12345", id="continue-12346" and id="continue-12347" where 12345,
12346 and 12347 is a dynamic numbers you could use the following
Where Dynamic id

< button id="continue-12345" >


< button id="continue-12346" >
< button id="continue-12347" >

XPath:------ //button[starts-with(@id, 'continue-')]

Where Dynamic name

< button name="continue-12345" >


< button name ="continue-12346" >
< button name="continue-12347" >

XPath:------ //button[starts-with(@name, 'continue-')]

Where Dynamic class

< button class ="continue-12345" >


< button class ="continue-12346" >
< button class ="continue-12347" >

XPath:------ //button[starts-with(@class, 'continue-')]


ends-with
________________________________________
We can use this function when ID in ending is constant then before dynamic.
if your (Loginbutton)dynamic element ids have the format where button
id="12345-continue", id="12346-continue" and id="12347-continue" where 12345,
12346 and 12347 is a dynamic numbers you could use the following

Where Dynamic id

< button id="12345-continue" >


< button id="12346-continue" >
< button id="12347-continue" >

XPath:------ //button[ends-with(@id, 'continue')]

Where Dynamic name

< button name="12345-continue " >


< button name ="12346-continue " >
< button name="12347-continue " >

XPath:------ //button[ends-with(@name, 'continue')]

Where Dynamic class

< button class ="12345-continue " >


< button class ="12346-continue " >
< button class ="12347-continue " >

XPath:------ //button[ends-with(@class, 'continue')]

contains
________________________________________
We can use this function when Id contain any fixed value at any place
Sometimes an element gets identfied by a value that could be surrounded by
other text, then contains function can be used.

Where Dynamic id

< button id="continue-12345-old" >


< button id="break-12345 -new”>
< button id="continue-12345-old" >

XPath:----- // button [contains(@id, '-12345-')].

Where Dynamic name

< button name ="continue-12345-old" >


< button name ="break-12345 -new”>
< button name ="continue-12345-old" >

XPath:------- // button [contains(@name, '-12345-')].

Where Dynamic class

< button class ="continue-12345-old" >


< button class ="break-12345 -new”>
< button class ="continue-12345-old" >

XPath: ------// button [contains(@class , '-12345-')].

How to handle dynamic element( Check availability )in selenium ?


________________________________________
Example :

Where Dynamic name

< button name =" btnchkavail b7f972c9">


< button name =" btnchkavail 060f3d3e">
< button name =" btnchkavail df4e91ef">

XPath:------- //input[@name='btnchkavail']

Selenium Code :
package SeleniumJavaTests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DynamicElement {

public static void main(String[] args) {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the AppUrl


driver.get("http://register.rediff.com/register/register.php?
FormName=user_details");
driver.findElement(By.xpath("//input[@name='btnchkavail']")).click();

Follow Html code :


________________________________________
<html>
<body>
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="middlename" placeholder="Middle Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="submit">
</body>
</html>
Note : Copy above html code and paste into notepad and save as
BrowserElement.html .

How to write the absolute xpath in manually for that password ?


Html code

Diagram:

Absolute Xpath :

Program:

How to write the absolute xpath in manually for that Username ?


Html code
Diagram:

Absolute Xpath :

Program:

How to write the absolute xpath in manually for that Gmail ?


Html code

Diagram:

Absolute Xpath :
Write the absolute xpath in manually for that Gmail : follow Red line
/html/body/div/div[1]/ div[1]/ div[1]/ div[1]/ div[1]/ div[1]/ div[1]/a
Program:
// open the firefox browser
WebDriver driver = new FirefoxDriver();

// navigate the AppUrl

driver.get("https://www.google.com/");
driver.findElement(By.xpath("/html/body/div/div[1]/div[1]/div[1]/div[1]/div[1]/
div[1]/div[1]/a")).click();

How to write the Relative xpath in manually for that password ?


Syntax :
//tagName[@attributeName='value']

Html code
<input type="text" name="password">

Example
//input[@name='password']

Selenium Java code


// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the AppUrl


driver.get("file:///E:/Selenium%20Files/Browser%20Elements/Browser
%20Element.html");
driver.findElement(By.xpath("//input[@name='password']")).click();
How to write the Relative xpath in manually for that Gmail ?
Syntax :
//tagName[@attributeName='value']

Html code
<a class="gb_g" data-pid="23" href="https://mail.google.com/mail/?
authuser=0&amp;ogbl" target="_top">Gmail</a>

Example
//a[@class='gb_g']

Selenium Java code


// open the firefox browser

WebDriver driver = new FirefoxDriver();


// navigate the AppUrl

driver.get("https://www.google.com/");

driver.findElement(By.xpath("//a[@class='gb_g']")).click();

Xpath function : text()


________________________________________
The XPath text() function is a built-in function of selenium webdriver which
is used to locate elements based on text of a web element.

If there is no alternative way like id, name, class name, or atleast one
attribute in your Html code then in this case text() required.

Html code

<h1>Welcome to Hanumanth</h1>

Syntax:

//tagName[@attributeName='value']

Example

//h1[text()='Welcome to Hanumanth']

Program

Xpath function : contains()


________________________________________

-If there is no alternative way like id, name, class name, or atleast one attribute
in your Html code then in this case contains() required.

Html code
<h1> Welcome to Hanumanthdshfshgfjahsgfkjhasdlkfjl djfjsdhfj shdj </h1>

Syntax:

//tagName[@attributeName='value']

Example

//h1[contains(text(),'shdj')]

Program

WebDriver driver=new FirefoxDriver();

driver.get("file:///E:/Selenium%20Files/Browser%20Elements/button
%20element.html");

String text =
driver.findElement(By.xpath("//h1[contains(text(),'kfjl')]")).getText();
System.out.println(text);

How to handle same name of the elements or objects in selenium ?


________________________________________
Automation using selenium is a great experience. It provides many ways to
identify an object or element on the web page.
But sometimes we face the problems of identifying the objects on a page that
have the same attributes.
When we get more than one element that is the same in attribute and name like
multiple checkboxes with the same name.
More than one checkbox having the same name. There is no way to distinguish
those elements. In this case, we have a problem instructing selenium to identify a
particular object on a web page.
I am giving you a simple example. In the below HTML source there are 6
checkboxes are there having the same type and the same name.
It is really tough to select third or fifth.
Open notepad and type the below and save as Checkboxes .html file
<html>
<body>
<input type='checkbox' name='chk'>chechbox
<br>
<input type='checkbox' name='chk'>chechbox
<br>
<input type='checkbox' name='chk'>chechbox
<br>
<input type='checkbox' name='chk'>chechbox
<br>
<input type='checkbox' name='chk'>chechbox
<br>
<input type='checkbox' name='chk'>chechbox

</body>
</html>
XPath function : position()
I will show you how to use above function in xpath to identify the object.
Function : position()
________________________________________
If you want to select any object based on their position using xpath then you
can use position() function in xpath.
You want to select second checkbox and forth checkbox then use below command
Examples :
driver.findElement(By.xpath("//input[@type='checkbox'][position()=2]"));
driver.findElement(By.xpath("//input[@type='checkbox'][position()=4]"));
above code will select second and forth checkbox respectively.
TestNG:
>Before going to TestNg we need to learn What is the difference between Manual
Testing and Automation Testing ?

>Types of testing
1.Functional Testing
2.Non-functional testing
>Here Functional Testing is divided into two types
1.Manual Testing
2.Automation testing
>What about Manual Testing?
>In manual testing our main activity is writing the manual test cases. These test
cases will be executed by some resources i.e Test Engineer.
>Here manual test cases are written by test engineer and he(test engineer) will
execute all the test cases manually.
>When it comes to automation testing what he(Test Engineer) will do this?
Ans: See The all the manual test cases will be converted to test script with the
help of some automation tools like selenium,qtp,Rft,silk test.....N of tools are
available. So the process of converting manual test cases to test script with the
help of some automation tools(selenium,qtp,Rft,silk test.....N) is nothing but
Automation.Here we can use any tool to convert into test script.
>You may get one doubt , In manual testing, we are writing the manual test cases
and execute the manual test cases when it comes to automation testing we are doing
same activity same test cases will be converted to automation test script and
execute the automation test script so what it is the use of automation?
>The main advantage of automation?
1. To save time
2. To save the money
3. Code reusability
4. To avoid the repeated code activities
5.Reduce the development time

1. To save time : How much time we can save? For example I want to go from
Kukatpally to Ameerpet.
>There are multiple ways manually I can go by walk but it takes time at that time
we need to follow some automation tools like bus, auto, car, the bike is, etc. Here
vehicles are nothing but automation tools.So with the help of vehicles to save time
and with the help of automation to save time.
Note : Vehicles = automation tools
>Convert the manual test cases into selenium automation test script < Next Write
the selenium automation test script into TestNg < here selenium code with the help
of TestNG can test the application.
Introduction to TestNg Framework
 Overview
 Install TestNg and Verify TestNg into Eclipse
 Create First TestNg Test Case
 Create Multiple Test Cases and Execute
I)Overview

>TestNG is a Testing unit Framework and it has been most popular with in short time
among test engineers.
>Testng inspired from junit(java platform) and Nunit(.Net platform).
>TestNG(latest version) has advance features compared to junit(old version)
>TestNG is a open source Testing Unit Framework,where NG stands for Next
Generation
>You can use any one either junit or testng but both are not required .
Requirements :
>TestNG requires JDK 1.7 or higher.
>Why we are using TestNG ?
Ans : By using TestNG,we can create the selenium automation test cases, execute
the selenium automation test cases and generate the test Reports and also generate
the log files.

Note :
1.Here Selenium IDE generate test reports but no detail(That means there is no
complete information in selenium ide report format)
2.Selenium RC OutDated(old version)
3.Here Selenium webDriver does not generate the test reports,here selenium
webDriver with the help of testng will generate the test Reports.
>Advantages of TestNG
1.TestNG Annotations are very easy to create test cases.
2.TestNG support prioritized testing and group testing.
3.Parallel test execution is possible.
How to Install TestNG step by step into Eclipse:
Way : 1
Follow the below steps to install TestNG in Eclipse IDE .
Step 1:
In Eclipse, on top menu bar, Under Help Menu, Click on "Install new Software" in
help window.

Step 2:
Enter the URL (https://dl.bintray.com/testng-team/testng-eclipse-release/) at Work
With field and click on "Add" button.

Step 3:
Once you click on "Add", it will display the screen, Enter the Name as "TestNG".

Step 4:
After clicking on "OK", it will scan and display the software available with the
URL which you have mentioned.
Now select the checkbox at TestNG and Click on "Next" button.

Step 5:
It will check for the requirement and dependencies before starting the
installation.
If there is any problem with the requirements/dependencies, it will ask you to
install them first before continuing with TestNG. Most of the cases it will
successfully get installed nothing to worry about it.

Step 6:
Once the above step is done, it will ask you to review the installation details. If
your are ready or Ok to install TestNG, click on "Next" to continue.
Step 7:
Accept the Terms of the license agreement and Click on "Finish" button.

Thats it... It will take few minutes to get installed.


Finally once the installation is done, you can if the TestNG is installed properly
or Not.
Go to Windows Menu bar, and Mouse Over on "Show View" and Click on "Other" at the
last as in the below screen shot.

Expand Java folder and see if the TestNg is available as in the below screen shot.

Way : 2
Install TestNg into Eclipse:

1. Open Eclipse  Click on Help Menu  Click on Eclipse Market Place


2. Goto Find  Type TestNG  Click on Go button

3. Click on TestNG for eclipse  Click on Install


4. Check TestNG and uncheck TestNG M2E integration.

5. Click on Next.
6. Accept the license Agreement  Click on Finish.

7. Goto the security window Click on OK


8. Click on Restart Now.

Note :
>By default Junit comes with eclipse but testng compulsory we need to install into
eclipse.
Important Annotations in TestNG
Annotation Description
@Test It represents a test case
@BeforeMethod Run before each test case in the current class.

@AfterMethod Run after each test case in the current class.


@BeforeClass Run before all the test case in the current class.

@AfterClass Run after all the test case in the current class.

@BeforeTest Run before all the test cases that belongs to classes
@AfterTest Run after all the test cases that belongs to classes
@parameters This is used to pass parameters to the test cases from a file called
TestNG.xml

Manual test cases :

>Who prepared the manual test cases in real-time ?


Ans: Junior Test Engineer, but sometimes you have to prepare the manual test cases
in small companies or big companies based on project and based on company.

Creating TestNG class(Selenium Automation Test Case)

>Step 1 : Create the TestNgPach package under the "src "source folder
Right click on "src "source folder<New<Package<Give the package name <then finish.
Figure : 1

Figure : 2

>Step 2 : Create TestNg_class under the TestNgPach package


Right click on TestNgPach package<TestNG<Create testNG class<Give the class
name<select @BeforeClass and @AfterClass annotations<Then finish.
Figure 1

Figure 2

Add TestNG library for that Project.


For adding TestNG library,
• Right click on your project-> Properties -> Java Build Path -> Libraries Tab.
• Click on Add Library button -> Select TestNG from Add Library popup and then
click on Next and Finish buttons.

It will add TestNg library in your project as shown in bellow image. Now click on
OK button to close that window.

TestSteps :
>Open the Firefox browser
>Navigate the application URL
>Get the title
>Print the title
>Verify the title
>close the browser
Selenium Program

package TestNGPackage;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class NewTest1 {

//instance variable

WebDriver driver;

@Test
public void VerifyLoginPage() {

//Enter the username

driver.findElement(By.name("txtUserName")).sendKeys("selenium");

// Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

//Click on Login

driver.findElement(By.name("Submit")).click();

//Identify welcome selenium text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

System.out.println(text);// Welcome selenium

//Verify Welcome Selenium

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified successfully");
}

//Click on Logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();
}

@BeforeClass
public void OpenBrowser() {

//Open the firefox browser

driver = new FirefoxDriver();//here driver is called object reference


variable

//Navigate the app URL

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

@AfterClass
public void CloseBrowser() {
driver.close();
}

>Can we access the instance variable into instance area directly ?


Ans : Yes, we can access
Executing the TestNG script :
Right click on selenium script < goto Run As < Click on TestsNG Test

>After executing the TestNg script then I want to see the TestNg results, How to
see the TestNG result?
Ans : First we need to refresh the project.After refreshed the project then we will
get a test-output folder.
Figure 1

Figure 2

Expand test-output folder < Find emailable-report.html < Right click on emailable-
report.html < goto Open With < Click on Web Browser < Then you will get TestNG HTML
Reports.
Figure 1

Figure 2
TestNG HTML Reports

>TestNG result is displayed into two windows:


1.Console Window : Refer the below screenshort for the result windows:

2.TestNG Result Window : Refer the below screenshort for the result windows:

>By default TestNg what type of reports it generates?


Ans : HTML Reports
Note :
>But HTML Reports are not effective to send the client, test lead or project
manager at
that time we need to follow Ant-XSLT Reports, here Ant-XSLT Reports are effective
to send the client, test lead or project manager. Here Ant-XSLT Reports mean
advanced HTML Reports.
Here,
1.First convert HTML Reports into Ant-XSLT Reports.
2.Next Email the Ant-XSLT Reports for your Test Lead.
>So we will discuss later How to convert HTML Reports into Ant-XSLT Reports and How
to email the Ant-XSLT Reports for your Test Lead.
Remember points :
>In java we need to create the main method but in TestNG no need to create the main
method but it contains something known as an annotation.
>What is an Annotation?
Ans: Annotation is a test method and start with @ sign and having simble (@)
Test,i.e @Test
@Test---It represents a selenium automation test case
>By default test case has created(@Test)while creating the TestNg class
>By default test case has created(@Test), here you can change the test case name
based on your requirement.
>In java execution stating point from the main method
>In TestNg execution stating point from @BeforeClass
>Here What is the difference between @BeforeClass and @AfterClass?
@BeforeClass :
>Run before all the test cases (@Test-Represents a Test Case) in the current
class/program
@AfterClass :
>Run after all the test cases (@Test-Represents a Test Case) in the current
class/program
@Test---It represents a Selenium Automation Test Case.
Example :
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
public class NewTest2 {
@Test
public void VerifyTitle()
{
System.out.println("VerifyTitle");
}
@BeforeClass
public void OpenBrowser() {
System.out.println("OpenBrowser");
}
@AfterClass
public void CloseBrowser() {
System.out.println("CloseBrowser");
}

}
>Suppose If you don't mention @Test annotation for that VerifyTitle method then JVM
will not execute the entire program.

>Suppose If you don't mention @BeforeClass annotation for that OpenBrowser method
then JVM will execute the entire program successfully except the OpenBrowser
method.

>Suppose If you don't mention @AfterClass annotation for that CloseBrowser method
then JVM will execute the entire program successfully except the CloseBrowser
method.

>Can we run multiple test cases in single class at a time ?


Ans : Yes ,we can run
Example
public class NewTest2 {
@Test
public void VerifyLoginPage()
{
System.out.println("VerifyLoginPage");
}
@Test
public void inbox()
{
System.out.println("Verify inbox module");
}
@Test
public void draft()
{
System.out.println("Verify draft module");
}
@Test
public void sentItems()
{
System.out.println("Verify sentItems module");
}
@BeforeClass
public void OpenBrowser() {
System.out.println("OpenBrowser");
}
@AfterClass
public void CloseBrowser() {
System.out.println("CloseBrowser");
}

>What is the default package of selenium?


Ans : org.openqa.selenium
>What is the default package of TestNg ? or What is the TestNg library file ?
Ans : org.testng.annotations
>In TestNG program, compulsory we need to import the testNG packages of that
corresponding annotations see below screenshorts.
Just mouse over on annotation then click on import option.

>We can create one more new class i.e NewTest2 under the same package.
>Here I want to run both NewTest1 and NewTest2 at a time,How to run both NewTest1
and NewTest2 at a time?
Ans : At that time we need to create testNG.xml file.From testNG.xml file you can
run
single test case or multiple test cases at a time.
>How to create testNG.xml file ? or How to create Test suite ?
Ans : Right click on package < TestNg < Convert to TestNg < Generate testng.xml
>Give the xml file name
>Give the Test Name
>Then click on finish
Figure 1

Figure 2

Now your testng.xml file will looks like below.


Note : TestSuite =Collection of test cases
In above testng.xml code,
Structure of testng.xml

>Here <Suite> tag can contains one or more tests


Syntax :

> <test> tag can contains one or more TestNg classes


Syntax :

>Here <class> tag can contains one or more test methods


Syntax :
<class name="Packagename.classname">
<methods>
<include name="testMethod"/>
<include name="testMethod"/>
<include name="testMethod"/>
<exclude name="testMethod"/>
</methods>
</class>
>Where we can create the xml file ?
Ans : Under Project or Under Package or Under the class
>When you have to create the xml file under the project ?
Ans : When you wants to run the multiple packages at a time then we need to create
the xml file under the project.
Navigation : Right click on project < goto TestNg < Convert to TestNg < Generate
testng.xml
>Give the xml file name
>Give the Test Name
>Then click on finish
>When you have to create the xml file under the package ?
Ans : Suppose if you want to run all the classes in a package then we need to
create xml file under the package
Navigation : Right click on package < TestNg < Convert to TestNg < Generate
testng.xml
>Give the xml file name
>Give the Test Name
>Then click on finish
>When you have to create the xml file under the class ?
Ans : Suppose i have 10 classes in a single package ,now here i want to run
particular
classes(for ex: 1st class and 5th class)
>How to run particular 1st class and 5th class ?
Ans : First we need to select both of the classes then create the xml file under
the selected classes
Navigation : Right click on selected classes < TestNg < Convert to TestNg <
Generate testng.xml
>Give the xml file name
>Give the Test Name
>Then click on finish
>Why we are using xml file ?
Ans : By using xml file we can run single test case or multiple test cases at a
time.
>How to run the xml file ?
Ans : Right click on xml file < Run As < Click on TestNG Suite option
>It will start execution of defined software test class
>Once execution is completed. Test case execution HTML report will looks like
below.

Working with Excel Files

Here,
1.First, we need to access the excel file into eclipse.
2.Next test on application.
3.Next, generate the test report
4.Next, see the result
>In java Project ,If u want to work with excel then We need to download and
configure poi.jar file for that project.
>In Maven Project ,If u want to work with excel then We need to set the poi
dependency for that project.
>Poi Jar: poi is a program interface for Microsoft Excel, Which allows the user
to read and write input data from excel sheets.
Here,
>Poi jar file support Xls file and Xlsx file

Here,
1.How to login with Xls File using poi jar file ?
2.How to login with Xlsx File using poi jar file ?
Follow below points :
1. First, download poi jar file and configure the jar file for that project.
Where we can download poi.jar file:
>Follow below URL :
https://poi.apache.org/
>Click on the download link in the left side
>Click on poi-bin-4.1.2-20200217.zip

>click on Download POI 4.1.2.jar Save jar file into drive.

Where we can download POI dependency file


Follow below URL
https://mvnrepository.com/
Enter POI into the search box and search it
Click on 4.1.2 Version link Save POI dependency into Maven poi.xml file
Figure 1

Figure 2

Figure 3

2.Next prepare the excel file

>If you want to work with xls file then we need to save the excel file in the 97-
2003 WorkBook format.
>If you want to work with xlsx file then we need to save the excel file directly.
Here no need to convert into the 97-2003 WorkBook format.
3.Next access the excel data into eclipse.
4.Next test on application
Manual Test Steps
>Open the firefox browser
>Navigate the app URL
>Before enter the username and password then we need to read the data from excel
sheet first
>How to read the data from excel sheet into Eclipse?
1.First we need to access the excel file into eclipse.
2.Get the workboook from excel
3.Get the sheet from workboook
4.Next read the data from sheet
>Enter the Username
>Enter the Password
>Click on Login
>Verify Welcome page
>Click on Logout
>Close the firefox browser.
Selenium Program
1.How to login with xls File using poi jar file ?
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class Login_With_xlsFile {

//Instance variable or global variable

WebDriver driver;

@Test
public void loginTest() throws IOException, InterruptedException {
//First we need to access the excel file into eclipse.

FileInputStream fis = new FileInputStream("F:\\Selenium


Software Dump Files\\SeleniumMaterial\\Login_With_xlsFile.xls");

//Get the workboook from excel(HSSF mean Horrible Spreadsheet


Format)

HSSFWorkbook workbook = new HSSFWorkbook(fis);

//Get the sheet from Workbook

HSSFSheet sheet = workbook.getSheetAt(0);

//read the data from sheet

//Read the username from excel sheet and store into username variable

String username=sheet.getRow(1).getCell(0).getStringCellValue();

//Read the password from excel sheet and store into password variable

String password=sheet.getRow(1).getCell(1).getStringCellValue();

//Enter the username


driver.findElement(By.name("txtUserName")).sendKeys(username);

//Enter the password

driver.findElement(By.name("txtPassword")).sendKeys(password);

//Click on Login

driver.findElement(By.name("Submit")).click();

//wait 3sec

Thread.sleep(3000);

//Identify Welcome Selenium text and get the text and store into
displaysuccess variable

String
text=driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

//print Welcome selenium

System.out.println(text);

// verify welcome page( Welcome Selenium text)

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified
successfully");
}

//click on logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

}
@BeforeClass
public void OpenBowser() {

//Open the firefox browser

driver=new FirefoxDriver();//here driver is a object reference variable

//Navigate the app URL

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

@AfterClass
public void CloseBrowser() {
//Close the firefox browser.
driver.close();
}
}
2.How to login with xlsx File using poi jar file ?
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class Login_With_xlsxFile {

//Instance variable or global variable

WebDriver driver;

@Test
public void loginTest() throws IOException, InterruptedException {
//First we need to access the excel file into eclipse.

FileInputStream fis = new FileInputStream("F:\\Selenium Software Dump


Files\\SeleniumMaterial\\Login_With_xlsxFile.xlsx");

//Get the workboook from excel(XSSF mean XML Spreadsheet Format)

XSSFWorkbook workbook = new XSSFWorkbook(fis);

//Get the sheet from Workbook

XSSFSheet sheet = workbook.getSheet("Result");

//read the data from sheet

//Read the username from excel sheet and store into username variable

String username=sheet.getRow(1).getCell(0).getStringCellValue();

//Read the password from excel sheet and store into password variable

String password=sheet.getRow(1).getCell(1).getStringCellValue();

//Enter the username

driver.findElement(By.name("txtUserName")).sendKeys(username);

//Enter the password

driver.findElement(By.name("txtPassword")).sendKeys(password);

//Click on Login

driver.findElement(By.name("Submit")).click();

//wait 3sec
Thread.sleep(3000);

//Identify Welcome Selenium text and get the text and store into
displaysuccess variable

String
text=driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

//print Welcome selenium

System.out.println(text);

// verify welcome page( Welcome Selenium text)

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified
successfully");
}

//click on logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

}
@BeforeClass
public void OpenBowser() {

//Open the firefox browser

driver=new FirefoxDriver();//here driver is a object reference variable

//Navigate the app URL

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

@AfterClass
public void CloseBrowser() {
//Close the firefox browser.
driver.close();
}

Excel Operations :
>FileInputStream : This is an inbuilt class in Apache-POI,by using this we can
access the excel file into eclipse.
HSSFWorkbook:- This is an inbuilt class in apache-POI, by using this we can access
the complete workbook in an excel file.
HSSFSheet:- This is an inbuilt class in apache-POI, by using this we can access
only one sheet in a workbook
XSSFWorkbook:- This is an inbuilt class in apache-POI, by using this we can access
the complete workbook in an excel file.
XSSFSheet:- This is an inbuilt class in apache-POI, by using this we can access
only one sheet in a workbook
ROW:- This is an interface in the apache-POI, by using this we can access only one
Row in an sheet.
Cell:- This is an interface in apache-POI, by using this we can access only one
cell in a Row.

Important methods In Apache-POI


getLastRowNum(): This will be used to capture the Last Row Num in the excel file.
getCellNum(): This will be used to capture the Last Cell Num in the Row.
getSheet(): This will be used to capture the specific sheet name in the excel
workbook.
createSheet():- This will be used to create an additional sheet in the excel
workbook.
getRow():- This will be used to capture one complete Row in the excel workbook.
createRow():- This will be used to create a new row in the sheet.
getCell():- This will be used to capture only one cell in a Row.
createCell():- This will used to create a new cell in an existing Row.
getStringCellValue():- This will be used to capture string data present in a cell.
getNumericCellValue():- This will be used to capture numeric data present in a
cell.
setCellValue():- This will be used to write the data into the cell.
write():- This will be used to save the excel file.
How to Verify Dropdown Values Using _xlsFile?

Dropdown Excel
1.Get the dropdown size

1.First,Identify dropdown
2.Next,Identify all the values from this dropdown 1.Get the Excel size(That
means count total rows from excel).
>How to count total rows from excel.
1.First,We need to access the Excel file into eclipse.
2. Get the workbook from Excel.
3. Get the sheet from Workbook.
4.Count total rows from excel sheet.

2.Create Arraylist object for that dropdown.


Arraylist<String> ddvalues=new Arraylist<String> (); 2.Create Arraylist object for
that Excel.
Arraylist<String> xlvalues=new Arraylist<String> ();
3.Store dropdown values in an ddvalues variable.See below

4.Compare dropdown size and Excel size 3.Store Excel values in an xlvalues
variable .See below

5. Compare dropdown values with Excel values one by one

Example :1

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class VerifyDropdownValues_usingXlsFile {

WebDriver driver;// instance variable

@Test
public void verifyDropdownValues() throws InterruptedException, IOException
{

// Navigate the Application Url

driver.get("http://www.tizag.com/htmlT/htmlselect.php");

// wait 3sec

Thread.sleep(3000);

// Identify dropdown

WebElement dropdown = driver.findElement(By.name("selectionField"));

// Identify dropdown values and store into dropdownCount variable

List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));

// Print dropdown size.

System.out.println("Dropdown size : " + dropdownCount.size());//3

/*
* FileInputStream – A FileInputStream is an inputstream for reading
* data from a Excel File.
*
* FileOutputStream – A FileOutputStream is an outputstream for writing
* data into a Excel File.
*/

// Now access the Excel file into eclipse

FileInputStream fis = new FileInputStream(


"F:\\Selenium Software Dump Files\\SeleniumMaterial\\
Login_With_xlsFile.xls");

// Get the workbook from Excel

HSSFWorkbook workbook = new HSSFWorkbook(fis);

// Get the sheet from Workbook

HSSFSheet sheet = workbook.getSheetAt(1);


// Get total rows from excel sheet

int total_Rows = sheet.getLastRowNum() + 1;

System.out.println("Excel size : " + total_Rows);//3

// Create ArrayList object for that excel values

ArrayList<String> xlvalues = new ArrayList<String>();

/*
*
* As you know,some times we need to perform same action with multiple
* times at that time we need to follow - forloop
*
*/

// Using for loop, we can iterate till the i value is true

for (int i = 0; i < total_Rows; i++) {

// Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}

// Create ArrayList object for that excel values

ArrayList<String> ddvalues = new ArrayList<String>();

// Using for loop, we can iterate till the j value is true

for (int j = 0; j < dropdownCount.size(); j++) {

ddvalues.add(dropdownCount.get(j).getText());
}

// Check for the required elements by Text and display matched elements
// and unmatched elements

if (total_Rows == dropdownCount.size()) {

for (int k = 0; k < total_Rows; k++)// here we have to give excel


size
{
if (xlvalues.get(k).equals(ddvalues.get(k))) {
System.out.println("Excel Data is Matching with
Application Data");
} else {
System.out.println("Excel Data is not Matching with
Application Data");
}

} else {
System.out.println("Size Not matched");
}

@BeforeClass
public void OpenBrowser() {

// Launch Firefox browser

driver = new FirefoxDriver();

@AfterClass
public void CloseBrowser() {
// close the browser

driver.close();
}

How to Verify Dropdown Values Using _xlsxFile ?

Example :2

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class VerifyDropdownValues_usingXlsFile {

WebDriver driver;// instance variable

@Test
public void verifyDropdownValues() throws InterruptedException, IOException
{

// Navigate the Application Url

driver.get("http://www.tizag.com/htmlT/htmlselect.php");

// wait 3sec

Thread.sleep(3000);
// Identify dropdown

WebElement dropdown = driver.findElement(By.name("selectionField"));

// Identify dropdown values and store into dropdownCount variable

List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));

// Print dropdown size.

System.out.println("Dropdown size : " + dropdownCount.size());//3

/*
* FileInputStream – A FileInputStream is an inputstream for reading
* data from a Excel File.
*
* FileOutputStream – A FileOutputStream is an outputstream for writing
* data into a Excel File.
*/

// Now access the Excel file into eclipse

FileInputStream fis = new FileInputStream(


"F:\\Selenium Software Dump Files\\SeleniumMaterial\\
Login_With_xlsxFile.xlsx");

// Get the workbook from Excel

XSSFWorkbook workbook = new XSSFWorkbook(fis);

// Get the sheet from Workbook

XSSFSheet sheet = workbook.getSheetAt(1);

// Get total rows from excel sheet

int total_Rows = sheet.getLastRowNum() + 1;

System.out.println("Excel size : " + total_Rows);//3

// Create ArrayList object for that excel values

ArrayList<String> xlvalues = new ArrayList<String>();

/*
*
* As you know,some times we need to perform same action with multiple
* times at that time we need to follow - forloop
*
*/

// Using for loop, we can iterate till the i value is true

for (int i = 0; i < total_Rows; i++) {

// Read the data from excel sheet


xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}

// Create ArrayList object for that excel values

ArrayList<String> ddvalues = new ArrayList<String>();

// Using for loop, we can iterate till the j value is true

for (int j = 0; j < dropdownCount.size(); j++) {

ddvalues.add(dropdownCount.get(j).getText());
}

// Check for the required elements by Text and display matched elements
// and unmatched elements

if (total_Rows == dropdownCount.size()) {

for (int k = 0; k < total_Rows; k++)// here we have to give excel


size
{
if (xlvalues.get(k).equals(ddvalues.get(k))) {
System.out.println("Excel Data is Matching with
Application Data");
} else {
System.out.println("Excel Data is not Matching with
Application Data");
}

} else {
System.out.println("Size Not matched");

@BeforeClass
public void OpenBrowser() {

// Launch Firefox browser

driver = new FirefoxDriver();

@AfterClass
public void CloseBrowser() {
// close the browser

driver.close();
}

}
>What is the difference betweeen == an equals() in java ?
Ans :

>Here == is a operator ,by using this we can compare the references


>Here equals() is a method,by using this we can compare the content or String

Example :

String s1=new String("Kosmik");//s1 is called object reference varible


String s2=new String("Kosmik");//s2 is called object reference varible

System.out.println(s1==s2);//false
System.out.println(s1.equals(s2));//true

Figure :

How to Verify Random Dropdown Values


How to Verify Random Dropdown Values Using _xlsxFile?

Dropdown Excel
1.Get the dropdown size

1.First,Identify dropdown
2.Next,Identify all the values from this dropdown 1.Get the Excel size(That
means count total rows from excel).
>How to count total rows from excel.
1.First,We need to access the Excel file into eclipse.
2. Get the workbook from Excel.
3. Get the sheet from Workbook.
4.Count total rows from excel sheet.

2.Create Arraylist object for that dropdown.


Arraylist<String> ddvalues=new Arraylist<String> (); 2.Create Arraylist object for
that Excel.
Arraylist<String> xlvalues=new Arraylist<String> ();
3.Store dropdown values in an ddvalues variable.See below

4.Compare dropdown size and Excel size 3.Store Excel values in an xlvalues
variable .See below

5. Compare dropdown values with Excel values one by one

Example
package SeleniumTests;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class VerifyRandowDropdownValues {

WebDriver driver;// instance variable

@Test
public void verifyDropdownValues() throws InterruptedException, IOException {

// Navigate the Application Url

driver.get("http://www.tizag.com/htmlT/htmlselect.php");

// wait 3sec

Thread.sleep(3000);

// Identify dropdown

WebElement dropdown = driver.findElement(By.name("selectionField"));

// Identify dropdown values and store into dropdownCount variable

List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));

// Print dropdown size.

System.out.println("Dropdown size : " + dropdownCount.size());// 3

/*
* FileInputStream – A FileInputStream is an inputstream for reading
* data from a Excel File.
*
* FileOutputStream – A FileOutputStream is an outputstream for writing
* data into a Excel File.
*/

// Now access the Excel file into eclipse

FileInputStream fis = new FileInputStream(


"F:\\Selenium Software Dump Files\\SeleniumMaterial\\
Login_With_xlsxFile.xlsx");

// Get the workbook from Excel

XSSFWorkbook workbook = new XSSFWorkbook(fis);

// Get the sheet from Workbook

XSSFSheet sheet = workbook.getSheetAt(2);

// Get total rows from excel sheet

int total_Rows = sheet.getLastRowNum() + 1;

System.out.println("Excel size : " + total_Rows);// 3

// Create ArrayList object for that excel values


ArrayList<String> xlvalues = new ArrayList<String>();

/*
*
* As you know,some times we need to perform same action with multiple
* times at that time we need to follow - forloop
*
*/

// Using for loop, we can iterate till the i value is true

for (int i = 0; i < total_Rows; i++) {

// Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}

// Create ArrayList object for that excel values

ArrayList<String> ddvalues = new ArrayList<String>();

// Using for loop, we can iterate till the j value is true

for (int j = 0; j < dropdownCount.size(); j++) {

ddvalues.add(dropdownCount.get(j).getText());
}

// Check for the required elements by Text and display matched elements

if (total_Rows == dropdownCount.size()) {

// To Read the excel values

for (int k = 0; k < total_Rows; k++)// here we have to give excel


// size
{

// To Read the dropdown values


for (int l = 0; l < dropdownCount.size(); l++)// here we
have to

// give dropdown

// size
{

if (xlvalues.get(k).equals(ddvalues.get(l))) {

System.out.println(xlvalues.get(k) + " is
Matching with " + ddvalues.get(l));

break;
}

} else {
System.out.println("Size Not matched");

@BeforeClass
public void OpenBrowser() {

// Launch Firefox browser

driver = new FirefoxDriver();

@AfterClass
public void CloseBrowser() {
// close the browser

driver.close();
}

}
How to Verify AutoSearch Results_xlsFile ?

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class HowtoVerifyAutoSearchResults_xlsFile {

WebDriver driver;

@BeforeClass
public void setUp() {
// Launch Firefox browser

driver = new FirefoxDriver();


// Maximize the browser window

driver.manage().window().maximize();
}

@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {

// Navigate the Application Url

driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");

//Enter i into textbox field

driver.findElement(By.id("myInput")).sendKeys("i");

//Identify AutoSuggets and store into AutoSuggets variable

List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));

//Print Size of the AutoSuggets

System.out.println("Size of the AutoSuggets is : " +


AutoSuggets.size());

//create ArrayList object for that AutoSuggets

ArrayList AutoSugget_values = new ArrayList();

System.out.println("************Application_AutoSearchResult*******");

/*

As you know,some times we need to perform same action with multiple times
at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for (int i = 1; i <= AutoSuggets.size(); i++) {

//Identify AutoSugget and get the text and store into value
variable

String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();

//print the AutoSugget

System.out.println(value);

//Store AutoSugget value into AutoSugget_values variable


AutoSugget_values.add(value);
}

//Now access the Excel file

FileInputStream fis = new FileInputStream("E:\\SeleniumSoftware dump\\


AutoSuggest_xlsFile.xls");

//Get the workbook from Excel

HSSFWorkbook workbook=new HSSFWorkbook(fis);

//Get the sheet from Workbook

HSSFSheet sheet=workbook.getSheet("Sheet5");

//Get total rows from excel sheet

int total_Rows=sheet.getLastRowNum()+1;

System.out.println("Total excel rows are : "+total_Rows);

//create ArrayList object for that Excel values

ArrayList xlvalues=new ArrayList();

/*

As you know,some times we need to perform same action with multiple


times at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for(int i=0;i<total_Rows;i++)
{

//Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());

//Check for the required elements by Text and display matched elements
and unmatched elements

if(total_Rows!=AutoSuggets.size())
{
System.out.println("Size Not matched");
}
else{
for(int k=0;k<total_Rows;k++)
{
if(xlvalues.get(k).equals(AutoSugget_values.get(k)))
{
System.out.println("Excel Data is Matching with
Application Data");
}
else
{
System.out.println("Excel Data is not Matching with
Application Data");
}

}
}

@AfterClass
public void closeBrowser()
{
//close the browser

driver.quit();
}
}

How to Verify AutoSearch Results_xlsxFile ?


package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class HowtoVerifyAutoSearchResults_xlsxFile {

WebDriver driver;

@BeforeClass
public void setUp() {
// Launch Firefox browser

driver = new FirefoxDriver();

// Maximize the browser window

driver.manage().window().maximize();
}
@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {

// Navigate the Application Url

driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");

//Enter i into textbox field

driver.findElement(By.id("myInput")).sendKeys("i");

//Identify AutoSuggets and store into AutoSuggets variable

List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));

//Print Size of the AutoSuggets

System.out.println("Size of the AutoSuggets is : " +


AutoSuggets.size());

//create ArrayList object for that AutoSuggets

ArrayList AutoSugget_values = new ArrayList();

System.out.println("************Application_AutoSearchResult*******");

/*

As you know,some times we need to perform same action with multiple times
at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for (int i = 1; i <= AutoSuggets.size(); i++) {

//Identify AutoSugget and get the text and store into value
variable

String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();

//print the AutoSugget

System.out.println(value);

//Store AutoSugget value into AutoSugget_values variable

AutoSugget_values.add(value);
}

//Now access the Excel file


FileInputStream fis = new FileInputStream("E:\\SeleniumSoftware dump\\
AutoSuggest_xlsxFile.xlsx");

//Get the workbook from Excel

XSSFWorkbook workbook=new XSSFWorkbook(fis);

//Get the sheet from Workbook

XSSFSheet sheet=workbook.getSheet("Sheet1");

//Get total rows from excel sheet

int total_Rows=sheet.getLastRowNum()+1;

System.out.println("Total excel rows are : "+total_Rows);

//create ArrayList object for that Excel values

ArrayList xlvalues=new ArrayList();

/*

As you know,some times we need to perform same action with multiple


times at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for(int i=0;i<total_Rows;i++)
{

//Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());

//Check for the required elements by Text and display matched elements
and unmatched elements

if(total_Rows!=AutoSuggets.size())
{
System.out.println("Size Not matched");
}
else{
for(int k=0;k<total_Rows;k++)
{
if(xlvalues.get(k).equals(AutoSugget_values.get(k)))
{
System.out.println("Excel Data is Matching with
Application Data");
}
else
{
System.out.println("Excel Data is not Matching with
Application Data");
}

}
}

@AfterClass
public void closeBrowser()
{
//close the browser

driver.quit();
}
}

How to Verify Webtable data Using _xlsFile?

WebTable Excel
1.Get the Webtable size

1.First,Get the total rows from webtable


a)First,Identify all the rows from webtable.
b)Then after get the total rows from webtable
2.Next, Get the total columns from webtable
a)First,Identify all the columns from webtable.
b)Then after get the total columns from webtable
1.Get the Excel size(That means count total rows from excel).
>How to count total rows from excel.
1.First,We need to access the Excel file into eclipse.
2. Get the workbook from Excel.
3. Get the sheet from Workbook.
4.Count total rows from excel sheet.

2.Create Arraylist object for that 1st column of the Webtable.


Arraylist<String> Wvalues=new Arraylist<String> (); 2.Create Arraylist object for
that Excel.
Arraylist<String> xlvalues=new Arraylist<String> ();
3.Store Webtable values in an Wvalues variable.See below

4.Compare Webtable size and Excel size 3.Store Excel values in an xlvalues
variable .See below

5. Compare Webtable values with Excel values one by one

Example

package SeleniumTests;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class VerifyWebtableData {

WebDriver driver;

@BeforeClass
public void openWebSite() {

// open the browser


driver = new FirefoxDriver();

// navigate the application url


driver.get("file:///F:/Selenium%20Software%20Dump%20Files/Browser
%20Elements/webtable.html");

@Test
public void CountRowsTest() throws IOException {

// To calculate the number of rows in a table


int allRows =
driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);

// To calculate the number of columns


int allCols =
driver.findElements(By.xpath("html/body/table/tbody/tr[1]/td")).size();

// Get Total columns in a Table


System.out.println("Total columns in a Table -- " + allCols);

// If you want to read the excel file then we use FileInputStream


object
FileInputStream fis = new FileInputStream("F:\\Selenium Software Dump
Files\\SeleniumMaterial\\Login_With_xlsxFile.xlsx");

// Get the Workbook from excel file


XSSFWorkbook w = new XSSFWorkbook(fis);

// Get the Sheet from Workbook


XSSFSheet sheet = w.getSheet("Sheet1");

// count the total rows from excel sheet


int total_rows = sheet.getLastRowNum() + 1;

System.out.println("Total rows from excel sheet :" + total_rows);

// create the ArrayList object for that Webtable


ArrayList Wvalues = new ArrayList();

System.out.println();

for (int m = 1; m <= allRows; m++) {

int n = 1;

String data =
driver.findElement(By.xpath("html/body/table/tbody/tr[" + m + "]/td[" + n +
"]")).getText();

System.out.println(data);
Wvalues.add(data);

// create the ArrayList object for that excel


ArrayList xlvalues = new ArrayList();

for (int i = 0; i < total_rows; i++) {

// read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}

System.out.println(" **************Compare WebTable data with Excel


data***************** " + "\n");

// Using for loop, we can iterate till the k value is true


for (int k = 0; k < total_rows; k++) {

if (xlvalues.get(k).equals(Wvalues.get(k))) {
System.out.println(Wvalues.get(k) + " is Matching with
" + xlvalues.get(k));
} else {
System.out.println(Wvalues.get(k) + " is not Matching
with " + xlvalues.get(k));
}

@AfterClass
public void tearDown() {
// close the browser
driver.quit();
}
}
How to Verify multiple rows and columns of the Webtable data Using _xlsFile?

WebTable Excel
1.Get the Webtable size

1.First,Get the total rows from webtable


a)First,Identify all the rows from webtable.
b)Then after get the total rows from webtable
2.Next, Get the total columns from webtable
a)First,Identify all the columns from webtable.
b)Then after get the total columns from webtable
1.Get the Excel size(That means count total rows and columns from
excel).
>How to count total rows from excel.
1.First,We need to access the Excel file into eclipse.
2. Get the workbook from Excel.
3. Get the sheet from Workbook.
4.Count total rows from excel sheet.
>Count total columns from excel.

2.Create Arraylist object for that multiple rows and columns of the Webtable.
Arraylist<String> Wvalues=new Arraylist<String> (); 2.Create Arraylist object for
that multiple rows and columns of the Excel.
Arraylist<String> xlvalues=new Arraylist<String> ();
3.Store multiple rows and columns of the Webtable values in an Wvalues
variable.See below

3.Store multiple rows and columns of the Excel values in an xlvalues


variable .See below

4. Compare Webtable values with Excel values one by one

Example

package SeleniumTests;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class VerifyMultipleWebtableData {

WebDriver driver;

@BeforeClass
public void openWebSite() {

// open the browser


driver = new FirefoxDriver();

// navigate the application url


driver.get("file:///F:/Selenium%20Software%20Dump%20Files/Browser
%20Elements/webtable.html");

@Test
public void CountRowsTest() throws IOException {

// To calculate the number of rows in a table


int allRows =
driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);// 6

// To calculate the number of columns


int allCols =
driver.findElements(By.xpath("html/body/table/tbody/tr[1]/td")).size();

// Get Total columns in a Table


System.out.println("Total columns in a Table -- " + allCols);// 3

// If you want to read the excel file then we use FileInputStream


object
FileInputStream fis = new FileInputStream(
"F:\\Selenium Software Dump Files\\SeleniumMaterial\\
Login_With_xlsxFile.xlsx");

// Get the Workbook from excel file


XSSFWorkbook w = new XSSFWorkbook(fis);

// Get the Sheet from Workbook


XSSFSheet sheet = w.getSheet("Sheet6");

// count the total rows from excel sheet

int total_rows = sheet.getLastRowNum() + 1;

System.out.println("Total rows from excel sheet :" + total_rows);// 6

int total_columns = sheet.getRow(0).getLastCellNum();

System.out.println("Total rows from excel sheet :" + total_columns);

ArrayList xlvalues = new ArrayList();

System.out.println();
System.out.println("**************Excel data*****************\n");

// Using for loop, we can iterate till the i value is true


for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {

// Using for loop, we can iterate till the j value is true


for (int j = 0; j < sheet.getRow(0).getLastCellNum(); j++) {

// print the excel data

System.out.print(sheet.getRow(i).getCell(j).getStringCellValue() + " ");

// read the data from excel sheet and store excel values in
an
// xlvalues ref_variable through add function

xlvalues.add(sheet.getRow(i).getCell(j).getStringCellValue());

}
System.out.println();
}

// create the ArrayList object for that Webtable


ArrayList Wvalues = new ArrayList();

System.out.println();
System.out.println("**************WebTable data*****************\n");

// Using for loop, we can iterate till the m value is true


for (int m = 1; m <= total_rows; m++) {
// Using for loop, we can iterate till the n value is true
for (int n = 1; n <= total_columns; n++) {
String data =
driver.findElement(By.xpath("html/body/table/tbody/tr[" + m + "]/td[" + n + "]"))
.getText();

// print the WebTable data


System.out.print(data + " ");

// store webtable values in an Wvalues ref_variable through


add
// function
Wvalues.add(data);

}
System.out.println();
}

System.out.println();

int total_rows_columns = total_rows * total_columns;

System.out.println(" **************Compare WebTable data with Excel


data***************** " + "\n");
// Using for loop, we can iterate till the k value is true
for (int k = 0; k < total_rows_columns; k++) {

if (Wvalues.get(k).equals(xlvalues.get(k))) {
System.out.println(Wvalues.get(k) + " is Matching with
" + xlvalues.get(k) );
} else {
System.out.println(Wvalues.get(k) + " is not Matching
with " + xlvalues.get(k) );
}

@AfterClass
public void tearDown() {
// close the browser
driver.quit();
}
}

Maven :

>Maven is a project build tool formally known as build tool.

>It provides the concept of a project object model (pom) file to manage project
build, dependency .

>Maven has its own repository where it keeps all plugins, jars etc..

>We can create maven project for writing scripts and create dependency using
pom.xml. once dependency set maven will download all the dependent jar files
automatically.

Part 1 :

1. Install maven into eclipse


2. Verify maven successfully install or not on ur eclipse

Part 2 :

Create Maven Project :

3. Go to Eclipse and click on JavaEE


4. File -> New -> Other->Maven->Select Maven Project
5. Check the check box Create a Simple Project
6. Give Group Id and Artifact
7. Click on Finish

>So let us create some sample selenium scripts with maven project.

GroupId
• domainName
ArtifactId
• project name as artifactId
Version
• 0.0.1

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>Banking</groupId>
<artifactId>com.Banking.OpenCart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>com.Banking.OpenCart</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<!-- Compiler plug-in -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>

</plugin>

<!-- Below plug-in is used to execute tests -->


<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>

<suiteXmlFiles>
<!-- TestNG suite XML files -->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>

</configuration>

</plugin>

</plugins>

</build>

</project>

Apache-MAVEN
What Is Maven?
Apache Maven Is a project build management tool.
Maven can help you to minimize your project build management time and
efforts.
Why Do We Use Maven In Selenium?
It makes the project build process easy.
It provides quality project document Information.
Managing project dependencies.
It downloads required dependency's jar files automatically from Maven central
repositories.
How To Download And Install Maven In Eclipse Step By Step

Installing Maven In Eclipse

Step 1 : Open eclipse IDE and go to Help -> Install New Software menu as shown In
bellow Image. It will open new software Installation window.

Step 2 : Add bellow given URL In Work with text field of eclipse and press keyboard
ENTER button. It will search for maven software to Install.

URL = http://download.eclipse.org/technology/m2e/releases

Step 3 : On search completion, It will show "Maven Integration For Eclipse" check
box as shown In bellow Image.

Select that check box and click on Next button as shown In above Image. It will
start processing as bellow. It can take 1 to 2 minutes.

Step 4 : When above process completed, Install Remediation page will display as
bellow. Click on Next On that screen.
Step 5 : Next screen will be Install Detail. Click on Next on It.

Step 6 : Next screen will be Review licenses. Select "I accept the terms of the
licenses agreement." radio button and click on Finish.

It will start Installing maven In eclipse as bellow and It can take 5 to 20 minutes
to complete Installation. You can run It In background too.

Step 7 : At the end of maven Installation, It will show you message to restart
eclipse. Click on Yes button as shown bellow. It will restart your eclipse.

How to confirm Maven Is Installed In your eclipse


>To confirm that maven Is Installed properly or not In your eclipse, You need to
open eclipse preferences window from menu Item -> Window -> preferences as bellow.
It will show you Maven In tree as bellow on preferences window. It means maven Is
Installed

You are done with maven Installation


Create New Maven Project In Eclipse For Selenium WebDriver + TestNG
Before creating maven project In eclipse IDE for selenium webdriver, You must
be aware about maven and It should be Installed properly In your eclipse IDE.
Earlier we learnt about what Is maven and how to download and Install maven So If
maven Is Installed In eclipse then you are ready to create new maven project as
described In bellow given steps.

Steps to create new maven project


Step 1 : First of all, Open eclipse IDE and go for creating new project from New ->
Other as shown In bellow Image.

It will open new project creation window.


Step 2 : Expand Maven folder In new project creation wizard window and select Maven
Project and then click on Next button as shown In bellow Image.

It will take you to project name and location selection screen.

Step 3 : On project name and location selection screen, You can choose work space
location for maven project by clicking on browse button. If wants to use default
work space location then select that check box and click on Next button as bellow.

It will take you to Archetype selection screen.

Steps 4 : On Archetype selection screen, Select Maven-archetype-quickstart option


as bellow and click on Next button.
Step 5 : On next screen, Enter Group Id = Banking, Artifact Id =
com.Banking.OpenCart and Package = Banking. com.Banking.OpenCart as shown In bellow
Image. Then click on Finish button.

It will create new maven project In eclipse as bellow.

Now your maven project Is created. You can see there Is pom.xml file under your
project as shown above.

Step 6 : Now you need to add selenium webdriver and TestNG dependencies with latest
version In pom.xml file. Open pom.xml file and copy-paste bellow given code In It
and then save It.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>Banking</groupId>
<artifactId>com.Banking.OpenCart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>com.Banking.OpenCart</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>

</dependencies>
<build>
<plugins>
<!-- Compiler plug-in -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>

</plugin>

<!-- Below plug-in is used to execute tests -->


<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>

<configuration>

<suiteXmlFiles>
<!-- TestNG suite XML files -->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>

</configuration>

</plugin>

</plugins>

</build>

</project>

Current latest version of selenium webdriver Is 3.141.59 TestNG latest version Is


6.8.8. You can change It If version updated version release In future.

Step 7 : Delete existing AppTest.java file from src/test/java folder package and
create new class file under same package with name = WebDriverTest.java as bellow.

Now copy-paste bellow given code In that WebDriverTest.java file and save It.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class WebDriverTest {

WebDriver driver;
//@BeforeClass - Run before Executing all test cases in the current
class/program
@BeforeClass
public void openbrowser() {
driver = new FirefoxDriver();

driver.manage().window().maximize();
driver.get("https://www.google.co.in/?");
}

//@AfterClass- Run After Executing all test cases in the current


class/program
@AfterClass
public void closebrowser() {
System.out.print("\nBrowser close");
driver.quit();
}

@Test
public void verifyTitle() {
String title = driver.getTitle();
System.out.print("Current page title is : "+title);
Assert.asserEquals(title,"Google");
}
}
Above file will show you errors as we do not have Included selenium and
testng jar files In project's build path. Here maven will do It automatically for
us.
When you save It, It will start building work space by downloading required
jar files from maven central repository and store In local repository based on your
selenium webdriver and TestNG versions as bellow. It can take 5 to 20 minutes based
on your Internet speed.

Running webdriver project from pom.xml file


When above process get completed, You can run your project from pom.xml file.
To run It, Right click on pom.xml file and select Run As -> Maven test as shown In
bellow Image.

It will start executing webdriver test WebDriverTest.java file. This Is the


way to create and run webdriver test In eclipse using maven and testng

1.What is a Framework
Framework is a s/w which contains some set of programs .By using these
programs we can do our work very easily.
2.Why Data Driven Framework
Usually, we place all our test data in excel sheets which we use in our test
runs. Assume, we need to run a test script (Say, login test) with multiple test
data. If we run the same test with multiple test data sets manually is time-
consuming, and error-prone. In the next section, we see a practical example.
In simple words, we adopt Data Driven Framework when we have to execute the same
script with multiple sets of test data.

3.Advantages of Data Driven Test Framework


1. Reduce the development time
2. Code reusability
3. Well organized code
4. Test data management
5. Easy of reporting
.
4. Where we can use data driven framework
By using this u can control all ur data by external files like xls,xlsx
Suppose we need to test the login/Register/ Any form with multiple input
fields with 100 different data sets.

Means that :

Case 1 : Suppose if u want to test the login with multiple input fields with 100
different data sets then we need to use data driven framework.
Case 2 : Suppose if u want to test the Register with multiple input fields with
100 different data sets then we need to use data driven framework.

Case 3 : Suppose if u want to test the Any form with multiple input fields with
100 different data sets then we need to use data driven framework.
5.How to work on Data Driven Framework in Selenium Using poi?
Selenium automates browsers.
And It’s a popular tool to automate web-based applications.
If u want to read and write the data from excel using Selenium then we use
poi.
Assume, you need to test the login form with 50 different sets of test data

As a manual tester, you do log in with all the 50 different sets of test data
50 times
As an automation tester, you create a test script and run it 50 times by
changing the test data on each run or you create 50 test scripts to execute the
scenario
Note: Data-Driven testing helps here and saves a lot of time for us.
6.How To Create Data Driven Framework in Selenium Using poi
Here I will take OpenCart Application to showcase the implementation of Data
Driven Framework in Selenium with Java using poi
1.Scenario:
Open OpenCart and do login and logout.
Suppose you are working with LogIn functionality with 100 different usernames
and passwords to check which username and password Are valid and which username and
password Are Invalid or wrong. So in this kind of situation, we are going to use a
data-driven Framework.
Follow below steps to Implement Data Driven framework.
First, we see how to read test data from excel sheet and then we see how to write
the result in the excel sheet.
7.Prerequisites to implement Data Driven Framework:
1. Eclipse IDE
2. TestNG
3. Selenium jars
4. poi dependency
5. Microsoft Excel
The structure of my project (Data Driven Project with Maven) is as follows:

 The main intention of creating separate packages for different file types Is
It will be very easy for us to find and manage any file.
 Supposing if you want to change something In the .xls file then directly you
can go to the " com.Banking.testData " package folder and update the file.
8.Create Bellow Given Packages Under the Project
1.src/main/java
>In this source folder, I will be keeping all the reusable components
2. src/test/java
>In this source folder, I will be keeping all the selenium automation test
cases
3.src/main/resources
> In this source folder, I will be keeping all the XML files
4.com. Banking.propertyFiles :-
>In this package I will be keeping all the property files like
1.config.properties
2.OR.properties
5. com.Banking.testData :-
>In this package i will be keeping all the client requirement .xls files.
6.Driver folder:
In this folder i will be keeping all the browser drivers
7.Screenshots:
In this folder i will be keeping all the screenshots
config.properties
In this file, I will be keeping all the configuration parameters like
1.TestSiteUrl
2.Browser name
3.Screenshotpath
Follow below steps
Here property file case sensitive and here doesn’t require space after
parameter.
In java, if you want to give the comment for a single line then we need to
give a double slash(//).
In the Property file, if you want to give the comment for a single line then
we need to give hash(#).

Here Property file is case sensitive, In property file suppose you have a
capital letter (S is a capital letter) ScreenshotPath = “Screenshot location” but
in ur selenium code you have given small letter(s is a small letter) at the time of
getProperty() so in this java compiler will through an error.

OR.properties
O.R is a place where we can store all the object(element) info.
And it acts as a interface in b/w Selenium automation testscript and Testing
Application in order to identify the element during execution.
And it is a centralized location of the Object and their properties.
O.R file will hold all the locator values of the elements of the application.

See Inheritance concept once :-----------

In superclass
In superclass, we have to create Common code and Additional code(optional)
Common code :
In this class i will be keeping all the
1.Launching the browser(@BeforeTest)
2.Closing the browser(@AfterTest)
3.Reusable Functions

Note : Here Common code for all the subclasses


In subclass
In Subclass, we have to create only additional code(mandatory), not
superclass code
Additional code(mandatory):
In this class i will be keeping all the selenium automation test cases like
@Test
@Test : It represents a selenium automation test case
How to read the property files and How to with property files?
Manual TestSteps:
 Read Property files
 Open the firefox browser
 Navigate the application url
 Enter the username
 Enter the password
 Clicking On Login Button
 Clicking On Logout Button
 Close the current Firefox Browser
Read Property files

Read config.property
1.Create the properties object for that config.property files
Properties config = new Properties();
2.Read the config.property file into working environment
FileInputStream fis = new FileInputStream("F:\\Seleniumworkspace\\
com.Banking.OpenCart\\src\\main\\java\\com\\Banking\\PropertyFile\\
config.properties");
3.Store config.property file into memory space
config.load(fis);
How to Store config.property file into memory space ?
Ans : By using load()
Read OR.properties
1.Create the properties object for that OR.properties file
Properties OR = new Properties();
2.Read the OR.properties file into working environment
FileInputStream fiss = new FileInputStream("F:\\Seleniumworkspace\\
com.Banking.OpenCart\\src\\main\\java\\com\\Banking\\PropertyFile\\OR.properties");
3.Store OR.properties file into memory space
OR.load(fiss);
How to Store OR.properties file into memory space ?
Ans : By using load()
Selenium Java code :
package com.Banking.Tests;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ReadPRopertyfile {
// @BeforeClass defines this Test has to run before every @Test methods in
// the current class/program
Properties config;
Properties OR;
WebDriver driver;

@BeforeClass
public void intilize() throws IOException {
// create the Properties object for that config.properties file

config = new Properties();

FileInputStream fis = new FileInputStream(


"F:\\Seleniumworkspace\\com.Banking.OpenCart\\src\\main\\
java\\com\\Banking\\PropertyFile\\config.properties");

config.load(fis);

// //create Properties object for that OR.properties file

OR = new Properties();
FileInputStream fiss = new FileInputStream(
"F:\\Seleniumworkspace\\com.Banking.OpenCart\\src\\main\\
java\\com\\Banking\\PropertyFile\\OR.properties");
OR.load(fiss);

if (config.getProperty("browser").equals("Firefox")) {

driver = new FirefoxDriver();

} else {
System.out.println("Unable to launch the Firefox browser");
}
}
@Test
public void Login() throws Exception {
driver.get(config.getProperty("TestSiteName"));
driver.findElement(By.name(OR.getProperty("username"))).sendKeys("selenium");

driver.findElement(By.name(OR.getProperty("password"))).sendKeys("selenium");

driver.findElement(By.name(OR.getProperty("login"))).click();

Thread.sleep(3000);

driver.findElement(By.xpath(OR.getProperty("logout"))).click();

@AfterClass
public void closebrowser() {
driver.close();

}
How to write the data into excel ?

package com.Banking.Tests;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class WriteXLSX {

public static void main(String[] args) throws IOException {


FileInputStream fis = new FileInputStream("E:\\test1.xls");

HSSFWorkbook readable_workbook = new HSSFWorkbook(fis);

HSSFSheet readable_sheet = readable_workbook.getSheet("Sheet1");

// Create First Row


HSSFRow row1 = readable_sheet.createRow(0);

HSSFCell r1c1 = row1.createCell(0);

r1c1.setCellValue("Emd Id");

HSSFCell r1c2 = row1.createCell(1);

r1c2.setCellValue("NAME");

HSSFCell r1c3 = row1.createCell(2);

r1c3.setCellValue("AGE");

// Create Second Row

HSSFRow row2 = readable_sheet.createRow(1);

HSSFCell r2c1 = row2.createCell(0);

r2c1.setCellValue("1");

HSSFCell r2c2 = row2.createCell(1);

r2c2.setCellValue("sai");

HSSFCell r2c3 = row2.createCell(2);

r2c3.setCellValue("4");

// Create Third Row

HSSFRow row3 = readable_sheet.createRow(2);

HSSFCell r3c1 = row3.createCell(0);

r3c1.setCellValue("2");

HSSFCell r3c2 = row3.createCell(1);

r3c2.setCellValue("Akki");

HSSFCell r3c3 = row3.createCell(2);

r3c3.setCellValue("3");

FileOutputStream writable_Excel = new FileOutputStream("E:\\


test1.xls");

readable_workbook.write(writable_Excel);
System.out.println("Save the readable workbook into writable_Excel");
}
}
What is a Method in Java?

• Method is a group of statements which is created to perform some actions or


operations when your java code call it from main method.
• Inside a method u can not be execute by itself.
• To execute that method,you need to call from main method block.

Methods (or) Functions: - Methods are used to create re-usable code.


Advantage : Code reusability.
Example:
package com.Banking.Tests;

public class Method_Function {

//here getObject() is called and executed when we call it

int getObject(int a,int b)


{
int c= a+b;

return c;//300(int type value)

public static void main(String[] args) {

Method_Function MF = new Method_Function();

int result = MF.getObject(10,20);// 30 call the getObject()

System.out.println(result);//30

int result1 = MF.getObject(100, 200);// 300 call the getObject() and pass
100,200

System.out.println(result1);//300

}
Capturing ScreenShots

TestCase_ID Test Step Step Description


TC_15 Step 1 Launch firefox
TC_15 Step 2 Naivgate to google
TC_15 Step 3 Take a screenshot

How to take the screenshot when test case failure ?


****************************************************
Manual Steps,
1.Create the screenshot location where our screenshot need to be generate .
2.Take the screenshot.
3.Now i want to copy screenshot to desired location with the help of copy()
Example
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Screenshots {
public static void main(String[] args) throws IOException {
WebDriver driver=new FirefoxDriver();
driver.get("http://google.com");
File desired_location = new File("C:\\Hanumanth.png")
File srcFile=(TakesScreenshot)driver.getScreenshotAs(OutputType.FILE);
FileHandler.copy(srcFile,desired_location);

}
}
Exception Handling:
>This is the process of overcoming an exception or error and remain the execution
of the remaining steps in the program.
>The section of code which might generate an error should be given in the try
block.
>If it generates an error the control comes into the catch block. The program
overcomes that error and continues the execution of remaining code.

JAVA Program
public class ExceptionHandling {
public static void main(String[] args) {
System.out.println("Selenium");
try
{
System.out.println(100/0);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("Java");
}

}
Priority Testing
 I have multiple test cases in the same class.when i run this by
default,these(@Test) annotations are execute alphabetically.So at that time u can
use prioritizing test.
 By using prioritizing test,u can execute the test cases in order.
 Based on the priority u can execute the test cases in order.
 U can give priority at method level
 If you don't mention the priority, it will take all the test cases as
"priority=0" bydefault.
public class PriorityTesting {
@Test
public void login(){
System.out.println("Login successful");
}
@Test
public void checkEmail(){
System.out.println("check email successful");
}
@Test
public void search(){
System.out.println("search successful");
}
@Test
public void logout(){
System.out.println("Logout successful");
}
}

Test Case execution Flow(As per Alfa bytical order):


check email successful
Login successful
Logout successful
search successful
public class PriorityTesting {

@Test(priority=0)
public void login(){
System.out.println("Login successful");
}
@Test(priority=1)
public void checkEmail(){
System.out.println("check email successful");
}
@Test(priority=2)
public void search(){
System.out.println("search successful");
}
@Test(priority=3,enabled = false)
public void logout(){
System.out.println("Logout successful");
}
}
How to skip the test case ?
Ans :
@Test(enabled = false)
public void logout(){
System.out.println("Logout successful");
}
Test Case execution Flow(As per priority):
Login successful
check email successful
search successful
Logout successful
Group of Testing :
 With the help of Grouping, you can make the groups of Test cases like you can
divide the test cases into multiple groups like Smoke, Sanity, and Regression.
Create & Execute Test Groups in TestNG
Here we are taking an example, In which we will create the two classes
“GroupTest1 ” and “GroupTest2”.
We can execute the Test Groups using “testng.xml” file. To execute the Test
group, you need to include the group in the testng.xml file.
Let’s see our Test Classes —>
TC_1 :
package RunMultipleGroups;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class GroupTest1 {
@Test(groups = "Smoke",priority=0)
public void login_Account() {
System.out.println("Account Login");
}
@Test(groups = "Smoke",priority=1)
public void checkMail() {
Assert.assertEquals("OrangeHRM","OrangeHRM");
System.out.println("Checking Mail in the Inbox");
}
@Test(groups = "Sanity",priority=1)
public void checkDrafts() {
System.out.println("Checking Drafts");
}
}

TC_2 :
package RunMultipleGroups;
import org.junit.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class GroupTest2 {
@Test(groups = "Sanity",priority=1)
public void checkPromotions() {
System.out.println("Checking Promotions");
}
@Test(groups = "Sanity",priority=2)
public void checkAccountDetails() {
System.out.println("Checking Account Details");
}
@Test(groups = "Smoke",priority=2)
public void composeMail() {
Assert.assertEquals("OrangeHRM","OrangeHRM");
System.out.println("Send a Mail ");
}
@Test(groups = "Smoke",priority=3)
public void deleteMail() {
System.out.println("Delete a Mail");
}
@Test(groups = "Sanity",priority=3)
public void logout_Account() {
System.out.println("Account Logout");
}
}
Execute Smoke Testing:

<suite name="Suite">

<test name="Smoke Testing" >


<groups>
<run>
<include name="Smoke" />
</run>
</groups>

<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>

</test>

</suite> <!-- Suite -->

Execute Sanity Testing:


<suite name="Suite">

<test name="Sanity Testing" >


<groups>
<run>
<include name="Sanity" />
</run>
</groups>

<classes>

<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>

</classes>
</test>

</suite> <!-- Suite -->

Including and excluding groups:


<include >:--> It tells testng.xml file that which group we need to execute.
< exclude > :-->It tells testng.xml file that which group we need to skip.
Simple way to execute failed test cases using Selenium
Most of the time we have faced this question in interviews that Can we
execute only failed test cases in Selenium or can we identify only failed test
cases in Selenium and re-run them.
I really love this feature of TestNG that you can run only failed test cases
explicitly without any code. This can be easily done by running one simple testng-
failed.xml.
Execute Failed test cases using Selenium
Real-time Example
Take an example that you have one test suite of 100 test cases and once you
start execution of test suite there are a number of chances that some test cases
will fail.Consider 15 test cases are failing out of 100 now you need to check why
these test cases are failing so that you can analyze and find out the reason why
they have failed.
Note- Your script can fail due to so many reasons some of them are
 Some locator has been changed in application because the application is
getting new feature- so in this case you need to modify your script in other words
you have to refine your script.
 Either functionality has been broken- in this case, you have to raise a
defect and assign to the respective person.
Execute Failed test cases using Selenium
Steps
1. If your test cases are failing then once all test suite completed then you
have to refresh your project . Right click on project > Click on refresh or Select
project and press f5.
2. Check test-output folder, at last, you will get testng-failed.xml
3. Now simply run testng-failed.xml.an be easily done by running one simple
testng-failed.xml.
How to run testng-failed.xml

We don’t have to perform any other activity once you will get testng-
failed.xml double click on this and analyze which test case are failing and why .
Then modify your script and run it.
To run above xml simple right click on xml then Select run as then TestNG Suite.

Generating XSLT reports through WebDriver ,Ant and TestNG

To generate XSLT reports, We have to use Apache Ant. Apache Ant Is open
source command-line tool which will help us to generate XSLT reports for our
selenium webdriver .
XSLT stands for XML Style-sheet language for transformation, It provide very
rich formatting report using TestNG framework.

Why need XSLT reports


Till now, We have generated testng reports as described In previous. But
testng reports are not so much Interactive and we can not send this kind of reports
to our manager or client. XSLT reports are very Interactive and easy to understand
them.

Steps for generating reports:

Let us Generate XSLT Report in Selenium WebDriver

1.Add build.xml File Under Your Project


You have to create build.xml file under your project because ant understand
only build.xml file's execution pattern. You can download ready made build.xml file
from bellow given link page to Include It In your project.
Go To This
Page(https://drive.google.com/drive/folders/0B5v_nInLNoquV1p5YWtHc3lkUkU) and
Download the XSLT report package
Step 1): Download the XSLT report package

Unzip the above folder you will get below items:

• lib
• build.xml
• testng-results.xsl

Step 2): Unzip the folder and copy all files and paste at the project home
directory as shown in below screen.

1. Create build.xml

Here
1.verify paths in build.xml file
2.Confirm required jar files added in project build path

<project name="TestAutomation" basedir=".">


<property name="LIB" value="${basedir}/lib" />
<property name="BIN" value="${basedir}/bin" />
<path id="master-classpath">
<pathelement location="${BIN}" />
<fileset dir="${LIB}" includes="*.jar"/>
</path>
<target name="generateReport">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/test-output/testng-results.xml"
style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"
/>
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS"
name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="master-classpath">
</classpath>
</xslt>
</target>

</project>

3.Before generating XSLT reports,you need to run your test suite from “
Testng.xml ” file first becoz XSLT reports are generated based on “ Testng-
results.xml “ file .

4. Create testng.xml file in your project with the following script for TestNG
execution

<?xml version="1.0" encoding="UTF-8"?>


<suite name="Ant Suite">
<test name="Ant Test">
<classes>
<class name=" XSLT_ReportsPack. xsltReports " ></class>
</classes>
</test>
</suite>

Next I want to generate the Ant xslt reports

Step 3): In this step run the build.xml file from eclipse as shown below:

Right click on the build.xml then click on run as Ant build.

Then a new window opens. Now select option 'generateReport'.

Click on Run button. It should generate the report.


Verifying XSLT Report
Once build is successful and moved to project home directory and refresh then You
will find the testng-xslt folder.

Inside this folder you will find index.html file as shown below:

Now open this HTML file in any browser like Firefox or Chrome, which support
javascript. You will find the report as shown in below screen.

We will get results like below image


Test suites overview

Test cases of Sanity Testing

Parameterization in TestNG using testng.xml


You can use parameter annotations through the testng.xml file to pass values
to test methods as arguments. However, at times it is required to pass values to
test methods, especially during the run time. It can be done in the same way as the
username and password are passed through testng.xml instead of hard coding it in
test methods or as the browser name is passed as a parameter to execute in a
specific browser.

Let us now try to understand parameterization with a basic example.

package com.parameterization;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestParameters {
@Parameters({ “browser” })
@Test
public void testCaseOne(String browser) {
System.out.println(“browser passed as :- ” + browser);
}
@Parameters({ “username”, “password” })
@Test
public void testCaseTwo(String username, String password) {
System.out.println(“Parameter for User Name passed as :- ” + username);
System.out.println(“Parameter for Password passed as :- ” + password);
}
}
In the above class, two parameters ‘username’ and ‘password’ are passed as
input to test method ‘testCaseOne’.
The following is the testng.xml file, in which we need to pass the parameter
values for the test method.

<! DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>


<suite name="Parameterization Test Suite">
<test name="Testing Parameterization">
<parameter name="browser" value="Firefox"/>
<parameter name="username" value="selenium"/>
<parameter name="password" value="selenium123"/>
<classes>
<class name="com.parameterization.TestParameters" />
</classes>
</test>
</suite>

Parallel Testing :

Browser compatibility software testing Is most Important thing for any


software web application and generally you have to perform browser compatibility
testing before 1 or 2 days of final release of software web application
In such a sort time period, you have to verify each Important functionality
In every browsers suggested by client.

If you want to run multiple tests In different browsers one by one then It
will take too much time to complete your software tests and you may not complete
It before release the project.

In this kind of situation, I want to run multiple tests In different


browsers parallely at the same time within sort time and will helps you to
save your time efforts.

Test_Parallel.java

package SampleTestCases;

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Test_Parallel {

public WebDriver driver;


@BeforeClass
//I have used @Parameters annotation to pass parameter In method
//parameter value will retrieved from testng.xml file's <parameter> tag.
@Parameters ({"browser"})
public void setup(String browser){
//Method will pass value of parameter.
if (browser.equals("FFX")) {
//If value Is FFX then webdriver will open Firefox Browser.
System.out.println("Test Starts Running In Firefox Browser.");

driver = new FirefoxDriver();

}else if (browser.equals("CRM")){
//If value Is CRM then webdriver will open chrome Browser.
System.out.println("Test Starts Running In Google chrome.");

System.setProperty("webdriver.chrome.driver","C:\\Users\\Hanumanthu\\Downloads\\
chromedriver.exe");
driver = new ChromeDriver();
}
else if (browser.equals("IE")){
//If value Is CRM then webdriver will open chrome Browser.
System.out.println("Test Starts Running In IE.");

System.setProperty("webdriver.ie.driver","C:\\Users\\Hanumanthu\\Downloads\\
IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
driver.manage().window().maximize();
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
}
//Both bellow given tests will be executed In both browsers.
@Test
public void verify_title(){
String title = driver.getTitle();
Assert.assertEquals("OrangeHRM - New Level of HR Management", title);
System.out.println("Title Is Fine.");
}
@AfterClass
public void closebrowser(){
driver.close();
}
}

testng.xml

<suite name="Parallel Testing" parallel="tests">

<test name="Test In FireFox" >


<parameter name="browser" value="FFX" />
<classes>
<class name="seleniumProject.Test_Parallel"/>
</classes>
</test>

<test name="Test In Google Chrome" >


<parameter name="browser" value="CRM"></parameter>
<classes>
<class name="seleniumProject.Test_Parallel"/>
</classes>
</test>

<test name="Test In IE" >


<parameter name="browser" value="IE"></parameter>
<classes>
<class name="seleniumProject.Test_Parallel"/>
</classes>
</test>

</suite>

Example 8
***************

byte b=12.7F; //invalid

System.out.println(b);

>We can say this(12.7F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
***************************************************************************
Ans : Yes
Found : float
Required : byte

Example 8
***************

byte b=2.7; //invalid double type value

System.out.println(b);

>We can specify floating-point literal value only in decimal form

What are the floating-point literal value ?


**************************************************
Ans : float value and double value

Float Examples :
********************
10.5f,10.1111F,2.3f,25f------------

Double Examples
*******************
10.5,10.1111,2.3,25------------

Note :
********
>by default every floating-point literal value is what type double type value

F : double type value


R : byte

Example 9
***************

byte b=129; //invalid int

System.out.println(b);

>129
>byte type
>min -128 to max 127

What are the integral integer datatypes in java ?


*****************************************************
Ans : byte ,short,int and long

What are the integral integer literal value in java ?


*****************************************************
Ans : byte value,short value ,int value and long value

note :
********
>by default every floating-point literal value is what type double type value

>By default every integral literal value is what type int type

F : int
R : byte
short datatype in java ?
****************************
>This will be used to store +ve and -ve nos
>min -32768 to max 32767

Example 1
***************

short s=32767; // valid short type value

System.out.println(s);

>32767
>short type
>min -32768 to max 32767

F : short type value


R : short type value

Example 2
***************

short s=32.767; // invalid double type value

System.out.println(s);

F : double type value


R : short

Example 3
***************

short s=32769; //invalid int type value

System.out.println(s);

>min -32768 to max 32767

F : int type value


R : short

Example 4
***************

short s=32767L; //invalid long type value

System.out.println(s);

F : long type value


R : short
Transfer statements in java ?
*********************************
Ans : This will be used to transfer from one place to another place nothing but
transfer

1.break
2.continue
3.return
4.try-catch-final

1.break statement
********************

Example 1
**************
public class Break_Stament {

public static void main(String[] args) {

int x=10;

if(x)
{
break;//error
}

System.out.println("Hanumanth");

Where we can create break statement ?


***********************************
Ans : Inside the loops and switch block

>

Without break statement inside switch block ?


***********************************************
Example 2
**************
public class Break_Stament {

public static void main(String[] args) {


int x=0;

switch(x){

case 0 : System.out.println("Hello");//Hello
case 1 : System.out.println("Hi");
case 2 : System.out.println("Hanumanth");
default : System.out.println("Kosmik");
}

}
With break statement inside switch block ?
***********************************************
Example 3
**************
public class Break_Stament {

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println("Hello");//Hello
case 1 : System.out.println("Hi");

break;
case 2 : System.out.println("Hanumanth");
default : System.out.println("Kosmik");
}

}
Why we are using break statement inside switch block ?
*****************************************************
Ans : To stop the fall-through

Without break statement inside forloop block ?


***********************************************
How to print 1(stating)-10(ending) nos ?
*************************
1
2
3
4
5
....10

Example 4
**************
public class Break_Stament {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{

System.out.println(i);
}

}
With break statement inside forloop block ?
***********************************************
How to print 1(stating)-3(ending) nos from 1-10 nos?
*******************************************************
Syntax :
************

for(initialization-part; conditional-part/testing-part ; increment/decrement-


part)
{

if(condition to break)
{
break;

statements;

Syntax Explanation :
***********************
1.
2.
3.
4.

Example 4
**************
public class Break_Stament {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{
if(i==4)
{
break;

System.out.println(i);
}

}
Why we are using break statement inside loops ?
**************************************************
Ans : To break the loop based on condition

continue statement
**********************
Example 1
**************
public class Break_Stament {

public static void main(String[] args) {

int x=10;

if(x)
{
continue;//error
}

System.out.println("Hanumanth");

Where we can create continue statement ?


*****************************************
Ans : Inside the loops only

Without continue statement inside forloop ?


*******************************************

How to print 1(stating)-10(ending) nos ?


*************************
1
2
3
4
5
....10

Example 4
**************
public class Break_Stament {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{

System.out.println(i);
}

}
With continue statement inside forloop ?
*******************************************

Syntax :
************

for(initialization-part; conditional-part/testing-part ; increment/decrement-


part)
{

if(condition to continue)
{
continue;

statements;

Syntax Explanation :
*************************
1.
2.
3.
4.

How to print 1-10 nos except 3 ?


************************************

Example 4
**************
public class Break_Stament {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{
if(i==3)
{
continue;

System.out.println(i);
}

}
DAtatypes in java ?
***********************

int x=10;

What is a variable in java ?


*******************************
Ans : Variable is a memory location and here variable x can store some data based

on datatype then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script

>In java or other programming languages,we know we need variables to store some
data

based on datatype.

>In java,every variable and every expression should have a datatype.

types of datatypes
**********************
1.primitive datatypes
2.Non-Primitive datatypes

What are the integral integer datatypes in java ?--IQ


*********************************************************
Ans : byte,short,int and long

What are the integral floating-point datatypes in java ?--IQ


*********************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


***********************************************
Ans : byte,short,int,long,float,double,char and boolean

What are the non-primitive datatypes in java ?--IQ


***********************************************
Ans : String,array,set,list etc.

byte datatype in java ?


***************************
>This will be used to store +ve and -ve nos
>Here byte datatype variable can store in the range of the values min -128 to max
127

min -128 to max 127

Example 1
************

byte b=125; //valid byte type value

System.out.println(b);

Code Explanation :
***********************
>Here providing value is 125
>Here Expected value is byte type value
>min -128 to max 127

Found : byte type value


Required : byte

Java compiler work


********************
Ans : Compile the java code line by line (That means checking the java code line by
line whether it is currect code or not)

JVM work
*************
Ans : Just execute the java code

Example 2
************

byte b=127; //valid byte type value

System.out.println(b);

>127
>byte type value
>min -128 to max 127

F : byte type value


R : byte

Example 3
************

byte b="Hanumanth"; //invalid String type value

System.out.println(b);

Note :
********
>We can say this("Hanumanth") is a string type value

>Here string mean collection of characters

Examples
************
"HYD" or "H" or "123" or "HYD123" or "#%$^^&%&^^"
>Here everything in double quotes its a string
>Here string always must be in double quotes

F : String type value


R : byte

Difference betweeen super() and this() ?


*******************************************

Example 1
**************
class Test
{

Test()
{
System.out.println("hanumanth");

super();//Invalid
}

}
>Here super() must be in the first line in the constructor

Example 2
**************
class Test
{

Test()
{
super();//valid
System.out.println("hanumanth");

}
>Here always super() must be in the first line in the constructor

Example 3
**************
class Test
{

Test()
{

System.out.println("hanumanth");
this();//invalid
}

}
>Here this() must be in the first line in the constructor

Example 4
**************
class Test
{

Test()
{
this();//valid
System.out.println("hanumanth");

>Here always this() must be in the first line in the constructor

Example 5
**************
class Test
{

Test()
{
super();//valid-----1st place
this();//invalid----2nd place
System.out.println("hanumanth");

}
Example 6
**************
class Test
{

void Test()
{
super();//invalid

System.out.println("hanumanth");

Where we can create super() and this() ?


********************************************
Ans : Only inside the constructor

How to call the superclass default constructor ?


***************************************************
Syntax : super();

How to call the superclass parameterization constructor ?


***************************************************
Syntax : super(value1,value2,value3);

How to call the current class default constructor ?


***************************************************
Syntax : this();

How to call the current class parameterization constructor ?


***************************************************
Syntax : this(value1,value2,value3);

How to call the superclass default constructor using super() ?


*********************************************************************
Example
***********
Manual Steps
****************
1.Create Superclass(Animal class)
2.Create Subclass(Cat) from Superclass
3.Create MainClass

Java code
**************

How to call the superclass parameterized constructor using super() ?


*********************************************************************
Example
***********

Manual Steps
****************
1.Create Superclass(Shape)
2.Create Subclass(Rectangel) from Superclass
3.Create MainClass

Java code
**************

Difference betweeen super and this ?


******************************************
Why we are using super keyword ?
************************************
Ans : By using super keyword,we can call the superclass members(variables +
methods)

Why we are using this keyword ?


************************************
Ans : By using this keyword,we can call the current class members(variables +
methods)
int datatype in java ?
**************************
>This will be used to +ve and -ve nos
>min -2147483648 to max 2147483647

Example 1
************
int i=2345; // valid int type value

System.out.println(i);

>2345
>int type
>min -2147483648 to max 2147483647

F : int type value


R : int

Example 2
************
int i=23.45; //invalid double type value

System.out.println(i);

F : double type value


R : int
java virtual machine

Example 4
***************

byte b= true; //invalid boolean type value

System.out.println(b);

Note :
***********

>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean type value


R : byte

Example 5
***************

byte b= 123L; //Invalid long type value

System.out.println(b);

Note :
**********
>We can say this(123L) is a long type value by suffixed 'l or 'L'

>Here suffixed 'l or 'L' is a mandatory for that long type value ?
*********************************************************************
Ans : Yes

Datatype rules
********************

byte(least) < short < int < long < float < double(highest)

1.We can assign left-side datatype value into any right-side datatype variable.

2.We can't assign right-side datatype value into any left-side datatype variable.

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required TypeCasting(Convert one datatype into another datatype).

Found : long type value


Required : byte
Example 6
***************

byte b= 12.7F; //invalid float type value

System.out.println(b);

Note :
*********
>We can say this (12.7F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
****************************************************************************
Ans : Yes

F : float type value


R : byte

Example 7
***************

byte b= 127.7345; //invalid double type value

System.out.println(b);

Note :
**********

1.What are the floating-point literal value ?


************************************************
Ans : float value and double value

2.We can specify floating-point literal value(float value and double value) only in
decimal form .

3.Float Examples
**********************

10.5f,2.3F,10.1111F,-123.345F-------

4.Double Examples
**********************

10.5,2.3,10.1111,-123.345-------

Note :
*******
>By default every floating-point literal value is what type double type.

F : double type value


R : byte
Example 8
***************

byte b= 129; //

System.out.println(b);

Difference betweeen super and this keyword ?


***********************************************

Why we are using super keyword ?


***********************************
Ans : By using super keyword ,we can call the super class members(variables +
methods)

How to call the superclass variable ?


****************************************
Syntax : super.variablename

Example
***********

Manual Steps
**************
1.Create Superclass(Animal)
2.create SubClass(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
***************

How to call the superclass methods ?


****************************************
Syntax : super.methodname();

Example
************

Manual Steps
**************
1.Create Superclass(Animal)
2.create SubClass(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
***************
Why we are using this keyword ?
***********************************
Ans : By using this keyword ,we can call the current class members(variables +
methods)

How to call the current class variable ?


****************************************
Syntax : this.variablename

How to call the current class methods ?


****************************************
Syntax : this.methodname();

How to call the superclass variable ?


****************************************
Syntax : super.variablename;

Example
**********
Manual Steps
*****************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass
3.Create Mainclass

Java code
**************

How to call the superclass methods ?


****************************************
Syntax : super.methodname();

Example
**********
Manual Steps
*****************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass
3.Create Mainclass

Java code
**************

polymorphism in java ?
*****************************
poly mean----many

morphs ----forms

polymorphism-----many forms

In real-world examples of polymorphism


*******************************************
Ex 1 : Here one form represents many forms then it is called polymorphism

Ex 2 : Here same name but with different sounds then it is called polymorphism.

Ex 3 : A person behaves like in different ways then it is called polymorphism

1.A person in shopping mall behave like a customer


2.A person in bus behave like a passenger
3.A person in school behave like a student
4.A person at home behave like a son

types of polymorphism
*************************

Method overloading in java ?


********************************
Definition 1:
****************
>Here method name same but with different argument types then it is called method
overloading.

Example
**********

void m1(int a)
void m1(String s)
void m1(long id)
Java program
****************

Int datatype in java ?


*************************

Example 2
*************
int i=23.45;//invalid double type value

System.out.println(i);

F : double type value


R : int

Example 3
*************
int i=2345L;//invalid long

System.out.println(i);

F : long
R : int

long datatype in java ?


**************************
>+ve and -ve nos
> min -9223372036854775808 to max 9223372036854775807

Example 1
*************

long l=2345L;//valid long type value

System.out.println(l);

F : long type value


R : long

Example 2
*************

long l=125;// valid int type value

System.out.println(l);

F : int type value


R : long

Example 3
*************

long l=12.5F;//invalid float

System.out.println(l);

F : float
R : long
String datatype in java ?
*****************************

>This will be used to store single character and group of characters

Examples
*************

"HYD" or "H" or "123" or "HYD123" or "^%%&^*&&("

>Here everything in double quotes it's a string


>Here string always must be in double-quotes
>Here range not applicable for string datatype

Example 1
*************

String s=0;// invalid int

System.out.println(s);

F : int
R : String

Example 2
*************

String s=true;// invalid

System.out.println(s);

F : boolean
R : String

Example 3
*************

String s=Hanumanth; // invalid

System.out.println(s);

Note :
**********
>Here this(Hanumanth ) is not applicable for any datatype

Example 4
*************

String s="Hanumanth"; // valid String

System.out.println(s);

F : String
R : String

boolean datatype in java ?


*****************************

>This will be used to store only boolean value such as true / false

>Here range not applicable for boolean datatype

Example 1
*************

boolean b=10; // invalid

System.out.println(b);

F : int
R : boolean

Example 2
*************

boolean b=True; // invalid

System.out.println(b);

Note :
*********
>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'

Example 3
*************

boolean b=true; // valid

System.out.println(b);

F : boolean
R : boolean

constructor in java ?
**************************

>This is similar to method

Why need constructor in java ?


********************************
Ans :

types of constructor
**********************
1.default constructor
2.parameterized constructor

1.default constructor
************************
Syntax :
*********
Student()
{

}
2.parameterized constructor
*****************************
Syntax:
***********

Student(para1,para2,para3)
{

>Student(para1,para2,para3)==>

>Here constructor doesn't return any value not even void

>In method ,return-type is mandatory ?


***************************************
Ans : Yes

1.In default constructor,how to initialize the values to an instance variable


*********************************************************************
Student()
{

name="Sai";
rollno=101;

Example 1
**************

When default constructor will be called ?


******************************************
Ans : Whenever u create an object by default default constructor will be called.

2.In parameterized constructor,how to initialize the values to a variable


***********************************************************************

Student(String S_name,int S_rollno)


{
name = S_name;

rollno = S_rollno;

Example 2
**************

When parameterized constructor will be called ?


******************************************
Ans : Whenever u create an object and passing the values then parameterized

constructor will be called.

In java,constructor overloading is possible ?


************************************************
Ans : Yes

What is a constructor overloading ?


***************************************
Ans : Here constructor name same but with different argument types then it is

constructor overloading.

Note :
***********
CAn we write multiple constructor in the same class ?
*********************************************************
Ans : Yes

3.A method is called and executed multiple times per single object
***********************************************************************

Example
**************

Selenium Free Demo

Selenium Automation Testing


What is Testing :
Definition :
>Here to verify whether the functionality works well or not i.e Testing (OR)
Simple Definition What is a Testing:
>We can say simply To find the defect or to find the error or to find the failure.
But What they are different between defect, error and failure? ---IQ
Error :
Ans: Here error is a mistake in your code found by the developer.
Defect :
Ans: Here defect is a mismatch if the expected value does not equal to actual value
then found by the Test Engineer.
failure:
Ans : Here failure is a problem in your software found by the customer or users.
>Take the example,
1. Here to verify whether the text enters into the text box or not. (OR)
2. To verify the size and range of the values from this input field (OR)
3. To verify the type from this input field.
For example, min 6 to max 12 ==>this range of values you have to check from this
input field first.
Next, What about type? To verify whether the special characters required or not as
well as numerical and blank fields everything you have to check from this input
field.
Types of Testing

1.Functional Testing
2. Non-functional
Here Functional Testing is divided into two types:
1.Manual Testing
2.Automation testing
Manual Testing :
Ans: Manual Testing is nothing but testers do manually without using any one of the
automation tool then it is called Manual Testing.
Drawbacks:
>Time consuming
>Not reusability
>Not repeatable
>Not programble
>It takes high man power
Automation Testing :
Ans: Automation Testing is nothing but testers do automatically with using anyone
one of the automation tool then it is called Automation Testing.
Benefits:
>It is very fast
>Code Reusability
>Repeatable
>Programble
>It takes less man power

>Here before going to selenium we need to learn what is the difference between M.T
and A.T?
Take the example 1,
>In Manual Testing every time you have to enter username and enter the password and
click on login after click on login then you will get the welcome page, now here to
verify whether the welcome page successfully opened or not.
>But in Automation Testing no need to follow these three steps (Enter the username,
password and click on login) every time once you write the code and then run it
will execute automatically.
Take the example 2,
>In manual testing our main activity is writing the manual test cases. These test
cases will be executed by some resources i.e Test Engineer.
>Here manual test cases are written by test engineer and he(test engineer) will
execute all the test cases manually.
When it comes to automation testing what he(test engineer) will do this?
Ans: See all the manual test cases will be converted to test script with the help
of some automation tools like selenium,qtp,Rft,silk test.....N of tools are
available. So the process of converting manual test cases to test script with the
help of some automation tools(selenium,qtp,Rft,silk test.....N) is nothing but
Automation. Here we can use any tool to convert into the test script.
You may get one doubt, In manual testing, we are writing the manual test cases and
execute the manual test cases when it comes to automation testing we are doing same
activity same test cases will be converted to automation test script and execute
the automation test script so what it is the use of automation?
The main advantage of automation?
1. To save time
2. To save the money
3. Code reusability
4. To avoid the repeated code activities
1. To save time: How much time we can save? For example, I want to go from
Kukatpally to Ameerpet.
>There are multiple ways manually I can go by walk but it takes time at that time
we need to follow some automation tools like bus, auto, car, the bike is, etc. Here
vehicles are nothing but automation tools. So with the help of vehicles to save
time and with the help of automation to save time.
Note : Vehicles = automation tools
>Convert the manual test cases into selenium automation test script < Next Write
the selenium automation test script into TestNg < here selenium code with the help
of TestNG can test the application.
History of selenium ?
>It was came into 2004, by jason huggins
>Selenium 1.0 have 3 tool
>Selenium IDE + Selenium RC +Selenium grid
>It was came into 2004
>Selenium 2.0 have 4 tools
> Selenium IDE + Selenium Rc + Selenium Webdriver + Selenium grid
>It was came into 2011
>Selenium 3.0 have 3 tools
> Selenium IDE + Selenium WebDriver + Selenium grid
> It was came into 2016
>Selenium 4.0 have 3 tools
> Selenium IDE + (Selenium WebDriver+Extra features) + Selenium grid
> It was came into 2019
Types of Functional Automation tools?
1.Opensource tools
2.Commercial tools
Here opensource tools like :
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.Sahi
4.Bad boy
5.Ruby
6.Watir etc.
Here Commercial tools like :
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.RFT(Rational Functional Tester)
5.Silk test etc.

What is the difference between selenium and QTP ?---IQ


Selenium :
>This is an opensource automation tool(free of cost) mainly it will be used for
Functional Testing and Regression Testing to test the application.
>Selenium Support multiple languages like java,c#, python, ruby, Perl, and PHP.
>Selenium support multiple browsers like FF, IE, Chrome, opera, safari, and Edge
browser.
>Selenium Support multiple operating systems like Windows, Linux, and Mac OS
>Selenium supports web applications but not mobile applications and desktop
applications.
Here selenium with the help of appium tool to handle the mobile applications.
Here selenium with the help of AutoIt, robot class to handle the desktop
applications.
QTP:
>Qtp is a commercial tool (paid tool)
>Qtp support only VBScript
>Qtp support multiple browsers like FF, IE, and chrome
>Qtp support windows only
>Qtp supports web applications, mobile applications, and desktop applications.
What are the selenium components ?

Difference between Selenium IDE, Selenium RC, and Selenium WebDriver?--IQ


************************************************************************

Selenium IDE
***************
1.Record and playback tool
2.FF and chrome
3.Web app only
4.Selenium IDE doesn't have any programming knowledge
4.Selenium IDE generate Test Reports but no details

No details
************
>Selenium IDE reports are not effective to send the client ,TestLead and project
manager

>There is no complete information in selenium IDE report format.

Selenium Rc(Remote controller)


****************
1.Selenium RC works with server but selenium webdriver doesn't work with server
2.Java,c#,python,ruby,perl and php.
3.FF,IE,chrome,opera,safari
4.Windows and linux
5.old versions only
6.Web app only

Here Selenium + Appium-------->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

Selenium WebDriver
**********************

What is a webdriver ?
**************************
Ans : webDriver it's an interface in betweeen selenium automation test script

and Testing Application.

2.Java,c#,python,ruby,perl and php.


3.FF,IE,chrome,opera,safari and Edge
4.Windows and linux adn mac os
5.old and new versions also
6.Web app only

Here Selenium + Appium-------->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app


---------------------part 1

Java for selenium(core java enough)-----------part 2


********************************
Java,

80%------------Selenium Webdriver + java(java oops concepts + collection)

TestNG------------------part 3
*******************

TestNG(latest)---Junit(old)

Why we are using Testng ?


****************************
Ans : By using TestNG,we can create selenium automation Test cases,execute

the selenium automation Test cases,it generate Test Reports and also generate

log files.

Main Why we are using Testng ?


****************************

1.Selenium IDE generate Test Reports but no details


2.Selenium Rc outdated(old)
3.Selenium Webdriver doesn't generate the Test Reports,and here selenium webdriver

with the help of TestNG will generate the Test Reports.

Add three parts,


********************

1 + 2 + 3--------->Selenium Webdriver + Java + TestNG

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework

In superclass
******************

common code + Additional code(optional)


In subclass
*************

Additional code(mandatory)

types of inheritance
*********************
1.Single inheritance
2.MultiLevel Inheritance
3.Hierarchical inheritance

1.Single inheritance
*************************

Example 2
**************
Manual Steps
*****************
1.Create Superclass(Parent)
2.Create Subclass(Child) from Superclass(Parent)
3.Create Mainclass

Java code
**************

Case 1
*********
Child C = new Child();

C.m1();//call the m1()


C.m2();//call the m2()

With child reference, we can call the parent class method

With child reference, we can call the child class method

Case 2
*********
Parent C = new Child();

C.m1();//call the m1()----valid


C.m2();//call the m2()---invalid

With parent reference, we can call the parent class method

With Parent reference, we can't call the child class method

Case 3
*********

Parent C = new Parent();

C.m1();//call the m1()----valid


C.m2();//call the m2()---invalid

With parent reference, we can call the parent class method


With Parent reference, we can't call the child class method

Multi-Level Inheritance in java ?


**********************************
Definition :
**************

Syntax :
*************
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Subclass1
{

}
Example 1
***********
Manual Steps
**************
1.Create Superclass(GrandFather)
2.Create Subclass1(Father) from Superclass(GrandFather)
3.Create Subclass2(Son) from Subclass1(Father)
4.Create Mainclass

Java code
******************

Example 2
***********

Handling popup
********************
1.How to handle web based popup or alert ?
2.How to handle model popup window ?
3.How to handle multiple windows ?

1.How to handle web based popup or alert ?


**********************************************
diagram:
***********

Manual Steps
***************
1.switch to alert
2.Verify alert text
3.click on ok

Testing = operation code + verification code

Selenium Java code


**********************
//1.switch to alert

Alert alt = driver.switchTo().alert();

//**************************Verify alert
text*********************************

//------------------------------------------------------operation code
//2.Verify alert text

String alert_text = alt.getText();

System.out.println(alert_text);//You Have Succesfully Logged Out!!

//----------------------------------------------------verification code

if(alert_text.equals("You Have Succesfully Logged Out!!"))


{
System.out.println("Alert text verified successfully");
}else
{

System.out.println("Alert text not verified successfully");


}

//3.click on ok

alt.accept();

2.How to handle model popup window ?


*****************************************
diagram:
***********

Manual Steps
*****************
1.switch to model popup window
2.do some action
3.click on model popup window

Selenium Java code


**********************

//1.switch to model popup window


driver.switchTo().window(driver.getWindowHandle());

//2.do some action

//3.click on model popup window

driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();

Transfer statements
************************

1.break
2.continue
3.return
4.try-catch-final

1.break statement
******************

Example 1
************

public class Student {

public static void main(String[] args)


{

int x=10;

if(x)
{

break;//error
}

System.out.println("Hanumanth");

}
}

Where we can create break statement ?


*****************************************
Ans : Inside the switch block and loops

Without break statement inside switch block


************************************************
Example 2
************

public class Student {

public static void main(String[] args)


{
int x=0;

switch(x){

case 0 : System.out.println("Hanumanth");//Hanumanth

case 1 : System.out.println("Hanumanth");

case 2 : System.out.println("Hanumanth");

default : System.out.println("Hanumanth");

}
}
}

With break statement inside switch block


************************************************
Example 3
************

public class Student {

public static void main(String[] args)


{

int x=0;

switch(x){

case 0 : System.out.println("Hanumanth");//Hanumanth

case 1 : System.out.println("Hanumanth");
break;
case 2 : System.out.println("Hanumanth");

default : System.out.println("Hanumanth");

}
}
}

Why we are using break statement inside switch block ?


********************************************************
Ans : To stop the fall-through

Without break statement inside forloop block


************************************************
How to print 1-10 nos ?
****************************
1
2
3
4
5
..............10
Example 4
************

public class Student {

public static void main(String[] args)


{

for(int i=1;i<=10;i++)
{
System.out.println(i);

}
}

With break statement inside forloop block


************************************************
Syntax :
***********

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{

if(condition to break)
{

break;

Statement;

Syntax Explanation :
***********************

1.
2.
3.
4.

How to print 1-3 from 1-10 nos ?


************************************

Example 4
************

public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

if(i==4)
{

break;
}

System.out.println(i);

}
}

Why we are using break statement inside loops ?


*************************************************
Ans : To break the loop based on condition

Continue statement
*******************

Example 1
**************
public class Student {

public static void main(String[] args)


{
int x=10;

if(x)
{
continue;//error

}
System.out.println("Hanumanth");

Where we can create continue statement ?


*******************************************
Ans : inside the loops only

Without continue statement inside forloop?


***********************************************
Example 2
**************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{
System.out.println(i);
}

With continue statement inside forloop?


***********************************************
Syntax :
***********

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{

if(condition to continue)
{

continue;

Statement;

Syntax Explanation :
***********************
1.
2.
3.
4.

How to skip 3 from 1-10 nos ?


********************************

Example 2
**************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

if(i==3)
{
continue;

System.out.println(i);

}
}

Selenium Automation Testing


******************************

What is a Testing ?
**********************
Ans : To verify whether the functionality works well or not . i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure

Difference betweeen defect,error and failure ?


****************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

Types of Testing
**********************
1.Functional Testing
2.Non-functional Testing

Types of functional automation tools


***************************************
1.opensource
=================
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.Sahi
4.Badboy
5.ruby
6.watir etc

2.commercial
***************
1.Qtp(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test

Difference betweeen selenium and Qtp ?--IQ


********************************************
Selenium
***********
1.opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here Selenium + appium--------->mobile app

Here Selenium + AutoIT or sikuli or robot class----->desktop app

Qtp
******
1.commercial (paid tool)
2.Vbscript
3.FF,Ie and chrome
4.Windows
5.Webapp ,mobile app and desktop app

History of selenium
**********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium Webdriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium Webdriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium Webdriver+Extra features) + Selenium Grid


>2019

Selenium Components---IQ
*************************
1.Selenium IDE
2.Selenium RC
3.Selenium WebDriver
4.Selenium Grid

Difference betweeen Selenium IDE,RC and Webdriver ?--IQ


**********************************************************

Selenium IDE
***************
1.Record and playback tool
2.FF and chrome
3.Web app only
4.Selenium IDE doesn't have any programming knowledge
5.Selenium IDE generate Test Reports but no details

No details
**************
>Selenium IDE reports are not effective to send the client , TestLead and project
manager

>There is no complete information in selenium IDE report format

Selenium Rc
****************
1.Selenium RC works with server but selenium webdriver doesn't work with server
2.java,c#,python,ruby,perl and php.
3.FF,Ie,chrome,opera,safari
4.Windows and linux
5.Old versions only
6.Web app only

Here Selenium + appium--------->mobile app

Here Selenium + AutoIT or sikuli or robot class----->desktop app

Selenium WebDriver
********************

What is a Webdriver ?
************************

Ans :WebDriver it's an interface in betweeen selenium automation test script

and Testing Application.

2.java,c#,python,ruby,perl and php.


3.FF,Ie,chrome,opera,safari and Edge
4.Windows and linux and mac os
5.old and new versions also
6.Web app only

Here Selenium + appium--------->mobile app

Here Selenium + AutoIT or sikuli or robot class----->desktop app

-----------------part 1

Java for selenium(core java enough)-----------part 2


********************

Java,

80%------------Selenium Webdriver + java(oops concepts + collection)

TestNG----------part 3
***********************

TestNG(latest)---Junit(old)

Why we are using TestNG ?


******************************
Ans : By using TestNG,we can create selenium automation Test cases,execute

the selenium automation Test cases,it generate Test Reports and also generate

log files.

Mainly Why we are using TestNG ?


******************************
>Selenium IDE generate Test Reports but no details
>Selenium Rc outdated(old)
>Selenium Webdriver doesn't generate the Test Reports,here selenium webdriver

with the help of TestNG will generate the Test Reports.

Add three parts


*******************

1 + 2 + 3----------->Selenium WebDriver + Java + TestNG

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

data driven framework


keyword driven framework
Hybrid framework

1.How to handle web based popup or alert ?


**********************************************
diagram:
**********

Manual Steps
****************
1.switch to alert
2.Verify alert text
3.click on ok

Testing = operation code + verification code

Selenium Java code


**********************
//1.switch to alert

Alert alt = driver.switchTo().alert();

//-------------------------------------------------------operation code
//2.Verify alert text

String alet_text = alt.getText();//You Have Succesfully Logged Out!!

System.out.println(alet_text);//You Have Succesfully Logged Out!!

//------------------------------------------------------verification
code

if(alet_text.equals("You Have Succesfully Logged Out!!"))


{
System.out.println("Alert text verified successfully");
}else
{
System.out.println("Alert text not verified successfully");

//3.click on ok

alt.accept();

2.How to handle model popup window ?


****************************************
diagram:
***********

Manual Steps
*************
1.switch to model popup
2.do some action
3.click on model popup

Selenium Java code


*******************

//1.switch to model popup

driver.switchTo().window(driver.getWindowHandle());
//2.do some action

//3.click on model popup

driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();
Selenium IDE :
>It is a record and playback tool
>It supports multiple browsers like FF, Chrome
>It supports only web applications
>If you want to work with Selenium IDE, here no need to learn any programming
knowledge
>It generates test reports but no details.
No details mean :
>Here selenium IDE reports they are not effective to send the Client, Test Lead or
Project Manager
>There is no complete information in the selenium IDE report format.
Selenium RC(Remote controller) :
>Selenium RC works with the server but selenium web driver doesn't work with the
server.
>Selenium RC Support multiple languages like java,c#, python, ruby, Perl, and PHP.
>Selenium Rc support multiple browsers like FF,IE, Chrome, opera, and safari.
>Selenium RC Support multiple operating systems like Windows and Linux.
>Selenium Rc support only old versions(In browser level and jar file
level).Nowadays most of the people and most of the companies following on latest
versions not old versions that's why selenium RC outdated(old version).
>Selenium RC support only web applications.
Selenium WebDriver :
>Selenium Webdriver Support multiple languages like java,c#, python, ruby, Perl,
and PHP.
>Selenium Webdriver support multiple browsers like FF,IE, Chrome, opera, and safari
and Edge browser.
>Selenium Webdriver Support multiple operating systems like Windows, Linux, and mac
os.
>Selenium Webdriver support old versions and the latest version also(In browser
level and jar file level).
>Selenium Webdriver supports web applications but not Mobile Applications and
Desktop Applications.

Here selenium Webdriver with the help of Appium tool to handle the Mobile
Applications.
Here selenium Webdriver with the help of AutoIt, Robot class to handle the Desktop
Applications.
>As we discussed up to here take this ----------part 1
Java:
>Here Selenium Webdriver Support multiple languages like java,c#, python, ruby,
Perl, and PHP.
>Here most of the people and most of the companies following on selenium webdriver
with java.
>Here 70% of people following on selenium webdriver with java.
>Here we need to learn (java oops concepts + Collections)- that means core
java(Core java enough)
>As we discussed up to here take this ----------part 2
TestNg :

>TestNG is a Testing unit Framework and it has been most popular within a short
time among test engineers.
>Testng inspired by JUnit(java platform) and Nunit(.Net platform).
>TestNG(latest version) has advance features compared to JUnit(old version)
>TestNG is an open-source Testing Unit Framework, where NG stands for Next
Generation
>You can use any one either junit or testng but both are not required.
Mainly Why we are using TestNG?
Ans: By using TestNG, we can create the selenium automation test cases, execute the
selenium automation test cases and generate the test Reports, and also generate the
log files.
Note :
1. Here Selenium IDE generate test reports but no detail(That means there is no
complete information in selenium ide report format)
2.Selenium RC OutDated(old version)
3. Here Selenium web driver does not generate the test reports, here selenium web
driver with the help of TestNG will generate the Test Reports.
>As we discussed up to here take this------------- part 3

Finally add three parts,


1 + 2 + 3====>Selenium WebDriver + Java + TestNG

Imp Points
>Cource Content--->Give me your Email id then I will send you Course Content
>Interview Questions and Answers on Java---->200+
>Interview Questions and Answers on Selenium--->200+
>Resume preparation --->After Course Complete
>Doubts sessions--->Daily
>Weekly Test --->Mon---Sat---->25+
>Job Assistance
>Mainly selenium and Java soft copy =low level students + average students + high-
level students

Selenium Java Training = Selenium basic level + Selenium Project level +Java
interview point of the level

Thanks.
Hanumanth P
Selenium Trainer

Developer

Test Engineer

Selenium Automation Testing


********************************

7386467494

Example 8
**************

byte b=129; //invalid int type value

System.out.println(b);
code Explanation :
*********************

>129
>byte type
>min - 128 to max 127

Note :
***********

>By default every integral literal value is what type int type value
>By default every floating-point literal value is what type double type value

F : int type value


R : byte

Short datatype in java ?


*************************
>+ve and -ve nos
>min -32768 to max 32767

Example 1
**************

short s=32767; //valid short type value

System.out.println(s);

>min -32768 to max 32767

F : short type value


R : short

Example 2
**************

short s=32.767; //invalid double type value

System.out.println(s);

F : double type value


R : short

Example 3
**************

short s=32767L; //invalid long

System.out.println(s);

F : long
R : short

int datatype in java ?


**************************

>+ve and -ve nos


>min -2147483648 to max 2147483647

Example 1
**************

int i=2345; //valid int

System.out.println(i);

Code Explanation :
***********************
>2345
>int type value
>min -2147483648 to max 2147483647

F : int
R : int

Example 2
**************

int i=2345L; //invalid long

System.out.println(i);

F : long
R : int

Example 3
**************

int i=23.45F; //invalid float

System.out.println(i);

F : float
R : int

long datatype in java ?


**************************

Example 2
***************
Definition 2:
********************
Ans : Here method name same but with different method signature then it is called
method overloading.

void m1(int a,int b)


void m1(int a,String b)
void m1(String a,String b)
void m1(String a,long b)
void m1(int a,String b,int c)

Program
**************

What is a method overriding in java ?


*****************************************
Definition 1 :
******************
Ans : Here i am not satisfied with parent class method implementation so that

in child class,i am rewriting that method(parent class method) with different

implementation then it is called method overriding.

Example 1
*************
Manual Steps
*****************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
**************

Can we override parent class method into child class ?


**********************************************************
Ans : Yes

>Here parent class method which is overridden then it is called overridden method

>Here Child class method which is overriding then it is called overriding method.

>This concept is called overriding concept

Note :
*********

>When i run this program by default JVM will always call to child class
method(overriding method)

not parent class method(overridden method)

Case 1
***********
Child C = new Child();

C.car_color();//call the car_color()

C.vehicle();//call the vehicle()

>
>
Case 2
***********

Wait 10min plz

float datatype in java ?


****************************

>+ve and -ve decimal value


>min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>We can specify floating-point literal value(float value or double value) only in
decimal form

Example 1
*************

float f=2.345F; //valid float

System.out.println(f);

F : float
R : float

Example 2
*************

float f=10.111111111F; // 9 1's valid float

System.out.println(f);

Example 3
*************

float f=25F; // valid float

System.out.println(f);

Example 4
*************

float f=25; // valid int

System.out.println(f);

Double datatype in java ?


******************************

>+ve and -ve decimal value

>min -1.7976931348623157e308d to max 1.7976931348623157e308D


Here e mean exponential form

>We can specify floating-point literal value(float value or double value) only in
decimal form

Example 1
*************

double d=2.345; // valid double

System.out.println(d);

Example 2
*************

double d=10.1111D; // valid double

System.out.println(d);

Example 3
*************

double d=10.1111111111111111D; // 16 1's valid

System.out.println(d);

Char datatype in java ?


***************************

>This will be used to store single character not group of characterss

Examples
*************

'H' or 'h' or '5' or '@'-------valid

'HJKL' or 'huioooo' or '57677' or '@*&(*('-------invalid

>Here everything in single quotes it's a character

>min 0 to max 65535

Example 1
*************

char ch="H"; // invalid String

System.out.println(ch);

Example 2
*************

char ch=H; // invalid

System.out.println(ch);
Example 3
*************

char ch='H'; // valid

System.out.println(ch);

Example 4
*************

char ch=68; // valid

System.out.println(ch);

what is a this keyword in java ?


*********************************8

How to call the current class instance variable from this keyword ?--IQ
*************************************************************
Syntax : this.variablename;

How to call the current class default constructor from this keyword ?--IQ
*************************************************************
Syntax : this();

How to call the current class parameterized constructor from this keyword ?--IQ
*************************************************************
Syntax : this(value1,value2);

How to call the current class method from this keyword ?--IQ
*************************************************************
Syntax : this.methodname();

long datatype in java ?


***************************

>+ve and -ve nos


>min -9223372036854775808 to max 9223372036854775807

Example 1
*************

long l=2345L; // valid long

System.out.println(l);

F : long
R : long

Example 2
*************
long l=125; // valid int

System.out.println(l);

min -2147483648 to max 2147483647

F : int
R : long

Example 3
*************

long l=12.5F; // valid int

System.out.println(l);

String datatype in java


*************************

>This will be used to store single character and group of characters

Examples
**************

"H" or "HYD" or "123" or "HYD123" or "%^%&^*()("

>Here everything in double-quotes it's a string


>Here String always must be in double quotes
>Here range not applicable for string datatype

Example 1
***************

String s=0; // invalid int

System.out.println(s);

F : int
R : String

Example 2
***************

String s=true; // invalid boolean

System.out.println(s);

F : boolean
R : String

Example 3
***************

String s=Hanumanth; // invalid

System.out.println(s);

>This is not applicable for any datatype


Example 4
***************

String s="Hanumanth"; // valid

System.out.println(s);

boolean datatype in java ?


****************************
>This will be used to store only boolean value such as true / false

>Here range not applicable for boolean datatype

Example 1
***************

boolean b=10; // invalid int

System.out.println(b);

Example 2
***************

boolean b="true"; // invalid String

System.out.println(b);

Example 3
***************

boolean b=True; // invalid

System.out.println(b);

Note :
*********

>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'

Example 4
***************

boolean b=true; // valid

System.out.println(b);

What is a method overriding in java ?


***************************************
Definition 2:
****************
>Here method name same and method signature same then this concept is called

method overriding concept.

Example
************
Manual Steps
****************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
**************

CAse 1
*********

Child C = new Child();

C.calculate(25.0);//call the calculate() and pass 25.0

Case 2
********
Parent C = new Child();

C.calculate(25.0);//call the calculate() and pass 25.0

CAse 3
**********
Parent C = new Parent();

C.calculate(25.0);//call the calculate() and pass 25.0

Method overriding rules


***************************

private(least) < protected < public(highest)

Method overloading Rules :


******************************

private(least) < protected < public(highest)


min 0 to max 65535(0 to 127)

Example 4
**************

char ch=65; // valid the ASCII value(65) of a character--'A'(char type value)

System.out.println(ch);

What is the ASCII value(65) of a character ?


******************************************
Ans : A

What is the ASCII value(97) of a character ?


******************************************
Ans : a

What is the ASCII value(115) of a character ?


******************************************
Ans : s

Example 5
**************

int i='D'; // valid the character('D') of ASCII value---68(int type value)

System.out.println(i);

What is the character('D') of ASCII value ?


*****************************************
Ans : 68

What is the character('g') of ASCII value ?


*****************************************
Ans : 103

Variable in java
*******************

int x=10;

What is a variable in java ?


*******************************
Ans :

variable types
***************
1.Instance variable
2.Local variable
3.Static variable

What is a Instance variable in java ?


****************************************
Ans :
>The values of the name and rollno are different from student to student such

type of variables are called instance variables.

>The values of the name and rollno are different from object to object such

type of variables are called instance variables.

Where we can create instance variables ?


********************************************
Ans : Inside the class or outside the method or outside the constructor or

outside the block(if,if-else,ladder if-else,while,do-while,forloop,static)

Example 1
*************

public class Student {

//instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//Error

CAn we access the instance variable into static area directly?


**********************************************************
Ans : No,we can't access

Object Syntax :
********************
//create the object for that student class

Student S = new Student();

Syntax Explanation :
************************

>Student()==>This is called Student constructor


>Here new is called keyword
Why we are using new keyword ?
***********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable

>Here Student is called class


Example 2
*************

public class Student {

//instance variable

String name="Sai";

public static void main(String[] args)


{
//create the object for that student class

Student S = new Student();

System.out.println(S.name);//Sai

CAn we access the instance variable into static area directly?


**********************************************************
Ans : No,but we can access through object reference

Calling default constructor from parameterized constructor


*************************************************************
Example
**************

Calling parameterized constructor from parameterized constructor


*******************************************************************

Example
***********

Why need constructor in java ?


*********************************

Inheritance in java(java oops concepts)


******************************************
Why need inheritance in java ?
********************************
Ans :

How to write the program,without inheritance ?


**************************************************
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create Mainclass

Java code
**************

What is a inheritance in java?


**********************************
Ans :

>

What are the advantages of inheritance ?


******************************************
Ans : By using inheritance,

1.We can reduce the code size


2.We can reduce the development time
3.We can avoid the duplicate code

What is the main advantage of inheritance ?


*********************************************
Ans : code reusability

Syntax
**********
class Superclass
{

}
class Subclass extends Superclass
{

Why we are using extends keyword ?


**************************************
Ans : By using extends keyword,we can inherit the subclass from superclass

Example
************
Manual Steps
***************
1.Create Superclass(Teacher class)
2.Create Subclass(Student class) from Superclass
3.Create Mainclass

Java code
****************

In superclass
****************

common code + Additional code(optional)


In subclass
***************

Additional code(Mandatory)

float datatype in java ?


*************************

>+ve and -ve decimal values


>min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>Here we can specify floating-point literal value(float value and double value)
only in decimal form

Example 1
**************

float f=2.345F; //valid float

System.out.println(f);

F :float
R : float

Example 2
**************

float f=10.111111111F; // 9 1's valid float

System.out.println(f);

Example 3
**************

float f=25F; // valid float

System.out.println(f);

Example 4
**************

float f=25; // valid int

System.out.println(f);

F : int
R : float

double datatype in java ?


***************************

>+ve and -ve decimal values


min -1.7976931348623157e308d to max 1.7976931348623157e308D

Here e mean exponential form

>Here we can specify floating-point literal value(float value and double value)
only in decimal form

Example 1
**************

double d=2.345; // valid double type value

System.out.println(d);

Example 2
**************

double d=2.345D; // valid double

System.out.println(d);

Example 3
**************

double d=10.1111111111111111D; // 16 1's valid

System.out.println(d);

Char datatype in java ?


**************************

>This will be used to store single character not group of characterss

Examples
***************
'H' or 'h' or '5' or '@'---------valid

'HHJHJKJKK' or 'hdfgd' or '56786' or '@*&(('---------invalid

>Here char value always must be in single quotes

>min 0 to max 65535(0 to 127)

Example 1
**************

char ch="H"; // invalid String

System.out.println(ch);

Example 2
**************

char ch=H; // invalid

System.out.println(ch);
Example 3
**************

char ch='H'; // valid char

System.out.println(ch);

Example 4
**************

char ch=68; //

System.out.println(ch);

Example 5
**************

int i='D'; //

System.out.println(i);

wait 10min plz

What is a abstract class in java ?


******************************
When we will go for abstract class in java ?
**************************************************
Ans :

abstract keyword in java ?


**************************
>Here abstract keyword is applicable only for methods and classes but not for
variables.

In general, abstract mean not clear,not complete,incomplete method,incomplete


class,

partial implementation just like that.

Here we need to learn 4 things


******************************
1.Concreate method
2.Concreate class
3.Abstract method
4.Abstract class

What is a Concreate method(regular method) in java ?


****************************************
Definition :
****************
A method has declaration part and implementation part such type of method is called

Concreate method.

Example
*************

public class Test {

//Concreate method

void m1()
{

}
//Concreate method

void m1(int a)
{

//Concreate method

public static void main(String[] args)


{

What is a Concreate class(regular class) in java ?


****************************************
Definition :
****************
A class can contain only concreate methods such type of class is called concreate
class.

Example
*************

public class Test { //implemented class

//Concreate method

void m1() //implemented method


{

}
//Concreate method

void m1(int a) //implemented method


{
}

//Concreate method //implemented method

public static void main(String[] args)


{

What is a abstract method in java ?


****************************************
Definition :
****************
A method has declaration part but not implementation part such type of method

is called abstract method.

Example
*************
public abstract class Test { Unimplemented class

//Concreate method

void m1() // implemented method


{

}
//abstract method

abstract void m2(); //Unimplemented method

>Here abstract method can be declared with abstract keyword such type of method

is called abstract method.

>Here abstract method should end with semicolon.

>Here abstract method must be override in child class

>Here who is the responsible to provide the implementation(body) for that abstract
method ?
***********************************************************************
Ans : Child class

>Here we can't create the object for that abstract class(Unimplemented class)

What is a abstract class in java ?


****************************************
Definition :
****************
A class can contain concreate method and abstract method such type of class is
called abstract class.

Example
*************
public abstract class Test { Unimplemented class

//Concreate method

void m1() // implemented method


{

}
//abstract method

abstract void m2(); //Unimplemented method

abstract class part 2


**************************

Example
**********
Manual Steps
***************
1.Create Superclass(Abstract class(Car))
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))
3.Create Subclass2(Santro) from Superclass(Abstract class(Car))
4.Create Mainclass

Java code
************

In superclass
*****************

common code + Additional code(optional)

common code
***************

1.regino
2.FuelTank
3.Steering
4.Brakes

In subclass
**************

Additional code(Mandatory)
Example 3
*************

Can we access the instance variable into instance area directly ?


*****************************************************************
Ans : Yes

When function will be called ?


********************************
Ans : Whenever u create an object after function will be called

Example 4
**************

public class Student {

//Instance variable

public static void main(String[] args)


{

Example 4
*************

public class Student {

//Instance variables

String name;
boolean b;
int i=10;

public static void main(String[] args)


{
Student S = new Student();

System.out.print.out.println(S.name);//null
System.out.print.out.println(S.b);//false
System.out.print.out.println(S.i);//10

}
Note :
**********

When i run this program by default JVM will provide default values for that
instance variables.

Example 5
*************

public class Student {

//Instance variables

private String name;


public boolean b;
protected int i=10;

public static void main(String[] args)


{
Student S = new Student();

System.out.print.out.println(S.name);//null
System.out.print.out.println(S.b);//false
System.out.print.out.println(S.i);//10

What are the access modifiers in java ?


*****************************************
1.private
2.public
3.protected
4.default

CAn we assign access modifiers for that instance variables ?


***************************************************************
Ans : Yes

CAn we access the instance variable anywhere ?


************************************************
Ans : No,but we can access through object reference

When instance variables will be accessible anywhere ?


************************************************
Ans : At the time of object creation

How many ways we can access instance variable anywhere ?


********************************************************
Ans : Only one way through object reference

Local variable in java ?


*****************************

class Test{

//method
void m1()
{
int x=10;//local variable

//constructor

Test()
{
int y=20;//local variable

//block

if()
{
int z=30;//local variable

Where we can create local variable ?


*****************************************
Ans : Inside the method or inside constructor or inside block such type of
variables

are called local variables.

Example 2
**************
public class Student {

public static void main(String[] args)


{

int j=1;//local variable

for(int i=1;i<3;i++)
{
System.out.println(i);//valid

System.out.println(j);//valid
}

System.out.println(i);//invalid

System.out.println(j);//valid

Example 3
**************
public class Student {
public static void main(String[] args)
{
//local variable

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error

Local variables Examples


****************************

int a; //invalid
int a=10;//valid
int a=0;//valid

Instanace variables Examples


****************************

int a; //valid
int a=10;//valid
int a=0;//valid

Static variables Examples


****************************

static int a; //valid


static int a=10;//valid
static int a=0;//valid

Example 4
**************
public class Student {

public static void main(String[] args)


{
//local variable

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error

}
}

types of inheritance
************************
1.Single inheritance
2.Multi-Level Inheritance
3.Hierarchical Inheritance

1.Single inheritance
*************************

Example 2
***************
manual Steps
****************
1.Create Superclass(Parent)
2.Create Subclass(Child) from Superclass(Parent)
3.Create Mainclass

Java code
***********

Case 1
*********

Child C = new Child();

C.m1();//call the m1()---valid


C.m2();//call the m2()---valid

>With child reference, we can call the parent class method


>With child reference, we can call the child class method

Case 2
*********
Parent C = new Child();

C.m1();//call the m1()---valid


C.m2();//call the m2()---invalid

>With Parent reference, we can call the parent class method


>With Parent reference, we can't call the child class method

Case 3
*********

Parent C = new Parent();

C.m1();//call the m1()---valid


C.m2();//call the m2()---invalid
>With Parent reference, we can call the parent class method
>With Parent reference, we can't call the child class method

2.Multi-Level Inheritance
***************************
Definition :
*****************
>Here Subclass1 acquired all the features of superclass and subclass2 acquired

all the features of subclass1 by using extends keyword then it is called Multi-
Level Inheritance.

Syntax:
**********
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Subclass1
{

Example 1
***********
Manual Steps
*****************

1.Create Superclass(GrandFather)
2.Create Subclass1(Father) from Superclass(GrandFather)
3.Create Subclass2(Son) from Subclass 1(Father)
4.Create Mainclass

Java code
**************

Definition :
**************

Example 2
***********

Manual Steps
*****************

1.Create Superclass(Calculation)
2.Create Subclass1(Sum) from Superclass(Calculation)
3.Create Subclass2(Subtraction) from Subclass 1(Sum)
4.Create Mainclass

Java code
**************

Hierarchical Inheritance
*****************************

Example 4
*************

char ch=68; //valid the ASCII value(68) of a character---'D'(char type value)

System.out.println(ch);//D

min 0 to max 65535(0 to 127)

What is the ASCII value(68) of a character ?


*******************************************
Ans : D

What is the ASCII value(97) of a character ?


*******************************************
Ans : a

What is the ASCII value(115) of a character ?


*******************************************
Ans : s

Example 5
*************

int i='G'; // valid the character('G') of ASCII value---71(int type value)

System.out.println(i);//71

What is the character('G') of ASCII value ?


**********************************************
Ans : 71

What is the character('d') of ASCII value ?


**********************************************
Ans : 100

Variable in java ?
**********************
Definition :
***************

int x=10;

Variable types
*****************
1.Instance variables
2.Local variables
3.Static variables

What are the Instance variables in java ?


*********************************************
Ans :

>The values of the name and rollno are different from student to student such

type of variables are called instance variables.

>The values of the name and rollno are different from object to object such

type of variables are called instance variables.

Where we can create instance variables ?


*****************************************
Ans : Inside the class or outside the method or outside the constructor or

outside the block(if,if-else,ladder if-else,switch,while,do-while,forloop,static)

Example 1
*************
public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{
System.out.println(name);// error

Can we access the instance variable into static area directly ?


*****************************************************************
Ans : No,we can't access

Object syntax :
*********************
//create the object for that student class

Student S = new Student();

Syntax Explanation :
***********************

>Student()==>This is called Student constructor

>Here new is called keyword

Why we are using new keyword ?


*********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable


>Here Student is called class

Example 2
*************
public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{

new Student();

System.out.println(name);// error

Can we access the instance variable into static area directly ?


*****************************************************************
Ans : No,but we can access through object reference

Abstract class part 2


**************************

Example
***********

Manual Steps
****************

Java code
***************

School project
*****************

Abstract class
*******************

1.Teacher ------100%------complete knowledge(void teacher(){})


2.Student ------100%------complete knowledge (void student(){})
3.chortboard----100%------complete knowledge (void chortboard(){})

4.fee------50%------incomplete knowledge (abstract void fee();)

abstract void atm();

Example 4
*************

public class Student {

public static void main(String[] args)


{
//local variables

private byte b=10; //invalid


public String s="Sai";//invalid
protected boolean b= false;//invalid

int x=10;//valid

final int y=20; //valid

CAn we assign access modifiers for that local variables ?


*******************************************************
Ans : No

>here final is called modifier


>here final means what constant
>Here y is called constant variable.So constant variable y value never be changed

that means no increment and no decrement.So always y is 20.

Can we access the local variable anywhere ?


******************************************
Ans : No,we can access inside the method or inside the constructor or inside the
block

When local variables will be accessible ?


**********************************************
Ans : While executing the methods or constructors or block
Static variable in java ?
*****************************

Definition :
****************

>The name of the college is same from student to student such type of variable is
called static variable.

>The name of the college is same from object to object such type of variable is
called static variable.

Where we can create static variable ?


*****************************************
Ans : Inside the class or outside the method or outside the constructor or outside
block

Example 1
*************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{
System.out.println(name);// Sai

CAn we access the static variable into static area directly ?


****************************************************************
Ans : Yes

Example 2
*************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(name);// Sai

}
Example 3
*************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(Student.name);// Sai

CAn we access the static variable into static area through classname ?
***************************************************************************
Ans : Yes

Syntax : classname.variablename

How many ways we can access the static variable ?


******************************************************
Ans : Three ways

1.Directly we can access


2.Through object reference
3.Through class name

Example 4
*************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(Student.name);// Sai

When static variable will be accessible ?


*********************************************
Ans :
Hierarchical Inheritance in java ?
*************************************
Definition :
**************

>Here multiple subclasses acquired all the features of one superclass by using
extends

keyword then it is called Hierarchical inheritance.

Syntax :
********

class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Superclass
{

}
class Subclass3 extends Superclass
{

Example 1
***********

Manual Steps
*****************
1.Create Superclass(Animal)
2.Create Subclass1(Dog) from Superclass(Animal)
3.Create Subclass2(Cat) from Superclass(Animal)
4.Create Subclass3(Cow) from Superclass(Animal)
5.Create Mainclass

Java code
**************
Case 1
**********
Dog D = new Dog();

D.eat();//call the eat()


D.bark();//call the bark()

>With Child reference ,we can call the parent class method
>With Child reference ,we can call the child class method

Case 2
**********
Animal D = new Dog();

D.eat();//call the eat()---valid


D.bark();//call the bark()----invalid

>With Parent reference ,we can call the parent class method
>With Parent reference ,we can't call the child class method

Example 2
***************

Difference betweeen super() and this() ?


*******************************************

Example 1
*************

class Test{

Test()
{

System.out.println("hanumanth");

super();//invalid
}
}

>Here super() must be in the 1st line in the constructor.

Example 2
*************

class Test{

Test()
{
super();//valid
System.out.println("hanumanth");

}
}
>Here always super() must be in the 1st line in the constructor.

Example 3
*************

class Test{

Test()
{

System.out.println("hanumanth");
this();//invalid

}
}

>Here this() must be in the 1st line in the constructor.

Example 4
*************

class Test{

Test()
{
this();//valid

System.out.println("hanumanth");

}
}

>Here always this() must be in the 1st line in the constructor.

Example 5
*************

class Test{

Test()
{
this();//valid-----1st place
super();//invalid----2nd palce
System.out.println("hanumanth");

}
}

Example 6
*************

class Test{

Test()
{
super();//valid-----1st place
this();//invalid----2nd palce
System.out.println("hanumanth");

}
}
Example 7
*************

class Test{

void Test()
{
super();//invalid

System.out.println("hanumanth");

}
}

Where we can create super() and this() ?


**********************************************
Ans : Inside the constructor only

Example 7
**************

> How to call the superclass default constructor using super()?


****************************************************************

How to call the super class default constructor ?


*******************************************************
Syntax : super();

Example
***********
manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
***********

How to call the super class parameterized constructor ?


*******************************************************
Syntax : super(value1,value2);

Example
***********
manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangel) from Superclass(Shape)
3.Create Mainclass

Java code
***********

How to call the current class default constructor ?


*******************************************************
Syntax : this();

How to call the current class parameterized constructor ?


*******************************************************
Syntax : this(value1,value2);

Selenium Automation Testing


*****************************

What is a Testing ?
***********************

Ans : To verify whether the functionality works well or not .i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure

Difference betweeen defect,error and failure ?--IQ


******************************************************
>Error : Developer
>Defect : Test Engineer
>Failure : Customer or User

Types of Testing
********************

1.Functional Testing
2.Non-functional Testing

Types of functional automation tools


******************************************
1.Opensource
==============
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.Sahi
4.Bad boy
5.Ruby
6.watir etc.

2.Commercial
================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4,Rft
5.Silk test etc.

Difference betweeen Selenium and Qtp ?--IQ


**********************************************
Selenium
*************
1.opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Only web app

Here Selenium + Appium---->mobile app

Here Selenium + AutoIT or sikuli or robot class---->desktop app

Qtp
********
1.commercial(paid tool)
2.Vbscript
3.FF,IE and chrome
4.Windows
5.Web app,mobile app and desktop app

History of selenium
************************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools


>Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid
>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium WebDriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium WebDriver+Extra features) + Selenium Grid


>2019

Selenium components---IQ
**************************

1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

Difference betweeen selenium IDE,RC and WebDriver ?--IQ


*********************************************************

Selenium IDE
*******************
1.Record and playback tool
2.FF and chrome
3.Web app
4.Selenium IDE Doesn't have any programming knowledge
5.Selenium IDE generate Test Reports but no details

no details
************
>Here selenium IDE reports are not effective to send the client ,Test Lead and
project manager

>There is no complete information in selenium IDE report format.

Selenium Rc
*****************
>Selenium RC works with server but selenium webdriver doesn't work with server

>Java,c#,python,ruby,perl and php


>FF,IE,chrome,opera and safari
>Windows and linux
>old versions only
>Only web app

Here Selenium + Appium---->mobile app

Here Selenium + AutoIT or sikuli or robot class---->desktop app

Selenium WebDriver
*********************

What is a Webdriver ?--IQ


***************************
Ans : Webdriver it's an interface in betweeen selenium automation test script

and Testing Application.

>Java,c#,python,ruby,perl and php


>FF,IE,chrome,opera and safari,Edge
>Windows and linux and mac os
>old and new versions also
>Only web app

Here Selenium + Appium---->mobile app

Here Selenium + AutoIT or sikuli or robot class---->desktop app

------------part 1

Java for selenium(core java enough)--------part 2


*********************************

Java,

80%--------selenium webdriver + java(java oops concepts + collections)

TestNG----------part 3
**************************

TestNG(latest)---Junit(old)

Why we are using TestNG ?


*****************************
Ans : By using Testng,we can create selenium automation test cases,execute

selenium automation test cases,it generate the Test Reports and also generate

log files.

Mainly Why we are using TestNG ?


*****************************

>Selenium IDE generate Test Reports but no details


>Selenium RC outdated(old)
>Selenium Webdriver doesn't generate the Test Reports and here selenium webdriver

with the help of TestNG will generate Test Reports.

Add three parts


*****************

1 + 2 + 3 --->Selenium WebDriver + Java + TestNG

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework

7386467494

Example 3
************

Can we access the instance variable into instance area directly ?


******************************************************************
Ans : Yes,we can access

Example 4
*************

public class Student {

//Instance variable

int i=10;
double d;
boolean b;

public static void main(String[] args)


{
//create the object for that student class

Student S = new Student();

System.out.println(S.i);//10
System.out.println(S.d);//0.0
System.out.println(S.b);//false

Example 5
*************

public class Student {

//Instance variable

private int i=10;


public double d;
protected boolean b;
public static void main(String[] args)
{
//create the object for that student class

Student S = new Student();

System.out.println(S.i);//10
System.out.println(S.d);//0.0
System.out.println(S.b);//false

What are the access modifiers in java ?


****************************************
Ans :

1.private
2.public
3.protected
4.default

CAn we assign access modifiers for that instance variables ?


*********************************************************
Ans : Yes

CAn we access the instance variable anywhere ?


*************************************************
Ans : No,but we can access through object reference

When instance variables will be accessible anywhere ?


*********************************************************
Ans : At the time of object creation

How many ways we can access the instance variable anywhere ?


*************************************************************
Ans : Only one way through object reference

Local variables in java ?


******************************

Example 1
***********
class Test{

//create method

void m1()
{

int x=10;//local variable


}

//constructor

Test()
{
int y=20;//local variable

//create block

if()
{

int z=30;//local variable


}

Where we can create local variables ?


*******************************************
Ans : Inside the method or inside the constructor or inside block such type of
variables

called local variables.

Exzample 2
***********

public class Student {

public static void main(String[] args) {

//local variable
int i;

int j;

System.out.println(i);//error

System.out.println(j);//error

Note :
********

>When i run this program by default JVM will not provide default values for that

local variables ,here compulsory we have to initialize the values for that local
variables.

Local variables examples


****************************
int a; //invalid
int a=0;//valid
int a=10;//valid
Instance variables examples
****************************
int a; //valid
int a=0;//valid
int a=10;//valid

static variables examples


****************************
static int a; //valid
static int a=0;//valid
static int a=10;//valid

Interface in java ?
************************

Why should we go for interface in java ?


******************************************
Ans :

Why should we go for Abstract class in java ?


******************************************
Ans :

Example
**********

Manual Steps
****************
1.Create Interface(Animal)
2.Create Subclass(Cat) from Interface(Animal)
3.Create MainClass

Java code
************

1.When i run this program by default JVM will provide public static final

for that variable.

CAn we change the variable value of interface ?


***************************************************
Ans : No

>In Interface, every variable are public static final

>In Interface, every variable and every method should be public

>Here abstract class is called Unimplemented class

>Here Interface is called Unimplemented interface


Note :
**********

>We can't create object for that class abstract(Unimplemented class) class and
interface(Unimplemented interface)

>We can create object for that implemented class

Difference betweeen extends and implements keywords ?


*******************************************************

extends keyword : By using extends keyword,we can inherit the subclass from
superclass

implements keyword : By using implements keyword,To implement an interface

in child class we must use implements keyword.

School project
******************

Abstract class :
*********************
case 1
***********
1.Teacher -------100%-----complete knowledge (void teacher(){})
2.Student--------100%-----complete knowledge (void student(){})
3.chortboard-----100%-----complete knowledge (void chortboard(){})

4.fee -----50%----------incomplete knowledge (abstract void fee();)

Interface concept:
************************

case 2
***********
1.Teacher -------50%-----incomplete knowledge (abstract void teacher();)
2.Student--------50%-----incomplete knowledge (abstract void student();)
3.chortboard-----50%-----incomplete knowledge (abstract void chortboard();)
4.fee -----50%----------incomplete knowledge (abstract void fee();)

Interface part 2
**********************

Instance variable part 2


***************************

Part 1
***********
1.Print 1st student details
2.Print 2st student details
---------
n.Print nth student details

Part 2
*********

1.Suppose if u want to print the 1st student details then we need to create

object for that 1st student.

2.Suppose if u want to print the 2st student details then we need to create

object for that 2st student.

3.Suppose if u want to print the nth student details then we need to create

object for that nth student.

part 3
***********
Print 1st student details
**************************

>First,initialize the values for that instance variables.


>Print 1st student details

Print 2st student details


******************************
>First,initialize the values for that instance variables.
>Print 2st student details

Print nth student details


*****************************

>First,initialize the values for that instance variables.


>Print nth student details

Instance variables part 2


************************

>For every object a separate copy of instance variables are created

>For every student a separate copy of name,rollno,marks will be created

If i change 1st stud1 marks then there are any effect for that remaining students
marks ?
**************************************************************************
Ans : No effect

Static variable part 2


***************************

>Create collegeName and share the collegename for all the students
>Create single copy and share this copy for all the objects.

If i change the 1st student collegeName then there are any effect for that

remaining students collename ?


**************************************************************************
Ans :Yes effect

Difference betweeen super and this keyword ?


************************************************

Why we are using super keyword ?


************************************
Ans : By using super keyword,we can call the superclass members(variables +
methods)

How to call the superclass variable ?


***************************************
Syntax : super.variablename

Example
***********
Manual Steps
****************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
*************

How to call the superclass method ?


***************************************
Syntax : super.methodname();

Example
***********
Manual Steps
****************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
*************
Why we are using this keyword ?
************************************
Ans : By using this keyword,we can call the current class members(variables +
methods)

How to call the current class variable ?


***************************************
Syntax : this.variablename

How to call the current class method ?


***************************************
Syntax : this.methodname();

polymorphism in java ?
**************************

poly---many

morphs---forms

polymorphism mean-------many forms

In real-world examples of polymorphism


*******************************************

Ex 1 : Here one form represents many forms then it is called polymorphism

Ex 2 : Here we have same name but with different sounds then it is called
polymorphism

Ex 3 : A person behaves like in different ways then it is called polymorphism

1.In shopping mall behave like a customer


2.In bus behave like a passenger
3.In school behave like a student
4.At home behave like a son

types of polymorphism
*************************

What is a Method overloading in java ?


*******************************
Definition 1 :
*******************
>Here method name same but with different argument types then this concept is
called method overloading concept

Example
**********

Definition 2 :
*******************

Selenium Automation Testing


*******************************

today 2nd class


******************

>If u want to access the java and selenium then we need to download JDK(Java
development kit) file first

Selenium 1st class


********************

What are the prerequisites to run the selenium webdriver ?


*************************************************************
Ans :

1.JDK file
2.Eclipse IDE/oxygen
3.Selenium jar files
4.Testing Application
5.browser

Part 1
*********
>download JDK(Java development kit) file first
>Install JDK(Java development kit) file into ur local system
>Verify JDK(Java development kit) file successful install or not into ur local
system
>Download Eclipse IDE / oxygen
>Directly open the Eclipse IDE /oxygen and here no need to install Eclipse IDE
/oxygen

Part 2
*********

1.Create new project


2.Create new package
3.Create new class
4.Add selenium jar files for that project

Example 5
***********

public class FirstProgram {

public static void main(String[] args) {

//local variables

int x=10;
final int y=20;// here y is called constant variable

switch(x){

case 0: System.out.println("Hello");//valid

case y: System.out.println("Hanumanth");//valid

fall-through inside switch block


***********************************

Ans : Here expression value is matched any case value from that case onwards

all the statements will be executed automatically until break statement then

this concept is called fall-through concept.

Example 6
***********
public class FirstProgram {

public static void main(String[] args) {

//local variables

byte b=0;

switch(b){

case 0: System.out.println("Sai");//valid

case 1: System.out.println("Akki");//valid

break;

case 2: System.out.println("Hanu");//valid

default: System.out.println("Kosmik");//valid
}

Example 7
***********

public class FirstProgram {

public static void main(String[] args) {

//local variables

char ch='r';

switch(ch){

case 'g': System.out.println("green");//valid

case 'r': System.out.println("Red");//valid

break;

case'y': System.out.println("yellow");//valid

default: System.out.println("no color");//valid


}

Default case rules


*********************
1.Here default case will be executed when expression value is not matched with

any case value.

2.In switch block,we can write default case only once

3.In switch block,we can write default case anywhere

Example 8
***********

public class FirstProgram {

public static void main(String[] args) {

//local variables

int furniture=0;

switch(furniture){

default: System.out.println("no furniture");//valid

case 0: System.out.println("table");//valid

case 1: System.out.println("chair");//valid

break;

case 2: System.out.println("cot");//valid

}
Datatype in java
*********************

int x=10;

What is a variable in java ?


********************************
Ans : variable is a memory location and here variable x can store some data

based on datatype then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script

>In java or other programming languages, we know we need variables to store

some data based on datatype.

>In java , every variable and every expression should have a datatype

types of datatypes
***********************
1.primitive datatypes
2.Non-Primitive datatypes

What are the integral integer datatypes in java ?--IQ


***************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


***************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


***************************************************
Ans : byte,short,int,long,float,double,boolean,char

What are the Non-primitive datatypes in java ?--IQ


***************************************************
Ans : String,array,set,list etc.

byte datatype in java ?


***************************

7386467494

Example 4
************

public class FirstProgram {

public static void main(String[] args) {

//local variables
private byte b=10; //invalid
public String s="Hanumanth";//invalid
protected boolean b= false;//invalid

int x=10; //valid

final int y = 20;//valid

}
>Here final is called modifier
>Here final means what constant
>Here y is called constant variable,here variable y value never be changed

that means no increment and no decrement.So always y is 20.

>CAn we assign final modifier for that local variable,instance variable and static
variable ?
**********************************************************************
Ans : Yes

CAn we assign access modifiers for that local variable ?


***********************************************************
Ans : NO

CAn we assign access modifiers for that Instance variable and static variable ?
***********************************************************
Ans : Yes

What are the access modifiers in java ?


******************************************
Ans :

1.private
2.public
3.protected
4.default

CAn we access the local variables anywhere ?


*********************************************
Ans : No,we can access inside the method or inside the constructor or inside the
block

When local variable will be accessible ?


*******************************************
Ans : While executing methods,constructor and block

Static variable in java ?


***************************
Definition:
*****************

>The name of the college is same from student to student such type of variable is
called static variable

>The name of the college is same from object to object such type of variable is
called static variable

Example 1
*************
public class FirstProgram {

//Static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//Sai

Can we access the static variable into static area directly ?


****************************************************************
Ans : Yes

Example 2
*************
public class Student {

//Static variable

static String name="Sai";

public static void main(String[] args)


{
//create the object for that student class

Student S = new Student();

System.out.println(S.name);//Sai

Can we access the static variable into static area through object reference ?
****************************************************************
Ans : Yes

Example 3
*************
public class Student {

//Static variable

static String name="Sai";

public static void main(String[] args)


{
System.out.println(S.name);//Sai

Can we access the static variable into static area through classname ?
****************************************************************
Ans : Yes

Syntax : classname.variablename

How many ways to access the static variable ?


***********************************************
Ans : 3 ways

1.Directly we can access


2.Through object reference
3.Through classname

Example 4
*************

When static variable will be accessible ?


****************************************
Ans :

What is a method / function in java ?


***************************************
Ans :

1.
2.
3.

Syntax :
*************

return-type methodname(para1,para2)
{

Statement1;
Statement2;
Statement3;
}

>Here method name always start with small letter and the next word start with
capital letter

Examples
***********

void add()
{
}

void addfunction()
{

}
void addFunction()
{

1.Write a program for a method,Without return-type and without passing parameters


*************************************************************************
Example 1
************

When function will be called ?


***********************************
Ans : Whenever u create an object after function will be called.

2.Write a program for a method,With return-type and without passing parameters


*************************************************************************
Example 2
************

3.Write a program for a method,Without return-type and with passing parameters


*************************************************************************
Example 2
************

Why we are using parameters ?


***********************************
Ans : By using these parameters,we can receive the data from outside into method

byte datatype in java ?


**************************

>This will be used to store +ve and -ve nos


>Here byte data type variable can store in the range of the values

min -128 to max 127

Example 1
**************

byte b=125; //valid byte type value

System.out.println(b);

Code Explanation :
*********************
>Here we are providing value is 125
>Here Expected value is byte datatype
>min -128 to max 127

java compiler work


**********************
>Compile the java code line by line (That means checking java code line by line
whether it is currect code or not)

JVM(java virtual machine) work


*********************************

>Simply execute the java code

Found : byte type value


Required : byte

Example 2
**************

byte b=127; //valid byte type value

System.out.println(b);

Code Explanation :
**********************
>127
>byte type value
>min -128 to max 127

F: byte type value


R : byte

Example 3
**************

byte b="Hanumanth"; //invalid String type value

System.out.println(b);

Note :
**********
>We can say this("Hanumanth") is a String type value
>Here String mean collection of characterss

Examples
************
"H" or "HYD" or "123" or "HYD123" or "%$^%&^^*&&"

>Here everything in double-quotes it's a string


>Here String always must be in double-quotes

F : String type value


R : byte

Example 4
**************

byte b=true; // invalid boolean type value

System.out.println(b);
Note :
**********
>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean type value


R : byte

Example 5
**************

byte b=127L; // invalid long type value

System.out.println(b);

Note :
***********
>Here We can say this(127L) is a long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
*************************************************************************
Ans : Yes

Datatype rules
****************

byte(least) < short < int < long < float < double(highest)

1.We can assign left-side data type value into any right-side datatype variable

2.We can't assign right-side datatype value into any left-side datatype variable

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required TypeCasting.

F : long type value


R : byte

Example 6
**************

byte b=10.5F; // invalid float

System.out.println(b);

Note :
**********

>We can say this(10.5F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
**************************************************************************
Ans : Yes

F : float
R : byte
Example 7
**************

byte b=10.5; // invalid

System.out.println(b);

Instance variable part 2


****************************

Part 1
********

1.Print 1st student details


2.Print 2nd student details
-----
3.Print nth student details

Part 2
***********

>Suppose if u want to print the 1st student details then we need to create object
for that 1st student

>Suppose if u want to print the 2nd student details then we need to create object
for that 2nd student

>Suppose if u want to print the nth student details then we need to create object
for that nth student

Part 3
***********

1.Print 1st student details


*********************************

>First,initialize the values for that instance variables


>Print 1st student details

2.Print 2nd student details


*******************************

>First,initialize the values for that instance variables


>Print 1st student details

3.Print nth student details


******************************

>First,initialize the values for that instance variables


>Print 1st student details

If i change the 1st student marks then there are any effect for that remaining
students marks ?
**************************************************************************
Ans : No effect

Instance variable part 2


**************************
>For every object a separate copy of instance variables are created

>For every Student a separate copy of name,rollno,marks will be created

Static variable part 2


***************************

>Create collegeName and share the collegeName for all the students

>Create single copy and share this copy for all the objects

Interface part 2
*********************
Multiple Inheritance in java?
********************************

>Here java doesn't support Multiple Inheritance(That means A class can't extend
multiple classes)

Syntax :
***********

class superclass1
{

}
class superclass2
{

}
class Subclass extends superclass1,superclass2
{
}
Example
************

class Father
{

}
class Mother
{

}
class Son extends Father,Mother
{

>A class can implement multiple intefaces

Syntax :
***********

class Interface1
{

}
class Interface2
{

}
class Subclass implements Interface1,Interface2
{

Example
***********

class Father
{

}
class Mother
{

}
class Son implements Father,Mother
{

Program :
***************
Manual Steps
***************
1.Create Interface1(Father)
2.Create Interface2(Mother)
3.Create Subclass(Son) from multiple interfaces
(Interface1(Father),Interface2(Mother))
4.Create Mainclass

Java code
************
Can we call the variable from inteface ?
*******************************************
Ans : yes

Syntax : interfacename.variablename

Can we call the variable from class ?


*******************************************
Ans : Yes

Syntax : classname.variablename

Son S = new Son(); //valid

Father S = new Son();//valid

Mother S = new Son();//valid

Father S = new Father();//invalid

Mother S = new Mother();//invalid

What is a class and object in java ?


****************************************

Examples
*************

Class : Vehicles Objects : car,bus,auto etc.


Class : Animals Objects : dog,cat,elephant etc.
Class : Furniture Objects : table,chair,cot etc.
Class : Fruits Objects : mango,orange,apple etc.

What is a object in java ?


****************************
Ans : it exists really / physically

Examples : car,dog,table,mango etc.

In real-world object has two things


*****************************************

1.State / properties
2.Behavior / Actions
What is a class in java ?
*****************************
Ans : It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

>Here class is a blueprint or Template or structure or design from which individual

objects are created.

>

In real-world car is a object and it has two things


*****************************************************

1.State / properties
2.Behavior / Actions

Object syntax
*****************

Student S = new Student();

Object syntax Explanation:


*****************
>Student()==>This is called Student constructor
>Here new is called keyword
Why we are using new keyword ?
*********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable

>Here Student is called class

Class Syntax :
********************
class <classname>
{

//1.State / properties-------variables

<datatype> variable1;
<datatype> variable2;

//2.Behavior / Actions-----methods

return-type methodname1()
{

}
return-type methodname2()
{
}

main()
{

Example
************

Difference betweeen class and object ?


*****************************************

Class
**********
1.It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

2.Why we are using class keyword ?


***********************************
Ans : By using class keyword,we can create class

3.In program,we can create class only once

4.Here memory space is not allowed when class is created

5.A class can contain variables and methods

Object
********
1.It exists really / physically

Examples : car,dog,table,mango etc.

2.Why we are using new keyword ?


*********************************
Ans : By using new keyword,we can create Student object(new Student();)

3.In program,we can create multiple objects

4.Here memory space is allowed when object is created

5.And object also can contain variables and methods

Methodoverloading in java ?
*******************************
Definition 2:
*****************
Ans : Here method name same but with different methid signature then this concept
is called method overloading concept.

Example 2
**********

void m1(int a,int b)


void m1(int a,int b,int c)
void m1(double a,int b)
void m1(int a,double b)
void m1(String a,int b)
void m1(int a,String b)

Program :
************

Method overriding in java ?


*********************************
Definition 1:
******************

>Here i am not satisfied with parent class method implementation so that

in child class ,i am rewriting that method(overridden method) with different

method implementation then it is called method overriding.

Example
***********
Manual Steps
****************

1.Create Parent class


2.Create Child class from Parent
3.Create Mainclass

Java code
**************

Can we override parent class method into child class ?


************************************************
Ans : yes

>Here parent class method is overridden then it is called overridden method.

>Here child class method which is overriding then it is called overriding

>This concept is called overriding concept


Note :
**********

When i run this program by default JVM will always call to child class
method(overriding method) not parent class method(overridden method)

Case 1
*********
Child C = new Child();

C.vehicle();//call the vehicle()

C.car_color();//call the car_color()

>With child reference,we can call the parent class method


>With child reference,we can call the child class method

Case 2
*********

Parent C = new Child();

C.vehicle();//call the vehicle()

C.car_color();//call the car_color()

>With Parent reference,we can call the parent class method


>With child reference,we can call the child class method

Case 3
*********

Parent C = new Parent();

C.vehicle();//call the vehicle()

C.car_color();//call the car_color()

>With Parent reference,we can call the parent class method


>With Parent reference,we can call the parent class method

Example 8
*************

byte b= 10.5555; //invalid double type value

System.out.println(b);

Note :
**********
>We can specify floating-point literal value(float value and double value) only in
decimal form

Float Examples
******************
10.5F,2.4f,10.1111F,-123.345F-------

Double Examples
******************

10.5,2.4,10.1111,-123.345-------

Note:
*********

F : double type value


R : byte

Example 9
*************

byte b= 129; //invalid int type value

System.out.println(b);

>129
>byte type value
>min -128 to max 127

What are the integral literal values ?


*****************************************
Ans : Byte value,short value,int value and long value

Note :
**********
>By default every integral literal value is what type int type value

>By default every floating-point literal value is what type double type value

F : int type value


R : byte

Short datatype in java ?


**************************
>+ve and -ve nos
>min -32768 to max 32767

Example 1
**************

short s=32767; // valid short

System.out.println(s);

>32767
>short type value
>min -32768 to max 32767
F : short
R : short

Example 2
**************

short s=32.767; // invalid double

System.out.println(s);

F : double
R : short

Example 3
**************

short s=32767L; // invalid long

System.out.println(s);

F : long
R : short

Example 4
**************

short s=32769; // invalid int

System.out.println(s);

>min -32768 to max 32767

F : int
R : short

Int datatype in java ?


**************************

>+ve and -ve nos


>min -2147483648 to max 2147483647

Example 1
**************

What is a method / function in java ?


****************************************

Definition:
**************
1.
2.
3.

Syntax :
**********
return-type methodname(para1,para2,para3)
{

Statement1;
Statement2;
Statement3;
}

>Here method name always start with small letter and then next word start with
capital letter

Examples
************
void add()
{

void addfunction()
{

}
void addFunction()
{

Write a program for a method,without return-type and without passing parameters.


******************************************************************************

Example
***********
When function will be called ?
********************************
Ans : Whenever u create an object after function will be called

Write a program for a method,with return-type and without passing parameters.


******************************************************************************

Example
***********

Write a program for a method,without return-type and with passing parameters.


******************************************************************************

Example
***********

Why we are using parameters ?


********************************
Ans : By using these parameters,we can receive the data from outside into method

Write a program for a method,with return-type and with passing parameters.


******************************************************************************
Example
***********

Note :
**********
Here method can never return more than one value

Examples
**************
return c; //valid

return a,b;//invalid

return a,return b;//invalid

Example 2
**************

Definition 2:
*****************
>Here method name same and method signature same then this concept is called method
overriding concept.

Manual Steps
****************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
**************

CAn we override parent class method into child class ?


********************************************************
Ans : Yes

CAse 1
********
Child C = new Child();

C.calculation(25.0);

>With child reference,we can call the child class method


CAse 2
********

Parent C = new Child();

C.calculation(25.0);

>With Parent reference,we can call the child class method

CAse 3
********

Parent C = new Parent();

C.calculation(25.0);

>With Parent reference,we can call the Parent class method

Method overriding rules


**************************

private(least) < protected < public(highest)

Method overloading rules


**************************

Abstract class in java ?


**************************

abstract keyword in java ?


*******************************
>Here abstract keyword is applicable for methods ,classes but not for variables.

>In general abstract mean not clear,not complete,incomplete method,incomplete


class,

partial implementation just like that

We need to learn 4 things


*******************************

1.concreate method
2.Concreate class
3.abstract method
4.abstract class

What is a concreate method(regular methods) in java ?


***************************************
Ans : A method has declaration part and implementation part such type of method is
called concreate method.

Example
***********

class Test{

//concreate method

void m1()
{

//concreate method

void m1(int i)
{

}
//concreate method

main()
{

}
What is a concreate class(regular class) in java ?
***************************************
Ans :A class can contain only concreate methods such type of class is called
concreate class.

Example
***********

class Test{

//concreate method

void m1()
{

//concreate method

void m1(int i)
{

}
//concreate method

main()
{

}
}

What is a abstract method in java ?


***************************************
Ans : A method has declaration part but not implementation part such type of method
is called abstract method.

Example
***********

abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

//abstract method

abstract void m2(); //Unimplemented method

>A method can be declared with abstract keyword then it is called abstract method

>Here abstract method should end with semicolon

>Here abstract method must be override in child class

>Who is the responsible to provide implementation for that abstract method ?


**********************************************************************
Ans : Child class

Note :
***********

>Here we can't create object for that abstract class(Unimplemented class)

>Here we can create object for that implemented class

What is a abstract class in java ?


***************************************
Definition :
*****************
A class can contain concreate methods and abstract methods such type of class is
called abstract class
Example
***********

abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

//abstract method

abstract void m2(); //Unimplemented method

Abstract class part 2


**************************

Selenium Automation Testing


*******************************

What is a Testing ?
***********************

>To verify whether the functionality works well or not . i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure.

Difference betweeen defect,error and failure ?--IQ


****************************************************
1.Error :Developer
2.Defect : Test Engineer
3.Failure : Customer or User

types of Testing
*********************
1.Functional Testing
2.Non-functional Testing

Types of functional automation tools


****************************************
1.Opensource
===============
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.sahi
4.Badboy
5.ruby
6.Watir etc.
2.commercial
==================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen Selenium and Qtp ?--IQ


********************************************

Selenium
***********
1.Opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here Selenium + Appium----->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

Qtp
********
1.commercial(paid tool)
2.Vbscript
3.FF,IE and chrome
4.Windows
5.Web app,mobile app and desktop app

History of Selenium
***********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium WebDriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium WebDriver+Extra features) + Selenium Grid


>2019

Selenium components---IQ
***************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

Difference betweeen Selenium IDE,RC and Webdriver ?--IQ


*********************************************************

Selenium IDE
**************
1.Record and playback tool
2.Ff and chrome
3.Web app only
4.Selenium IDE doesn't have any programming knowledge
5.Selenium IDE generate Test Reports but no details

no details
*************
1.Selenium IDE reports are not effective to send the client,Test Lead and project
manager.

2.There is no complete information in selenium IDE Report format.

Selenium Rc
**************
1.Selenium Rc works with server but selenium webdriver doesn't work with server.

2.Java,c#,python,ruby,perl and php


3.FF,IE,chrome,opera,safari
4.Windows and linux
5.old versions only
6.Web app only

Here Selenium + Appium----->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

Selenium WebDriver
*********************

What is a webdriver ?
************************
Ans : Webdriver it's an interface in betweeen selenium automation test script and
Testing Application.

2.Java,c#,python,ruby,perl and php


3.FF,IE,chrome,opera,safari and Edge
4.Windows and linux and mac os
5.old versions and latest versions also
6.Web app only

Here Selenium + Appium----->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

----------------part 1

Java for selenium(core java enough)----------part 2


******************************
Java,

80%--------->Selenium WebDriver + java(oops concepts + collections)

TestNG----------part 3
************************

TestNG(latest)---Junit(old)

Why we are using TestNG ?


*****************************
Ans : By using Testng, we can create selenium automation test cases,execute the

selenium automation test cases,it generate Test Reports and also generate log
files.

Mainly Why we are using TestNG ?


*****************************
1.Selenium IDE generate Test Reports but no details
2.Selenium Rc outdated(old)
3.Selenium Webdriver doesn't generate the Test reports,here selenium webdriver

with the help of TestNG will generate the Test Reports.

Add three parts,


*******************

1 + 2 + 3----->Selenium WebDriver + Java + TestNG

7386467494

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework

Abstract class part 2


***********************
Example
************

Manual Steps
**************
1.Create Superclass(Abstract class(Cat))
2.Create Subclass1(Maruti) from Superclass(Abstract class(Cat))
3.Create Subclass2(Santro) from Superclass(Abstract class(Cat))
4.Create MainClass

Java code
**************

Common code
***************
1.regino
2.FuelTank
3.Steering
4.Brakes

When we will go for abstract class ?


*************************************
Ans :

School project
*****************

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

4.fee---------50%----------incomplete knowledge (abstract void fee();)

abstract void atm();

Interface in java ?
**********************

When we will go for interface in java ?


***************************************
Ans :

Example
*********
Manual Steps
*****************
1.Create interface(Animal)
2.Create Subclass(Cat) from interface(Animal)
3.Create Mainclass

Java code
***************

>When i run this program by default JVM will provide public static final for that
variable.

Can we change the variable value of interface ?


**************************************************
Ans : No
>In the interface,all the variables are public static final
>In the Interface,every variable and every abstract method should be public

Difference betweeen extends and implements keyword ?


********************************************************

extends keyword : By using this, we can inherit the subclass from superclass

implements keyword : To implement an interface in child class we must use


implements keyword.

>We can create the object for that implemented class

>We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented interface)

School project
*****************

CAse 1
*************
Abstract class
******************

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

4.fee---------50%----------incomplete knowledge (abstract void fee();)

CAse 2
*************
Interface concept
***********************
1.Teacher---------50%-----incomplete knowledge (abstract void teacher();)
2.Student---------50%-----incomplete knowledge (abstract void student();)
3.chortboard------50%-----incomplete knowledge (abstract void chortboard();)
4.fee-------------50%-----incomplete knowledge (abstract void fee();)

Today 2nd class


*******************
>if u want to access the java and selenium then we need download JDK(Java
development kit) file first

Part 1
*********
1.download JDK(Java development kit) file first
2.Install JDK(Java development kit) file into ur local system
3.Verify JDK(Java development kit) file successful install or not into ur local
system
4.Download Eclipse IDE/oxygen
5.Directly open the Eclipse oxygen and here no need to install Eclipse oxygen
Part 2
***********
1.Create new JavaProject
2.Create new package
3.Create new class

Datatype in java ?
***********************

int x=10;

What is a variable in java ?


*******************************
Ans : Variable is a memory location and here variable x can store some data based
on datatype

then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script.

>In java or other programming languages,we know we need variables to store some
data based on datatype.

>In java , every variable and every expression should have a datatype.

types of datatypes
*******************
1.primitive datatypes
2.Non-Primitive datatypes

What are the integral integer datatypes in java ?--IQ


*****************************************************
Ans : Byte,short,int and long

What are the integral floating-point datatypes in java ?--IQ


*****************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


*****************************************************
Ans : Byte,short,int,long,float,double ,boolean and char

What are the non-primitive datatypes in java ?--IQ


*****************************************************
Ans : String,array,set,list etc

Byte datatype in java ?


***********************

Flow-control in java ?
***********************

Selection statements
************************
1.if
2.if-else
3.ladder if-else
4.switch

If statement
*****************

Syntax :
*************

if(boolean conditional-part/testing-part) // here must be boolean condition


{

//if body

}
Syntax Explanation :
*************************

>if(boolean conditional-part/testing-part)==>If condition is true then JVM will


execute if block.

>if(boolean conditional-part/testing-part)==>If the condition is false then JVM

will come of the if block and execute the statements that appear after if block.

Example 1
************
public class If_statement {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{

System.out.println("Animals age matched");

==---->By using this ,we can compare values or references

=---->By using this,we can assigning the value into variable.

>if(cat_age==dog_age)==>If condition is true then JVM will execute if block.

>if(cat_age==dog_age)==>If condition is false then JVM will print nothing output.

But my requirement if condition is false then JVM has to print something in the

console.So in this kind of situation we are going to use else part.


Example 2
************
public class If_statement {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{

System.out.println("Animals age matched");

}else
{
System.out.println("Animals age not matched");

Conclusion
************
>If u want to check only true condition then we have to go if statement.

>If u want to check true / false condition then we have TO go if-else statement.

Example 3
************
public class If_statement {

public static void main(String[] args)


{
int A=100;

if(100) // here must be boolean condition


{

System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

>if(100)==>Here JVM will expecting boolean value not integral literal value and
floating-point literal value.
>if(100)==>Here if u are trying to use any other type except boolean then
immediately

java compiler will through an error.

Found : int

Required : boolean

Example 4
************
public class If_statement {

public static void main(String[] args)


{
int A=100;

if(A>50) // here must be boolean condition


{

System.out.println("A is more than 50");

}else
{
System.out.println("A is less than 50");

Example 5
************
public class If_statement {

public static void main(String[] args)


{
int x=10;

if(x=20) // here must be boolean condition


{

System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

}
>int x=10;//now onwards x value will become 20
>if(x),here x means what 20

>if(20)==>Here JVM will expecting boolean value not integral literal value and
floating-point literal value.

Found : int
Required : boolean

Example 6
************
public class If_statement {

public static void main(String[] args)


{
int x=10;

if(x==20) // here must be boolean condition


{

System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

Example 7
************
public class If_statement {

public static void main(String[] args)


{
boolean b=true;

if(b=false) // here must be boolean condition


{

System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

>boolean b=true;//now onwards b value will become false


>if(b),here b means what false

>if(false)==>

Found : boolean
Required : boolean

Example 8
************
public class If_statement {

public static void main(String[] args)


{
boolean b=false;

if(b==false) // here must be boolean condition


{

System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

Can we can compare boolean values ?


****************************************
Ans : Yes

switch statement
*******************
>If u want to check one or more conditions then we have to go switch statement.

ArrayList in java ?
*********************

Why we are using arratList in java ?


****************************************
Ans :

Example 1
*************

A program must import java.util package to use arratList class


>Suppose if u want to store only integer type values then we should follow below
syntax

ArrayList<Integer> arralist = new ArrayList<Integer>();

Example
********

ArrayList<Integer> arralist = new ArrayList<Integer>();

arralist.add(10); //store 10 in an arralist through add()

arralist.add(20); //store 20 in an arralist through add()

arralist.add(30); //store 30 in an arralist through add()

arralist.add(40); //store 40 in an arralist through add()

>Suppose if u want to store only float type values then we should follow below
syntax

ArrayList<Float> arralist = new ArrayList<Float>();

Example
************
ArrayList<Float> arralist = new ArrayList<Float>();

arralist.add(10.1f); //store 10 in an arralist through add()

arralist.add(20.2f); //store 20 in an arralist through add()

arralist.add(30.3F); //store 30 in an arralist through add()

arralist.add(40.4f); //store 40 in an arralist through add()

>Suppose if u want to store only double type values then we should follow below
syntax

ArrayList<Double> arralist = new ArrayList<Double>();

Example
************

ArrayList<Double> arralist = new ArrayList<Double>();

arralist.add(10.1); //store 10 in an arralist through add()

arralist.add(20.2); //store 20 in an arralist through add()

arralist.add(30.3); //store 30 in an arralist through add()

arralist.add(40.4); //store 40 in an arralist through add()


>Suppose if u want to store only Boolean type values then we should follow below
syntax

ArrayList<Boolean> arralist = new ArrayList<Boolean>();

Example
***********
ArrayList<Boolean> arralist = new ArrayList<Boolean>();

arralist.add(true); //store 10 in an arralist through add()

arralist.add(true); //store 20 in an arralist through add()

arralist.add(false); //store 30 in an arralist through add()

arralist.add(false); //store 40 in an arralist through add()

>Suppose if u want to store only String type values then we should follow below
syntax

ArrayList<String> arralist = new ArrayList<String>();

Example
**********
ArrayList<String> arralist = new ArrayList<String>();

arralist.add("Sai"); //store 10 in an arralist through add()

arralist.add("Akki"); //store 20 in an arralist through add()

arralist.add("Hanu"); //store 30 in an arralist through add()

arralist.add("Kosmik"); //store 40 in an arralist through add()

>Suppose if u want to store only character type values then we should follow below
syntax

ArrayList<Character> arralist = new ArrayList<Character>();

Example
***********

ArrayList<Character> arralist = new ArrayList<Character>();

arralist.add('a'); //store 10 in an arralist through add()

arralist.add('b'); //store 20 in an arralist through add()

arralist.add('c'); //store 30 in an arralist through add()

arralist.add('d'); //store 40 in an arralist through add()

>Suppose if u want to store int,float,double,boolean,string,character type values


then we should follow below syntax

ArrayList arralist = new ArrayList();

Example
************
ArrayList arralist = new ArrayList();

arralist.add(10); //store 10 in an arralist through add()

arralist.add(10.5f); //store 20 in an arralist through add()

arralist.add(20.5); //store 30 in an arralist through add()

arralist.add('d'); //store 40 in an arralist through add()

arralist.add(true); //store 30 in an arralist through add()

arralist.add("Hanumanth"); //store 40 in an arralist through


add()

Interface part 2
******************

Multiple inheritance in java ?


*************************************

>Here java doesn't support multiple inheritance(Tha means A class can't extend
multiple classes)

Syntax:
*********
class Superclass1
{

}
class Superclass2
{

}
class Subclass extends Superclass1,Superclass2
{

}
Example
***********
Syntax:
*********
class Father
{

}
class Mother
{
}
class Son extends Father,Mother
{

>A class can implement multiple interfaces

Syntax :
*************
interface interface_name1
{

}
interface interface_name2
{

}
class Subclass implements interface_name1,interface_name2
{

Example
***********
interface Father
{

}
interface Mother
{

}
class Son implements Father,Mother
{

Program
***********
Manual Steps
***************
1.Create Interface1(Father)
2.Create Interface2(Mother)
3.Create Subclass(Son) from multiple interfaces(Interface1,Interface2)
4.Create Mainclass

Java code
***************

Can we access the variable from Interface ?


*********************************************
Ans : Yes

Syntax : interfacename.variablename

Can we access the variable from class ?


*********************************************
Ans : Yes

Syntax : classname.variablename

Son S = new Son();//valid

Father S = new Son(); //valid

Mother S = new Son();//valid

Father S = new Father();//invalid

Mother S = new Mother();//invalid

Today 2nd class


**************
>Here if u want to access the java and selenium then we need to download JDK(Java
development kit) file first

Part 1
*********
1.download JDK(Java development kit) file first
2.Install JDK(Java development kit) file into ur local system
3.Verify JDK(Java development kit) file successful install or not into ur local
system
4.Download Eclipse IDE/oxygen
5.Directly open the Eclipse IDE/oxygen and here no need to install Eclipse
IDE/oxygen

Part 2
*********
1.Create new JavaProject
2.Create new package
3.Create new class

Datatype in java ?
**********************

int x=10;

What is a variable in java ?


******************************
Ans : Variable is a memory location and here variable x can store some data

based on datatype then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script
>In java or other programming languages,we know we need variables to store some
data based on datatype

>In java,every variable and every expression should have a datatype

types of datatypes
**********************
1.primitive datatypes
2.Non-Primitive datatypes

What are the integral integer datatypes in java ?--IQ


*******************************************************
Ans : byte,short,int and long

What are the integral floating-point datatypes in java ?--IQ


*******************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


*******************************************************
Ans : byte,short,int,long,float,double,boolean,char

What are the non-primitive datatypes in java ?--IQ


*******************************************************
Ans : String,array,set,list etc.

byte datatype in java ?


**************************

byte datatype in java ?


***************************
>This will be used to store +ve and -ve nos
>Here byte datatype variable can store in the range of the values min -128 to max
127

Example 1
*************

byte b=125; //valid byte type value

System.out.println(b);

Code Explanation :
***********************
>Here we are providing value is 125

>Here Expected value is byte type value


>min -128 to max 127

Found : byte type value


Required : byte type value
Java compiler work
*********************

>Compile the java code line by line(That means checking the java code line by line
whether it is currect code or not)

JVM(Java virtual machine) work


********************************

>Simply execute the java code

Example 2
*************

byte b="Hanumanth"; //invalid String type value

System.out.println(b);

Note :
**********
>We can say this("Hanumanth") is a string type value
>Here String mean collection of characterss
Examples
**************

"HYD" or "H" or "123" or "HYD123" or "^%^&%&^^*&*"

>Here everything in double-quotes it's a string


>Here string always must be in double-quotes

Found : String type value


R : byte

Example 3
*************

byte b=127; //valid byte type value

System.out.println(b);

>127
>byte type value
>min -128 to max 127

F : byte type value


R : byte

Example 4
*************

byte b=true; // invalid boolean type value

System.out.println(b);

note :
*********
>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean type value


R : byte

Example 5
*************

byte b=127L; // invalid long type value

System.out.println(b);

Note :
**********
>We can say this(127L) is a long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is mandatory for that long type value ?
**************************************************************************
Ans : Yes

Datatype rules
*****************

byte(least) < short < int < long < float < double(highest)

>We can assign left-side datatype value into any right-side datatype variable.

>We can't assign right-side datatype value into any left-side datatype variable.

>Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required typecasting.

F : long
R : byte

Example 6
*************

byte b=10.5F; // invalid float

System.out.println(b);

>We can say this(10.5F) is float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
***************************************************************************
Ans : Yes

F : float
R : byte

Example 7
*************

byte b=10.5; // invalid


System.out.println(b);

Switch statement
******************
>Suppose If you want to check one or more conditions then we will go for a switch
statement.

Syntax :
***********

switch(Expression value){

case value 0 : statement 1--->code to be executed;


break;
case value 1 : statement 2--->code to be executed;
break;
case value 2 : statement 3--->code to be executed;
break;
default : statement 4--->Here default case will be executed when
expression value is not matched any case value;

Syntax Explanation :
***********************
1.
2.
3.
4.
5.
6.

Example 1
*************

public class Switch_Statement {

public static void main(String[] args) {

int a=10;

switch(a){

System.out.println("Hanumanth");

}
}

>In switch block,every statement should be under case value and default case
>In switch block,independent statement is not allowed.

Example 2
*************

public class Switch_Statement {

public static void main(String[] args) {

int x=10;
int y=20;

switch(x){

case 0 : System.out.println("Hello");//valid

case y : System.out.println("Hanumanth");//invalid
}
}

>In switch block,every case value should be constant not variable

Example 3
*************

public class Switch_Statement {

public static void main(String[] args) {

//local variables

int x=10;
final int y=20; //here y is called constant variable

switch(x){

case 10 : System.out.println("Hello");//Hello
case 11 : System.out.println("Hello");
case 12 : System.out.println("Hello");
case 13 : System.out.println("Hello");
case y : System.out.println("Hanumanth");//valid
}
}

Example 4
*************

public class Switch_Statement {

public static void main(String[] args) {

//local variables

int x=10;
switch(x){

case 10 : System.out.println("Hello");//valid
case 11 : System.out.println("Hello");//invalid
case 11 : System.out.println("Hello");//invalid

}
}

>In switch block,duplicate case value is not required

Example 4
*************

public class Switch_Statement {

public static void main(String[] args) {

//local variables

byte b=10; //min -32768 to max 32767

switch(b){

case 10 : System.out.println("Hello");//valid

case 100 : System.out.println("Hi");//valid

case 1000 : System.out.println("Hanumanth");//invalid

}
}

>Here byte datatype variable can store in the range of the values min -128 to max
127

min -128 to max 127

>Here case 10 is allowed in the range of the values min -128 to max 127

>Here case 100 is allowed in the range of the values min -128 to max 127

>Here case 1000 is not allowed in the range of the values min -128 to max 127

>Here if u are trying to use(case 1000) more than 127 then immediately java
compiler will through

an error

>In switch block,every case value should be in the range of the argument type.
Case value rules
**********************

>In switch block,every case value should be constant not variable

>In switch block,duplicate case value is not required

>In switch block,every case value should be in the range of the argument type.

fall-through(fall-down) inside switch block


***********************************

What is a fall-through in java ?


***********************************
Ans :

Example 5
*************

public class Switch_Statement {

public static void main(String[] args) {

//local variables

int x=0;

switch(x){

case 0 : System.out.println("Hello");//valid

case 1 : System.out.println("Hi");//valid

break;

case 2 : System.out.println("Hanumanth");//invalid

default : System.out.println("NewIndia");//invalid

}
}

ArrayList part 2
*******************

Can we store duplicate values in an arralist ?


*************************************************
Ans : Yes

CAn we remove 20 in an arralist ?


*************************************
Ans : Yes

Syntax :
*************
array_list.remove(index);

Example
**********
array_list.remove(1); //removed 20 in an arralist

Program
************

Can we replace 20 with 50 in an arralist ?


**********************************************
Ans : Yes

Syntax :
*************

array_list.set(int index,object obj);

Example
*************
array_list.set(1,50); //replaced 20 with 50 in the position of 1

Program
************

Can we insert 50 in the position of 1 ?


*******************************************
Ans : Yes

Syntax :
**************

array_list.add(int index,object obj);

Example
*********

array_list.add(1,50); //insert 50 in the position of 1

Program
***********
can we remove all the values present in the arralist ?
**********************************************************
Ans : Yes

Syntax :
**********
array_list.clear();

Example
***********

array_list.clear();//remove all the values present in the arralist

Program :
*************
How to verify arralist has empty or not ?
*********************************************
Ans : By using isEmpty()

Syntax :
************

array_list.isEmpty();

Example
**********

array_list.isEmpty(); //verify arralist has empty or not

Note :
**********

>If arralist has empty then it returns true


>If arralist has not empty then it returns false

Program :
*************

Flow-control in java ?
**********************

1.Selection statement
*************************
1.if
2.if-else
3.ladder if-else
4.switch

If statement
*****************

Syntax :
*********

if(boolean conditional-part/testing-part) //here must be boolean condition


{
// if body

}
Syntax Explanation :
**********************

1.
2.

Example 1
***********

public class If_Statement {

public static void main(String[] args) {

int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

==----->By using this,we can compare values or references


=------>By using this,we can assigning the value into variable

>If condition is false then JVM will print nothing output

Example 2
***********

public class If_Statement {

public static void main(String[] args) {

int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}else
{

System.out.println("Animals age not matched");


}

Conclusion
**************
1.if
2.if-else

Example 3
***********

public class If_Statement {

public static void main(String[] args) {

int A=100;

if(100) //here must be boolean condition


{
System.out.println("Hello");

}else
{

System.out.println("Hanumanth");
}

1.
2.

Found : int
Required : boolean

Example 4
***********

public class If_Statement {

public static void main(String[] args) {

int A=100;

if(A>50) //here must be boolean condition


{
System.out.println("A is greater than 50");

}else
{

System.out.println("A is less than 50");


}

Example 5
***********

public class If_Statement {


public static void main(String[] args) {

int x=10;

if(x=20) //here must be boolean condition


{
System.out.println("Hello");

}else
{

System.out.println("Hanumanth");
}

>int x=10;//now onwards x value will become 20

>if(x),here x means what 20

>if(20)==>

F : int
R : boolean

Example 6
***********

public class If_Statement {

public static void main(String[] args) {

int x=10;

if(x==20) //here must be boolean condition


{
System.out.println("Hello");

}else
{

System.out.println("Hanumanth");
}

Example 7
***********

public class If_Statement {

public static void main(String[] args) {

boolean b=true;
if(b=false) //here must be boolean condition
{
System.out.println("Hello");

}else
{

System.out.println("Hanumanth");
}

>boolean b=true;//now onwards b value will become false


>if(b),here b means what false
>if(false)

f : boolean
R : boolean

Example 8
***********

public class If_Statement {

public static void main(String[] args) {

boolean b=false;

if(b==false) //here must be boolean condition


{
System.out.println("Hello");

}else
{

System.out.println("Hanumanth");
}

Can we compare boolean values ?


***********************************
Ans : Yes

Switch statement
******************

Ans : Suppose if u want to check one or more conditions then we have to switch
statement

Syntax :
************

switch(Expression value){
case value 0 : statement1--->code to be executed ;
break;

case value 1 : statement2--->code to be executed ;

break;
case value 2 : statement3--->code to be executed ;

break;

default : statement4--->Here default case will be executed when


expression value is not matched any case value ;

Syntax Explanation :
*************************
1.
2.
3.
4.
5.
6.

Example 1
**************
public class Switch_Statement {

public static void main(String[] args) {

int x=10;

switch(x){

System.out.println("hanumanth");

1.In switch block,every statement should be under case value and default case

2.In switch block,independent statement is not allowed

Example 2
**************
public class Switch_Statement {

public static void main(String[] args) {

int x=10;
int y=20;

switch(x){
case 10 : System.out.println("Hello");//valid

case y : System.out.println("hanumanth");//invalid
}

}
>In switch block,every case value should be constant not variable

Example 3
**************
public class Switch_Statement {

public static void main(String[] args) {

int x=10;
int y=20;

switch(10){

case 10 : System.out.println("Hello");//invalid

case 10 : System.out.println("hanumanth");//invalid
}

>In switch block,duplicate case value not required

Example 4
**************
public class Switch_Statement {

public static void main(String[] args) {

int x=10;
final int y=20;

switch(x){

case 10 : System.out.println("Hello");//invalid

case 11 : System.out.println("hanumanth");//invalid
}

}
ArrayList in java ?
*********************

Why we are using arralist ?


********************************
Ans :

Example
***********

A program must import java.util package to use arrayList class

>Suppose if u want to store only integer type values then we should follow below
syntax

ArrayList<Integer> arraylist = new ArrayList<Integer>();

Example
*********

arraylist.add(10); // store 10 in an arraylist object through add()

arraylist.add(20); // store 20 in an arraylist object through add()

arraylist.add(30); // store 30 in an arraylist object through add()

arraylist.add(40); // store 40 in an arraylist object through add()

>Suppose if u want to store only float type values then we should follow below
syntax

ArrayList<Float> arraylist = new ArrayList<Float>();

Example
*********
ArrayList<Float> arraylist = new ArrayList<Float>();

arraylist.add(10.1f); // store 10 in an arraylist object through add()

arraylist.add(20.2F); // store 20 in an arraylist object through add()

arraylist.add(30.3f); // store 30 in an arraylist object through add()

arraylist.add(40.4f); // store 40 in an arraylist object through add()

>Suppose if u want to store only double type values then we should follow below
syntax

ArrayList<Double> arraylist = new ArrayList<Double>();

Example
***********
ArrayList<Double> arraylist = new ArrayList<Double>();

arraylist.add(10.1); // store 10 in an arraylist object through add()


arraylist.add(20.2); // store 20 in an arraylist object through add()

arraylist.add(30.3); // store 30 in an arraylist object through add()

arraylist.add(40.4); // store 40 in an arraylist object through add()

>Suppose if u want to store only String type values then we should follow below
syntax

ArrayList<String> arraylist = new ArrayList<String>();

Example
********
ArrayList<String> arraylist = new ArrayList<String>();

arraylist.add("Sai"); // store 10 in an arraylist object through add()

arraylist.add("Akki"); // store 20 in an arraylist object through


add()

arraylist.add("Hanu"); // store 30 in an arraylist object through


add()

arraylist.add("Kosmik"); // store 40 in an arraylist object through


add()

>Suppose if u want to store only Boolean type values then we should follow below
syntax

ArrayList<Boolean> arraylist = new ArrayList<Boolean>();

Example
***********
ArrayList<Boolean> arraylist = new ArrayList<Boolean>();

arraylist.add(true); // store 10 in an arraylist object through add()

arraylist.add(true); // store 20 in an arraylist object through add()

arraylist.add(false); // store 30 in an arraylist object through add()

arraylist.add(false); // store 40 in an arraylist object through add()

>Suppose if u want to store only character type values then we should follow below
syntax

ArrayList<Character> arraylist = new ArrayList<Character>();

Example
***********
ArrayList<Character> arraylist = new ArrayList<Character>();

arraylist.add('a'); // store 10 in an arraylist object through add()

arraylist.add('b'); // store 20 in an arraylist object through add()

arraylist.add('c'); // store 30 in an arraylist object through add()


arraylist.add('d'); // store 40 in an arraylist object through add()

>Suppose if u want to store int,float,double,boolean,String,character type values


then we should follow below syntax

ArrayList arraylist = new ArrayList();

Example
************
ArrayList arraylist = new ArrayList();

arraylist.add(10); // store 10 in an arraylist object through add()

arraylist.add(10.5f); // store 20 in an arraylist object through add()

arraylist.add(20.4); // store 30 in an arraylist object through add()

arraylist.add(true); // store 40 in an arraylist object through add()

arraylist.add("hanumanth"); // store 30 in an arraylist object through


add()

arraylist.add('d'); // store 40 in an arraylist object through add()

CAn we remove 20 in an arrayList?


************************************
Ans : Yes

Syntax :
***********

arraylist.remove(index);

Example
**********

arraylist.remove(1); //remove 20 in an arrayList

Program
**********

CAn we store duplicate values in an arrayList?


*************************************************
Ans : Yes

Can we replace 20 with 50 in an arrayList?


***************************************************
Ans : Yes

Syntax :
***********
arraylist.set(int index,Object obj);

Example
***********

arraylist.set(1,50); //replace 20 with 50 in the position of 1


Program
***********

Can we insert 50 in the position of 1 in an arralist?


***************************************
Ans : Yes

Syntax :
***********

arraylist.add(int index,Object obj);

Example
***********

arraylist.add(1,50); //insert 50 in the position of 1

Program
********

Can we remove all the values present in the arrayList ?


**********************************************************
Ans : Yes

Syntax :
**********
arraylist.clear();

Example
***********

arraylist.clear(); //remove all the values present in the arrayList

Program
************

How to verify arralist has empty or not ?


**********************************************
Ans : By using isEmpty()

Syntax :
***********

arraylist.isEmpty();

Example
************

arraylist.isEmpty(); //verify arralist has empty or not

>If arrayList has empty then it returns true


>If arralist has not empty then it returns false

Program :
**************
Example 8
*************

byte b= 10.5; //invalid double type value

System.out.println(b);

F : double type value


R : byte

What are the integral literal values ?


****************************************
Ans : byte value,short value,int value and long value

What are the integral floating-point literal values ?


********************************************************
Ans : float value and double value

Note :
*********
>We can specify floating-point literal value(float value and double value) only in
decimal form

>By default every floating-point literal value is what type double type value

>By default every integral literal value is what type int type value

Float Examples
**************

10.5f,2.4F,10.1111F,-124.345F-------

Double examples
*******************

10.5,2.4,10.1111,-124.345-------

Example 9
*************

byte b= 129; // invalid int

System.out.println(b);

>128
>byte type value
>min -128 to max 127

F : int
R : byte
Short datatype in java ?
**************************
>+ve and -ve nos
>min -32768 to max 32767

Example 1
*************

short s= 32767; // valid short

System.out.println(s);

>32767
>short type value
>min -32768 to max 32767

F : short
R : short

Example 2
*************

short s= 32.767; // invalid double

System.out.println(s);

Example 3
*************

short s= 32767L; // invalid long

System.out.println(s);

Example 4
*************

short s= 32769; // invalid int

System.out.println(s);

>min -32768 to max 32767

min -128 to max 127

int datatype in java ?


**************************

>+ve and -ve nos


>min -2147483648 to max 2147483647

Example 1
*************

int i= 2345; // valid int

System.out.println(i);
>2345
>int type value
>min -2147483648 to max 2147483647

Example 2
*************

int i= 23.45F; // invalid float

System.out.println(i);

Example 3
*************

int i= 2345L; // invalid long

System.out.println(i);

Selenium 1st class


********************

What are the prerequisites to run the selenium webdriver ?


*************************************************************
Ans :

1.JDK file
2.Eclipse IDE/oxygen
3.Selenium jar files
4.Testing Application
5.browser

byte datatype in java ?


*************************

>This will be used to store +ve and -ve nos


>Here byte datatype variable can store in the range of the values

min -128 to max 127

Example 1
**************

byte b=125; //valid byte

System.out.println(b);

Code Explanation :
**********************
>Here we are providing value is 125
>Here Expected value is byte type value
>min -128 to max 127

Found : byte type value

Required : byte

Java compiler work


**********************

>Compile the java code line by line (That means checking the java code

line by line whether it is currect code or not)

JVM(Java virtual machine) work


*********************************

Simply Just execute the java code

Example 2
**************

byte b="Hanumanth"; //invalid String type value

System.out.println(b);

Note:
**********
>We can say this("Hanumanth") is a string type value

>Here String mean collection of characterss

Examples
**************

"HYD" or "H" "123" or "HYD123" or "%^$^&*&(*("

>Here everything in double-quotes it's a String

>Here String always must be in double-quotes

F : String type value


R : byte

Example 3
**************
byte b=127; // valid byte type value

System.out.println(b);

>127
>byte type value
>min -128 to max 127

F : byte type value


R :byte

Example 4
**************

byte b=true; // invalid boolean type value

System.out.println(b);

Note :
********
>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean type value


R : byte

Example 4
**************

byte b=127L; // invalid long type value

System.out.println(b);

F : long
R : byte

>We can say this(127L) is a long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
*************************************************************************
Ans : Yes

Datatype rules
*****************

byte(least) < short < int < long < float < double(highest)

1.We can assign left-side datatype value into any right-side datatype variable.

2.We can't assign right-side datatype value into any left-side datatype variable

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required TypeCasting.


Example 5
**************

byte b=10.5F; // invalid float

System.out.println(b);

F : float
R : byte

>We can say this(10.5F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
********************************************************************
Ans : Yes

Example 7
**************

byte b=10.5; // invalid

System.out.println(b);

long datatype in java ?


***************************
>+ve and -ve nos
> min -9223372036854775808 to max 9223372036854775807

Example 1
*************

long l=127L; //valid long

System.out.println(l);

Found : long
Required : long

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
***************************************************************************
Ans : Yes

Example 2
*************

long l=12.7; // invalid double

System.out.println(l);

F : double
R : long
Example 3
*************

long l=127; // valid int

System.out.println(l);

F : int
R : long

String datatype in java ?


****************************

>This will be used to store single character and group of characters.


>Here range not applicable for string datatype

Examples
*************
"HYD" or "H" or "123" or "HYD123" or "%$^%^&*&(*"

>Here everything in double quotes it's a string

>Here string always must be in double-quotes

Example 1
*************

String s=10; // invalid int

System.out.println(s);

Note :
**********
>By default every integral literal value is what type value int type value

>By default every floating-point literal value is what type double type value.

F : int
R : String

Example 2
*************

String s=true; // invalid

System.out.println(s);

F : boolean
R : String

Example 3
*************

String s=Hanumanth; // invalid

System.out.println(s);
Example 4
*************

String s="Hanumanth"; // valid String

System.out.println(s);

F : String
R : String

Boolean datatype in java ?


***************************

>This will be used to store only boolean value such as true /false

>Here range not applicable for boolean datatype

Example 1
*************

boolean b=0; // invalid int

System.out.println(b);

Example 2
*************

boolean b=True; // invalid

System.out.println(b);

>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'

Example 3
*************

boolean b="true"; // invalid String

System.out.println(b);

Example 4
*************

boolean b=true; // valid

System.out.println(b);

float datatype in java ?


**************************

Selenium Automation Testing


*******************************
What is a Testing ?
*********************
>To verify whether the functionality works well or not .i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure.

Difference betweeen defect,error and failure ?--IQ


**************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

types of Testing
******************
1.functional Testing
2.Non-functional Testing

Types of functional automation tools


***************************************
1.opensource
===============
1.Selenium Rc(Remote controller)
2.selenium webdriver
3.sahi
4.badboy
5.ruby
6.watir etc.

2.commercial
================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen selenium and qtp ?--IQ


******************************************

Selenium
*************
1.Opensource(free of cost)
2.Java,c#,python,ruby,perl and php.
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here selenium + Appium---->mobile app

Here Selenium + Autoit or sikuli or robot class--->desktop app

QTP
********
1.commercial(paid tool)
2.Vbscript
3.FF,IE and chrome
4.Windows
5.Web app,mobile app and desktop app

History of selenium
*******************

>It was came into 2004 by jason huggins


>Selenium 1 have 3 tools

>Selenium IDE+Selenium RC+Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE+Selenium RC+ Selenium Webdriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE+ Selenium Webdriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE+ (Selenium Webdriver+Extra features) + Selenium Grid


>2019

Selenium Components---IQ
****************************
1.selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

Difference betweeen selenium IDE,RC and Webdriver ?--IQ


*********************************************************

Selenium IDE
*****************
1.Record and playback tool
2.FF and chrome
3.Web app only
4.Selenium IDE doesn’t have any programming knowledge
5.Selenium IDE generate Test Reports but no details

no details
***************
1.Here Selenium IDE reports are not effective to send the client,TestLead and
project manager.

2.There is no complete information in selenium ide report format.

Selenium Rc
***************
>Here selenium RC works with server but selenium webdriver doesn't work with
server.

>Java,c#,python,ruby,perl and php.

>FF,IE,chrome,opera and safari


>Windows and linux
>old versions only
>Web app only
Here selenium + Appium---->mobile app

Here Selenium + Autoit or sikuli or robot class--->desktop app

Selenium webdriver
*******************
What is a webdriver ?
************************
Ans : Webdriver it's an interface in betweeen selenium automation test script and
Testing Application.

>>Java,c#,python,ruby,perl and php.


>FF,IE,chrome,opera and safari and Edge
>Windows and linux and mac os
>old and new versions also
>Web app only

Here selenium + Appium---->mobile app

Here Selenium + Autoit or sikuli or robot class--->desktop app

----------------part 1

Java for selenium(core java enough)--------part 2


*********************************

Java,

80%----------selenium webdriver + java(java oops concepts +collections)

TestNG--------part 3
************************

TestNG(latest)----Junit(old)

Why we are using TestNG ?


****************************
Ans : By using testNG,we can create selenium automation test cases ,execute

the selenium automation test cases ,it generate Test Reports and also generate

log files

Mainly Why we are using TestNG ?


****************************

1.Selenium IDE generate Test Reports but no details


2.Selenium RC outdated(old)
3.Selenium WebDriver doesn't generate the Test Reports and here selenium webdriver

with the help of TestNG will generate the Test Reports.

Add three parts


*******************

1+ 2 + 3 ----->Selenium webdriver + java + TestNG


AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


Keyword driven framework
Hybrid framework

Example 3
**************
public class Test {

public static void main(String[] args) {

int j=1; //local variable

for(int i=1;i<3;i++)
{

System.out.println(i);

System.out.println(j);
}

System.out.println(i);

System.out.println(j);
}

Nested forloop(forloop inside another forloop) in java ?


*********************************************************

Syntax :
**********

for(initialization-part ; conditional-part/testing-part ; increment/decrement-part)


{
for(initialization-part ; conditional-part/testing-part ; increment/decrement-
part)
{

//Inner forloop body

}//Inner forloop end

//Outer forloop body

}//Outer forloop end

Syntax Explanation :
***********************

Example
************

Output
**********
0 1 2
3 4 5
6 7 8

Difference betweeen print() and println() in java?


*********************************************
print()
***********
>By using this ,we can print the text and the curser waits on the same

line to print the next text.

Example
***********

System.out.print("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
***********
Hello---Hi---
Hanumanth

println()
**************

Example
***********

System.out.print("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");
Output
***********

What is a default package of selenium ?


***************************************
Ans : org.openqa.selenium

get() :

Testing = operation code + verification code

How to verify title of the webpage ?


****************************************
Ans :

Manual Steps
***************
 Get the Title of the WebPage
 Print the title of the webpage
 Verify Title of the WebPage

selenium java code


*********************
//------------------------operation code

// Get the Title of the WebPage

String title = driver.getTitle();

// Print the title of the webpage

System.out.println(title);//OrangeHRM - New Level of HR Management

//--------------------------verification code

// Verify Title of the WebPage

if(title.equals("OrangeHRM - New Level of HR Management"))


{

System.out.println("title verified successfully");


}else
{
System.out.println("title not verified successfully");
}

Loops in java ?
*********************
WHy we are using loops in java ?
************************************
Ans : Here loops are used to execute a group of statements repeatedly

as long as the condition is true.

Example 1
***************

public class FirstProgram {

public static void main(String[] args) {

System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");

}
types of loops
*************

3.forloop

Where exactly we can use forloop ?


***********************************
Ans : Sometimes we need to perform same action with multiple times so at that

time we need to follow forloop.

Example 2
************
Syntax :
***************

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{

//loop body

Syntax Explanation :
*********************
1.
2.

How to print 1(starting)-1000(ending) nos ?


**************************
1
2
3
4
5
............10

i++

i=i+1
i=1+1
i=2
---------------
i++

i=i+1
i=2+1
i=3

Example 2
**************
public class FirstProgram {
public static void main(String[] args) {

int j=1; //local variable

for(int i=1;i<=10;i++)
{

System.out.println(i);

System.out.println(j);
}

System.out.println(i);

System.out.println(j);
}

Nested forloop(forloop inside another forloop) in java ?


**********************************************************

Output
**********

0 1 2
3 4 5
6 7 8

Difference betweeen print() and println() in java ?


******************************************************

print():
***********
>By using this ,we can print the text and the curser waits on the same line

to print the next text.

Example
**************
System.out.print("Hello---");
System.out.println("HI---");
System.out.println("Hanumanth");

Output
***********
Hello---HI---
Hanumanth

println():
**************
>By using this,we can print the text and the curser move next line automatically
to print the next text.

Example
**************
System.out.println("Hello---");
System.out.println("HI---");
System.out.println("Hanumanth");

Output
***********

Hello---
HI---
Hanumanth

What is a default package of selenium ?


****************************************
Ans : org.openqa.selenium

Why we will import the packages ?


**********************************
Ans : We will import the packages which contain some specific classes

to use their functions in the test script.

get() :

Testing = operation code + verification code

if(act.equals(exp))
{

}else
{

How to verify title of the webpage ?


**************************************
Manual Steps
****************
 Get the Title of the WebPage
 Print the title of the webpage
 Verify Title of the WebPage

Selenium Java code


*********************
//-----------------operation code
// Get the Title of the WebPage

String title = driver.getTitle();

// Print the title of the webpage

System.out.println(title);//OrangeHRM - New Level of HR Management

//-------------------------verification code

// Verify Title of the WebPage

if(title.equals("OrangeHRM - New Level of HR Management"))


{

System.out.println("title verified successfully");


}else
{
System.out.println("title not verified successfully");
}

Example 7
*************

byte b=-10.5768; //invalid double

System.out.println(b);

F : double
R : byte

>What are the floating-point literal values ?


*************************************************
Ans : float value and double value

>We can specify floating-point literal value(float value and double value) only in
decimal form

Float Examples
******************

10.5f,2.6F,10.1111f,-123.345F-------

Double Examples
*******************

10.5,2.6,10.1111,-123.345-------

Note :
**********

Example 8
*************

byte b=128; // invalid int type value

System.out.println(b);

F : int
R : byte

Note :
**********
>128
>byte type value
>min -128 to max 127

What are the integral integer literal values ?


*********************************************
Ans : byte value,short value,int value and long value

Note :
**********
>By default every floating-point literal value is what type double type value

>By default every integral literalvalue is what type int type value

short datatype in java ?


***************************
>+ve and -ve nos
>min -32768 to max 32767

Example 1
*************

short s=32767; // valid short

System.out.println(s);

Code Explanation :
*********************
>32767
>short type value
>min -32768 to max 32767

F : short
R : short

Example 2
*************

short s=32.767; // invalid double

System.out.println(s);
F : double
R : short
Example 3
*************

short s=32768; // invalid int

System.out.println(s);

Code Explanation :
***********************

>32768
>short type value
>min -32768 to max 32767

F : int
R : short

int datatype in java ?


*************************
>+ve and -ve nos
>min -2147483648 to max 2147483647

Example 1
*************

int i=125; // valid int

System.out.println(i);

Example 2
*************

int i=125L; // invalid long

System.out.println(i);

Example 2
*************

int i=12.5F; // invalid float

System.out.println(i);

long datatype in java ?


***************************
>+ve and -ve nos
> min -9223372036854775808 to max 9223372036854775807

Example 1
*************

long l=2345L; // valid long

System.out.println(l);

Example 2
*************
long l=125; // valid int

System.out.println(l);

F : int
R : long

String datatype in java ?


*****************************
>This will be used to store single character and group of characterss
>Here range not applicable for string datatype

Examples
************

"HYD" or "H" or "123" or "HYD123" or "^%&^*&&("

>Here everything in double-quotes it's a string


>Here String always must be in double quotes

Example 1
*************

String s=0; // invalid int

System.out.println(s);

Example 2
*************

String s=true; // invalid boolean

System.out.println(s);

Example 3
*************

String s=Hanumanth; // invalid

System.out.println(s);

Example 4
*************

String s="Hanumanth"; // valid

System.out.println(s);

float datatype in java ?


****************************

>This will be used to store +ve and -ve decimal value


>min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>Here we can specify floating-point literal value(float value and double value)
only in decimal form

Example 1
*************

float f=2.345F; // valid float

System.out.println(f);

Example 2
*************

float f=10.111111111F; // 9 1's valid float

System.out.println(f);

Note :
********
>Here float datatype variable can store only decimal value upto 6 digits after
decimal.

Example 3
*************

float f=10.1111; // invalid double

System.out.println(f);

Example 4
*************

float f=25F; // valid float

System.out.println(f);

Note :
*********
>When i run this program by default JVM will provide 25.0 instead of 25

while assigning value into float type variable f.

Example 5
*************

float f=25; // valid int

System.out.println(f);

F : int
R : float

Double datatype in java ?


****************************
>+ve and -ve decimal value
>min -1.7976931348623157e308d to max 1.7976931348623157e308D

>Here we can specify floating-point literal value(float value and double value)
only in decimal form

Example 1
*************

double d=2.345; // valid double

System.out.println(d);

Example 2
*************

double d=10.1111111111111111; // 16 1's valid

System.out.println(d);

Example 3
*************

double d=10.1111D; // valid

System.out.println(d);

char datatype in java ?


*************************
>This will be used to store single character not group of characters
>min 0 to max 65535(0 to 127)

Examples
************

'H' or 'h' or '5' or '&'------valid

'HHH' or 'hh' or '123' or '*(&(**'----invalid

>Here everything in single quotes it's a character

>Here char value always must be in single quotes

Example 1
*************

char ch="H"; // invalid String

System.out.println(ch);

Example 2
*************

char ch=H; // invalid

System.out.println(ch);

Example 3
*************
char ch='H'; // valid char

System.out.println(ch);

Example 4
*************

char ch=68; // valid

System.out.println(ch);

today 2nd class


*****************

>If u want to access the java and selenium then we need to download JDK(Java
development kit) file first

Part 1
**********

1.download JDK(Java development kit) file first


2.Install JDK(Java development kit) file into ur local system
3.Verify JDK(Java development kit) file successful install or not into ur local
system
4.Download Eclipse IDE/oxygen
5.Directly open the Eclipse IDE/oxygen and here no need to install Eclipse
IDE/oxygen

Part 2
********
1.Create new JavaProject
2.Create new package
3.Create new class

Datatype in java ?
********************

int x=10;

What is a variable in java ?


******************************
Ans : Variable is a memory location and here variable x can store some data

based on datatype then it is called variable.

>We can use datatypes in our selenium webdriver to prepare the selenium

automation test script.

>In java or other programming languages,we know we need variables to store

some data based on datatype.

>In java,every variable and every expression should have a datatype.


types of datatypes
**********************
1.primitive datatypes
2.Non-primitive datatypes

What are the integral integer datatypes in java ?--IQ


*******************************************************
Ans: byte,short,int and long

What are the integral floating-point datatypes in java ?--IQ


*******************************************************
Ans: float and double

What are the primitive datatypes in java ?--IQ


*******************************************************
Ans: byte,short,int ,long,float,double,boolean and char

What are the non-primitive datatypes in java ?--IQ


*******************************************************
Ans: String,array,set,list etc

byte datatype in java ?


*************************

7386467494

Example
************

Output :
----------

0 1 2
3 4 5
6 7 8

transfer statements
**********************
>

1.break
2.continue
3.return
4.try-catch-final

break statement
********************

Where exactly we can use break statement ?


**********************************************
Ans : Inside the switch block and loops

Example 1
*************
public class Break_statement {

public static void main(String[] args) {

int x=10;

if(x)
{

break; //error
}

System.out.println("Hanumanth");

Without break statement inside switch block


*******************************************

Example 2
*************

public class Break_statement {

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println("Hello");//Hello

case 1 : System.out.println("Hi");

case 2 : System.out.println("Hanumanth");
}

With break statement inside switch block


*******************************************

Example 3
*************

public class Break_statement {

public static void main(String[] args) {

int x=0;
switch(x){

case 0 : System.out.println("Hello");//Hello

case 1 : System.out.println("Hi");//Hi

break;

case 2 : System.out.println("Hanumanth");
}

Why we are using break statement inside switch block ?


*********************************************************
Ans : To stop the fall-through

Without break statement inside forloop block


*******************************************

How to print 1(starting)-10(ending) nos ?


*****************************
1
2
3
4
5
........10

Example 4
*************

public class Break_statement {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{
System.out.println(i);

With break statement inside forloop block


*******************************************

Example 5
*************

public class Break_statement {

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println("Hello");//Hello

case 1 : System.out.println("Hi");//Hi

break;

case 2 : System.out.println("Hanumanth");
}

Difference betweeen print() and println() in java ?


*****************************************************

Ans :
print():
**************
This will be used to print the text and the curser waits on the same line

to print the next text.

Examples :
***************
System.out.print("Hello...");
System.out.println("Hi...");
System.out.println ("Hanumanth");

Output :
*************
Hello...Hi...
Hanumanth

println():
***************
This will be used to print the text and the curser move to the next line
automatically to print the next text.

Examples :
****************
System.out.println("Hello");
System.out.println("Hi");
System.out.println("Hanumanth");

Output :
**************
Hello
Hi
Hanumanth

Selenium WebDriver
*********************

1.By using Selenium WebDriver,we can identify element /object

2.After identify the element then do some action on that element

Difference betweeen findElement() and findElements() ?


**********************************************************

sendKeys():

How to verify particular text in a web page ? or

How to verify successful message in selenium ?


****************************************************
Manual Steps
****************
 Identify and get the Welcome Selenium Text
 Print the Welcome Selenium Text
 To verify whether the welcome page successfully opened or not

Selenium Java code


**********************
//----------------------------------------------------operation code

// Identify and get the Welcome Selenium Text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();
System.out.println(text);//Welcome selenium

//---------------------------------------------------verification code

if(text.equals("Welcome selenium"))
{

System.out.println("welcome page verified successfully");


}else
{

System.out.println("welcome page not verified successfully");


}

Testing = operation code + verification code

Difference betweeen findElement() and findElements() ?


**********************************************************

sendKeys() :

How to verify particular text in a webpage ? or

How to verify successful message in selenium ?

*************************************************

Testing = operation code + verification code

Manual Steps
***************
 Identify and get the Welcome Selenium Text
 Print the Welcome Selenium Text
 To verify whether the welcome page successfully opened or not
Selenium Java code
************************

//---------------------------------------------------operation code

// Identify and get the Welcome Selenium Text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

System.out.println(text);//Welcome selenium

//--------------------------------------------------verification code

if(text.equals("Welcome selenium"))
{

System.out.println("welcome page verified successfully");


}else
{

System.out.println("welcome page not verified successfully");


}

Nested forloop(forloop inside another forloop) in java ?


***********************************************************

Syntax :
************
for(initialization-part ; conditional-part/testing-part ;increment/decrement-
part)
{

for(initialization-part ; conditional-part/testing-
part ;increment/decrement-part)
{

//Inner forloop body

}//Inner forloop end

//outer forloop body

}//outer forloop end

Syntax Explanation :
*******************

Output
**********
0 1 2
3 4 5
6 7 8

transfer statements
*********************

1.break
2.continue
3.return
4.try-catch-final

1.break statement
********************

Where exactly we can use break statement ?


*******************************************
Ans : Inside the switch block and loops

Example 1
*************

public class Break_statement {

public static void main(String[] args) {

int x=10;

if(x)
{

break;//error
}

System.out.println("Hanumanth");

Without break statement inside switch block


**********************************************

Example 2
*************

public class Break_statement {

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println("Hello");
case 1 : System.out.println("HI");

case 2 : System.out.println("Hanumanth");

With break statement inside switch block


**********************************************

Example 2
*************

public class Break_statement {

public static void main(String[] args) {

int x=0;

switch(x){

case 0 : System.out.println("Hello");

case 1 : System.out.println("HI");

break;

case 2 : System.out.println("Hanumanth");

Why we are using break statement inside switch block ?


*********************************************************
Ans : To stop the fall-through

boolean datatype in java ?


******************************
>This will be used to store only boolean values such as true / false
>Here range not applicable for boolean datatype

Example 1
**************

boolean b=10; //invalid int

System.out.println(b);

Example 2
**************

boolean b="true"; // invalid String

System.out.println(b);

Example 3
**************

boolean b=True; // invalid

System.out.println(b);

>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'

Example 4
**************

boolean b=true; // valid boolean

System.out.println(b);

float datatype in java ?


****************************
>This will be used to store +ve and -ve decimal value
>min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>We can specify floating-point literal value(float value and double value) only in
decimal form

Example 1
***************

float f=2.345F; // valid float

System.out.println(f);

Example 2
***************

float f=10.111111111F; // 9 1's valid float

System.out.println(f);

>Here float type variable can store only decimal value upto 6 digits after decimal

Example 3
***************

float f=25F; // valid float

System.out.println(f);

Note :
***********
When i run this program,by default JVM will provide 25.0 instead of 25 while

assigning value into float type variable f.

Example 4
***************

float f=25; // valid int

System.out.println(f);

double datatype in java ?


*******************************
>+ve and -ve decimal values
>min -1.7976931348623157e308d to max 1.7976931348623157e308D

>We can specify floating-point literal value(float value and double value) only in
decimal form

Example 1
***********

double d=2.345; // valid double

System.out.println(d);

Example 2
***********

double d=10.1111111111111111; // 16 1's valid double

System.out.println(d);

Example 3
***********

double d=10.1111D; // valid

System.out.println(d);

sendKeys() : If u want to give the value to the input field(textbox,text area)

then we use sendKeys().

getText() : If u want to get the particular text in a webpage then we use


getText().

Example 4
**************
char ch=68; //valid the ASCII value(68) of a character---'D'(char type value)

System.out.println(ch);//D

What is the ASCII value(68) of a character ?


*******************************************
Ans : D

What is the ASCII value(97) of a character ?


*******************************************
Ans : a

What is the ASCII value(115) of a character ?


*******************************************
Ans : s

Example 5
**************

int i='G'; // valid ---the character('G') of ASCII value---71(int type value)

System.out.println(i);//71

What is the character('G') of ASCII value ?


*****************************************
Ans : 71

What is the character('s') of ASCII value ?


*****************************************
Ans : 115

Variable in java ?
**********************

int x=10;

What is a variable in java ?


*******************************
Ans :

Variable types
******************
1.Instance variable
2.Local variable
3.Static variable

What are the Instance variables in java ?


********************************************
Ans :

>The values of the name and rollno are different from student to student such
type of variables are called instance variables.

>The values of the name and rollno are different from Object to object such

type of variables are called instance variables.

1.
2.
3.
4.

Example 1
*************

public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//error

Where we can create instance variables ?


******************************************
Ans : Inside the class or outside the method or outside the constructor or

outside the block(if,if-else,ladder if-else,switch,while,do-while,forlop,static)

Can we access the instance variable into static area directly ?


******************************************************************
Ans : No we can't access

Object syntax
*****************

Student S = new Student();

Syntax Explanation :
************************

>Student()==>This is called Student constructor

>Here new is called keyword

Why we are using new keyword ?


********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable


>Here Student is called class

Example 2
*************

public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//error

Byte datatype in java ?


***********************
>This will be used to store +ve and -ve nos
>Here byte datatype variable can store in the range of the values

min -128 to max 127

Example 1
**************

byte b=125; //valid byte type value

System.out.println(b);

Code Explanation :
*********************
>Here we are providing value is 125
>Here Expected value is byte type value
>min -128 to max 127

Found : byte type value


Required : byte

Java compiler work


********************
>Compile the java code line by line (That means Checking the java code line by line

whether it is currect code or not)


JVM(Java virtual machine) work
**********************************
>Simply execute the java code

Example 2
**************

byte b="Hanumanth"; // invalid String

System.out.println(b);

Code Explanation :
***********************
>"Hanumanth"
>byte type value
>>min -128 to max 127

Note :
*********
>We can say this("Hanumanth") is a string type value

>Here String mean collection of characters

Examples
************
"HYD" or "H" or "123" or "HYD123" or "$%^%&^*&(*&"

>here everything in double-quotes it's a string

>Here string always must be in double quotes

Example 3
**************

byte b=127; // valid byte

System.out.println(b);

>127
>byte type value
>min -128 to max 127

F : byte
R : byte

Example 4
**************

byte b=true; // invalid boolean

System.out.println(b);

>We can say this(true) is a boolean type value


>Here boolean mean true / false
F : boolean
R : byte

Example 5
**************

byte b=127L; // invalid long

System.out.println(b);

>Here we can say this(127L) is a long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
**************************************************************************
Ans : Yes

F : long
R : byte

Datatype rules
*****************

byte(least) < short < int < long < float < double(highest)

1.We can assign left-side datatype value into any right-side datatype variable

2.We can't assign right-side datatype value into any left-side datatype variable.

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required typecasting.

Example 6
**************

byte b=10.5F; // invalid float

System.out.println(b);

>Here we can say this(10.5F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
**************************************************************************
Ans : Yes

F : float
R : byte

Example 7
**************
byte b=10.5; //

System.out.println(b);

With break statement inside forloop ?


**************************************

Syntax :
************
for(initialization-part ; conditional-part/testing-part
;increment/decrement-part)
{

if(condition to break)
{
break;

statements;

Syntax Explanation :
***********************
1.
2.
3.
4.

How to print 1-3 nos from 1(starting)-10(ending) nos ?


***************************************

Example
***********
public class FirstProgram {

public static void main(String[] args)


{

for(initialization-part ; conditional-part/testing-
part ;increment/decrement-part)
{

if(condition to break)
{
break;

}
statements;

Why we are using break statement inside loop?


************************************************
Ans : To break the loop based on condition

Continue statement in java ?


*****************************

Where we can use continue statement ?


***************************************
Ans :Inside the loops only

Example 1
************
public class FirstProgram {

public static void main(String[] args)


{

int x=10;

if(x)
{

continue; //error
}

System.out.println("Hanumanth");

}
Without continue statement inside forloop ?
*********************************************

Example 2
************
public class FirstProgram {

public static void main(String[] args)


{

for(int i=1 ; i<=10 ;i++)


{

System.out.println(i);//1 2 3
}

With continue statement inside forloop ?


*********************************************

Syntax :
**************

for(initialization-part ; conditional-part/testing-part
;increment/decrement-part)
{

if(condition to continue)
{
continue;

statements;

Syntax Explanation :
*********************
1.
2.
3.
4.

Example 3
************
public class FirstProgram {

public static void main(String[] args)


{

for(int i=1 ; i<=10 ;i++)


{

System.out.println(i);//1 2 3

}
}

Constructor in java ?
***************************

>This is similar to method

Why need constructor in java ?


*********************************
Ans :

types of constructor
***********************
1.default constructor
2.parameterized constructor

1.default constructor
***********************
Syntax :
*************
Student()
{

2.parameterized constructor
*******************************
Syntax:
***********

Student(para1,para2,para3)
{

>Here constructor doesn't return any return-type not even void

In method,return-type is mandatory ?
****************************************
Ans : Yes

Example 1
***************

1.In default constructor,how to initialize the values to an instance variable


**************************************************************************

Student()
{
name="sai";

rollno=101;
}

When default constructor will be called ?


*********************************************
Ans : Whenever u create an object by default default constructor will be called

When function will be called ?


***********************************
Ans : Whenever u create an object after function will be called

2.In parameterized constructor,how to initialize the values to a variable


*****************************************************************************

Student(String S_name,int S_rollno)


{
name = S_name;

rollno = S_rollno;
}

Example
***********

When parameterized constructor will be called ?


*********************************************
Ans : Whenever u create an object and passing the values then parameterized
constructor will be called

Example 3
***************

double d=10.1111d;// valid double

System.out.println(d);

char datatype in java ?


**************************
>This will be used to store single character not group of characterss

>min 0 to max 65535(0 to 127)

Examples
***********

'H' or 'h' or '5' or '@'--------valid

'HYD' or 'hyd' or '567' or '@786789'--------invalid

>Here everything in single quotes it's a character


>Here char value always must be in single quotes

Example 1
*************

char ch="H";// invalid String

System.out.println(ch);

Example 2
*************

char ch=H;// invalid

System.out.println(ch);

Example 3
*************

char ch='H';// valid

System.out.println(ch);

Example 4
*************

char ch=65;// valid the ASCII value(65) of a character---'A'(char type value)

System.out.println(ch);

What is the ASCII value(65) of a character ?


*******************************************
Ans : A

What is the ASCII value(97) of a character ?


*******************************************
Ans : a

What is the ASCII value(115) of a character ?


*******************************************
Ans : s

Example 5
*************

int i='D';// valid the character('D') of ASCII value----68(int type value)

System.out.println(i);//68
What is the character('D') of ASCII value ?
******************************************
Ans : 68

What is the character('g') of ASCII value ?


******************************************
Ans : 103

What is a variable in java ?


*****************************
Ans :

int x=10;

variables types
******************
1.Instance variables
2.Local variables
3.Static variables

What are the Instance variables in java ?


******************************************
Ans :

>The values of the name and rollno are different fron student to student such

type of variables are called instance variables.

>The values of the name and rollno are different fron object to object such

type of variables are called instance variables.

1.
2.
3.
4.

Where we can create instance variables ?


*******************************************
Ans : Inside the class or outside method or outside constructor or outside the
block

(if,if-else,ladder if-else,switch,while,do-while,forloop,static)

Example 1
************
public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);// error
}

Can we access the instance variable into static area directly ?


****************************************************************
Ans : No ,we can't access

Object Syntax:
****************
//create student class object

Student S = new Student();

Syntax Explanation :
*******************
>Student()==>This is called Student constructor
>Here new is called keyword
Why we are using new keyword ?
***********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable

>Here Student is called class

Example 2
************
public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);// error

Example 3
************
public class Student {

//Instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);// error
}

Example 7
************

byte b= -610.5; //invalid double

System.out.println(b);

Found : double
Required : byte

Note :
*******

>By default every floating-point literal value is what type double type value.

>We can specify floating-point literal value(float value and double value) only in
decimal form.

Float Examples
******************

10.5F,2.6F,10.1111f,-123.5f......

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
**************************************************************************
Ans : Yes

Double Example
*******************

10.5,2.6,10.1111,-123.5......

Example 8
************
byte b= 128; // invalid

System.out.println(b);

Code Explanation:
********************
>128
>byte type value
>min -128 to max 127

What are the integral literal values ?


******************************************
Ans : Byte,short,int and long

What are the floating-point literal values ?


***********************************************
Ans : float value and double value

Note :
***********

>By default every integral literal value is what type int type value.

>By default every floating-point literal value is what type double type value.

Short datatype in java ?


**************************
>+ve and -ve nos
>min -32768 to max 32767

Example 1
************

short s= 32767; // valid short

System.out.println(s);

Code Explanation :
*********************
>32767
>short type value
>>min -32768 to max 32767

F : short
R : short

Example 2
************

short s= 32.767; // invalid double

System.out.println(s);
F : double
R : short

Example 3
************

short s= 32767L; // invalid long

System.out.println(s);

Example 4
************

short s= 32768; // invalid int

System.out.println(s);

F : int
R : short

>min -32768 to max 32767

What are the integral literal values ?


******************************************
Ans : Byte,short,int and long

What are the floating-point literal values ?


***********************************************
Ans : float value and double value

Int datatype in java ?


*************************
>+ve and -ve nos
>min -2147483648 to max 2147483647

Example 1
************

int i= 2345; // valid int

System.out.println(i);

>2345
>int type value
>>min -2147483648 to max 2147483647

Example 2
************

int i= 23.45F; // invalid float

System.out.println(i);
Example 3
************

int i= 2345L; // invalid long

System.out.println(i);

Example 3
**************
public class Student {

public static void main(String[] args)


{

When function will be called ?


********************************
Ans : Whenever u create an object after function will be called.

CAn we access the instance variable into instance area directly ?


******************************************************************
Ans : Yes

CAn we access the instance variable into static area directly ?


******************************************************************
Ans : No,but we can access through object reference

Example 4
************
public class Student {

//Instance variables

int i=10;
String name;
boolean b;
double d;

public static void main(String[] args)


{

Student S = new Student();

System.out.println(S.i);//10
System.out.println(S.name);//null
System.out.println(S.b);//false
System.out.println(S.d);//0.0

}
}

>When i run this program by default JVM will provide default values for that
instance variables and static variables

Example 5
************
public class Student {

//Instance variables

private int i=10;


public String name;
protected boolean b;

public static void main(String[] args)


{

Student S = new Student();

System.out.println(S.i);//10
System.out.println(S.name);//null
System.out.println(S.b);//false

What are the access modifiers in java ?


****************************************
Ans :

1.private
2.public
3.protected
4.default

Can we assign access modifiers for that instance variables and static variables ?
*************************************************************************
Ans : Yes

Can we access the instance variable anywhere ?


***********************************************
Ans : No,but we can access the through object reference

When instance variables will be accessible anywhere ?


******************************************************
Ans : At the time of object creation

How many ways we can access the instance variable anywhere ?


************************************************************
Ans : only one way through object reference

Local variables in java ?


**************************

Example 1
*************

class Test{

//create method

void m1()
{
int x=10;//local variable

//constructor

Test()
{
int y=20;//local variable

//create block

if()
{
int z=30;//local variable

Where we can create local variables ?


**************************************
Ans : Inside the method or inside the constructor or inside block such type

of variables are called local variables.

Example 2
***********
public class Student {

public static void main(String[] args)


{
int j=1;//local variable

for(int i=1;i<10;i++)
{

System.out.println(i);

System.out.println(j);

System.out.println(i);

System.out.println(j);
}

Example 3
***********
public class Student {

public static void main(String[] args)


{
//local variable

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error
}

>When i run this program by default JVM will not provide default values for that

local variables.So compulsory we have to initialize the values for that local
variables.

Local variables
*****************

int a; //invalid
int a=10;//valid
int a=0;//valid

Instance variables
*****************

int a; //valid
int a=10;//valid
int a=0;//valid

staitc variables
*****************

static int a; //valid


static int a=10;//valid
static int a=0;//valid

Example 4
***********
public class Student {

public static void main(String[] args)


{
//local variable

private byte b=10; //invalid


public String name="Sai";//invalid
protected boolean b=false;//invalid

int x=10;//valid

final int y=20; //valid

CAn we assign access modifiers for that local variables ?


***********************************************************
Ans : No

>Here final is called modifier


>Here final means what constant
>Here y is called constant variable.So variable y variable vlue never be changed
that

means on increment and no decrement.So always y is 20.

String datatype in java ?


**************************
>This will be used to single character and group of characterss
>Here range not applicable for string datatype
Examples
***********
"HYD" or "H" or "123" or "HYD123" or "%$$%^%&^&^"

>Here everything in double-quotes it's string


>Here String always must be in double quotes

Example 1
**********

String s=10; //invalid int

System.out.println(s);

F : int
R : String

Example 2
**********

String s=true; // invalid boolean

System.out.println(s);

F : boolean
R : String

Example 3
**********

String s=Hanumanth; // invalid


System.out.println(s);

Example 4
**********

String s="Hanumanth"; // valid

System.out.println(s);

Found : String
Required : String

boolean datatype in java ?


****************************
Example 1
*************
boolean b=0; // invalid int

System.out.println(b);

F : int
R : boolean

Example 2
*************

boolean b="true"; // invalid String

System.out.println(b);

Example 3
*************

boolean b=True; // invalid

System.out.println(b);

Note :
*********
>here boolean type variable can store obly boolean value by prefixed with 't' not
'T'

Example 4
*************

boolean b=true; // valid boolean

System.out.println(b);

In java, Constructor overloading is possible?


********************************************
Ans : Yes

What is a constructor overloading ?


***************************************
Ans :

Here constructor name same but with different argument types then this concept is
called

constructor overloading.

1.A method is called and executed multiple times per single object
*********************************************************************

Example
*************

2.A constructor is called and executed only once per single object (or)
3.We can write one or more constructors in the same class but with
different parameters.

Example
************

4.If instance variable and local variable both are not same then in this case this
keyword an optional.
***************************************************************************

Example
************

5. If the instance variable and local variable both are same then in this case we
have to give this keyword mandatory.
**************************************************************************

Example 1
************

Handle frames
****************

1.How to handle single frame


2.How to handle multiple frames
3.How to handle nested(frame inside another frame) frame

1.How to handle single frame


*************************************

Example 3
*************
Can we access the instance variable into instance area directly ?
********************************************************************
Ans : Yes

Can we access the instance variable into static area directly ?


********************************************************************
Ans : No,but we can access through object reference

Example 4
*************

public class Student {

//Instance vairable

int a=10;
boolean b;
double d;

public static void main(String[] args) {

Student S = new Student();

System.out.println(S.a);//10
System.out.println(S.b);//false
System.out.println(S.d);//0.0

Example 5
*************

public class Student {

//Instance vairable

private int a=10;


public boolean b;
protected double d;

public static void main(String[] args) {

Student S = new Student();

System.out.println(S.a);//10
System.out.println(S.b);//false
System.out.println(S.d);//0.0

}
What are the access modifiers in java ?
****************************************
Ans :
1.private
2.public
3.protected
4.default

Can we assign access modifiers for that instance variables and static variable?
****************************************************************
Ans : Yes

CAn we access the instance variable anywhere ?


*************************************************
Ans : No,but we can access through object reference

When instance variables will be accessible anywhere ?


********************************************************
Ans : At the time of object creation

How many ways we can access the instance variables anywhere ?


****************************************************************
Ans : Only one way through object reference

Local variables in java ?


*****************************
Example 1
***************

class Test{

//create method

void m1()
{

int x=10;//local variable


}

//create constructor

Test()
{
int y=20;//local variable

//create block

if()
{
int z=30;//local variable

Where we can create local variables ?


****************************************
Ans :
Example 2
***************

public class Student {

public static void main(String[] args) {

int j=1; //local variable

for(int i=1;i<10;i++)
{

System.out.println(i);

System.out.println(j);
}

System.out.println(i);

System.out.println(j);
}

Example 3
***************

public class Student {

public static void main(String[] args) {

//local variable

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error
}

Local variables Examples


**************************

int a; //invalid
int a=10;//valid
int a=0;//valid

Instance variables Examples


**************************

int a; //valid
int a=10;//valid
int a=0;//valid

static variables Examples


**************************

static int a; //valid


static int a=10;//valid
static int a=0;//valid

long datatype in java ?


**************************
>+ve and -ve nos
> min -9223372036854775808 to max 9223372036854775807

Example 1
*************

long l=127L; //valid long

System.out.println(l);

> min -9223372036854775808 to max 9223372036854775807

Example 2
*************

long l=12.7F; // invalid float

System.out.println(l);

Found : float
Required : long

Example 3
*************

long l=127; // valid int

System.out.println(l);

F : int
R : long

Note :
***********
>By default every integral literal value is what type int type value

>By default every floating-point literal value is what type double type value

Float datatype in java ?


***************************

>This will be used to store +ve and -ve decimal value


>min -3.4028235e38F to max 3.4028235e38F

>Here e mean exponential form

>We Can specify floating-point literal value(float value and double value) only in
decimal form

Float examples
*******************

10.5F,2.6f,10.1111F,-123.345F-------

Double examples
*******************

10.5,2.6,10.1111,-123.345-------

What are floating-point literal values ?

Ans : float value and double value

What are the integral literal values ?


**************************************
Ans : byte ,short,int and long

Example 1
*************

float f=2.345F; //valid float

System.out.println(f);

Example 2
*************

float f=10.111111111F; // 9 1's valid float

System.out.println(f);

Note :
******

Here float type variable can store only decimal value upto 6 digits after decimal

Example 3
*************

float f=25F; // valid float

System.out.println(f);

Example 4
*************
float f=25; // valid int

System.out.println(f);

Double datatype in java ?


*****************************

>+ve and -ve decimal value


>min -1.7976931348623157e308d to max 1.7976931348623157e308D

>

Example 1
*************

double d=2.345; // valid double

System.out.println(d);

Example 2
*************

double d=10.1111111111111111; // 16 1's valid double

System.out.println(d);

Example 3
*************

double d=10.1111D; // valid double

System.out.println(d);

Char datatype in java ?


***************************

this keyword in java ?


************************

Example 5
************
public class Student {

public static void main(String[] args) {

//Local variables
private byte b=10;//invalid

public boolean b= false;//invalid

protected double d=10.5;//invalid

int x=10; //valid

final int y =20; //valid

}
What are the access modifiers in java ?
*************************************
Ans :

1.private
2.public
3.protected
4.default

>Here final is called modifier


>Here final means what constant
>Here y is called constant variable.
>Here constant variable value never be changed that means no increment

and no decrement.So always y is 20.

CAn we assign final modifier for that local variable ?


**********************************************************
Ans : yes

CAn we assign final modifier for that Instance variable and static variables ?
**********************************************************
Ans : Yes

CAn we access the local variables anywhere ?


**********************************************
Ans : No,We can access the local variables inside the method or inside constructor
or inside the block

When local variables will be accessible ?


*********************************************
Ans : While executing the method or constructor or block

Static variable in java ?


****************************
>The name of the college is same from student to student such type of variable

is called static variable.

>The name of the college is same from object to object such type of variable

is called static variable.


Where we can create static variable ?
***************************************
Ans :

Example 1
************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//Sai

Can we access the static variable into static area directly ?


***************************************************************
Ans : yes

Example 2
************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{
Student S = new Student();

System.out.println(S.name);//Sai

Example 3
************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{
System.out.println(Student.name);//Sai

Can we access the static variable into static area through classname ?
*************************************************************************
Ans : Yes

Syntax : classname.variablename

Example 4
************

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(Student.name);//Sai

How many ways we can access the static variable ?


*****************************************************
Ans : 3 ways

1.Directly we can access


2.Through object reference
3.Through classname

When static variable will be accessible ?


********************************************
Ans :

Example 5
**************

public class Student {

public static void main(String[] args)


{
//Local variables

private byte b=10;//invalid

public boolean b=false;//invalid


protected double d=10.5;//invalid

int x=10; //valid

final int y = 20; //valid

}
>Here final is called modifier
>Here final means what constant
>Here y is called constant variable
>Here constant variable variable value never be changed,that means no increment

no decrement.So always y is 20.

>CAn we assign final modifier for that local variable ?


***********************************************************
Ans : yes

>CAn we assign final modifier for that instance variable and static variable?
***********************************************************
Ans : yes

What are the access modifiers in java ?


******************************************
Ans :
1.private
2.public
3.protected
4.default

CAn we assign access modifiers for that local variables ?


**********************************************************
Ans : No

CAn we assign access modifiers for that instance variables and static variables ?
**********************************************************
Ans : Yes

CAn we access the local variable anywhere ?


**********************************************
Ans :

When local variable will be accessible ?


*******************************************
Ans :

Static variable in java ?


***************************
>The name of the college is same from student to student such type of variable is
called

static variable.

>The name of the college is same from object to object such type of variable is
called
static variable.

Where we can create static variable ?


*****************************************
Ans :

Example 1
************
public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//Sai
}

CAn we access the static variable into static area directly ?


*************************************************************
Ans : Yes

Example 2
************
public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{
Student S = new Student();

System.out.println(S.name);//Sai
}

Example 3
************
public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(Student.name);//Sai
}
}

Can we access the static variable into staitc area through classname ?
*********************************************************************
Ans :Yes

Syntax : classname.variablename

Example 4
************
public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(Student.name);//Sai
}

How many ways we can access the static variable ?


******************************************************
Ans : 3 ways

1.Directly we can access


2.Through object reference
3.Through classname

When static variable will be accessible ?


******************************************
Ans :

char datatype in java ?


****************************

>This will be used to store single character not group of characters.


>min 0 to max 65535(0 to 127)

Examples
*************
'H' or 'h' or '5' or '@'----------valid

'HHH' or 'hhhh' or '5234' or '@*&^&*&'----------invalid

>Here everything in single quotes it's a character

>Here always char value must be in single quotes

Example 1
**************
char ch="H";//invalid String

System.out.println(ch);

Example 2
**************

char ch=H;//invalid

System.out.println(ch);

Example 3
**************

char ch='H';// valid char

System.out.println(ch);

Example 4
**************

char ch=68;// valid the ASCII value(68) of a character--->'D'(char type value)

System.out.println(ch);//D

What is the ASCII value(68) of a character ?


*****************************************
Ans : D

What is the ASCII value(97) of a character ?


*****************************************
Ans : a

What is the ASCII value(115) of a character ?


*****************************************
Ans : s

Example 5
**************

int i='G';// the character('G') of ASCII value--->71(int type value)

System.out.println(i);//71

What is the character('G') of ASCII value ?


*****************************************
Ans : 71

What is the character('S') of ASCII value ?


*****************************************
Ans : 83

Variable in java ?
********************

What is a variable in java ?


********************************
Ans :

Types of variables ?
***********************
1.Instance variables
2.Local variables
3.Static variables

What are the Instance variables in java ?


********************************************
Ans :

>The values of the name and rollno are different from student to student such

type of variables are called instance variables.

>The values of the name and rollno are different from object to object such

type of variables are called instance variables.

1.
2.
3.
4.

Where we can create instance variables ?


******************************************
Ans : Inside the class or outside the method or outside the constructor or outside
the block

(if,if-else,ladder if-else,switch,while,do-while,forloop,static)

Example 1
*************

public class Student {

//instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//error
}

Can we access the instance variable into static area directly ?


*****************************************************************
Ans : No,we can't access

Example 2
*************

public class Student {

//instance variable

String name="Sai";

public static void main(String[] args)


{
//create the object for that Student class

Student S = new Student();

System.out.println(S.name);//Sai
}

Object Syntax :
*****************

Student S= new Student();

Syntax Explanation :
**********************

>Student()===>This is called Student constructor

>Here new is called keyword


>why we are using new keyword ?
***********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable

>here Student is called class

Can we access the instance variable into static area directly ?


*****************************************************************
Ans : No,but we can access through object reference

Example 3
*************

public class Student {

//instance variable

String name="Sai";

public static void main(String[] args)


{
//create the object for that Student class
Student S = new Student();

System.out.println(S.name);//Sai
}

this keyword in java ?


***********************

Example 1
***********

How to call the current class instance variable from this keyword ?
********************************************************
Syntax : this.variablename

How to call the current class default constructor from this keyword ?
********************************************************
Syntax : this();

How to call the current class parameterized constructor from this keyword ?
********************************************************
Syntax : this(value1,value2);

How to call current class the method from this keyword ?


*********************************************
Syntax : this.methodname();

Example 2
***********

Calling parameterized constructor and method from default constructor


*************************************************************************

Calling default constructor from parameterized constructor


***************************************************************

Calling parameterized constructor from parameterized constructor


********************************************************************

Why need constructor in java ?


*********************************

Suppose if u don't mention constructor in this class,so in this case JVM will
provide

default constructor and initialize the default values for that instance variables

see below

Student()
{
name = null;
rollno = 0;
}

>Here output i am not satisfied with default values,so in this case i want to give
my

own values or user/programmer defined values.so in this kind of situation we are


going to learn new thing .i.e Constructor

Instance vairable part 2


*************************

Part 1
**********
1.Print 1st student details
2.Print 2nd student details
3.Print nth student details

Part 2
*********
>Suppose if u want to Print 1st student details then we need to create object

for that 1st student.

>Suppose if u want to Print 2nd student details then we need to create object

for that 2nd student.

>Suppose if u want to Print nth student details then we need to create object

for that nth student.

Part 3
**********

1.Print 1st student details


*******************************
>First,initialize the values for that instance variables
>Print 1st student details

2.Print 2nd student details


******************************
>First,initialize the values for that instance variables
>Print 2nd student details

3.Print nth student details


*******************************
>First,initialize the values for that instance variables
>Print nth student details

If i change the 1st student marks then there are any effect for that remaining

students marks ?
*************************************************************************
Ans : No effect

Instance variable part 2


*************************

>For every object a separate copy of instance variables will be created


>For every student a separate copy of name,rollno and marks will be created

Static variable part 2


************************

>Create collegeName and share the collegeName for all the students

>Create single copy and share this copy for all the objects

Can we access the static variable into static area through classname ?
************************************************************************
Ans : Yes

Syntax : classname.variablename

Instance variable part 2


**************************

Part 1
**********
1.print 1st student details
2.print 2nd student details
3.print nth student details

Part 2
**********
>Suppose if u want to print 1st student details the

Example 3
***********

CAn we access the instanc variable into instance area directly?


**********************************************************
Ans : Yes

When method / function will be called ?


********************************
Ans :

Example 4
***********

When i run this program by default JVM will provide default values for that
instance variables and static variables but not for local variables.

Can we assign default values for that instance variables and static variables?
***********************************************************************
Ans : Yes

Can we assign default values for local variables?


***********************************************************************
Ans : No

Example 5
***********

public class Student {

//Instance variables

private String name="Sai";


public boolean b;
protected double d;

public static void main(String[] args) {

Student S = new Student();

System.out.println(S.name);//Sai

System.out.println(S.b);//false

System.out.println(S.d);//0.0
}

What are the access modifiers in java ?


*****************************************
Ans :

1.private
2.public
3.protected
4.default

Can we assign access modifiers for that instance variables and static variables ?
**************************************************************************
Ans : Yes

Can we assign access modifiers for that local variables ?


**************************************************************************
Ans : NO

Can we access the instance variables anywhere ?


***************************************************
Ans : No,but we can access through object reference

When instance variables will be accessible anywhere?


***********************************************
Ans : At the time of object creation

How many ways we can access the instance variable anywhere ?


***********************************************************
Ans : Only one way through object reference

Local variables in java ?


****************************
Example 1
*************

class Test{

//crate method

void m1()
{

int x=10;//local variable


}

//create constructor

Test()
{
int y=20;//local variable

//create block

if()
{
int z=30;//local variable

Where we can create local variables ?


*****************************************
Ans :

Example 2
*************
public class Student {

public static void main(String[] args) {

int j=1;//local variable

for(int i=1;i<10;i++)
{
System.out.println(i);//valid

System.out.println(j);//valid
}
System.out.println(i);//invalid

System.out.println(j);//valid
}

Example 3
*************

public class Student {

public static void main(String[] args) {

//local variable

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error
}

When i run this program by default JVM will not provide default values for that

local variables.so compulsory we have to initialize the values for that local
variables.

Local variables Examples


**************************

int a; //invalid
int a=10;//valid
int a=0;//valid

Instance variables Examples


**************************

int a; //valid
int a=10;//valid
int a=0;//valid

static variables Examples


**************************

static int a; //valid


static int a=10;//valid
static int a=0;//valid

Example 4
*************

public class Student {


public static void main(String[] args) {

//local variable

byte b=10;

class and object in java ?


******************************

Examples
***********

Class : Vehicles Objects : car,bus,auto etc.


Class : Animals Objects : cat,dog,elephant etc.
Class : Furniture Objects : table,chair,cot etc.
Class : Fruits Objects : apple,orange,mango etc.

What is a Object in java ?


*****************************
Ans : It exists really / physically

Examples : car,cat,table,apple etc.

In general object has two things,


***********************************
1.State/properties
2.Behavior / Action

What is a class in java ?


**************************
Ans : It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc

In general car is a object and it has two things


**************************************************
1.State/properties
2.Behavior / Action

>Here class is a blueprint or Template or structure or design from which


individual objects are created.

Object syntax :
********************

Student S = new Student();

Syntax Explanation :
************************
>
>
>Why we are using new keyword ?
***********************************
>By using new keyword,we can create Student object(new Student();)

>

Class syntax:
****************
class <classname>
{

//1.State/properties---------variables

<datatype> variable1;
<datatype> variable2;

//2.Behavior / Actions-------methods / functions

return-type methodname1()
{

}
return-type methodname2()
{

main()
{

Example
***********

Difference betweeen class and object ?


*****************************************
class
*******
1.It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc

2.Why we are using class keyword ?


***********************************
Ans : By using class keyword, we can create class

3.In program,we can create class only once

4.We can create class without creating an object

5.Here memory space is not allowed when class is created

6.A class can contain variables and methods

Object
*********

1.It exists really / physically

Examples : car,cat,table,apple etc.

2.Why we are using new keyword ?


***********************************
>By using new keyword,we can create Student object(new Student();)

3.In program,we can create objects multiple times

4.We can't create objects without class

5.Here memory space is allowed when object is created

6.And object also can contain variables and methods

Example 4
************
public class Student {

public static void main(String[] args) {

//local variables

private byte b=10;//invalid


public double d=10.5;//invalid
protected boolean b=false;//invalid

int x=10; //valid


final int y =20;//valid

CAn we assign access modifiers for that local variables ?


*******************************************************
Ans : NO

>Here final is called modifier


>Here final means what constant
>Here y is called constant variable.Here constant variable value never be changed
that means

no increment and no decrement.So always y is 20.

CAn we assign final modifier for that local variable ?


*********************************************************
Ans : Yes

CAn we assign final modifier for that instance variables and static variables ?
*********************************************************
Ans : Yes

Can we access the local variable anywhere ?


*********************************************
Ans : No,we can access inside the method or inside the constructor or inside the
block

When local variables will be accessible ?


***************************************
Ans : While executing the methods,constructors and block

Static variable in java ?


*****************************
>The name of the college is same from student to student such type of

variable is called static variable.

>The name of the college is same from object to object such type of

variable is called static variable.

Where we can create static variable ?


*****************************************
Ans : Inside the class or outside the method,constructor,block

Example 1
***********

public class Student {


//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//Sai

CAn we access the static variable into static area directly ?


*****************************************************
Ans : Yes

Example 2
***********

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

//create the object for that student class

Student S = new Student();

System.out.println(S.name);//Sai

CAn we access the static variable into static area through object reference ?
*****************************************************
Ans : Yes

Example 3
***********

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{
System.out.println(Student.name);//Sai

CAn we access the static variable into static area through classname ?
*****************************************************
Ans : Yes

Syntax : classname.variablename

Example 4
***********

public class Student {

//static variable

static String name="Sai";

public static void main(String[] args)


{

System.out.println(Student.name);//Sai

How many ways we can access the static variable ?


*****************************************************
Ans : 3 ways

1.Directly we can access


2.Through object reference
3.Through class name

When static variable will be accessible ?


******************************************
Ans :

Instance variable part 2


*****************************

Part 1
**********
1.Print 1st student details
2.Print 2nd student details
3.Print nth student details

Part 2
********
>Suppose if u want to Print 1st student details then we need to create object for
that
1st student
>Suppose if u want to Print 2nd student details then we need to create object for
that

2nd student

>Suppose if u want to Print nth student details then we need to create object for
that

nth student

Part 3
*********

Print 1st student details


******************************

>First,initialize the values for that instance variables


>Print 1st student details

2.Print 2nd student details


******************************
>First,initialize the values for that instance variables
>Print 1st student details

3.Print nth student details


********************************
>First,initialize the values for that instance variables
>Print 1st student details

If i change the 1st student marks then there are any effect for that remaining

students marks ?
**************************************************************************
Ans : No effect

Instance variable part 2


***************************

>For every object a separate copy of instance variables will be created

>For every student a separate copy of name,rollno,marks will be created

Static variable part 2


**********************

>Create collegeName and share the collegeName for all the students

>Create single copy and share this copy for all the objects

If i change the 1st student college name then there are any effect for that
remaining

students collegeName ?
**************************************************************************
Ans : Yes effect

Inheritance in java ?(oops concept)


************************
Why need inheritance in java ?
************************************
Ans :

Without inheritance
**********************
Example
************

Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create Mainclass

Java code
*************

With inheritance
**********************

What is a inheritance in java ?


**********************************
Ans :

Note :
**********

Advantages of inheritance
**************************
>By using inheritance,we can

1.Reduce the code size


2.Reduce the development time
3.Avoid the duplicate code

Main Advantages of inheritance


**************************
>code reusability

Syntax:
***********

class Superclass
{

}
class Subclass extends Superclass
{

}
Example
**********
Manual Steps
**************
1.Create Superclass(Teacher)
2.Create Subclass(Student) from Superclass(Teacher)
3.Create Mainclass

Java code
*************

Handling Frames
*******************
1.How to handle single frame
2.How to handle multiple frames
3.How to handle Nested frames(frame inside another frame)

getText() :

return type : String

1.How to handle single frame


******************************

a) How to print all the dropdown values ?


****************************************

>First,get the dropdown size or count dropdown values

1.First,Identify dropdown
2.Next,Identify all the values from this dropdown

>print all the dropdown values

Without break statement inside forloop ?


*******************************************

How to print 1(Starting)-10(ending) nos ?


***************************

1
2
3
4
....10
Example
***********
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

System.out.println(i);
}
}

With break statement inside forloop ?


*******************************************

Syntax :
***********

for(initialization-part ; conditional-part/testing-part; increment/decrement-


part)
{

if(condition to break)
{

break;
}

Syntax Explanation :
*********************
1.
2.
3.
4.

Example
***********
How to print 1-3 from 1-10 nos ?
**************************************

Continue statement in java ?


****************************

Example 1
**************

public class Student {

public static void main(String[] args)


{
int A=50;

if(A>100)
{

continue;//error

System.out.println(A);

Where we can create continue statement ?


*********************************************
Ans : Inside the loops only

Example 2
**************

Without continue statement inside forloop ?


***********************************************

public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

System.out.println(i);
}
}

With continue statement inside forloop ?


***********************************************

Syntax :
***********

for(initialization-part ; conditional-part/testing-part; increment/decrement-


part)
{

if(condition to continue)
{

continue;
}

Statement;
}

Syntax Explanation:
*********************

1.
2.
3.
4.

Example
**********
How to print 1-10 except 3 ?
*******************************

constructor in java ?
*************************
>This is similar to method

Why need constructor in java ?


********************************
Ans :

types of constructor
************************
1.default constructor
2.parameterized constructor

1.default constructor
************************
Syntax :
************

Student()
{

2.parameterized constructor
******************************
Syntax :
************

Student(para1,para2,para3)
{

In method, return-type is mandatory ?


****************************************
Ans : Yes

1.In default constructor,how to initialize the values for that instance variables
****************************************************************************

Student()
{
name = "Sai";
rollno=101;
}

Example
*********

When default constructor will be called ?


*******************************************
Ans : Whenever u create an object by default default constructor will be called

1.In parameterized constructor,how to initialize the values for that instance


variables
****************************************************************************
Example
*********

Handling frames
*****************

1.How to handle single frame


2.How to handle multiple frames
3.How to handle Nested frames(frame inside another frame)

getText() :

return-type : String

1.How to handle single frame


*******************************
a) How to print all the dropdown values
******************************************

>First,get the dropdown size or count dropdown values


*********************************************************

diagram :
************

Manual steps
***************

1.First,Identify dropdown
2.Next,Identify all the values from this dropdown

Selenium java code


**********************
//1.First,Identify dropdown

WebElement dropdown = driver.findElement(By.id("loc_code"));

//2.Next,Identify all the values from this dropdown

List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));

System.out.println(droplist.size());//3

>print all the dropdown values


*********************************

//>print all the dropdown values

for(int i=0;i<droplist.size();i++)
{

System.out.println(droplist.get(2).getText());

Output
*********
AA
BB
CC

What is a method /function in java ?


***************************************

>
>
>

Syntax :
*************

return-type methodname(para1,para2)
{

statement1;
statement2;
statement3;
}

Examples
*************
void add()
{

}
void addfunction()
{

}
void addFunction()
{

How to write a program for a method,without return-type and without passing


parameters
***************************************************************************

Example
*************

When function will be called ?


*********************************
Ans : Whenever u create an object after function will be called

How to write a program for a method,with return-type and without passing parameters
***************************************************************************

Example
*************

How to write a program for a method,without return-type and with passing parameters
***************************************************************************

Example
*************

Why we are using parameters ?


*******************************
Ans : By using these parameters ,we can receive the data from outside into method

How to write a program for a method,with return-type and with passing parameters
***************************************************************************

Example
*************

Here method can never return more than one value

Examples
**************

return c; //valid

return a,b;//invalid

return a,return b;//invalid

What is a class and object in java ?


*************************************
class and object examples
***************************
Class : Vehicles Objects : car,bus,auto etc.
Class : Animals Objects : cat,dog,elephant etc.
Class : Furniture Objects : table,chair,cot etc.
Class : Fruits Objects : mango,orange,apple etc.

What is a object in java ?


*****************************
Ans : It exists really / physically

Examples : car,cat,table,mango etc.

In general object has two things


************************************

1.State/properties
2.Behavior / Actions

What is a class in java ?


*************************
Ans : It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits

Here class is a blueprint or Template or structure or design from which

individual objects are created.

>

In general car is object and it has two things


***********************************************

1.State/properties
2.Behavior / Actions

Object syntax
****************

Student S = new Student();

syntax Explanation :
**********************
>Student()==>
>new
>new Student();
>S
>Student

class Syntax
***************
class <classname>
{
//1.State/properties----------variables

<datatype> variable1;
<datatype> variable2;

//2.Behavior / Actions--------Methods

return-type methodname1()
{

return-type methodname2(para1,para2)
{

main()
{

Example
***********

Difference betweeen class and object in java ?


***********************************************

What is a method / function in java ?


**************************************
>
>
>

Syntax:
**********

return-type methodname(para1,para2,par3)
{
Statement1;
Statement2;
Statement3;
}
Examples
************
void add()
{
}
void addfunction()
{

}
void addFunction()
{

1.Write program for a method,without return-type and without passing parameters


****************************************************************************
Example
*************
When function will be called ?
*********************************
Ans : Whenever u create an object after function will be called

2.Write program for a method,with return-type and without passing parameters


****************************************************************************
Example
*************

3.Write program for a method,without return-type and with passing parameters


****************************************************************************
Example
*************

Why we are using parameters ?


**********************************
Ans : By using parameters,we can receive the data from outside into method

4.Write program for a method,with return-type and with passing parameters


****************************************************************************
Example
*************

Here method can never return more than one value

Examples
***********
return c; //valid

return a,b; //invalid

return a,return b;//invalid

What is a class and object in java ?


**************************************

class and object Examples


****************************

Class : Vehicles Objects : car,bus,auto etc.


Class : Animals Objects : cat,dog,elephant etc.
Class : Furniture Objects : table,chair,cot etc.
Class : Fruits Objects : mango,orange,apple etc.
What is a object in java ?
****************************
Ans: It exists really / physically

Examples : car,cat,table,mango etc.

In general object(Student(Sai)) has two things


*******************************************
1.State/properties
2.Behavior / Actions

What is a class in java ?


****************************

Selenium Automation Testing


******************************

What is a Testing ?
************************
>To verify whether the functionality works well or not.i.e Testing or

Simply we can say to find the defect or to find the error of to find the failure

Difference betweeen defect,error and failure ?--IQ


************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

types of Testing
*********************
1.Functional Testing
2.NOn functional Testing

Types of functional automation tools


****************************************
1.opensource
================
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.Sahi
3.Badboy
4.Ruby
5.watir etc.

2.commercial
==============
1.Qtp(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen Selenium and Qtp ?--IQ


*******************************************
Selenium
**********
1.opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here Selenium + Appium---->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

Qtp
*******
1.commercial(paid tool)
2.Vbscript
3.FF,IE and chrome
4.windows
5.Web app and mobile app and desktop app

History of selenium
***********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium WebDriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + ( Selenium WebDriver+Extra features) + Selenium Grid


>2019

Selenium Components---IQ
****************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

Difference betweeen Selenium IDE,RC and WebDriver ?--IQ


********************************************************

b) How to Select the dropdown value inside a frame


****************************************************
diagram :
************

Manual Steps
****************
>Switch to frame
>Identify dropdown
>Select the dropdown value

Selenium Java code


*********************
// Switch to frame by id

driver.switchTo().frame("rightMenu");

//1.First,Identify dropdown

WebElement dropdown = driver.findElement(By.id("loc_code"));

// >Select the dropdown value

Select S = new Select(dropdown);

S.selectByIndex(2);

c) verify selected value from dropdown


*****************************************
diagram :
***************

Manual Steps
******************
>get the selected value
>Verify selected value

Selenium Java code


*******************

Testing = operation code + verification code

//---------------------------------------------------operation code

//>get the selected value

String selected_value = S.getFirstSelectedOption().getText();

System.out.println(selected_value);//Emp. First Name

//-----------------------------------------------------verification code

//>Verify selected value

if(selected_value.equals("Emp. First Name"))


{
System.out.println("Selected value verified successfully");

}else
{
System.out.println("Selected value not verified successfully");

}
2.Verify Multiple selections are allowed or Not from a list box.
********************************************************************

//-----------------------------------------------operation code

1.How to select multiple options from listbox?


****************************************************
Manual Steps
*****************
1.Identify the Lisbox
2.select multiple options from a list box.

Selenium Java code


***********************

//3.Identify the Lisbox

WebElement listbox =
driver.findElement(By.id("ctl00_MainContent_lbCountry"));

//.select multiple options from a list box.

Select S = new Select(listbox);

S.selectByIndex(3);

S.selectByVisibleText("ARGENTINA");

//------------------------------------------------verification code
//Verify Multiple selections are allowed or Not from a list box.

if(S.isMultiple())
{

System.out.println("Multiple selections are allowed from


listbox");
}else
{
System.out.println("Multiple selections are not allowed from
listbox");
}

How to verify single checkbox in a webpage using selenium?


****************************************************************
diagram :
**********

Manual Steps
*****************

 Identify Checkbox1
 Click Checkbox1
 Verify Checkbox1

Selenium Java code


**********************
//---------------------------------------------------operation code
/ Identify Checkbox1

WebElement checkbox1 = Driver.findElement(By.id("vfb-6-0"));

// Click Checkbox1

checkbox1.click();

//-------------------------------------------------verification code
// Verify Checkbox1

if(checkbox1.isSelected())
{
System.out.println("checkbox1 selected");
}else
{

System.out.println("checkbox1 not selected");


}

How to Verify multiple checkboxes ?


*****************************************
diagram :
************

Manual Steps
****************
 Identify all Checkboxes
 Count total checkboxes in a webpage
 Verify multiple checkboxes one by one

Selenium Java code


*************************
// Identify all Checkboxes

List<WebElement> Allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));

System.out.println(Allchk.size());//3

// Verify multiple checkboxes one by one

for(int i=0;i<Allchk.size();i++)
{

Allchk.get(i).click();
if(Allchk.get(i).isSelected())
{
System.out.println("checkbox selected");

}else
{
System.out.println("checkbox not selected");

xpath syntax :
*****************

//tagName[@attributeName='value']

Example
**********

//input[@type='checkbox']

In parameterized constructor,how to initialize the values for that instance


variables
****************************************************************************
Student(String S_name,int S_rollno)
{
name =S_name;

rollno = S_rollno;
}

Example
***********

In java ,constructor overloading is possible ?


**************************************************
Ans : Yes

What is a constructor overloading ?


**************************************
Ans : Here constructor name same but with different argument types then this

concept is called constructor overloading.

1.A method is called and executed multiple times per single object
***********************************************************************
Example
***********
2.A constructor is called and executed only once per single object (or)

3.How to write one or more constructors in the same class but with
different parameters.

Example
***********

4.If instance variable and local variable both are not same then in this case this
keyword an optional.
*****************************************************************************
Example
***********

5. If the instance variable and local variable both are same then in this case we
have to give this keyword mandatory.
**************************************************************************
Example
**********

this keyword in java ?


**************************
Example 1
*************
Whnever u create an object by default this keyword is also created internally

Ans here this keyword refer to student class object.

How to call the current class instance variables from this keyword ?
*******************************************************
Syntax : this.variablename

How to call the current class default constructor from this keyword ?
*******************************************************
Syntax : this();

How to call the current class parameterized constructor from this keyword ?
*******************************************************
Syntax : this(value1,value2);

How to call the current class method from this keyword ?


*******************************************************
Syntax : this.methodname();

Example 2
*************

Calling parameterized constructor and method from default constructor


***************************************************************
Example
************
Calling default constructor from parameterized constructor
***************************************************************
Example
***********

Calling parameterized constructor from parameterized constructor


******************************************************************
Example
***********

Why need constructor in java ?


********************************
Ans :

Note :
**********
>When i run this program by default JVM will provide default constructor

and initialize the default values for that instance variables.see below

Student()
{
name = null;

rollno = 0;

Output
**********
Student name : null
Student rollno : 0

Here output, i am not satisfied with default values,in this case i want to give my

own values or user/programmer defined values.So in this kind of situation

we are going to learn new thing i.e Constructor

Difference betweeen class and object in java ?


***********************************************

Class
*******
1.It doesn't exis really /physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

2.Why we are using class keyword ?


*************************************8
Ans : By using class keyword,we can create class

3.In program,we can write class only once

4.We can create class without creating an object

5.Here memory space is not allowed when class is created

6.A class can contain variables and methods

Object
*********
1.It exists really / physically

Examples : car,cat,table,mango etc.

2.Why we are using new keyword ?


*************************************8
Ans : By using new keyword,we can create object

3.In program,we can write object multiple times

4.We can't create object without class

5.Here memory space is allowed when object is created

6.And object also can contain variables and methods

Flow-control in java ?
**************************

Selection statements
***********************
1.if statement / block
2.if-else
3.ladder if-else
4.switch

if statement
*****************

Syntax :
*************

if(conditional-part/testing-part) //here must be boolean condition


{
//body
}

Syntax Explanation :
**********************
1.
2.

Example 1
***************
public class Student {

public static void main(String[] args)


{
int cat_age=5;

int dog_age=5;

if(cat_age==dog_age)
{

System.out.println("Animals age matched");


}

}
}

>Here if the condition is true then JVM will execute if block.

>Here if the condition is false then JVM has to print something in the console.

So in this kind of situation we are going to use else part .

Example 2
***************
public class Student {

public static void main(String[] args)


{
int cat_age=5;

int dog_age=5;

if(cat_age==dog_age)
{

System.out.println("Animals age matched");


}else
{
System.out.println("Animals age not matched");

}
}

Conclusion
**************
>Here if u want to check only true condition then we have to go if statement.

>Here if u want o check true /false condition then we have to go if-else statement.

Example 3
***************
public class Student {

public static void main(String[] args)


{
int A=100;

if(A>50)
{

System.out.println("A greater than 50");


}else
{
System.out.println("A less than 50");

}
}
}

Example 4
***************
public class Student {

public static void main(String[] args)


{
int A=100;

if(A) //here must boolean condition


{

System.out.println("Hello");
}else
{
System.out.println("Hanumanth");

}
}

>if(A)===>if(100)==>

F : int
R : boolean

Example 5
***************
public class Student {

public static void main(String[] args)


{
int x=10;

if(x=20) //here must boolean condition


{

System.out.println("Hello");
}else
{
System.out.println("Hanumanth");

}
}

>int x=10;//now onwards x value will become 20

>if(x),here x means what 20

>if(20)==>
F : int
R : boolean

Example 6
***************
public class Student {

public static void main(String[] args)


{
int x=10;

if(x==20) //here must boolean condition


{

System.out.println("Hello");
}else
{
System.out.println("Hanumanth");

}
}

==------>By using this we can compare the values / references / boolean value
=------->By using this we can assigning the value into variable

Example 7
***************
public class Student {

public static void main(String[] args)


{
boolean b=true;

if(b=false) //here must boolean condition


{

System.out.println("Hello");
}else
{
System.out.println("Hanumanth");

}
}

>boolean b=true;//now onwards b value will become false


>if(b),here b means what false
>if(false)==>

F : boolean
R : boolean
Example 8
***************
public class Student {

public static void main(String[] args)


{
boolean b=false;

if(false==false) //here must boolean condition


{

System.out.println("Hello");
}else
{
System.out.println("Hanumanth");

}
}

Switch block
************
>Suppose if u want to check one or more condition then we have to go switch block

Syntax :
***********

switch(Expression value){

case value1 : Statement1--->code to be executed


break;
case value2 : Statement2--->code to be executed
break;
case value3 : Statement3--->code to be executed

break;
default : Statement4--->Here default case will be executed when
expression value is not matched with any case value.

Syntax Explanation :
**********************

1.
2.
3.
4.
5.
6.

Example 1
*************
public class Student {
public static void main(String[] args)
{
int x=1;

switch(x){

System.out.println("hanumanth");

}
}

>In switch block, every statement should be under case value and default case

>In switch block,independent statement is not allowed

Example 2
*************
public class Student {

public static void main(String[] args)


{
int x=0;

int y=1;

switch(x){

case 0 : System.out.println("Hello");//valid

case y : System.out.println("hanumanth");//invalid
}

}
}

>In switch block,every case value should be constant not variable

Example 3
*************
public class Student {

public static void main(String[] args)


{
int x=0;

final int y=1;

switch(x){

case 0 : System.out.println("Hello");//Hello
case 1 : System.out.println("Hello");
case 2 : System.out.println("Hello");
case 3 : System.out.println("Hello");

break;
case y : System.out.println("hanumanth");//valid
}

}
}

1.
2.
3.

Example 4
*************
public class Student {

public static void main(String[] args)


{
int x=1;

switch(1){

case 1 : System.out.println("Hello");//invalid

case 1 : System.out.println("hanumanth");//invalid
}

}
}

>In switch block,duplicate case value not required

Example 5
*************
public class Student {

public static void main(String[] args)


{
short x=10; //min-32768 to max 32767

switch(x){

case 10 : System.out.println("Hello");//valid

case 100 : System.out.println("Hi");//valid

case 1000 : System.out.println("hanumanth");//invalid


}

}
}

>Here byte type variable can store in the range of the values min-128 to max 127

>Here case 10 is allowed in the range of the values min-128 to max 127
>Here case 100 is allowed in the range of the values min-128 to max 127

>Here case 1000 is not allowed in the range of the values min-128 to max 127

Case value rules


***********************

1.>In switch block,every case value should be constant not variable


2.>In switch block,duplicate case value not required
3.>In switch block,every case value should be in the range of argument type

What is a fall-through inside switch block ?


**********************************************
Ans : Here expression value is matched with any case value,from that case onwards

all the statements will be executed automatically until break statement then

this concept is called fall-through concept.

Example 6
*************
public class Student {

public static void main(String[] args)


{
int x=0;

switch(x){

case 0 : System.out.println("Hello");//

case 1 : System.out.println("Hi");//
break;
case 2 : System.out.println("hanumanth");//

default : System.out.println("NewIndia");//
}

}
}

Example 7
*************
public class Student {

public static void main(String[] args)


{
char ch='r';

switch(ch){

case 'g' : System.out.println("green");//


case 'r' : System.out.println("Red");//
break;
case 'y' : System.out.println("Yellow");//

default : System.out.println("no color");//


}

}
}

default case rules


**********************
1.In switch block, we can write default case only once
2.Here default case will be executed when expression value is not matched with any
case value
3.In switch block, we can write default case anywhere

Example 8
*************
public class Student {

public static void main(String[] args)


{
int furniture=0;;

switch(furniture){

default : System.out.println("no furniture");//

case 0 : System.out.println("table");//
break;
case 1 : System.out.println("chair");//

case 2 : System.out.println("cot");//

}
}

loops in java ?
******************
Why we are using loops ?
****************************
Ans : Here loops are used to execute a group of statements repeatedly as long as

the condition is true.

Example 1
*************

public class Student {

public static void main(String[] args)


{
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
}
}

types of loops
*****************

3.forloop

Where exactly we can use forloop ?


*************************************
Ans : Some times we need to perform same action with multiple time so at that

time we need to follow forloop.

Syntax:
**********

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
//loop body
Statement1;
Statement2;
Statement3;
}

Syntax Explanation :
**********************

1.
2.

How to print (starting)1-10(ending) nos ?


***************************
1
2
3
4
5
.......10

Example 1
*************
public class Student {

public static void main(String[] args)


{

for(int i=1;i<=10;i++)
{

System.out.println(i);

}
}

i++;

i=i+1
i=1+1
i=2
-----------
i++;

i=i+1
i=2+1
i=3

Example 2
*************
public class Student {

public static void main(String[] args)


{
int j=1;//local variable

for(int i=1;i<=10;i++)
{

System.out.println(i);

System.out.println(j);

}
System.out.println(i);

System.out.println(j);
}
}

Difference betweeen print() and println() in java ?


*******************************************************
print()
***********

>By using this we can print the text and the curser waits on the same line

to print the next text.

Example
************
System.out.print("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
**********
Hello---Hi---
Hanumanth

println()
*************
>By using this we can print the text and the curser move to next line
automatically.

Example
************
System.out.println("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
**********
Hello---
Hi---
Hanumanth

System.out.println();= go to new line / next line

Nested for loop(forloop inside another forloop) in java ?


**********************************************************

Syntax :
************
for(initialization-part ; conditional-part/testing-part ; increment/decrement-part)
{

for(initialization-part ; conditional-part/testing-part ; increment/decrement-


part)
{

//Inner forloop body

}//Inner forloop end

//outer forloop body

}//outer forloop end

Syntax Explanation :
***********************

Output
*********

0 1 2
3 4 5
6 7 8
check ur email
what is a class in java ?
******************************
Ans : It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

>Here class is a blueprint or Template or structure or design from which individual

objects are created.

Note : Here always created from class to object ,not object to class

In general car is a object,and it has two things


****************************************************
1.State/properties
2.Behavior / Actions

Object syntax
*****************

Student S = new Student();

Object syntax Explanation :


******************************
>Student()==>
>new==>

Why we are using new keyword ?


*******************************
Ans : By using new keyword,we can create Student object(new Student();)
>S
>Student

class syntax:
***************

class <classname>
{

//1.State/properties---------variables

<datatype> variable1;

<datatype> variable2;
//2.Behavior / Actions-------methods

return-type method_name1()
{

return-type method_name2()
{

main()
{

}
}

class and object example


***************************

Difference betweeen class and object in java ?


************************************************
class
*******
1.It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

2.Why we are using class keyword ?


*************************************
Ans : By using class keyword ,we can create class

3.In program,we can create class only once

4.We can create class without creating an object

5.Here memory space is not allowed when class is created

6.A class can contain variables and methods

Object
***********
1.It exists really / physically

Examples : car,table,cat,apple etc.

2.Why we are using new keyword ?


*******************************
Ans : By using new keyword,we can create Student object(new Student();)
3.In program,we can create object multiple times

4.We can't create object without class

5.Here memory space is allowed when object is created

6.And object also can contain variables and methods

Flow-control in java ?
**************************

Selection statement
**********************

if statement / block
*************************

Syntax :
*************

if(conditional-part/testing-part) //here must be boolean condition


{

//body
}

Syntax Explanation:
*************
1.
2.

Example 1
***********
public class Student {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}
}

Example 2
***********
public class Student {
public static void main(String[] args)
{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}else
{
System.out.println("Animals age not matched");
}

}
}

Conclusion
*************
>If u want to check only true condition then we have to go if statement

>If u want to check true / false condition then we have to go if-else statement

Example 3
***********
public class Student {

public static void main(String[] args)


{
int A=100;

if(A>50)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

Example 4
***********
public class Student {

public static void main(String[] args)


{
int A=100;

if(A) //error //here must be boolean condition


{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}

}
}

>if(A)==>if(100)==>

F : int
R : boolean

Example 5
***********
public class Student {

public static void main(String[] args)


{
int x=10;

if(x=20)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

>Here int x=10;now onwards x value will become 20


>if(x),here x means what 20
>if(20)==>

F : int
R : boolean

Example 6
***********
public class Student {

public static void main(String[] args)


{
int x=10;

if(x==20)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

==------->By using this,we can compare the values / references / boolean value
=-------->By using this,we can assigning the value into variable

Example 7
***********
public class Student {

public static void main(String[] args)


{
boolean b=true;

if(b=false)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

>Here boolean b=true;now onwards b value will become false

>if(b),here b means what false


>if(false)==>

F : boolean
R : boolean

Example 8
***********
public class Student {

public static void main(String[] args)


{
boolean b=false;

if(b==false)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

Switch block
***************

>Suppose if u want to check one or more conditions then we have to go with switch
block

Example 2
***********
Definition :
****************

Manual Steps
***************
1.Create Superclass(Calculation)
2.Create Subclass1(Sum) from Superclass(Calculation)
3.Create Subclass2(Subtraction) from Subclass1(Sum)
4.Create Mainclass

Java code
****************

Hierarchical Inheritance in java


*****************************

Definition:
***************

Here multiple subclasses acquired all the features of one superclass by using

extends keyword then it is called Hierarchical Inheritance.

Syntax :
*************

class Superclass
{

}
class Subclass1 from Superclass
{

}
class Subclass2 from Superclass
{

}
class Subclass3 from Superclass
{

Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclass1(Dog) from Superclass(Animal)
3.Create Subclass2(Cat) from Superclass(Animal)
4.Create Subclass3(Cow) from Superclass(Animal)
5.Create Mainclass

Java code
**************

Case 1
*********
Dog D = new Dog();

D.eat();-----valid
D.bark();----valid
Case 2
*********
Animal D = new Dog();

D.eat();//--valid
D.bark();//invalid

Example 2
************

super() and this() in java ?


********************************
Example 1
***************
class Test{

Test()
{

System.out.println("Hanumanth");

super();//invalid
}
}
>Here super() must be in the 1st place in the constructor

Example 2
***************
class Test{

Test()
{
super();//valid
System.out.println("Hanumanth");

}
}

>Here always super() must be in the 1st place in the constructor

Example 3
***************
class Test{
Test()
{

System.out.println("Hanumanth");
this();//invalid

}
}

>Here this() must be in the 1st place in the constructor

Example 4
***************
class Test{

Test()
{
this();//valid
System.out.println("Hanumanth");

}
}

>Here always this() must be in the 1st place in the constructor

Example 5
***************
class Test{

Test()
{
super();//valid---1st place
this();invalid---2nd place
System.out.println("Hanumanth");

}
}

Example 6
***************
class Test{

void test()
{
super();//invalid

System.out.println("Hanumanth");

}
}

Where we can create super() and this() ?


********************************************
Ans : Inside the constructor only
3.How to handle multiple windows ?
*************************************
diagram:
***********

Manual Steps
****************
1.Count total windows
**************************
Set<String> totalWindows = driver.getWindowHandles();

System.out.println("totalWindows : "+totalWindows.size());//2

2.Handle child window

>switch to child window


>do some action
>close the child window

Selenium java code


*********************
//>switch to child window

driver.switchTo().window(allwindowhandles.get(1));

//>do some action

System.out.println(driver.getTitle());

//>close the child window

driver.close();

3.Handle Main window

>switch to Main window


>do some action
>close the child window

Selenium Java code


********************

//>switch to Main window

driver.switchTo().window(allwindowhandles.get(0));

//>do some action

System.out.println(driver.getTitle());

//>close the child window


driver.close();

Action class in selenium


****************

1.How to perform dragAndDrop operation in selenium ?


*******************************************************

Inheritance in java(java oops concept)


********************************************
Why need inheritance concept in java ?
**************************************
Ans :

Without Inheritance
************************
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create Mainclass

Java code
***************
What is a inheritance in java ?
*******************************

Definition:
****************

What are the advantages of inheritance ?


*******************************************
Ans : By using inheritance,

1.Reduce the code size


2.Reduce the development time
3.Avoid the duplicate code

What is the main advantage of inheritance ?


*********************************************
Ans : code reusability

Syntax:
***********
class Superclass
{

}
class Subclass extends Superclass
{

Example
************
Manual Steps
*****************
1.Create Superclass(Teacher)
2.Create Subclass(Student) from Superclass(Teacher)
3.Create Mainclass

Java code
*************

In superclass
***************

Common code + Additional code(optional)

In subclass
***************

Additional code(mandatory)

3.How to handle multiple windows in selenium?


*************************************

Diagram:
************

Manual Steps
**************
1.Count total windows
*************************
Set<String> totalWindows = driver.getWindowHandles();

System.out.println("totalWindows : "+totalWindows.size());//2

2.Handle child window

>switch to child window


>do some action
>close the child window

Selenium Java code


*********************

3.Handle Main window

>switch to Main window


>do some action
>close the Main window

Selenium Java code


*********************
Constructor in java ?
************************
>This is similar to method

Why need constructor in java ?


***********************************
Ans :

Types of constructor
************************
1.default constructor
2.parameterized constructor

1.default constructor
***********************
Syntax:
***********
Student()
{

}
2.parameterized constructor
*****************************
Syntax:
***********
Student(para1,para2,para3)
{

>here constructor doesn't return any value not even void

1.In default constructor,how to initialize the values for that instance variables.
********************************************************************
Student()
{
name ="Sai";

rollno=101;
}

Example 1
***********
When default constructor will be called ?
********************************************
Ans : Whenever u create an object by default default constructor will be called

When function will be called ?


********************************
Ans : Whenever u create an object after function will be called

2.In parameterized constructor,how to initialize the values for that instance


variables.
********************************************************************
Student(String Akki,int 102)
{

name = Akki;

rollno =102;
}

When parameterized constructor will be called ?


**************************************************
Ans : Whenever u create an object and passing the values then parameterized

constructor will be called.


Example
***********

In method,return-type is mandatory ?
*******************************************
Ans : Yes

In java,constructor overloading is possible ?


*************************************************
Ans : Yes

What is a constructor overloading ?


***************************************
Ans : Here constructor name same but with different argument types then this

concept is called constructor overloading concept.

3.A method is called and executed multiple times from single object.
*********************************************************************
Example
***********

4.A constructor is called and executed only once from single object
**********************************************************************
Example
*************

Note :
**********

Here we can create one or more constructors in the same class but with different

argument types.

>Here instance variables and local variables both are not same so in this case

this keyword an optional.


*************************************************************************
Example
************

>Here instance variables and local variables both are same so in this case

we have to create this keyword .


***********************************************************************
Example
**********
>When i run this program by default JVM will always call to current method variable

value not instance variable value.

this keyword in java ?


***************************

>Whenever u create an object,by default this keyword is also created automatically

and here this keyword refer to student class object.

How to call the current class instance variable from this keyword ?
********************************************************
Syntax : this.variablename

How to call the current class default constructor from this keyword ?
********************************************************
Syntax : this();

How to call the current class parameterized constructor from this keyword ?
********************************************************
Syntax : this(value1,value2);

How to call the current class method from this keyword ?


********************************************************
Syntax : this.methodname();

Switch Statement
********************

>Suppose if u want to check one or more conditions then we have to go switch


statement

Syntax:
***********

switch(Expression value){

case value 1 : statement1--->code to be executed

break;
case value 2 : statement2--->code to be executed

break;
case value 3 : statement3--->code to be executed

break;
default : statement4--->Here default case will be executed
when expression

value is not matched


with any case value.
}

Syntax Explanation :
**************************
1.
2.
3.
4.
5.
6.

Example 1
*************

public class Student {

public static void main(String[] args)


{

int x=0;

switch(x){

System.out.println("Hanumanth");

}
>In switch block,every statement should be under case value and default case.

>In switch block,independent statement is not allowed

Example 2
*************

public class Student {

public static void main(String[] args)


{

int x=0;

int y=1;

switch(x){

case 0 : System.out.println("Hello");//valid

case y : System.out.println("Hanumanth");//invalid
}

>In switch block,every case value should be constant not variable

Example 3
*************

public class Student {

public static void main(String[] args)


{

int x=0;
final int y=1;

switch(x){

case 0 : System.out.println("Hello");//Hello
case 1 : System.out.println("Hello");
case 2 : System.out.println("Hello");
case 3 : System.out.println("Hello");

case y : System.out.println("Hanumanth");//valid
}

>
>
>

Example 4
*************

public class Student {

public static void main(String[] args)


{
//Local variables

int x=10;

switch(x){

case 10 : System.out.println("Hello");//valid
case 11 : System.out.println("Hello");//invalid
case 11 : System.out.println("Hello");//invalid

}
>In switch block ,duplicate case value not required

Example 5
*************

public class Student {

public static void main(String[] args)


{
//Local variables

short b=10; //min -32768 to max 32767

switch(b){
case 10 : System.out.println("Hello");//valid
case 100 : System.out.println("Hi");//valid
case 1000 : System.out.println("Hanumanth");//invalid

>min -128 to max 127

>Here case 10 is allowed in the range of the values min -128 to max 127
>Here case 100 is allowed in the range of the values min -128 to max 127
>Here case 1000 is not allowed in the range of the values min -128 to max 127

Case value rules


**********************
1.In switch block,every case value should be constant not variable
2.In switch block ,duplicate case value not required
3.In switch block,every case value should be in the range of argument type.

What is a fall-through inside a switch block ?


**************************************************
Ans : Here expression value is matched with any case value, from that case onwards

all the statements will be executed automatically until break statement then this
concept

is called fall-through concept.

Example 6
*************
public class Student {

public static void main(String[] args)


{
int x=0;

switch(x){

case 0 : System.out.println("Hello");

case 1 : System.out.println("Hi");

break;
case 2 : System.out.println("Hanumanth");

default : System.out.println("Kosmik");
}

}
Today 2nd class
******************

>If u want to access the java and selenium then we need to download JDK(Java
development kit) file first

Part 1
********
>download JDK(Java development kit) file first
>Install JDK(Java development kit) file into ur local system
>Verify JDK(Java development kit) file successful install or not into ur local
system
>Download Eclipse IDE/oxygen
>Directly open the Eclipse IDE/oxygen and here no need to install Eclipse
IDE/oxygen

Part 2
*********
1.Create new JavaProject
2.Create new package
3.create new class

Datatype in java ?
***********************

int x=10;

What is a variable in java ?


********************************
Ans : Variable is a memory location and here variable x can store some data

based on datatype then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script
>In java or other programming languages,we know we need variables to store

some data based on datatype.


>In java,every variable and every expression should have a datatype

type of datatypes
******************
1.Primitive datatypes
2,Non primitive datatypes

What are the integral integer datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


**************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long,float,double,boolean,char

What are the non-primitive datatypes in java ?--IQ


**************************************************
Ans : String ,array,set,list etc.

byte datatype in java ?


***************************

How to call the superclass default constructor using super()?


*********************************************************
Example 1
************

Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
**************

How to call the superclass default constructor ?


************************************************
Syntax : super();

How to call the superclass parameterized constructor ?


************************************************
Syntax : super(value1,value2);

How to call the superclass parameterized constructor using super()?


*********************************************************
Example 2
************
Manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangle) from Superclass(Shape)
3.Create MainClass

java code
************88

Difference betweeen super and this keyword ?


***********************************************

Why we are using super keyword ?


**********************************
Ans : By using super keyword,we can call superclass members(variables + methods)

How to call the superclass variable ?


***************************************
Syntax : super.variablename

Example
***********
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
**************

How to call the superclass method ?


***************************************
Syntax : super.methodname();

Example
**********
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
**************

super() and this()

Where we can create super() and this() ?


********************************************
Ans :

Where we can create super and this keyword?


********************************************
Ans :

Why we are using this keyword ?


**********************************
Ans : By using super keyword,we can call the current class members(variables +
methods)

How to call the current class variable ?


***************************************
Syntax : this.variablename
How to call the current class method ?
***************************************
Syntax : this.methodname();

Action class
*************

1.How to perform Drop & Drag operation in Selenium ?


***********************************************************
diagram:
************

Manual Steps
****************

Selenium Java code


*********************

2.How to perform Mouse hover in selenium?


********************************************

Manual Steps
****************

Selenium Java code


*********************

3.To verify whether the DoubleClick operation successfully performed or Not?


************************************************************************

Manual Steps
****************

Selenium Java code


*********************

How to perform rightClick operation in selenium?


******************************************************

Example
***********

Types of inheritance
*********************
1.single inheritance
2.Multi-Level Inheritance
3.Hierarchical inheritance

1.single inheritance
*************************
Example 2
***************
Manual Steps
***************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
**************
Case 1
**********
Child C = new Child();

C.m1();//call the m1()----valid


C.m2();//call the m2()----valid

Case 2
**********
Parent C = new Child();

C.m1();//call the m1()---valid


C.m2();//call the m2()---invalid

Case 3
**********
Parent C = new Parent();

C.m1();//call the m1()---valid


C.m2();//call the m2()---invalid

Multi-Level Inheritance
***************************
Definition :
****************

Syntax :
**********
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Subclass1
{

Example 1
***************
Manual Steps
*************
1.Create Superclass(GrandFather)
2.Create Subclass1(Father) from Superclass(GrandFather)
3.Create Subclass2(Son) from Subclass1(Father)
4.Create MainClass

Java code
************

Example 2
***********

Action class in selenium


*****************

1.How to perform Drop & Drag operation in Selenium ?


*******************************************************
diagram:
*************

Manual Steps
**************

Selenium java code


**********************

2.How to perform Mouse hover in selenium?


*******************************************

Manual Steps
**************

Selenium java code


**********************

Example 2
**************

Calling parameterized constructor and method from default constructor


************************************************************************

Calling default constructor from parameterized constructor


*************************************************************
Example
************

Calling parameterized constructor from parameterized constructor


*****************************************************************
Example
***********
Why need constructor in java ?
*********************************
Note :
********
1.Suppose if u don't mention constructor in this class ,by default JVM will provide

default constructor and initialize the default values for that instance variables.
see below

Student()
{
name =null;
rollno=0;

output
********
Student name : null
Student rollno : 0

>Here output ,i am not satisfied with default values,so in this case i want to give
my

own values or user/programmer defined values.So in this kind of situation

we are going to learn new thing i.e Constructor

Example 7
************
public class Student {

public static void main(String[] args)


{
char ch='r';

switch(ch){

case 'g' : System.out.println("green");

break;
case 'r' : System.out.println("Red");//Red
break;
case 'y' : System.out.println("yello");

default : System.out.println("no color");


}

default case rules


***********************
>Here default case will be executed when expression value is not matched with any
case value
>In switch block,we can write default case only once
>In switch block,we can write default case anywhere but switch is recommended

to write at last

Example 7
************
public class Student {

public static void main(String[] args)


{
int furniture=0;

switch(furniture){

default : System.out.println("no furniture");

case 0 : System.out.println("table");
break;
case 1 : System.out.println("chair");

case 2 : System.out.println("cot");
}

Iterative statement
**********************
1.while
2.do-while
3.forloop

Loops in java
**************

How to print hanumanth 10 times ?


******************************
Example 1
****************
public class Student {

public static void main(String[] args)


{
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
System.out.println("hanumanth");
}

Why we are using loops in java ?


******************************
Ans : Here loops are used to execute a group of statements repeatedly as long as

the condition is true.

types of loops
******************

3.forloop

Where exactly we can use forloop ?


***************************************
Ans : Sometimes we need to perform same action with multiple times so at

that time we need to follow forloop.

Syntax :
************
for(initialization-part ;conditional-part/testing-part ; increment/decrement-
part)
{
statement1;
statement2;
statement3;
}

Syntax Explanation :
***********************
How to print (starting)1-10(ending) nos ?
************************
1
2
3
4
5
.........10

Example 2
**************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

System.out.println(i);

i++

i=i+1
i=1+1
i=2
-----------
i++

i=i+1
i=2+1
i=3

Example 3
**************
public class Student {

public static void main(String[] args)


{

int j=1; //local variable

for(int i=1;i<=10;i++)
{

System.out.println(i);//valid

System.out.println(j);//valid

System.out.println(i);//invalid

System.out.println(j);//valid
}

Nested forloop(forloop inside another forloop) in java ?


**********************************************************

byte datatype in java ?


**************************

>This will be used to store +ve and -ve nos


>Here byte datatype variable can store in the range of the values
min -128 to max 127

Example 1
************

byte b=125; //valid byte type value

System.out.println(b);

Code Explanation :
***********************
>Here providing value is 125
>Here Expected value is byte datatype value
>min -128 to max 127

Found : byte type value


Required : byte

Java compiler work


***********************
>Compile the java code line by line (That means checking the java code line by line

whether it is currect code or not)

JVM(Java virtual machine) work


**********************************

Just Simply execute the java code

Example 2
************

byte b="Hanumanth"; //invalid String

System.out.println(b);

>We can say this("Hanumanth") is a String type value

>Here String mean collection of characterss

Examples
***********
"HYD" or "H" or "123" or "HYD123" or "%^%^&^*&(*"

>Here everything in double quotes it's a string

>Here String always must be in double-quotes


F : String
R : byte

Example 3
************

byte b=127; //valid byte type value

System.out.println(b);

>127
>byte type value
>min -128 to max 127

F : byte type value


R : byte type value

Example 4
************

byte b=true; // invalid boolean type value

System.out.println(b);

Code Explanation :
*********************

>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean type value


R : byte

Example 5
************

byte b=125L; // invalid long

System.out.println(b);

>We can say this(125L) is long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
****************************************************************************
Ans : Yes

Datatype rules
********************

byte(least) < short < int < long < float < double(highest)

1.We can assign left-side datatype value into any right-side datatype variable

2.We can't assign right-side datatype value into any left-side datatype variable

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable
then we required typecasting.

F : long
R : byte

Example 6
************

byte b=10.5F; // invalid float

System.out.println(b);

>We can say this(10.5F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
************************************************************************
Ans : Yes

F : float
R : byte

Example 7
************

byte b=10.5; //

System.out.println(b);

Polymorphism in java ?
*************************

poly mean-------many

morphs---forms

Polymorphism mean -------many forms

In general examples of polymorphism


***************************************

Ex 1 : Here one form represents many forms then it is called polymorphism

Ex 2 : Here same name but with different sounds then it is called polymorphism

Ex 3 : A person behaves like in different ways then it is called polymorphism

1.A person in shopping mall behave like a customer


2.A person in bus behave like a passenger
3.A person in school behave like a student
4.A person at home behave like a son
types of polymorphism
***********************

What is a method overloading in java ?


***************************************
Definition 1:
***************

Here method name same but with different argument types then this concept is called

method overloading

Example 1
**************

Definition 2:
***************

Here method name same but with different method signature then this concept

is called method overloading.

Method overriding in java


****************************

Definition 1 :
*****************

>Here i am not satisfied with parent class method implementation(body),so that

in child class i am rewriting that method(parent class method) with different

method implementation then this concept is called method overriding concept.

Note :
**********

When i run this program by default JVM will always call to child class
method(overriding method)

not parent class method (overridden method)

Example 1
***********

Manual Steps
************
1.Create Parent class
2.Create child class from parent class
3.Create MainClass

Java code
***************

CAn we override parent class method into child class ?


*********************************************************
Ans : Yes

>Here parent class method which is overridden then it is called overridden method

>Here child class method which is overriding then it is called overriding method

>This concept is called overriding concept

Difference betweeen print() and println() ?


************************************************

print()
**********
>This will be used to print the text and the curser waits on the same line

to print the next text.

Example
************
System.out.print("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
*********
Hello---Hi---
Hanumanth

println()
***********

This will be used to print the text and the curser move to next line automatically

to print the next text.

Example
************
System.out.println("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
*********
Hello---
Hi---
Hanumanth

Nested forloop(forloop inside another forloop) in java ?


*********************************************************

Syntax:
**********

for(initialization-part ; conditional-part/testing-part ; increment/decrement-part)


{

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{

//Inner forloop body

}//Inner forloop end

//outer forloop body

}//outer forloop end

Syntax Explanation:
*********************

Example
**********

Output
********

0 1 2
3 4 5
6 7 8

Example 7
***********

byte b= 10.5; //invalid double

System.out.println(b);

>We can specify floating-point literal value(float value and double value) only in
decimal form

What are the floating-point literal value?


********************************************
Ans : float value and double value

Float Examples
******************
10.5F,2.5f,10.1111f,-123.234f--------

double Examples
******************

10.5,2.5,10.1111,-123.234--------

Found : double
Required : byte

Example 8
***********

byte b= 128; //invalid int

System.out.println(b);

Code Explanation :
*********************
>128
>byte type value
>min -128 to max 127

What are the integral literal values ?


*****************************************
Ans : byte value,short value,int value,long value

What are the floating-point literal value?


********************************************
Ans : float value and double value

Note :
*********
By default every integral literal value is what type int type value

By default every floating-point literal value is what type double type value

F : int
R : byte

Short datatype in java ?


**************************
>+ve and -ve nos

>min -32768 to max 32767

Example 1
************

short s= 32767; // valid short type value

System.out.println(s);
code Explanation :
********************
>32767
>short type value
>min -32768 to max 32767

F : short type value


R : short

Example 2
************

short s= 32.767; // invalid double

System.out.println(s);

F : double
R : short

Example 3
************

short s= 32767L; // invalid long

System.out.println(s);

F : long
R : short

int datatype in java ?


*************************

>+ve and -ve nos


>min -2147483648 to max 2147483647

Example 1
***********

int i= 2345; //valid int type value

System.out.println(i);

>2345
>int type value
>min -2147483648 to max 2147483647

F : int type value


R : int

Example 2
***********

int i= 2345L; // invalid long type value

System.out.println(i);

F : long type value


R : int
Example 3
***********

int i= 23.45; // invalid double

System.out.println(i);

F : double
R : int

Long datatype in java ?


***************************
>+ve and -ve nos
> min -9223372036854775808 to max 9223372036854775807

Example 1
***********

long l= 2345L; // valid long

System.out.println(l);

Example 2
***********

long l= 125; // valid int

System.out.println(l);

F : int
R : long

Example 3
***********

long l= 12.5F; // invalid

System.out.println(l);

String datatype in java ?


*****************************
>This will be used to store single character and group of characterss
>Here range not applicable for string datatype
Examples
**********

"HYD" or "H" or "HYD123" or "123" or "%^^%^&%&*"

>Here everything in double quotes it's a String


>Here string always must be in double-quotes
Example 1
***********

String s= 0; // invalid int

System.out.println(s);

byte,short,long,float,double

F : int
R : String

Example 2
***********

String s= true; // invalid

System.out.println(s);

Example 3
***********

String s= Hanumanth; // invalid

System.out.println(s);

Example 4
***********

String s= "Hanumanth"; // valid String

System.out.println(s);

Boolean datatype in java ?


******************************
>This will be used to store only boolean value such as true / false
>Here range not applicable for boolean datatype

Example 1
***********

boolean b= 10; // invalid int

System.out.println(b);

F : int
R : boolean

Example 2
***********

boolean b= "Hanumanth"; // invalid String

System.out.println(b);

Example 3
***********
boolean b= True; // invalid

System.out.println(b);

>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'

Example 4
***********

boolean b= true; // valid boolean

System.out.println(b);

3.To verify whether the DoubleClick operation successfully performed or Not?


***********************************************************************

Diagram:
***********

Manual Steps
****************

Selenium Java code


*********************

// identify copyText button element


WebElement copyText =
driver.findElement(By.xpath("html/body/button"));

Actions act = new Actions(driver);

act.doubleClick(copyText).perform();
//------------------------------------------------------------------Operation
code

String entered_text =
driver.findElement(By.id("")).getAttribute("value");//Hello World!

System.out.println(entered_text);//Hello World!

//----------------------------------------------------------------
Verification code

if(entered_text.equals("Hello World!"))
{

System.out.println("Double click operation successfully


verified");
}else
{

System.out.println("Double click operation not successfully


verified");
}

How to perform rightClick operating in selenium ?


*************************************************
Manual Steps
***************

Selenium Java code


*******************

How to give the input value from keyword ?


*********************************************
or

How to perform single action using action class ?


******************************************************
Ans : by using sendKeys()

Examples
**********

sendKeys(Keys.ARROW_DOWN)
sendKeys(Keys.ARROW_RIGHT)
sendKeys(Keys.ENTER)
sendKeys(Keys.DELETE)
sendKeys("a")

How to perform multiple actions at a time


*******************************
Abs : By using KeyDown() and KeyUp()

KeyDown() :perform the keypress


KeyUp() : perform the keyrelease

Examples
************

Ctrl+a,Ctrl+c,Ctrl+v,Shift+a,Ctrl+F11 etc

Ctrl+a = control press + press a + Control release

Ctrl+c = keyDown(Keys.CONTROL) + sendKeys("c") +keyUp(Keys.CONTROL)

Shift+a = Shift press + press a + Shift release

Shift+a = keyDown(Keys.SHIFT) +sendKeys("a") +keyUp(Keys.SHIFT)

Example How to perform Ctrl+a in selenium ?


***********************************************

Difference betweeen LinkText and partialLinkText Locators in selenium ?


***********************************************************************

LinkText locator
********************

Definition :
*****************

Syntax :
************
driver.findElement(By.linkText(locator value));

Example
***********

driver.findElement(By.linkText("Verified Rights Owner (VeRO) Program"));

program
***********

Manual Steps
***************

Selenium Java code


*********************

partialLinkText Locators
****************************

Definition :
*****************

Syntax :
************
driver.findElement(By.patialLinkText(locator value));

Example
***********

driver.findElement(By.patialLinkText("Owner (VeRO)"));

program
***********

Manual Steps
***************

Selenium Java code


*********************

Example 2
************
Definition :
******************

Manual Steps
****************
1.Create Superclass(Calculation)
2.Create Sum class from Superclass(Calculation)
3.Create Subtraction class from Sum class
4.Create Mainclass

Java code
************

Hierarchical inheritance in java


****************************
Definition 1:
***************

Syntax :
**********

class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Superclass
{

}
class Subclass3 extends Superclass
{
}

Example
***********
1.Create Superclass(Animal)
2.Create Subclass1(Dog) from Superclass(Animal)
3.Create Subclass2(Cat) from Superclass(Animal)
4.Create Subclass3(Cow) from Superclass(Animal)
5.Create Mainclass

Java code
*************

Case 1
**********
Dog D = new Dog();

D.eat();----valid
D.bark();----valid

Case 2
**********
Animal D = new Dog();

D.eat();----valid
D.bark();----invalid

Example 2
***************
super() and this() in java ?
*******************************

Example 1
***********

class Test
{

Test()
{

System.out.println("Hanumanth");

super();//invalid
}
}
>Here super() must be in the first place in the constructor

Example 2
***********

class Test
{

Test()
{
super();//valid
System.out.println("Hanumanth");
}
}
>Here always super() must be in the first place in the constructor

Example 3
***********

class Test
{

Test()
{

System.out.println("Hanumanth");
this();//invalid

}
}

>Here this() must be in the first place in the constructor

Example 4
***********

class Test
{

Test()
{
this();//valid
System.out.println("Hanumanth");

}
}

>Here always this() must be in the first place in the constructor

Example 5
***********

class Test
{

Test()
{
this();//valid---1st place
super();//invalid----2nd place
System.out.println("Hanumanth");

}
}

Example 6
***********

class Test
{

Test()
{
super();//valid---1st place
this();//invalid----2nd place
System.out.println("Hanumanth");

}
}

Example 7
***********

class Test
{

void Test()
{
this();//invalid

System.out.println("Hanumanth");

}
}

Where we can create super() and this() ?


**********************************
Ans : Inside the constructor only

How to call the super class default constructor ?


****************************************
Syntax : super();

Example 1
*************

Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
***********8

How to call the super class parameterized constructor ?


****************************************
Syntax : super(value1,value2)

Example 2
*************
Manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangle) from Superclass(Shape)
3.Create MainClass

Java code
***********8

difference betweeen super and this keyword in java ?


****************************************************

Why we are using super keyword ?


*********************************
Ans : By using super keyword ,we can call the superclass members(variables +
methods)

How to call the superclass variable ?


*************************************
Syntax : super.variablename

Example
***************
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
***********8

How to call the superclass method ?


*************************************
Syntax : super.methodname();

Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
***********8
Why we are using this keyword ?
*********************************
Ans : By using this keyword ,we can call the current class members(variables +
methods)

How to call the current class variable ?


*************************************
Syntax : thid.variablename

How to call the current class method ?


*************************************
Syntax : this.methodname();

Transfer statement:
*********************

1.Break statement.
*******************
Example 1
**************
public class Student {

public static void main(String[] args)


{
int x=10;

if(x)
{
break;//error
}

System.out.println(Hanumanth);
}

Where we can create break statement ?


*************************************
Ans : Inside the loops and switch block

Without break statement inside switch block


*********************************************
Example 2
**************
public class Student {

public static void main(String[] args)


{
int x=0;

switch(x){

case 0: System.out.println(Hello);
case 1: System.out.println(Hi);
case 2: System.out.println(Hanumanth);
default: System.out.println(Kosmik);

With break statement inside switch block


*********************************************
Example 2
**************
public class Student {

public static void main(String[] args)


{
int x=0;

switch(x){

case 0: System.out.println(Hello);
case 1: System.out.println(Hi);
break;

case 2: System.out.println(Hanumanth);
default: System.out.println(Kosmik);

Why we are using break inside switch block ?


**********************************************
Ans : To stop the fall-through

Without break statement inside forloop block


*********************************************

How to print (starting)1-10(ending) nos?


**************************
1
2
3
4
5
.......10

Example 2
**************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{
System.out.println(i);

With break statement inside forloop block


*********************************************
Syntax:
*************

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{

if(condition to break)
{
break;

Statements;

Syntax Explanation:
********************
1.
2.
3.
4.
How to print 1-3 from 1-10 nos ?
**************************************

Example 4
**************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

if(i==4)
{
break;

}
System.out.println(i);

Why we are using break statement inside loops ?


***************************************************
Ans : To break the loop based on condition

Continue statement
**********************

Example 1
************
public class Student {

public static void main(String[] args)


{
int x=10;

if(x)
{
continue;//error

System.out.println("Hanumanth");

Where we can create continue statement ?


******************************************
Ans : Inside the loops only

Without continue statement inside forloop block


*********************************************

How to print 1-10 nos ?


***************************
Example 2
************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{
System.out.println(i);

With continue statement inside forloop block


*********************************************
Syntax:
*************

for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{

if(condition to continue)
{
continue;

Statements;

Syntax Explanation:
********************
1.
2.
3.
4.

How to print 1-10 nos except 3 ?


***************************
Example 2
************
public class Student {

public static void main(String[] args)


{
for(int i=1;i<=10;i++)
{

if(i==3)
{

continue;

}
System.out.println(i);

Constructor in java ?
*************************
>This is similar to method

Why need constructor in java ?


**********************************
Ans :

types of constructor
***********************
1.Default constructor
2.Parametarized constructor

1.Default constructor
*********************
Syntax:
*************
Student()
{

2.Parametarized constructor
*******************************

Syntax:
*************
Student(para1,para2,para3)
{

}
>Here constructor doesn't return any value not even void

In method,return-type is mandatory ?
*****************************************
Ans : Yes

1.In default constructor,how to initialize the values for that instance variables ?
***********************************************************************************

1.In default constructor,how to initialize the values for that instance variables?
*************************************************************************

Student()
{
name = "Sai";

rollno = 101;

Example
***********
When default constructor will be called ?
*********************************************
Ans : Whenever u create an object by default default constructor will be called

When method / function will be called ?


***********************************
Ans : Whenever u create an object after function will be called

When parameterized constructor will be called ?


*********************************************
Ans : Whenever u create an object and passing the values then parameterized
constructor will be called

1.In parameterized constructor,how to initialize the values for that instance


variables?
*************************************************************************

Student(String Akki,int 102)


{

name = Akki;

rollno = 102;
}

Example
*************

In java,constructor overloading is possible ?


************************************************
Ans : Yes

What is a constructor overloading in java ?


**********************************************
Ans : Here constructor name same but with different argument types then this

concept is called constructor overloading concept.

Example
***********

3. A method is called and executed multiple times from single object ?


*************************************************************************

Example
************

float datatype in java ?


*****************************
>This will be used to store +ve and -ve decimal value

> min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>Here we can specify floating-point literal value(float value and double value)
only in decimal form

Example 1
***********

float f = 23.45F; //valid float

System.out.println(f);

Example 2
***********

float f = 10.111111111F; // 9 1's valid float

System.out.println(f);

Example 3
***********

float f = 25F; // valid float


System.out.println(f);

Note :
********
When i run this program by default JVM will provide 25.0 instead of 25 while

assigning the value into float type variable f.

Example 4
***********

float f = 25; // valid int

System.out.println(f);

Double datatype in java ?


****************************
>This will be used to store +ve and -ve decimal value

>Here we can specify floating-point literal value(float value and double value)
only in decimal form

min -1.7976931348623157e308d to max 1.7976931348623157e308D

Example 1
***********

double d = 12.5; // valid double type value

System.out.println(d);

Example 2
***********

double d = 10.1111111111111111; // 16 1's valid double

System.out.println(d);

Example 3
***********

double d = 10.1111D; // valid double

System.out.println(d);

Char datatype in java ?


***************************
>This will be used to store single character not group of characterss

Examples
***********

'H' or '5' or '@'------valid

'Hjhgj' or '534324' or '@^*&(*&(*'------invalid

>Here everything in single quotes it's a character


>min 0 to max 65535(0 to 127)

Example 1
***********

char ch = "H"; // invalid String

System.out.println(ch);

Example 2
***********

char ch = H; // invalid

System.out.println(ch);

Example 3
***********

char ch = 'H'; // valid char

System.out.println(ch);

Example 4
***********

char ch = 65; // valid

System.out.println(ch);

Example 2
************
Definition 2:
****************
Ans : Here method name same and method signature same then this concept is called

method overriding.

Manual Steps
***************
1.Create Parent class
2.Create Child class from Parent class
3.Create MainClass

Java code
************

Method overriding rules


*************************
private < protected < public

Method overloading rules


************************

private < protected < public

Abstract class in java ?


***************************

When will u go for abstract class in java and selenium ?


***********************************************************
Ans :

abstract keyword in java ?


*****************************

>

In general abstract mean not clear,not complete,incomplete method,incomplete class

partial implementation just like that.

We need to learn 4 things


****************************
1.concreate method
2.concreate class
3.abstract method
4.abstract class

What is a concreate method(regular method) in java ?


*************************************
Ans : A method has declaration part and implementation part such type of method is
called

concreate method.

Example 1
************

class Test{

//concreate method

void m1()
{

}
//concreate method

void m1(int i)
{

}
//concreate method

main()
{

}
}
What is a concreate class(regular class) in java ?
*************************************
Ans : A class can contain only concreate methods such type of class is called

concreate class.

Example 2
************

class Test{

//concreate method

void m1()
{

}
//concreate method

void m1(int i)
{

}
//concreate method

main()
{

}
}

What is a abstract method in java ?


*************************************

Ans : A method has declaration part but not implementation part such type of method
is called

abstract method.
Example 3
************

abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

//abstract method

abstract void m2(); //Unimplemented method

1.
2.
3.
4.

Here who is the responsible to provide implementation(body) for that abstract


method ?
********************************************************************************
Ans : Child class

Note :
*******

>Here we can't create the object for that abstract class (Unimplemented class)

What is a abstract class in java ?


************************************

Ans : A class can contain concreate methods and abstract methods such type of class
is called

abstract class.

Example 4
************

abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

//abstract method
abstract void m2(); //Unimplemented method

Abstract class part 2


***************************

Inheritance in java
***********************

When we will u go for inheritance concept in java and selenium ?


******************************************************************
Ans :

Without inheritance
*********************
Example
***********
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create MainClass

Java code
*************

With inheritance
*********************
Example
***********

What is a inheritance in java?


********************************
Ans :

Note :
******

Advantages of inheritance
*****************************
Ans : By using inheritance

1.We can reduce the code size


2.We can reduce the development time
3.Avoid the duplicate code

Main Advantages of inheritance


*****************************
Ans: code reusability
Syntax:
**********

class Superclass
{

}
class Subclass extends Superclass
{

Example
***********
Manual Steps
****************
1.Create Superclass(Teacher class)
2.Create Subclass(Student) from Superclass(Teacher class)
3.Create MainClass

Java code
*************

In superclass
*****************

common code + Additional code(optional)

In subclass
******************

Additional code(mandatory)

types of inheritance
***********************
1.Single inheritance
2.Multi-Level Inheritance
3.Hierarchical inheritance

1.Single inheritance
*************************

Example 2
************
Manual Steps
**************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
************

Case 1
*********
Child C = new Child();
C.m1();//call the m1()---valid
C.m2();//call the m2()---valid

Case 2
*********

Parent C = new Child();

C.m1();//call the m1()---valid


C.m2();//call the m2()---invalid

Case 3
*********
Parent C = new Parent();

C.m1();//call the m1()//---valid


C.m2();//call the m2()//---invalid

2.Multi-Level Inheritance in java ?


*************************************
Definition :
***************

Syntax :
**********
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Subclass1
{

Example 1
**************
Manual Steps
****************
1.Create Superclass(GrandFather)
2.Create Subclass1(Father) from Superclass(GrandFather)
3.Create Subclass2(Son) from Subclass1(Father)
4.Create MainClass

Java code
************

Example 2
**************
Definition:
***************
Action class part 2
***********************
Example
************

Manual Steps
****************
1.Create Superclass(Abstract class(Car))
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))
3.Create Subclass2(Santro) from superclass(Abstract class(Car))
4.Create Mainclass

Java code
************

Common code
***************
1.regino
2.FuelTank
3.steering
4.breaks

school project
****************
Abstract class
*********************

//concreate methods

1.Teacher--------100%---------complete knowledge (void teacher(){})


2.Student--------100%---------complete knowledge (void student(){})
3.chortboard-----100%---------complete knowledge (void chortboard(){})

//abstract method

4.fee------------50%---------incomplete knowledge (abstract void fee();)

abstract void atm();

Keyboard Actions:
*********************
1.How to give the input value from the keyboard ?or How to perform single action in
a webpage using selenium?
Ans)By using sendKeys()

Examples
*****************
>sendKeys(Keys.ARROW_DOWN)
>sendKeys(Keys.ARROW_UP)
>sendKeys(Keys.DELETE)
>sendKeys(Keys.F12)
>sendKeys(Keys.ENTER)
>sendKeys("a")

2.How to perform multiple Actions at a time in a webpage using selenium?


**************************************************************************
Ans : By using keyDown() and keyUp()

>keyDown()===>Perform the key press


>keyUp()===>Perform the key release

Examples

*************
Ctrl + a,Ctrl + c ,Ctrl +v,Shift + a,Alt+ F ,Ctrl + N, Ctrl + T, Ctrl + w---------

Ctrl + a = Ctrl press + press a + Ctrl release

Ctrl + a = keyDown(Keys.CONTROL) +sendKeys("a") + keyUp(Keys.CONTROL)


Ctrl +v = keyDown(Keys.CONTROL) +sendKeys("v") + keyUp(Keys.CONTROL)

Shift + a = Shift press + press a + Shift release


Shift + a = keyDown(Keys.SHIFT) + sendKeys("a") + keyUp(Keys.SHIFT)

How to perform Ctrl + a in selenium using action class ?


**********************************************************
Example
************

How to enter text into input field(textbox,text area) using action class ?
***********************************************************************
WebElement SearchBox = driver.findElement(By.name("q"));

//Create action class object for that driver

Actions action = new Actions(driver);

action.sendKeys(SearchBox,"html").perform();

How to upload file in selenium ?


********************************

Polymorphism in java ?
*************************

poly mean ---many


morphs----forms

Polymorphism------many forms

In general examples of polymorphism


***************************************

Ex 1 : Here one form represents many forms then it is called polymorphism

Ex 2 : Here same name but with different sounds then it is called polymorphism

Ex 3 : A person behaves like in different ways then it is called polymorphism

1.A person in shopping mall behave like a customer


2.A person in bus behave like a passenger
3.A person in school behave like a student
4.A person at home behave like a son

types of polymorphism
**********************

What is a method overloading in java ?


******************************************
Definition 1:
****************
Here method name same but with different argument types then this concept is called
method overloading

Example 1
*************

Example 2
*************

Definition 2:
*****************

2.A constructor is called and executed only once per single object
*******************************************************************
Example
***********
4.If instance variable and local variable both are not same then in this case this
keyword an optional.
**********************************************************************************
Example
**********

5. If the instance variable and local variable both are same then in this case we
have to give this keyword mandatory.
***********************************************************************************
***
Example
************

this keyword in java ?


************************

How to call the current class instance variable from this keyword ?
********************************************************
Syntax : this.variablename

How to call the current class default constructor from this keyword ?
********************************************************
Syntax : this();

How to call the current class parameterized constructor from this keyword ?
********************************************************
Syntax : this(value1,value2);

How to call the current class method from this keyword ?


********************************************************
Syntax : this.methodname();

Example 2
**************

Example 4
***********

char ch=65; //valid the ASCII value(65) of a character---'A'(char type value)

System.out.println(ch);

What is the ASCII value(65) of a character ?


*******************************************
Ans : A

What is the ASCII value(97) of a character ?


*******************************************
Ans : a

What is the ASCII value(115) of a character ?


*******************************************
Ans : s

Example 5
***********

int i='D'; // valid the character('D') of ASCII value---68(int type value)

System.out.println(i);//68

What is the character('D') of ASCII value ?


*****************************************
Ans : 68

What is the character('g') of ASCII value ?


*****************************************
Ans : 103

Variable in java ?
***********************

int x=10;

What is a variable in java ?


*******************************
Ans :

Types of variables
*********************
1.Instance variables
2.Local variables
3.Static variables

What are the Instance variables in java ?


******************************************
Ans :

>The values of the name and rollno are different from student to student such type
of variables

instance variables.

>The values of the name and rollno are different from object to object such type of
variables

instance variables.

1.
2.
3.
4.

Where we can create instance variables ?


****************************************
Ans : Inside the class or outside the method or outside the constructor or outside
the block(

if,if-else,ladder if-else,switch,while,do-while,forloop,static)

Example 1
************
public class Student {

//Instance variable

String name = "Sai";


public static void main(String[] args)
{

System.out.println(name);//error

Can we access the instance variable into static area directly ?


****************************************************************
Ans : NO

Object Syntax:
***************

Student S = new Student();

Syntax Explanation :
*********************

>Student()==>This is called Student constructor


>Here new is called keyword
Why we are using new keyword ?
*********************************
Ans : By using new keyword ,we can create Student object(new Student();)

>Here S is called object reference variable

>Here Student is called class

Example 2
************
public class Student {

//Instance variable

String name = "Sai";

public static void main(String[] args)


{
//create the object for that Student class

Student S = new Student();

System.out.println(S.name);//Sai

Can we access the instance variable into static area directly ?


****************************************************************
Ans : NO,but we can access through object reference

Example 3
************

Hi Mam,

Please find my details

1.Sorry mam i can't pay u that much of amount


2.I am looking for 6yrs(Manual 3 + Automation 3)
3.I am Expected package 10L-11L
4.If any one is ok for 1Lakh then plz let me know,i am waiting mam

******I am waiting from last 2months Please help me mam for job*********

Thank you

Hanumanth.

Interface in java
*****************

When will u go for interface in java and selenium ?


********************************************************
Ans :

When will u go for abstract class in java and selenium ?


********************************************************
Ans :

Example
*********
Manual Steps
****************
1.Create Interface(Animal)
2.Create Subclass(Cat) from Interface
3.Create Mainclass

Java code
**************

1.When i run this program by default JVM will provide public static final for that
variable

2.In Interface,every variable are public static final

3.

4.
5

Difference betweeen extends and implements keyword ?


*****************************************************

extends : By using this,we can inherit the subclass from superclass

implements keyword : To implement an interface in child class we must use


implements keyword

Note :
***********
>We can't create object for that interface(Unimplemented interface) and abstract
class(Unimplemented class)

>We can create object for that implemented class

School project
***************

Case 1
***********

Abstract class
**********************
//concreate methods

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

//abstract method

4.fee-------------50%-----incomplete knowledge (abstract void fee();)

Case 2
***********

Interface
***********************
//Abstract methods

1.Teacher---------50%-----incomplete knowledge (abstract void teacher();)


2.Student---------50%-----incomplete knowledge (abstract void student();)
3.chortboard------50%-----incomplete knowledge (abstract void chortboard();)
4.fee-------------50%-----incomplete knowledge (abstract void fee();)

Interface part 2
******************
AutoIT
**********

1.Download autoit

2.Download autoit Editor

What is a method overriding in java ?


**************************************
Definition 1:
*****************
>Here i am not satisfied with parent class method implementation(body),so that in
child i am

rewriting that method(parent class method)with different implementation then it is


called method overriding.

Example 1
**************

Manual Steps
***************
1.Create Parent class
2.Create Child class from Parent class
3.Create MainClass

Java code
**************

>Here parent class method which is overridden then it is called overridden method

>Here child class method which is overriding then it is called overriding method

>This concept is called overriding concept

Example 2
**************

Definition 2 :
*****************

Here method name same and method signature same then this concept is called method
overriding

Manual Steps
***************
1.Create Parent class
2.Create Child class from Parent class
3.Create MainClass
Java code
**************

Method overriding rules


****************************

private(least) < protected < public(highest)

Abstract class in java ?


***********************

When we will go for Abstract class in java and selenium ?


*******************************************
Ans :

abstract keyword in java ?


*******************************

>In general abstract mean not clear,not complete,incomplete class, incomplete


method,

partial implementation just like that.

We need to learn 4 things\


******************************
1.Concreate method
2.concreate class
3.abstract method
4.abstract class

What is a Concreate method(regular method) in java ?


******************************************
Ans : A method has declaration part and implementation part such type of method is
called

Concreate method.

Example
**********

class Test
{

//concreate method

void m1()
{

}
//concreate method
void m1(int i)
{

//concreate method

main()
{

What is a Concreate class(regular class) in java ?


******************************************

Ans : A class can contain only concreate methods such type of class is called
Concreate class

Example
**********

class Test
{

//concreate method

void m1()
{

}
//concreate method

void m1(int i)
{

//concreate method

main()
{

What is a abstract method in java ?


******************************************

Ans : A method has declaration part but not implementation part such type of method
is called
abstract method.

Example
**********

abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

//abstract method

abstract void m2(); //Unimplemented method

1.
2.
3.Here abstract method must be override in child class

4.Here who is the responsible to provide implementation(body) for that abstract


method ?
***********************************************************************************
**
Ans : Child class

Note :
*********

>We can't create object for that abstract class / Unimplemented class

What is a abstract class in java ?


******************************************

Ans : A class can contain concreate methods and abstract methods such type of class
is called

abstract class.

Example
**********

abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

//abstract method

abstract void m2(); //Unimplemented method

Abstract class part 2


**************************

Hierarchical Inheritance in java ?


**************************************
Definition :
*******************

Syntax :
************
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Superclass
{

}
class Subclass3 extends Superclass
{

}
Example 1
**********
Manual Steps
**************
1.Create Superclass (Animal)
2.Create Subclass1(Dog) from Superclass (Animal)
3.Create Subclass2(Cat) from Superclass (Animal)
4.Create Subclass3(Cow) from Superclass (Animal)
5.Create MainClass

Java code
*************
Case 1
*******
Dog C = new Dog();

C.eat();//---valid
C.bark();//---valid

Case 2
*******
Animal C = new Dog();

C.eat();//---valid
C.bark();//---invalid

Example 2
*************

Difference betweeen super() and this() ?


****************************************

Example 1
*************
class Test{

Test()
{

System.out.println("Hanumanth");

super();//invalid
}

>Here super() must be in the first line in the constructor

Example 2
*************
class Test{

Test()
{
super();//valid
System.out.println("Hanumanth");

}
>Here always super() must be in the first line in the constructor

Example 3
*************
class Test{

Test()
{
System.out.println("Hanumanth");
this();//invalid

>Here this() must be in the first line in the constructor

Example 4
*************
class Test{

Test()
{
this();//valid
System.out.println("Hanumanth");

>Here always this() must be in the first line in the constructor

Example 5
*************
class Test{

Test()
{
super();//valid-------1st place
this();//invalid----2nd place
System.out.println("Hanumanth");

Note :
***********

Example 6
*************
class Test{

void test()
{
super();//invalid

System.out.println("Hanumanth");

Where we can create super() and this() ?


***********************************************
Ans : Inside the constructor only

How to call the superclass default constructor ?


*****************************************************
Syntax : super();

Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
*************

How to call the superclass parameterized constructor ?


*****************************************************
Syntax : super(value1,value2);

Example
************

Manual Steps
**************
1.Create Superclass(Shape)
2.Create Subclass(Rectangle) from Superclass(Shape)
3.Create MainClass

Java code
*************

Difference betweeen super and this keyword ?


**********************************************

Why we are using super keyword ?


***********************************
Ans : By using super keyword,we can call the superclass members (variables +
methods)

How to call the superclass variable ?


*****************************************
Syntax : super.variablename

How to call the superclass method ?


*****************************************
Syntax : super.methodname();
Why we are using this keyword ?
***********************************
Ans : By using this keyword,we can call the current class members (variables +
methods)

How to call the current class variable ?


*****************************************
Syntax : this.variablename

How to call the current class method ?


*****************************************
Syntax : this.methodname();

Calling default constructor from parameterized constructor


***********************************************************
Example
*************

Calling parameterized constructor from parameterized constructor


*******************************************************************
Example
*********

Why need constructor in java ?


**********************************

Example
*****

Note :
***********
When i run this program by default JVM will provide default constructor and
initialize the default

values for that instance variables.see below

Student()
{
name = null;

rollno = 0;

Output
**********
Student name : null
Student rollno : 0

Note :
********
>Here output i am not satisfied with default values,so in this i want to give my
own value or user/programmer defined value

.So in this kind of situation we are to learn new thing i.e Constructor

Inheritance in java ?(Java oops concept)


************************

Why need inheritance in java ?


**********************************
Ans :

Without Inheritance
**********************

Manual Steps
**************
1.Create Teacher class
2.Create Student class
3.Create Mainclass

Java code
**************

Example 3
***********
CAn we access the instance variable into instance area directly ?
**************************************************************
Ans : Yes,we can access

CAn we access the instance variable into static area directly ?


**************************************************************
Ans : No,but we can access through object reference

When method / function will be called ?


*******************************************
Ans : Whenever u create an object after function will be called

Example 4
**************

public class Student {

//Instance variable

String name="Sai";
int i;
boolean b;

public static void main(String[] args)


{
Student S = new Student();

System.out.println(S.name);//Sai
System.out.println(S.i);//0
System.out.println(S.b);//false
}

Note :
**********
>When i run this program by default JVM will provide default values for that
instance variables and static variables

Example 5
**************

public class Student {

//Instance variable

private String name="Sai";


protected int i;
public boolean b;

public static void main(String[] args)


{
Student S = new Student();

System.out.println(S.name);//Sai
System.out.println(S.i);//0
System.out.println(S.b);//false
}

What are the access modifiers in java ?


*********************************************
Ans :

1.private
2.protected
3.public
4.default

Can we assign access modifiers for that instance variables and static varibles ?
********************************************************************************
Ans : Yes

CAn we access the instance variable anywhere ?


***********************************************
Ans : No,but we access through object reference

How many ways we can access the instance variable anywhere ?


*************************************************************
Ans : Only one way through object reference

When instance variables will be accessible anywhere?


**********************************************
Ans : At the time of object creation

Local variables in java ?


*****************************
Example 1
************

class Student
{

//create method

void m1()
{
int x=10;//local variable
}

//create Constructor

Student()
{
int y=20;//local variable
}

//create block

if()
{

int z=30;//local variable


}

Where we can create local variable ?


************************************
Ans : Inside the method or inside the constructor or inside the block

Example 2
************

public class Student {

public static void main(String[] args)


{

int j=1; //local variable

for(int i=1;i<10;i++)
{
System.out.println(i);

System.out.println(j);
}

System.out.println(i);

System.out.println(j);

Example 3
************

public class Student {

public static void main(String[] args)


{

//local variables

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error

1.
2.

Note :
***********
When i run this program by default JVM will not provide default values for that
local variables
.So here compulsory we have to initialize the values for that loca variables.

Local variables examples


****************************

int i; //invalid
int i=0;//valid
int i=10;//valid

Instance variables examples


****************************

int i; //valid
int i=0;//valid
int i=10;//valid

static variables examples


****************************

static int i; //valid


static int i=0;//valid
static int i=10;//valid

Example 4
************

public class Student {

public static void main(String[] args)


{

//local variables

private byte b=10; //invalid


protected double d=10.5; //invalid
public boolean b=false;//invalid

int x=10; //valid

final int y=20; //valid

>Here final is called modifier


>Here final means what constant
>Here y is called constant variable.So constant variable value never be changed
that means

no increment and no decrement . So always y is 20.

>Can we access the local variable anywhere ?


***********************************************
Ans : No,we can access inside the methods ,constructor and block

When local variable will be accessible ?


******************************************
Ans : While executing the methods ,constructor and block

Interface part 2
********************

Multiple inheritance in java ?


*********************************

>Here java doesn't support multiple inheritance(That means a class can't extend
multiple classes)
Syntax :
*************
class Superclass1
{

}
class Superclass2
{

}
class Subclass extends Superclass1,Superclass2
{

Example
***********

class Father
{

}
class Mother
{

}
class Son extends Father,Mother
{

A class can implement multiple interfaces

Syntax :
*******
interface interface1
{

}
interface interface2
{

}
class Subclass implements interface1,interface2
{

Example
************

interface Father
{
}
interface Mother
{

}
class Son implements Father,Mother
{

Program
**********
Manual Steps
*****************
1.Create Interface(Father)
2.Create Interface(Mother)
3.Create Subclass(Son) from Interface(Father),Interface(Mother)
4.Create Mainclass

Java code
*************

Can we call the variable from interface ?


*****************************************
Ans : Yes

Syntax : interfacename.variablename

Can we call the variable from class ?


*****************************************
Ans : Yes

Syntax : classname.variablename

Note :
********
>We can't create object for that interface(Unimplemented interface) and abstract
class(Unimplemented class)

>We can create object for that implemented class

Son S = new Son(); //valid

Father S = new Son();//valid

Mother S = new Son();//valid

Father S = new Father();//invalid

Mother S = new Mother();//invalid


tagName locator in selenium
*******************************

1.
2.
3.

How to count total links in a webpage ?


******************************************

List<WebElement> totalLinks = driver.findElements(By.tagName("a"));

System.out.println("totalLinks : "+totalLinks.size());//3

How to count total frames in a webpage ?


******************************************

List<WebElement> totalFrames = driver.findElements(By.tagName("iframe"));

System.out.println("totalFrames : "+totalFrames.size());//3

className locator in selenium


*******************************

Example 1
************

xpath in selenium
*********************

Abstract class part 2


***********************
Example
***********
Manual Steps
****************
1.Create Superclass(Abstract class(Car))
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))
3.Create Subclass2(Santro) from Superclass(Abstract class(Car))
4.Create Mainclass

Java code
*************

Common Things or common code


****************
1.regino
2.OpenFuelTank
3.steering
4.breaks

school project
******************

Abstract class
****************

//concreate methods

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

//abstract method

4.fee-------------50%-----incomplete knowledge (abstract void fee();)

abstract void atm();

difference betweeen super and this keyword ?


***********************************************

polymorphism in java ?
***************************
poly mean--------many
morphs-------forms

polymorphism mean----------many forms

In general examples of polymorphism


**************************************

Ex 1 : Here one form represents many forms then it is called polymorphism

Ex 2 : Here same name but with different sounds then it is called polymorphism

Ex 3 : A person behaves like in different ways then it is called polymorphism

1.A person in shopping mall behave like a customer


2.A person in bus behave like a passenger
3.A person in school behave like a student
4.A person at home behave like a son

Types of polymorphism
************************

What is a method overloading in java ?


******************************************
Definition 1:
***************
Here method name same but with different argument types then this concept is called
method overloading

Definition 2:
***************

Here method name same but with different method signature then this concept is
called method overloading

Example 2
*********

Method overriding in java


***************************
Definition 1 :
**************

Here i am not satisfied with parent class method implementation(body) .so that in
child class i am

rewriting that method(parent class method) with different method implementation


then it is called method overriding.

Example
*************

Manual Steps
*****************

1.Create Parent class


2.Create Child class from parent class
3.Create Mainclass

Java code
**************

>Here parent class method which is overridden then it is called method overridden

>Here child class method which is overriding then it is called overriding method

>This concept is called overriding concept

When i run this by default JVM will always call to child class method (overriding
method)not parent class method(overridden method)

What is a inheritance in java ?


********************************
Ans :

Syntax :
************
class Superclass
{

}
class Subclass extends Superclass
{

Example
***********
Manual Steps
****************
1.Create Superclass(Teacher)
2.Create Subclass(Student) from Superclass(Teacher)
3.Create Mainclass

Java code
*************

In Superclass
*****************

common code + Additional code(optional)

In Subclass
******************

Additional code(Mandatory)

What are the advantages of inheritance


***************************************
Ans : By using inheritance

1.We can reduce the code size


2.We can reduce the development time
3.Avoid the duplicate code

Main What are the advantages of inheritance


***************************************
Ans : code reusability

Types of inheritance
***********************
1.Single Inheritance
2.Multi-Level Inheritance
3.Hierarchical Inheritance

Single Inheritance
***********************
Example 2
************
Manual Steps
***************
1.Create Parent class
2.Create Child class from parent class
3.Create MainClass

Java code
***************

Case 1
**********
Child C = new Child();

C.m1();//call the m1()--valid


C.m2();//call the m2()--valid

Case 2
**********
Parent C = new Child();

C.m1();//call the m1()--valid


C.m2();//call the m2()--invalid

Case 3
**********
Parent C = new Parent();

C.m1();//call the m1()--valid


C.m2();//call the m2()--invalid

Static variable in java ?


*************************
Definition :
****************

>The name of the college is same from student to student such type of variable is
called

static variable.

>The name of the college is same from Object to object such type of variable is
called

static variable.

Where we can create static variable and instance variables ?


****************************************************************
Ans : Inside the class or outside the method or outside constructor or outside the
block

Example 1
**********

public class Student {

//Static variable
static String name="sai";

public static void main(String[] args)


{

System.out.println(name);//sai

Can we access the static variable into static area directly ?


****************************************************************
Ans : Yes

Example 2
**********

public class Student {

//Static variable

static String name="sai";

public static void main(String[] args)


{
//create the object for that class

Student S = new Student();

System.out.println(S.name);//sai

Can we access the static variable into static area through object reference ?
****************************************************************
Ans : Yes

Example 3
**********

public class Student {

//Static variable

static String name="sai";

public static void main(String[] args)


{
//create the object for that class

System.out.println(S.name);//sai

}
}

Can we access the static variable into static area through classname ?
****************************************************************
Ans : Yes

Syntax : classname.variablename

Example 4
**********

public class Student {

//Static variable

static String name="sai";

public static void main(String[] args)


{
//create the object for that class

System.out.println(S.name);//sai

How many ways we can access the static variable ?


******************************************************
Ans : 3

1.Directly we can access


2.Through object reference
3.Through class name

When static variable will be accessible ?


********************************************
Ans :

Arraylist in java(collection topic)


*************************************
Why we are using arrayList in java and selenium ?
****************************************************
Ans :

Example
***********

>Suppose if u want to only integer type value in an arralist then we should follow
below syntax
ArrayList<Integer> arralist = new ArrayList<Integer> ();

arralist.add(10);//store 10 into arraylist through add()


arralist.add(20);//store 20 into arraylist through add()
arralist.add(30);//store 30 into arraylist through add()
arralist.add(40);//store 40 into arraylist through add()

>Suppose if u want to only float type value in an arralist then we should follow
below syntax

ArrayList<Float> arralist = new ArrayList<Float> ();

arralist.add(10.1f);//store 10 into arraylist through add()


arralist.add(20.2f);//store 20 into arraylist through add()
arralist.add(30.3f);//store 30 into arraylist through add()
arralist.add(40.4F);//store 40 into arraylist through add()

>Suppose if u want to only Double type value in an arralist then we should follow
below syntax

ArrayList<Double> arralist = new ArrayList<Double> ();

arralist.add(10.1);//store 10 into arraylist through add()


arralist.add(20.2);//store 20 into arraylist through add()
arralist.add(30.3);//store 30 into arraylist through add()
arralist.add(40.4);//store 40 into arraylist through add()

>Suppose if u want to only String type value in an arralist then we should follow
below syntax

ArrayList<String> arralist = new ArrayList<String> ();

arralist.add("Sai");//store 10 into arraylist through add()


arralist.add("Akki");//store 20 into arraylist through add()
arralist.add("Hanu");//store 30 into arraylist through add()
arralist.add("NewIndia");//store 40 into arraylist through add()

>Suppose if u want to only boolean type value in an arralist then we should follow
below syntax

ArrayList<Boolean> arralist = new ArrayList<Boolean> ();

arralist.add(true);//store 10 into arraylist through add()


arralist.add(true);//store 20 into arraylist through add()
arralist.add(false);//store 30 into arraylist through add()
arralist.add(false);//store 40 into arraylist through add()

>Suppose if u want to only char type value in an arralist then we should follow
below syntax

ArrayList<Character> arralist = new ArrayList<Character> ();

>Suppose if u want to only int,float,double,string,boolean,char type value in an


arralist then we should follow below syntax

ArrayList arralist = new ArrayList();


Can we store duplicate values in an arrayList?
*************************************************
Ans : Yes

Can we remove 20 in an arralist ?


*****************************************
Ans : Yes

Syntax :
***********

arralist.remove(index);

Example
*********

arralist.remove(1); // removed 20 in the position of 1

program
**********

Can we replace 20 with 50 ?


********************************
Ans yes

Syntax :
***********

arralist.set(int index,object obj);

Example
*********

arralist.set(1,50);// replace 20 with 50 in the position of 1

Program
***********

CAn we insert 50 in the position of 1 ?


******************************************
Ans :Yes

Syntax :
***********

arralist.add(int index,object obj);

Example
********

arralist.add(1,50); //insert 50 in the position of 1

program
***********

Can we remove all the values from arralist ?


***********************************************
Ans : yes
Syntax :
************

arralist.clear();

Example
**********

arralist.clear();//remove all the values from arralist

program
************

How to verify arrayList has empty or not ?


*********************************************

>If arrayList has empty then it returns true


>If arrayList has not empty then it returns false

Syntax :
************
arralist.isEmpty();

Example
**********

arralist.isEmpty();//verify arrayList has empty or not

Sir, in array list if I store all data types then if I need to separate them while

printing then do I need to use Switch and for loops?

Example 2
************

Definition 2:
****************
>Here method name same and method signature same then this concept is called method
overriding

Manual Steps
*****************
1.Create Parent class
2.Create Child class from Parent
3.Create Mainclass

Java code
**********

Method overriding rules


****************************

private(least) < protected < public(highest)


Method overriding rules
*************************

Abstract class in java ?


*****************************

Why need abstract class in java and selenium ?


************************************************
Ans :

abstract keyword in java ?


*******************************

In general abstract mean not clear,not complete,incomplete method,in complete


class,

partial implementation

Here we need to learn 4 things


**********************************
1.concreate method
2.concreate class
3.abstract method
4.abstract class

What is a concreate method (regular methods)in java ?


**************************************
Ans : A method has declaration part and implementation(body) part such type of
method is called

concreate method .

Example
*********

class Test
{

//concreate method

void m1()
{

//concreate method

void m1(int i)
{

//concreate method

main()
{

What is a concreate class (regular class)in java ?


**************************************

>A class can contain only concreate methods such type of class is called concreate
class

Example
*********

class Test
{

//concreate method

void m1()
{

//concreate method

void m1(int i)
{

//concreate method

main()
{

What is a abstract method in java ?


**************************************
Ans : A method has declaration part but not implementation part such type of method
is called abstract method

Example
*********

abstract class Test //Unimplemented class


{

//concreate method

void m1() //implemented method


{

}
//abstract method

abstract void m2(); //Unimplemented method

1.
2.

Note :
*********
>We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented interface)

>We can create the object for that implemented class

What is a abstract class in java ?


**************************************
Ans : A class can contain concreate methods and abstract methods such type of class
is called abstract class.

Example
*********

abstract class Test //Unimplemented class


{

//concreate method

void m1() //implemented method


{

//abstract method

abstract void m2(); //Unimplemented method

Abstract class part 2


**************************

selenium 1st class


************************

7:22 PM

Praveena to Everyone

Sir, if any relevent jar file is missed will it show error during execution of
script?
What are the prerequisites to run the selenium webdriver ?--IQ
**************************************************************
Ans :

1.Jdk file
2.Eclipse IDE
3.Selenium Jar files
4.Testing Application
5.Browser(firefox)

Part 1
***********

1.Create new Javaproject


2.Create new package
3.Create new class
4.Add selenium jar files for that project
5.Download / Add geckodriver.exe for that project

Why we are using selenium java jar files ?


**********************************************
Ans :

Where we can get the selenium java jar files ?


*************************************************
Ans :

Xpath(is defined as xmlPath) in Selenium


********************************************
1.
2.
3.

Types of xpath
***************
1.Absolute xpath
2.Relative xpath

Difference betweeen Absolute xpath and Relative xpath in selenium ?


**************************************************************

How to get the Absolute XPath and Relative XPath in Firefox?


**************************************************************
Ans : By using SelectorsHub

How to install SelectorsHub into firefox ?


********************************************

Absolute XPath
*****************
/html[1]/body[1]/div[4]/form[1]/div[1]/div[1]/div[2]/div[1]/div[2]/input[1]

Relative XPath
********************

//input[@title='Search']

How to get the Absolute XPath and Relative XPath in chrome?


**************************************************************
Ans : By using SelectorsHub

How to install SelectorsHub into chrome ?


********************************************

Absolute XPath
******************

/html[1]/body[1]/div[1]/div[3]/form[1]/div[1]/div[1]/div[1]/div[1]/div[2]/input[1]

Relative XPath
********************

//input[@title='Search']

How to get the Absolute XPath and Relative XPath in IE?


**************************************************************
Ans : By using Fire IE Browser tool

How to download Fire IE Browser tool ?


******************************************

How to verify xpath is valid or not in firefox ?


****************************************************

How to verify xpath is valid or not in chrome ?


****************************************************

How to verify xpath is valid or not in IE ?


****************************************************

Interface part 1
*******************

Why need interface in java and selenium ?


*********************************************
Ans :

Example
***********
Manual Steps
**************
1.Create Interface(Animal)
2.Create Subclass(Cat) from Interface(Animal)
3.Create MainClass

Java code
**********

1.
2.
3.
4.
5.
6.
7.
8.

Difference betweeen extends and implements keyword ?


*****************************************************

extends keyword : By using this,we can inherit the subclass from superclass

implements keyword : To implement an interface in child class we must use


implements keyword

school project
*****************
abstract class
****************
Case 1
**********

//concreate methods
**************************
1.Teacher ------100%--------complete knowledge (void teacher(){})
2.student-------100%--------complete knowledge (void student(){})
3.chortboard-----100%-------complete knowledge (void chortboard(){})

//abstract method

4.fee-------------50%-----incomplete knowledge (abstract void fee();)

Case 2
**********
interface
****************

//abstract methods

1.Teacher ------50%--------incomplete knowledge (abstract void teacher();)


2.student-------50%--------incomplete knowledge (abstract void student();)
3.chortboard-----50%-------incomplete knowledge (abstract void chortboard();)
4.fee-------------50%-----incomplete knowledge (abstract void fee();)
Interface part 2
*********************

Multiple inheritance in java ?


*********************************

>Here java doesn't support multiple inheritance(That means A class can not extend
multiple classes)

Syntax :
********

class Superclas1
{

}
class Superclas2
{

}
class Subclass extends Superclas1,Superclas2
{

}
Example
************
class Father
{

}
class Mother
{

}
class Son extends Father,Mother
{

A class can implement multiple interfaces

Syntax:
**********
interface interfaceName1
{

}
interface interfaceName2
{

}
class Subclass implements interfaceName1,interfaceName2
{
}
Example
**********

interface Father
{

}
interface Mother
{

}
class Son implements Father,Mother
{

Program
***********

Manual Steps
**************
1.create Interface1(Father)
2.Create interface2(Mother)
3.Create Subclass(Son) from Interface1(Father),interface2(Mother)
4.Create Mainclass

Java code
************
Can we call the variable from interface ?
******************************************
Ans : Yes

Syntax : Interfacename.variablename

Can we call the variable from class ?


******************************************
Ans : Yes

Syntax : classname.variablename

Son S = new Son();//valid

Father S = new Son();//valid

Mother S = new Son();//valid

Father S = new Father();//invalid

Mother S = new Mother();//invalid

Abstract lcaa part 2


**********************

Example
*********
Manual Steps
**************
1.Create Superclass(Abstract class(Car))
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))
3.Create Subclass2(Santro) from Superclass(Abstract class(Car))
4.Create MainClass

Java code
***********

Common code / common things


***************************
1.regino
2.FuelTank
3.steering
4.breaks

School Project
*****************

Abstract class
*******************

//concreate methods

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

//abstract method

4.fee-------------50%-----incomplete knowledge (abstract void fee();)

Concreate class(Regular class)


*********************

//concreate methods

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

Interface

*************

//abstract methods

1.Teacher---------50%-----incomplete knowledge (abstract void teacher();)


2.Student---------50%-----incomplete knowledge (abstract void student();)
3.chortboard------50%-----incomplete knowledge (abstract void chortboard();)
4.fee-------------50%-----incomplete knowledge (abstract void fee();)
abstract void atm();

Multi-Level Inheritance in java ?


**********************************

Definition
*************

Syntax :
***********
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Subclass1
{

}
Example 1
*********
Manual Steps
**************
1.Create Superclass(GrandFather)
2.Create Subclass1(Father) from Superclass(GrandFather)
3.Create Subclass2(Son) from Subclass1(Father)
4.Create Mainclass

Java code
***************

Example 2
*********

Manual Steps
**************
1.Create Superclass(Calculation)
2.Create Subclass1(Sum) from Superclass(Calculation)
3.Create Subclass2(Subtraction) from Subclass1(Sum)
4.Create Mainclass

Java code
***************

Hierarchical inheritance
**************************
Definition:
**************

Syntax:
***********
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Superclass
{

}
class Subclass3 extends Superclass
{

Example 1
*********
1.Create Superclass(Animal)
2.Create Subclass1(Dog) from Superclass(Animal)
3.Create Subclass2(Cat) from Superclass(Animal)
4.Create Subclass3(Cow) from Superclass(Animal)
5.Create Mainclass

Java code
************

Case 1
********
Dog D = new Dog();

D.eat();//call the eat()//---valid

D.bark();//----valid

Case 2
********
Animal D = new Dog();

D.eat();//call the eat()//---valid

D.bark();//----invalid

Example 2
***********

Selenium Automation Testing


*******************************

What is a Testing ?
***********************

Ans : To verify whether the functionality works well or not .i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure
Difference betweeen defect,error and failure ?--IQ
*****************************************************
1.Error : Developer
2.Defect: Test Engineer
3.Failure : Customer or User

Types of Testing
********************
1.Functional Testing
2NOn-functional Testing

Types of functional automation tools


*************************************
1.opensource
============
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.Sahi
4.Badboy
5.Ruby
6.watir etc.

2.commercial
****************
1.Qtp(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen Selenium and Qtp ?--IQ


******************************************

Selenium
***********
1.Opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,Chrome ,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here Selenium + Appium-------->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

Qtp
********
1.Commercial tool(paid tool)
2.Vbscript
3.FF,IE and chrome
4.Windows
5.Webapp,mobile app and desktop app
History of selenium
**********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE +Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE +Selenium RC + Selenium Webdriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium Webdriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium Webdriver+Extra features) + Selenium Grid


>2019

Selenium Components---IQ
***************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

Difference betweeen Selenium IDE,RC and Webdriver ?--IQ


***********************************************************
Selenium IDE
*****************
1.Record and playback tool
2.FF and chrome
3.Web app only
4.Selenium IDE doesn't have any programming knowledge
5.Selenium IDE generate Test Reports but no details

no details
*************
>Selenium IDE reports are not effective to send the client ,TestLead and project
manager

>There is no complete information in selenium IDE report format.

Selenium Rc
***************
1.Selenium RC works with server but selenium webdriver doesn’t work with server
2.Java,c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari
4.Windows,linux
5.old versions
6.Web app only

Here Selenium + Appium-------->mobile app


Here Selenium + Autoit or sikuli or robot class---->desktop app

Selenium WebDriver
*********************

What is a webdriver ?
**************************
Ans : Webdriver it's an interface in betweeen selenium automation test script and
Testing application

2.Java,c#,python,ruby,perl and php


3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Old and new versions
6.Web app only

Here Selenium + Appium-------->mobile app

Here Selenium + Autoit or sikuli or robot class---->desktop app

-------------part 1

Java for selenium(core java enough)---------part 2


********************

Java,

80%-----------selenium webdriver + java(java oops concepts + collection)

TestNG------part 3
****************

TestNG(latest)-----Junit(old)

Why we are using TestNG ?


******************************
Ans : By using TestNG,we can create selenium automation test cases,execute the

selenium automation test cases,it generate Test Reports and also generate log
files.

Mainly Why we are using TestNG ?


******************************

>Selenium IDE generate Test Reports but no details

>Selenium RC outdated(old)

>Selenium Webdriver doesn't generate the Test Reports and here selenium webdriver

with the help of TestNG will generate the Test Reports.

Add three parts


*****************

1 + 2 + 3------>Selenium Webdrive + Java + TestNG


AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework

Selenium 1st class


*********************

What are the prerequisites to run the selenium webdriver ?


***********************************************************
Ans :

1.JDK file
2.Eclipse IDE
3.Selenium Jar files
4.Testing Application
5.Browser

Part 1
*********
1.Create new JavaProject
2.Create new package
3.Create new class
4.Add selenium jar files for that project
5.Download / Add geckodriver.exe files for that project

Why we are using selenium java jar files ?


**********************************************
Ans :

Where we can get the selenium java jar files ?


************************************************
Ans :
What is a Webdriver ?
***********************
Ans :

What is the default package of selenium ?


*******************************************
Ans : org.openqa.selenium

Why we will import the packages ?


**********************************
Ans :

get() :

getTitle() :

return-type : String

How to verify title of the webpage ?


****************************************
Testing = operation code + verification code

Manual Steps
**************
1.Get the Title of the WebPage
2.Print the title of the webpage
3.Verify Title of the WebPage

Selenium Java code


*********************

//------------------verify title of the webpage------------------------

//-----------------------------------------------------------operation code

// Get the Title of the WebPage

String title = driver.getTitle();

// Print the title of the webpage

System.out.println(title);//OrangeHRM - New Level of HR Management

//----------------------------------------------------------verification code

// Verify Title of the WebPage

if(title.equals("OrangeHRM - New Level of HR Management"))


{

System.out.println("Title verified successfully");


}else
{
System.out.println("Title not verified successfully");
}

Selenium WebDriver
********************
1.By using selenium webdriver, we can identify element
2.After identify the element then do some action on that element

Difference betweeen findElement() and findElements() ?


******************************************************
Ans :

What are the different element Locators to identify the element in selenium ?
******************************************************

1. id----------1
2. Name---------2
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName---------3
7. cssSelector
8. Xpath---------------4

sendKeys() :

getText() :

return-type : String

How to verify particular test in a webpage ? or

How to verify successful message in selenium ?


*****************************************************

Testing = operation code + verification code

Manual Steps
****************
1.Identify and get the Welcome Selenium Text
2.Print the Welcome Selenium Text
3.Verify Welcome Selenium Text

Selenium Java code


***********************
//-----------------verify Welcome Selenium Text ---------------------

//-----------------------------------------------------------operation code

// Identify and get the Welcome Selenium Text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

// Print the Welcome Selenium Text

System.out.println(text);//Welcome selenium
//----------------------------------------------------------verification code

//Verify Welcome Selenium Text

if(text.equals("Welcome selenium"))
{

System.out.println("Welcome page verified successfully");


}else
{

System.out.println("Welcome page not verified successfully");


}

Example 2
***********

Difference betweeen super() and this() ?


*******************************************

Example 1
************

class Test{

Test()
{

System.out.println("Hanumanth");
super();//invalid

>Here super() must be write in the first line in the constructor

Example 2
************

class Test{

Test()
{
super();//valid
System.out.println("Hanumanth");

>Here always super() must be write in the first line in the constructor

Example 3
************
class Test{

Test()
{

System.out.println("Hanumanth");
this();//invalid

>Here this() must be write in the first line in the constructor

Example 4
************

class Test{

Test()
{
this();//valid
System.out.println("Hanumanth");

>Here always this() must be write in the first line in the constructor

Example 5
************

class Test{

Test()
{
super();//valid------1st place
this();//invalid----2nd place
System.out.println("Hanumanth");

Note :
**********

Example 6
************

class Test{

void test()
{
super();//invalid
System.out.println("Hanumanth");

}
Where we can create super() and this() ?
**********************************************
Ans : Inside the constructor only

How to call the current class default constructor ?


*****************************************************
Syntax : this();

How to call the current class parameterized constructor ?


*****************************************************
Syntax : this(value1,value2);

How to call the superclass default constructor ?


*****************************************************
Syntax : super();

Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclas(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
**************

How to call the superclass parameterized constructor ?


*****************************************************
Syntax : super(value1,value2);

Example
***********
Manual Steps
**************
1.Create Superclass(Shape)
2.Create Subclas(Rectangle) from Superclass(Shape)
3.Create Mainclass

Java code
**************

Difference betweeen super and this keyword ?


***********************************************
Why we are using super keyword ?
**********************************
Ans : By using super keyword,we can call the superclass members(variables +
methods)

Why we are using this keyword ?


**********************************
Ans : By using this keyword,we can call the current class members(variables +
methods)

How to call the current class variable ?


****************************************
Syntax : this.variablename

How to call the superclass method ?


****************************************
Syntax : thid.methodname();

How to call the superclass variable ?


****************************************
Syntax : super.variablename

Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclas(Cat) from Superclass(Animal)
3.Create Mainclass

Java code
**************

How to call the superclass method ?


****************************************
Syntax : super.methodname();

Today 2nd class


******************

>Suppose if u want to access the java and selenium then we need to download
JDK(Java development kit) file first

Part 1
**********

1.download JDK(Java development kit) file first


2.Install JDK(Java development kit) file into ur local system
3.Verify JDK(Java development kit) file successfully install or not into ur local
system
4.Download Eclipse IDE / oxygen
5.Directly open the Eclipse IDE /oxygen and here no need to install Eclipse IDE
/oxygen

Part 2
***********

1.Create New JavaProject


2.Create new package
3.Create new class

Datatype in java
********************

int x=10;

What is a variable in java ?


*******************************
Ans : Variable is a memory location and here variable x can store some data based
on

datatype then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium

automation test script.

>In java or other programming languages,we know we need variables to store some
data

based on datatype.

>In java,every variable and every expression should have a datatype

types of datatype
********************
1.primitive datatype
2.Non-primitive datatype

What are the integral integer datatypes in java ?--IQ


*****************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


*****************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


*****************************************************
Ans : byte,short,int,long,float,double,char,boolean

What are the non-primitive datatypes in java ?--IQ


*****************************************************
Ans : String ,array,set,list etc.

byte datatype in java ?


*************************
>This will be used to store +ve and -ve nos
>Here byte datatype variable can store in the range of the values

min -128 to max 127

Example 1
***********

byte b= 125; //valid byte type value

System.out.println(b);

Code Explanation:
**********************
1.Here providing value is 125
2.Here expected value is byte type
3.min -128 to max 127

Found : byte type value


Required : byte

Java compiler work


**********************

Compile the java code line by line(That means checking the java code line by line
whether it is currect code or not)

JVM(Java virtual machine) work


*********************************

Just simply execute the java code

Example 2
***********

byte b= "Hanumanth"; //invalid String type value

System.out.println(b);

Code Explanation:
********************
>We can say this("Hanumanth") is a String type value

>Here String mean collection of characterss

Examples
**************

"HYD" or "H" or "123" or "HYD123" or "%$^%*&^*"


>Here everything in double-quotes it's a string

>Here String always must be in double-quotes

F : String type value


R : byte

Example 3
***********

byte b= 127; //valid byte type value

System.out.println(b);

Code Explanation :
*******************
>127
>byte type value
>min -128 to max 127

F : byte
R : byte

Example 4
***********

byte b= true; // invalid boolean

System.out.println(b);

Code Explanation :
*********************

>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean
R : byte

Example 5
***********

byte b= 127L; // invalid long type value

System.out.println(b);

>We can say this(127L) is a long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
*************************************************************************
Ans : Yes

Datatype rules
******************

byte(least) < short < int < long < float < double(highest)
1.We can assign left-side datatype value into any right-side datatype variable

2.We can't assign right-side datatype value into any left-side datatype variable.

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required typecasting.

F : long
R : byte

Example 6
***********

byte b= 12.7F; // invalid float

System.out.println(b);

>We can say this(12.7F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is mandatory for that float type value ?
*********************************************************************
Ans : yes

F : float
R : byte

Example 7
***********

byte b= 12.7; // invalid double

System.out.println(b);

F : double
R : byte

Code Explanation :
***********************

>We can specify floating-point literal value(float value and double value) only in
decimal form

What are the floating-point literal values?


********************************************
Ans : float value and double value

Float Examples
********************

10.5f,10.1111f,2.6f,-123.456f...........
Double Examples
********************

10.5,10.1111,2.6,-123.456...........

Example 8
***********

byte b= 128; // invalid

System.out.println(b);

Note :
*********
>By default every floating-point literal value is what type double type value

>By default every integral literal value is what type int type value

F : int
R : byte

Code Explanation :
*********************
>128
>byte type value
>min -128 to max 127

What are the integral floating-point literal values in java ?--IQ


*****************************************************
Ans : float value and double value

What are the integral literal values in java ?--IQ


*****************************************************
Ans : byte,short,int,long
How to verify xpath is valid or not in firefox ?
*************************************************

//input[@title='Search']

Syntax :$x("xpath")

Example
*********
$x("//input[@title='Sear']")

How to verify xpath is valid or not in chrome ?


*************************************************

How to verify xpath is valid or not in IE ?


*************************************************
Ans : No

How to handle dynamic elements in selenium ?


************************************************

1.Selenium(Relative xpath) + xpath functions(starts-with) ------>To handle the


dynamic elements

Xpath : //button[starts-with(@id,'Submit')]

Code : driver.findElement(By.xpath("//button[starts-with(@id,'Submit')]")).click();

2.Selenium(Relative xpath) + xpath functions(ends-with) ------>To handle the


dynamic elements

Xpath : //button[ends-with(@id,'Submit')]

Code : driver.findElement(By.xpath("//button[ends-with(@id,'Submit')]")).click();

3.Selenium(Relative xpath) + xpath function(contains) ------>To handle the dynamic


elements

Code : driver.findElement(By.xpath("//button[contains(@id,'Submit')]")).click();

xpath : //button[contains(@id,'Submit')] or

xpath : //button[contains(@id,'button')] or
xpath : //button[contains(@id,'188')]

Relative xpath syntax


**********************

//tagName[@attributeName = 'value']

//button[ends-with(@id,'Submit')]

driver.findElement(By.xpath("//button[starts-with(@id,'Submit')]")).click();

How to write the xpath in manually ? or

How to write the customized xpath in selenium?


*********************************************

How to write the absolute xpath for that password ?


***************************************************

write the absolute xpath for that password : Follow Red line

/html/body/input[2]

How to write the absolute xpath for that Username ?


***************************************************

write the absolute xpath for that Username : Follow Red line

/html/body/input[1]

How to write the absolute xpath in manually ?


**********************************************

How to write the absolute xpath for that Gmail : Follow red line

/html/body/div/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/a

How to write the Relative xpath for that Username in manually ?


**********************************************

Element : Username

Html code
************

<input type="text" name="username">

Syntax :
************

//tagName[@attributeName='value']

Example
***********

//input[@name='username']

Program:
*************
--------------------------------------------------------
Element : Gmail

Html code
************

<a class="gb_f" data-pid="23" href="https://mail.google.com/mail/?


authuser=0&amp;ogbl" target="_top">Gmail</a>

Syntax :
************

//tagName[@attributeName='value']

Example
***********

//a[@class='gb_f']

Program:
*************

ArrayList in java ?(collection topic)


***************************************
Why we are using arralist in java and selenium ?
*****************************************************
Ans :

Example
**********

>Suppose if u want to store only integer type values in an arralist then we should
follow below syntax

ArrayList<Integer> arraylist = new ArrayList<Integer>();

arraylist.add(10);//store 10 in an arraylist through add()


arraylist.add(20);//store 20 in an arraylist through add()
arraylist.add(30);//store 30 in an arraylist through add()
arraylist.add(40);//store 40 in an arraylist through add()

>Suppose if u want to store only float type values in an arralist then we should
follow below syntax

ArrayList<Float> arraylist = new ArrayList<Float>();


arraylist.add(10.1f);//store 10 in an arraylist through add()
arraylist.add(20.2f);//store 20 in an arraylist through add()
arraylist.add(30.3f);//store 30 in an arraylist through add()
arraylist.add(40.4F);//store 40 in an arraylist through add()

>Suppose if u want to store only double type values in an arralist then we should
follow below syntax

ArrayList<Double> arraylist = new ArrayList<Double>();

arraylist.add(10.1);//store 10 in an arraylist through add()


arraylist.add(20.2);//store 20 in an arraylist through add()
arraylist.add(30.3);//store 30 in an arraylist through add()
arraylist.add(40.4);//store 40 in an arraylist through add()

>Suppose if u want to store only boolean type values in an arralist then we should
follow below syntax

ArrayList<Boolean> arraylist = new ArrayList<Boolean>();

arraylist.add(true);//store 10 in an arraylist through add()


arraylist.add(true);//store 20 in an arraylist through add()
arraylist.add(false);//store 30 in an arraylist through add()
arraylist.add(true);//store 40 in an arraylist through add()

>Suppose if u want to store only String type values in an arralist then we should
follow below syntax

ArrayList<String> arraylist = new ArrayList<String>();

arraylist.add("Sai");//store 10 in an arraylist through add()


arraylist.add("Akki");//store 20 in an arraylist through add()
arraylist.add("Hanu");//store 30 in an arraylist through add()
arraylist.add("NewIndia");//store 40 in an arraylist through add()

>Suppose if u want to store only character type values in an arralist then we


should follow below syntax

ArrayList<Character> arraylist = new ArrayList<Character>();

>Suppose if u want to store only int,float,double,String,boolean,character type


values in an arralist then we should follow below syntax

ArrayList arraylist = new ArrayList();

Can we store duplicate values in an arralist ?


************************************************
Ans : Yes

Can we remove 20 in an arralist ?


*************************************
Ans : Yes
Syntax :
*************

arraylist.remove(index);

Example
************

arraylist.remove(1); // removed 20 in an arralist in the position of 1

program
***********

Can we replace 20 with 50 ?


********************************
Ans : Yes

Syntax :
*************

arraylist.set(int index,Object obj);

Example
************

arraylist.set(1,50);//replace 20 with 50 in the position of 1

Program :
************

Can we insert / add 50 in the position of 1 ?


**********************************************
Ans : Yes

Syntax :
*************

arraylist.add(int index,Object obj);

Example
************

arraylist.add(1,50);//insert / add 50 in the position of 1

Program :
**********

Can we remove all the values present in the arralist ?


***********************************************************
Ans : Yes

Syntax :
************

arralist.clear();

Example
************
arralist.clear();//remove all the values present in the arralist

Program :
***********

Verify arraylist has empty or not ?


****************************************

>If arrayList has empty then it returns true


>If arrayList has not empty then it returns false

Syntax :
************

arralist.isEmpty();

Example
************

arralist.isEmpty();

Program :
************

1.
2.

How to call the superclass method ?


**********************************
Syntax : super.methodname();

Example
************
Manual Steps
***************
1.Create Superclas(Animal)
2.Create Subclass(Cat) from Superclas(Animal)
3.Create MainClass

Java code
*************

How to call the current class method ?


**********************************
Syntax : this.methodname();

Polymorphism in java ?
***************************

poly mean ----------many

morphs mean--------forms
polymorphism mean--------many forms

In general examples of polymorphism


*************************************
Ex 1 : Here one form represents many forms then it is called polymorphism

Ex 2 : Here same name but with different sounds then it is called polymorphism

Ex 3 : A person behaves like in different ways then it is called polymorphism

1.A person in shopping mall behave like a customer


2.A person in bus behave like a passenger
3.A person in school behave like a student
4.A person at home behave like a son

Types of polymorphism
************************

What is a method overloading in java ?


******************************************
Definition 1 :
******************
Here method name same but with different argument types then this concept is called

method overloading.

Example
***********

What is a method overloading in java ?


******************************************
Definition 2 :
******************

>Here method name same but with different method signature then this concept is
called

method overloading.

Example 2
**************

What is a method overriding in java ?


**************************************
Definition 1 :
*****************

Example
***********
Manual Steps
*****************
1.Create parent class
2.Create Child class from parent class
3.Create Mainclass
Java code
************

short datatype in java ?


****************************

>+ve and -ve nos


>min -32768 to max 32767

Example 1
*************

short s=32767; //valid short

Syste.out.println(s);

Code Explanation :
**********************

>32767
>short type value
>min -32768 to max 32767

F : short
R : short

Example 2
*************

short s=32767L; // invalid long

System.out.println(s);

F : long
R : short

Example 3
*************

short s=32.767; // invalid double

System.out.println(s);

F : double
R : short

Example 4
*************

short s=32768; // invalid int

System.out.println(s);

>min -32768 to max 32767


What are the floating-point literal values ?
***********************************************
Ans : float and double

What are the integral literal values ?


***********************************************
Ans : byte,short,int,long

F : int
R : short

int datatype in java ?


**************************
>+ve and -ve nos
>min -2147483648 to max 2147483647

Example 1
*************

int i=2345; // valid int

System.out.println(i);

Code Explanation :
**********************
>2345
>int type value
>min -2147483648 to max 2147483647

Example 2
*************

int i=23.45F; // invalid float

System.out.println(i);

long datatype in java ?


*************************

>+ve and -ve nos


>min -9223372036854775808 to max 9223372036854775807

Example 1
*************

long l=2345L; // valid long

System.out.println(l);

Example 2
*************

long l=125; // valid int

System.out.println(l);

F : int
R : long
String datatype in java ?
*****************************
>This will be used to store single character and group of characterss

>Here range not applicable for string datatype

Example
************
"HYD" or "H" or "123" or "123HYD" or "$^%&^*O("

>here everything in double-quotes it's a String

>Here String always must be in double quotes

Example 1
*************

String s=0; // invalid int

System.out.println(s);

Example 2
*************

String s=true; // invalid boolean

System.out.println(s);

Example 3
*************

String s=Hanumanth; // invalid

System.out.println(s);

Example 4
*************

String s="Hanumanth"; // valid

System.out.println(s);

boolean datatype in java ?


*****************************

>This will be used to store only boolean value such as true / false

>Here range not applicable for boolean datatype

Example 1
*************

boolean b=10; // invalid

System.out.println(b);

Example 2
*************
boolean b="H"; // invalid String

System.out.println(b);

Example 3
*************

boolean b=True; // invalid

System.out.println(b);

Example 4
*************

boolean b=true; // valid

System.out.println(b);

float datatype in java ?


*************************

Handle Frames
******************
1.How to handle single frame
2.How to handle multiple frames
3.How to handle Nested frames(Frame inside another frame)

How to handle single frame ?


********************************
Manual Steps
*****************

Selenium java code


**********************

How to print all the dropdown values?


**************************************

diagram :
**************

Manual steps
****************
>First,get the dropdown size or count dropdown values

Manual steps
*****************
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown
Selenium Java code
***********************
WebElement dropdown = driver.findElement(By.id("loc_code"));

List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));

System.out.println("droplist size : "+droplist.size());//3

>print all the dropdown values

What are the xpath functions ?


**********************************
1.starts-with()
2.ends-with()
3.contains()
4.text()
5.position()

4.text()
**************
Example
**********

Element : Welcome to Hanumanth

Html code
***********

<h1>Welcome to Hanumanth</h1>

Syntax :
**********

//tagName[text()='value']

Example
**********

//h1[text()='Welcome to Hanumanth
sjhdfkjsahfkjsahfkjashfkjjhaskjjfhkashfklaslkflkaskfgdsg']

contains()
***************

Element : Welcome to Hanumanth


sjhdfkjsahfkjsahfkjashfkjjhaskjjfhkashfklaslkflkaskfgdsg

Html code
***********

<h1>Welcome to Hanumanth
sjhdfkjsahfkjsahfkjashfkjjhaskjjfhkashfklaslkflkaskfgdsg</h1>
Syntax :
**********

//tagName[contains(text(),'value')]

Example
**********

//h1[contains(text(),'Hanumanth')]

program
***********

position()
****************
Example 1
********

//h1[contains(text(),'Hanumanth')][position()=2]

Example 2
********
Element : checkbox

Htmlcode
*************

<input type="checkbox" name="chk">

How to handle same name of the elements in selenium ?


*******************************************************
Ans : Here Selenium(Relative xpath) + xpath function(position())---------->to
handle same name of the elements

Example
*********

//input[@name='chk'][position()=5]

program :
**************

How to handle dynamic elements in selenium ?


*********************************************
Ans : Here Selenium(Relative xpath) +xpath functions(starts-with,ends-
with,contains)------>to handle dynamic elements

Interface in java ?
*******************

When we will go for abstract class in java and selenium ?


**************************************************
Ans :

When we will go for interface in java and selenium ?


**************************************************
Ans :

Example
***********
Manual Steps
**************
1.Create Interface(Animal)
2.Create Child class(Cat) from Interface(Animal)
3.Create MainClass

Java code
*************

1.
2.
3.
4.
5.
6.
7.
8.
9

Difference betweeen extends keyword and implements keyword ?


**************************************************************

extends keyword :By using this,we can inherit the subclass from superclass

implements keyword : To implement an interface in child class we must use


implements keyword

Note :
********

1.We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented interface)

2.We can create object for that implemented class

School project
**************

Case 1
**********
Abstract class
********************

//concreate methods
1.Teacher--------100%-------complete knowledge (void teacher(){})
2.Student--------100%-------complete knowledge (void student(){})
3.Chort board----100%-------complete knowledge (void chortboard(){})

//abstract method

4.Fee-------50%---------incomplete knowledge (abstract void fee();)

Case 2
**********
Concreate class
*********************

//concreate methods

1.Teacher--------100%-------complete knowledge (void teacher(){})


2.Student--------100%-------complete knowledge (void student(){})
3.Chort board----100%-------complete knowledge (void chortboard(){})
4.Fee------------100%-------complete knowledge (void fee(){})

Case 3
**********
interface concept
***********************

//abstract methods

1.Teacher--------50%-------incomplete knowledge (abstract void teacher();)


2.Student--------50%-------incomplete knowledge (abstract void student();)
3.Chort board----50%-------incomplete knowledge (abstract void chortboard();)
4.Fee------------50%-------incomplete knowledge (abstract void fee();)

Multiple inheritance in java


*******************************

Here java doesn't support multiple inheritance(That means A class can't extend
multiple classes)

Syntax :
***********
class Superclass1
{

}
class Superclass2
{

}
class Child extends Superclass1,Superclass2
{

Example
***********
class Father
{

}
class Mother
{

}
class Son extends Father,Mother
{

A class can implement multiple interfaces

Syntax:
************
interface interface1
{

}
interface interface2
{

}
class Child implements interface1,interface2
{

Example
************
interface Father
{

}
interface Mother
{

}
class Son implements Father,Mother
{

Example
*************
Manual Steps
****************
1.Create interface1(Father)
2.Create Interface2(Mother)
3.Create Child(Son) class from interface1(Father),Interface2(Mother)
4.Create Mainclass

Java code
************

Can we call the variable from interface ?


*********************************************
Ans : Yes

Syntax :interfacename.variablename

Can we call the variable from class ?


*********************************************
Ans : Yes

Syntax :classname.variablename

Note :
***********

Here we can't create the object for that interface but we can create reference

Son S = new Son();//valid

Father S = new Son();//valid

Mother S = new Son();//valid

Father S = new Father();//invalid

Mother S = new Mother();//invalid

What is a Method overriding in java ?


******************************************
Definition 1:
*****************
>Here i am not satisfied with parent class method implementation(body),so that in
child

class i am rewriting that method(parent class) with different implementation then


this

concept is called method overriding concept.

Example
***********
Manual Steps
***************
1.
2.
3.
Can we override parent class method into child class ?
**********************************************************
Ans : Yes

>Here parent class method which is overridden then it is called overridden method.

>Here child class method which is overriding then it is called overriding method

>This concept is called overriding concept

Note :
**********
When run this program by default JVM will always call to child class
method(overriding method) not parent class method(overridden method)

What is a Method overriding in java ?


******************************************
Definition 2:
*****************
>Here method name same and method signature same then this concept is called method
overriding concept

Example
*********
Manual Steps
**************
1.Create Parent class
2.Create Child class from parent class
3.Create MainClass

Java code
*************

Method overriding rules


**************************

private(least) < protected < public(highest)

Method overloading rules


**************************

private(least) < protected < public(highest)

Instance variable part 2


**************************
Part 1
*********
1.Print 1st student details
2.Print 2nd student details
3.Print nth student details
Part 2
*********
1.Suppose if u want to print the 1st student details then we need to create object
for that 1st student
2.Suppose if u want to print the 2nd student details then we need to create object
for that 2nd student
3.Suppose if u want to print the nth student details then we need to create object
for that nth student

Part 3
***********
1.Print 1st student details
********************************
1.First,initialize the values for that instance vairables
2.Print 1st student details

2.Print 2nd student details


*********************************
1.First,initialize the values for that instance vairables
2.Print 2nd student details

3.Print nth student details


*******************************
1.First,initialize the values for that instance vairables
2.Print nth student details

If i change the 1st student marks then there are any effect for that remaining
student

marks ?
****************************************************************************
Ans : No effect,you can change

Instanace variable part 2


***************************

>For every object a separate copy of instance variables will be create

>For every student a separate copy of name,rollno,marks will be create

Static variable part 2


*****************************

>Create collegeName and share the collegeName for all the students

>Create Single copy and share this copy for all the objects

a) How to print all the dropdown values


*********************************************
>First,get the dropdown size or count dropdown values
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown

>print all the dropdown values

b) How to Select the dropdown value inside a frame


*******************************************************

diagram
*********

Manual Steps
*****************
>Switch to frame
>Identify dropdown
>Select the dropdown value

Selenium Java code


**********************

// Switch to frame by id

driver.switchTo().frame("rightMenu");

//1.First,Identify dropdown

WebElement dropdown = driver.findElement(By.id("loc_code"));

//>Select the dropdown value

Select S = new Select(dropdown);

S.selectByIndex(1);

c)How to verify selected value from dropdown


******************************************
Diagram :
************

Manual Steps
*************
>get the selected value
>Verify selected value

Testing = operation code + verification code

Selenium Java code


************************

//--------------------------------------------------------------operation code
//>get the selected value
String selected_value = S.getFirstSelectedOption().getText();

System.out.println(selected_value);//Emp. ID

//-------------------------------------------------------------
verification code

if(selected_value.equals("Emp. ID"))
{

System.out.println("Selected value verified successfully");


}else
{
System.out.println("Selected value not verified successfully");
}

1.How to select multiple options from listbox?


*************************************************

diagram
**********

Manual Steps
***************
1.Identify the Lisbox
2.select multiple options from a list box.

Selenium Java code


***********************

javascript.executeScript("window.scrollBy(x-axis,y-axis)");

How to handle hidden and disabled mode of the elements in selenium ?


*************************************************************************
Ans : Here Selenium + Javascript code ----------->to handle hidden and disabled
mode of the elements

Why we should we go for javascript in selenium ?


*************************************************
Ans :

1.
2.
3.

Syntax :
***********

(javascriptExecutor)driver.executeScript(script,argument);

Syntax Explanation :
*********************

>javascriptExecutor===>Here javascriptExecutor it's an interface,which will help us


to

execute the javascript code through selenium webdriver.

>(javascriptExecutor)driver==>Convert driver object into javascriptExecutor

>Here javascriptExecutor,it contains executeScript ,by using this we can execute


the

javascript code.

>script===>This is a javascript code

>argument==>This is a argument for that javascript code

Note :
***********

>By default javascript,it understand arguments[0] for that every single element

>By default javascript,it understand arguments[0] for that 1st element

>By default javascript,it understand arguments[1] for that 2nd element

>By default javascript,it understand arguments[2] for that 3rd element

Html code
*************

<input type="submit" value="Submit">

Syntax :
***********
//tagName[@attributeName='value']

Example
***********

//input[@type='submit']

Abstract class in java


***********************
Abstract keyword in java ?
*******************************

>Here abstract method is applicable for that methods and classes but not for
variables

>In general abstract mean not clear,not complete,incomplete method ,incomplete


class

partial implementation just like that.

Here we need to learn 4 things


***********************************
1.concreate method
2.Concreate class
3.Abstract method
4.Abstract class

What is a concreate method(regular method) in java ?


*************************************
Ans : A method has declaration part and implementation part such type of method is
called

concreate method.

Example 1
*************
class Test{

//concreate method

void m1()
{

}
//concreate method

void m1(int i)
{

//concreate method

main()
{

}
What is a concreate class(regular class) in java ?
*************************************

Ans :A class can contain only concreate methods such type of class is called
concreate class

Example 2
*************
class Test{

//concreate method

void m1()
{

}
//concreate method

void m1(int i)
{

}
//concreate method

main()
{

What is a Abstract method in java ?


*************************************
Ans : A method has declaration part but not implementation part such type of method
is called

Abstract method.

Example 3
*************
abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{

}
//abstract method

abstract void m2(); //Unimplemented method

1.
2.
3.
4.
5.
6.
7.

What is a Abstract class in java ?


*************************************
Ans : A class can contain concreate methods and abstract methods such type of class
is called

abstract class.

Example 3
*************
abstract class Test{ //Unimplemented class

//concreate method

void m1() //implemented method


{
}
//abstract method

abstract void m2(); //Unimplemented method

When we will go for abstract class in java and selenium ?


************************************************************
Ans :

When we will go for interface in java and selenium ?


************************************************************
Ans :

Abstract class part 2


**************************
Example
***********
Manual Steps
****************
1.Create Superclas(abstract class(Car))
2.Create Subclass1(Maruti) from Superclas(abstract class(Car))
3.Create Subclass2(Santro) from Superclas(abstract class(Car))
4.Create Mainclass

Java code
************

In superclass
****************

common code + Additional code(optional)

common things / common code


*******************************
1.regino
2.FuelTank
3.steering
4.breaks

In subclass
************

Additional code (mandatory)

School project
****************
1.Teacher---------100%-----complete
What is a method / function in java ?
****************************************
Ans :

1.
2.
3.

Syntax :
*************

return-type methodname(para1,para2,para3)
{

statement1;
statement2;
statement3;
}

>Here method name always start with small letter and then next word start with
capital letter

Examples
***********

void add()
{

}
void addfunction()
{

void addFunction()
{

How to write the program for a method,without return-type and without passing
parameters
***********************************************************************************
**
Example
*************

When function will be called ?


********************************
Ans : Whenever u create an object after function will be called.

How to write the program for a method,with return-type and without passing
parameters
***********************************************************************************
**
Example
*************

How to write the program for a method,without return-type and with passing
parameters
***********************************************************************************
**
Example
*************

Why we are using parameters in method ?


***************************************
Ans : By using these parameters,we can receive the data from outside into method

How to write the program for a method,with return-type and with passing parameters
***********************************************************************************
**
Example
*************
Note :
***********
A method can never return more than once value

Examples
***********
return c;//valid

return a,b;//invalid

return a,retunt b;//invalid

1.How to select multiple options from listbox?


***********************************************

Manual Steps
***************

1.Identify the Lisbox


2.select multiple options from a list box

Selenium Java code


**********************

WebElement listbox=driver.findElement(By.id("ctl00_MainContent_lbCountry"));

Select S = new Select(listbox);

S.selectByIndex(3);

S.selectByVisibleText("ARGENTINA");

2.Verify Multiple selections are allowed or Not from a list box.


**********************************************************************
Manual Steps
***************

1.Identify the Lisbox


2.select multiple options from a list box
3.Verify Multiple selections are allowed or Not from a list box.

Selenium Java code


**********************

Testing = operation code + Verification code

//------------------------------------------------------- operation code

//identify the listbox


WebElement
listbox=driver.findElement(By.id("ctl00_MainContent_lbCountry"));

Select S = new Select(listbox);

S.selectByIndex(3);

S.selectByVisibleText("ARGENTINA");

//-------------------------------------------------------------
Verification code
//.Verify Multiple selections are allowed or Not from a list box.

if(S.isMultiple())
{
System.out.println("Multiple selections are allowed from
listbox");
}else
{
System.out.println("Multiple selections are not allowed from
listbox");
}

How to verify single checkbox in a webpage using selenium?


************************************************************

Manual Steps
***************

 Identify Checkbox1
 Click Checkbox1
 Verify Checkbox1

Selenium Java code


**********************
//----------------------------------------------------------------- operation code
// Identify Checkbox1

WebElement checkbox1 = Driver.findElement(By.id("vfb-6-0"));

// Click Checkbox1

checkbox1.click();
//-----------------------------------------------------------------Verification
code
// Verify Checkbox1

if(checkbox1.isSelected())
{

System.out.println("checkbox1 is selected");
}else
{

System.out.println("checkbox1 not selected");


}

How to Verify multiple checkboxes ?


****************************************

xpath syntax :
*******************

//tagName[@Attributename='value']

//input[@type='checkbox']

diagram
***********

Manual Steps
****************
 Identify all Checkboxes
 Count total checkboxes in a webpage
 Verify multiple checkboxes one by one

Selenium java code


********************

//-------------------------------------------------------------------
// Identify all Checkboxes

List<WebElement> allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));

System.out.println("Total checkboxes : "+allchk.size());//3

//------------------------------------------------------------------------

// Verify multiple checkboxes one by one

for(int i=0;i<allchk.size();i++)
{

allchk.get(i).click();

if(allchk.get(i).isSelected())
{
System.out.println("checkbox selected");
}else
{
System.out.println("checkbox not selected");
}

Estng
2017

[SELENIUM TRAINING BY HANUMANTH]

Selenium Automation Tool Handbook


A basic referential guide to Selenium
2019

What is mean by Testing?

1.The process of exercising software to verify that it satisfies specified


requirements and to detect errors.
2. The process of analyzing a software item to detect the differences between
existing and required conditions (that is, bugs), and to evaluate the features of
the software item.
3.The process of operating a system or component under specified conditions,
observing or recording the results, and making an evaluation of some aspect of the
system or component.

Disadvantages of Manual Testing


1. Manual tests can be very time consuming
2.For every release you must rerun the same set of tests which can be time
consuming
3. Requires heavy investment
4.Requires more number of human resources

Automation :

Automation Testing: Testing which is done by any other third party tool

Test automation is the use of software to control the execution of tests, the
comparison of actual outcomes to predicted outcomes, the setting up of test
preconditions, and other test control and test reporting functions. Commonly, test
automation involves automating a manual process already in place that uses a
formalized testing process.

Input
Report/output

Advantages:
Reliable: Tests perform precisely the same operations each time they are run,
thereby eliminating human error
Repeatable: You can test how the software reacts under repeated execution of the
same operations. Programmable: You can program sophisticated tests that bring out
hidden information from the application.
Comprehensive: You can build a suite of tests that covers every feature in your
application.
Reusable: You can reuse tests on different versions of an application, even if the
user interfaces changes.
Better Quality Software: Because you can run more tests in less time with fewer
resources
Fast: Automated Tools run tests significantly faster than human users.
Cost Reduction: As the number of resources for regression test are reduced.
Reporting: Customized reporting of application defects

Disadvantages of Automation Testing


• Proficiency is required to write the automation test scripts.
• Debugging the test script is major issue. If any error is present in the test
script, sometimes it may lead to deadly consequences.
• Test maintenance is costly in case of playback methods. Even though a minor
change occurs in the GUI, the test script has to be rerecorded or replaced by a new
test script.
• Maintenance of test data files is difficult, if the test script tests more
screens.
Functional Testing Tools

Open Source Commercial


Selenium-1.0 QTP
Web driver 2.0 Test Partner
Sahi Test complete
Bad Boy RFT
Ruby Silk
Watir

Selenium vs. QTP


Selenium QTP
Open source Paid tool
Works on all OS (Windows, OS X, Linux,
Mac os) Works on Windows
Tests Web and mobile applications Tests web , mobile and desktop applications
Works on almost all browsers(IE, Firefox, chromeSafari, Opera) Works on Firefox
3.5.x and IE
Code can be made in any one of languages such as Java, C#, Ruby, Python, pearl, php
etc VB Script
Html ID, name,className,Xpath, CSS, DOM, Link text,partialLinktext Object
properties, Repository objects
There is no option, can record script in Selenium IDE, can spy objects using IE
developer tool bar GUI Spy
IDE sometimes does not record some events Recording is a little reliable
Set of Libraries, around 20MB (Need to include other supporting software) Around
1.5GB

Steps to configure Selenium WebDriver with java to develop test scripts.


Pre-conditions: We need below files
Step 1 :Download and Install JDK 8
Follow below URL
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Select Accept License Agreement radio button 

Choose version to download: Windows 86 or x64 based on your OS (jdk-8-windows-


i586.exe and jdk-8-windows-x64.exe)

wait until complete download.


copy downloaded file and paste in personal folder.
click on setup to start installation.
click on next until installation will go to end
click on close.
Restart Computer.

Note :
After completion of JDK installation tester can create environment variable for
JAVA_HOME in your windows system by following below navigation

Click on start
Right click on mycomputer
 Click on properties
 Click on Advanced system setting
Select Advanced tab
 Click on Environment variable button
Go to user variables
click on New button
Type JAVA_HOME and provide path of JDK folder
click on ok
Follow below image

Go to system variable


Select path
click on Edit button
Add path of JDK bin folder followed by semicolon(;) at the end of existing path
value
Click on ok
 Click on ok
Follow below image

How to verify java successfully installed or not into your local system
 Open the command prompt.
 Run command "java -version"

It should show your installed java version detail as shown in above image.
That means java is installed successfully into your local system and you are ready
to use it.
Step 2 : Download and launch Eclipse IDE
1. IDE stands for Intigrated Development Environment.Eclipse Ide is useful to
write our test scripts in java or java based tools like selenium.
2. We need to follow below URL to download and launch Eclipse Ide
http://www.eclipse.org/downloads/packages/release/Mars/2
Download the Eclipse Mars , you can choose version Windows 32 bit or 64 bit based
on your OS

wait until complete download.


copy downloaded file and paste into personal folder and extract
click on Eclipse folder
Here click on 'eclipse.exe' file directly.Here no need to install eclipse into
your local system.
Step 3 : Download Selenium WebDriver Jar Files.
After completion of eclipse Ide launching with the creation of project,package and
class with main(),we need to download selenium webdriver jar file.
Follow the below steps :
 Go to google search
 Enter seleniumhq then search it
 Click on first link(https://www.seleniumhq.org/download/)
 Click on download
 Scroll to Selenium Client & WebDriver Language Bindings
 Click on download for java based selenium webdriver

 wait until complete download.


 copy downloaded jar file and paste into personal folder and extract

Step 4 : Associate selenium webdriver with eclipse Ide.

 click on 'eclipse.exe' to start eclipse


 First time when you start eclipse software application, it will ask you to
select your workspace where your work will be stored as shown in bellow image.

Choose a workspace folder name as D:\workspace and click on ok button .Here You can
change the workspace location from 'Switch Workspace' under 'file' menu of eclipse.
Create new project
 Go to File
 New
 Java Project and give your project name 'SeleniumProject' > Click on finish
button.
Create new package
 Right click on source folder(src)
 New
 Package
 give the package name ‘SeleniumTests’
 Click on finish button.
Create New Class
 Right click on package ‘SeleniumTests’
 New
 Class
 give the class name 'myTestLogin'
 click on Finish button.
Add external jars for that project
 Right click on project 'SeleniumProject'
 go to Java build path
 configure build path
 >select Libraries
 Click on add external JARs button
 Then go your jar file folder path location
 select both .jar files from D:\selenium-java 3.12.0.
 click on open button
 Click on add external JARs button
 Then go your jar file folder path location
 select all .jar files from D:\selenium-java 3.11.0\libs
 click on open button
 click on ok button
Steps to Download and Install firebug Add-on.
Follow my below url to install Fire Bug
https://addons.mozilla.org/en-US/firefox/addon/firebug/
Click on Add to Firefox button

Click on Install button

After install FireBug then go to


Tools > Web Developer > Firebug > Open Firebug (or)you can use shortcut key ‘F12’

After open the firebug . Right click on field or element in your application then
click on inspect element with firebug option.
In html code take either id(or)name(or)className etc. from highlighted section.
See below image

Note :Here no need to restart your Firefox after installing Firebug Add-On
Steps to Download and Install firepath Add-on.
Follow my below url to install Firepath add-on
https://addons.mozilla.org/en-US/firefox/addon/firepath/
Click on Add to Firefox button

Click on Install button

Click on Restart Now

After install firepath then go to


Tools > Web Developer > Firebug > Open Firebug (or)you can use shortcut key ‘F12’

You could find ‘FirePath’ as shown below image

Install Chropath Addon for Firefox Browser


Note: ChroPath Add-on can be installed on both Chrome and Firefox Browsers
This is for the Firefox fans, who are interested in using ChroPath Add-on on the
Firefox Browser.
Let’s get started.

Follow the below steps for installing ChroPath Add-on on Firefox Browser:
1) Open Firefox browser> go to google search >Enter ChroPath then search it> click
on the link ChroPath for Firefox as shown below:

2) Click on ‘Add to Firefox’ button as shown below:

3) Click on ‘Add’ button as shown below:

4) Observe that The ChroPath has been added to Firefox as shown below

Hence, we have successfully installed ChroPath in Firefox Browser.

How to use Chropath add-on in Chrome Browser?


Pre-requisite : Install Chropath Add-on on Chrome Browser as explained in the
previous topic.

FireBug and Firepath add-ons got deprecated and hence discontinued. Hence we need
to use Chropath add-on in place of them. In this topic, I will explain, how to use
Chropath in Chrome browser in a step by step manner. Please follow the below steps
to understand.
1. Launch Chrome Browser and browse any site say www.google.com

2. Press 'F12' key on your keyboard, then you will get the developer tool in Chrome
Browser as shown below.

3.Select 'Elements' tag and then select the 'Chropath' option as shown below.

4. Click on the 'Inspect Element' option on the Chrome Developer tool Options as
shown below, select any UI element on the page say 'Google Logo' and ensure that
the source code of the selected UI element (i.e. Google Logo in this example) is
highlighted as shown below.

Also, observe that the XPath Expressions and CSS Selectors locators got auto-
generated as shown below (The usage of these locators are explained in previous
topic).

5. Observe that the above highlighted source code is in html format. We may need
this source code to identify the properties of the selected UI element (i.e. Google
Logo in this example).

6. For example if we want to know the id property details of the selected UI


element Google Logo. First we need to inspect the Google Logo by following the
above 4 steps and copy the 'id' details from the highlighted source code as shown
below.

7. You can also copy the XPath Expressions and CSS Selectors locators that are
auto-generated by Chropath as shown below.

Java Comments

The java comments are statements that are not executed by the compiler and
interpreter. The comments can be used to provide information or explanation about
the variable, method, class or any statement. It can also be used to hide program
code for specific time.

Types of Java Comments

There are 3 types of comments in java.

1. Single Line Comment


2. Multi Line Comment

1) Java Single Line Comment : The single line comment is used to comment only one
line.
Syntax:

//This is single line comment


Example:

public class CommentExample1 {


public static void main(String[] args) {
int i=10;//Here, i is a variable
System.out.println(i);
}
}
2) Java Multi Line Comment : The multi line comment is used to comment multiple
lines of code.

Syntax:

/*
This
is
multi line
comment
*/
Example:

public class CommentExample2 {


public static void main(String[] args) {
/* Let's declare and
print variable in java. */
int i=10;
System.out.println(i);
}
}

Java Control Statements

The Java if statement is used to test the condition. It checks boolean condition:
true or false. There are various types of if statement in java.
o if statement
o if-else statement
o nested if statement

Java IF Statement

The Java if statement tests the condition. It executes the if block if condition is
true.

Syntax:

if(condition){
//code to be executed
}

Example:

public class IfExample {


public static void main(String[] args) {
int age=20;
if(age>18){
System.out.print("Age is greater than 18");
}
}
}

Java IF-else Statement

The Java if-else statement also tests the condition. It executes the if block if
condition is true otherwise else block is executed.

Syntax:

if(condition){
//code if condition is true
}else{
//code if condition is false
}

public class IfElseExample {


public static void main(String[] args) {
int number=13;
if(number%2==0){
System.out.println("even number");
}else{
System.out.println("odd number");
}
}
}
Java Nested IF-else Statement

The Nested if-else statement executes one condition from multiple statements.

Syntax:
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}

Example:

public class IfElseIfExample {


public static void main(String[] args) {
int marks=65;

if(marks<50){
System.out.println("fail");
}
else if(marks>=50 && marks<60){
System.out.println("D grade");
}
else if(marks>=60 && marks<70){
System.out.println("C grade");
}
else if(marks>=70 && marks<80){
System.out.println("B grade");
}
else if(marks>=80 && marks<90){
System.out.println("A grade");
}else if(marks>=90 && marks<100){
System.out.println("A+ grade");
}else{
System.out.println("Invalid!");
}
}
}
Java Naming conventions

Java naming convention is a rule to follow as you decide what to name your
identifiers such as class, package, variable, constant, method etc.

But, it is not forced to follow. So, it is known as convention not rule.


All the classes, interfaces, packages, methods and fields of java programming
language are given according to java naming convention.

Advantage of naming conventions in java

By using standard Java naming conventions, you make your code easier to read for
yourself and for other programmers. Readability of Java program is very important.
It indicates that less time is spent to figure out what the code does.

Name Convention
class name should start with uppercase letter and be a noun e.g. String, Color,
Button, System, Thread etc.

method name should start with lowercase letter and be a verb e.g.
actionPerformed(), main(), print(), println() etc.
variable name should start with lowercase letter e.g. firstName, orderNumber
etc.
package name should be in lowercase letter e.g. java, lang, sql, util etc.
constants name should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY
etc.

WEBDRIVER

Web driver is an interface implemented in java.

Browser Launching Automation

Firefox: - FireFoxDriver is an in-built class of selenium which is use to automate


the Firefox browse, we should create an object of this class.

Program 1:- Program to Launch Firefox browser and navigate to google


import org.openqa.selenium.firefox.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;
public class LaunchFireFoxBrowser {
public static void main(String[] args) {

WebDriver driver=new FirefoxDriver();


driver.get("https://google.com");
String url=driver.getCurrentUrl();
System.out.println(url);
driver.close();

}
}
Chrome Browser : - To automate chrome browser we should first download its
corresponding driver executable file and specify the path of that file using
“system.setProperty”.

Navigation:-
1. Open seleniumhq.org
2. Click on Download
3. Scroll down to third party browser drivers not developed by seleniumhq>>click
on the latest version of “ChromeDriver” and download it.
4. Extract it and open it, we will find “ChromeDriver.exe” file. The path of the
file should be given in the selenium program using “system.setProperty”.
5. Chrome driver Is the in-built class of selenium to automate chrome browser.
We should create an object of this class.

Program 2:- Program to Launch Chrome browser and navigate to google

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.server.browserlaunchers.Sleeper;

public class ChromeLaunch {

public static void main(String[] args)


{
System.setProperty("webdriver.chrome.driver","c:\\Users\\mmotupalli\\
Desktop\\Hanumanth\\Selenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://google.com");

}
}

IE Browser : - To automate IE browser we should first download its corresponding


driver executable file and specify the path of that file using
“system.setProperty”.

Navigation:-
1. Open seleniumhq.org
2. Click on Download
3. Scroll down to internetExplorer Driver Server >>download the corresponding
version.
4. Extract it and open it, we will find “IEDriverServer.exe” file. The path of
the file should be given in the selenium program using “system.setProperty”.
5. InternetExplorerDriver Is the in-built class of selenium to automate IE
browser. We should create an object of this class.
Program 4:- Program to Launch IE browser and navigate to google
import org.openqa.selenium.ie.InternetExplorerDriver;
public class IElaunch {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","c:\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.get("http://google.com");
}

FireFox Chrome IE Browser


Download the exefile and mention the path of the file Download the exefile and
mention the path of the file Download the exefile and mention the path of the file
geckoDriver ChromeDriver IEDriverServer

Program 5:- Program to Launch Firefox browser and navigate to yahoo mail

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

public class YahooLogin {


public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.navigate().to("http://yahoomail.com");
System.out.println(driver.getWindowHandle());
driver.manage().window().maximize();
driver.findElement(By.id("login-username")).sendKeys(“*****");
driver.findElement(By.id("login-signin")).click();
driver.findElement(By.id("login-passwd")).sendKeys("AABBCC");
driver.findElement(By.name("signin")).click();
}
}
Different Types of Locators in Selenium:
Before moving to the question what is locators?, let’s understand
what is object identification first?
In any application, as you see Browser window, page, edit box, button, image, drop
down, text etc.All can be considered as objects, or say elements. Now in automation
testing, our task is to identify these objects to perform required actions upon
them. All objects posses some properties and values, which are used to define those
objects in AUT(Application under Test). Same properties and values will be helpful
to identify these objects in automation.
The locators are used to identify these objects or elements in the webpage.In
selenium, there are 8 types of locators as given below.
Note :Locators are given with priority of usage during implementation.
1. id
2. Name
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName
7. cssSelector
8. Xpath

Let’s understand them one by one with example.


id Locator:
>The most preferable way to locate an element in the webpage.

>It is always better to identify the object with unique property.

>Because id is always unique (like employee id, roll number etc) that’s why it will
be faster and reliable way for locating an element.
>You can use developer tool(Source code of the webpage) to look
for the id of an element.
>We can take Gmail application for the demo. Suppose, we need
to identify the username in Gmail. let’s see how to take locator
value by using id.
>From the below image, username is having id “Email”
(Highlighted).So , we will use this locator value to Identify the
webElement(object).

Html Code :
<input id="keyword" class="form-control" type="text" value=""
placeholder="Enter Keyword" name="keyword">

TestSteps :
>open the Firefox Browser
>Navigate the App Url
>Enter the Keyword
How to use it in the Selenium Code ?
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Locators_Id {

public static void main(String[] args) {

//open the Firefox Browser

WebDriver driver=new FirefoxDriver();

//Navigate the App Url

driver.get("https://www.kosmiktechnologies.com/new-batches/");

//Enter the Keyword

driver.findElement(By.id("keyword")).sendKeys("selenium");

}
Don’t forget:
We might find situations where we cannot use the id attribute due to the following
reasons:

> If no Id in your Html code of any element.


>If The id attribute values are dynamically generated.

2. name Locator: If no Id in your Html code of any element. Then we preferred name
locator.
Note : If there are multiple elements with the same name in the webpage, then
Selenium will identify the first element only with that name.

Html Code :
<input class="gLFyf gsfi" type="text" data-
ved="0ahUKEwjhiNGa_onkAhUMTY8KHczDAOUQ39UDCAQ" autocomplete="both"
jsaction="paste:puy29d" name="q" maxlength="2048">
TestSteps :
>open the Firefox Browser
>Navigate the App Url
> Enter the Kosmik Technologies into search box
How to use it in the Selenium Code ?
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Locator_Name {

public static void main(String[] args) {


//open the Firefox Browser

WebDriver driver=new FirefoxDriver();

//Navigate the App Url

driver.get("https://www.google.com/");

//Enter the Kosmik Technologies into search box

driver.findElement(By.name("q")).sendKeys("Kosmik Technologies");

Don’t forget:
We might find situations where we cannot use the name attribute due to the
following reasons:

> If no name in your Html code of any element.


>If The name attribute values are dynamically generated.

3.Linktext Locator:
>Here linkText and partialLinkText locators these will be used only for links.
>Here linkText locator it takes entire text to identify any link By its text .
Note : If there are multiple links with the same text in the webpage (like same
link header and footer on the page), then Selenium will identify first link only by
default.

Html Code :
<a href="https://www.kosmiktechnologies.com/new-batches/">New Batches</a>
TestSteps :
>open the Firefox Browser
>Navigate the App Url
> Click on New Batches footer link
How to use it in the Selenium Code ?
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Locator_linkText {

public static void main(String[] args) {

//open the Firefox Browser

WebDriver driver=new FirefoxDriver();

//Navigate the App Url

driver.get("https://www.kosmiktechnologies.com/new-batches/");

//Click on New Batches footer link

driver.findElement(By.linkText("New Batches")).click();

4. partialLinkText Locator :
>This is similar to linkText locator.
>Here partialLinkText Locator it takes partial text to identify any link
By its text .

Html Code :
<a href="https://www.kosmiktechnologies.com/new-batches/">New Batches</a>
TestSteps :
>open the Firefox Browser
>Navigate the App Url
> Click on New Batches footer link
How to use it in the Selenium Code ?
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Locator_PartialLinkText {

public static void main(String[] args) {


//open the Firefox Browser

WebDriver driver=new FirefoxDriver();

//Navigate the App Url

driver.get("https://www.kosmiktechnologies.com/new-batches/");

//Click on New Batches footer link

driver.findElement(By.partialLinkText("Batches")).click();
}

5. tagName Locator:
Every element has some tagName like div, input, span etc. Now, If you want to
identify list of elements(and here elements having the same tagName) at a time in a
webpage then we use tagName locator.
For Ex :
>If you want to identify drop down values at a time in a webpage then we use
tagName locator.
> If you want to identify list of frames at a time in a webpage then we use tagName
locator.
> If you want to identify list of links at a time in a webpage then we use tagName
locator.

Html Code Ex :
<a href="/index.php/auth/requestPasswordResetCode">Forgot your password?</a>
Test Steps :
>open the firefox browser
>navigate the App Url
>Identify All the Links and store into allitems variable
>Print total Links in a webpage
How to use it in the Selenium Code ?
package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TotalLinks {

public static void main(String[] args) {

//open the firefox browser

WebDriver driver = new FirefoxDriver();

//Navigat the App Url

driver.get("https://opensource-demo.orangehrmlive.com/");

//Identify All the Links and store into allitems variable

List<WebElement> allitems = driver.findElements(By.tagName("a"));

//Print total Links in a webpage

System.out.println(allitems.size());
}
}

6. className Locator:
Solution 1:
If no Id and name in your Html code of any element. Then we preferred className
locator.
Note : If there are multiple elements with the same className in the webpage, then
Selenium will identify the first element only with that className.

Html Code Ex :
<input id="email" class="inputtext" type="email" data-testid="royal_email"
name="email">
Test Steps :
>open the firefox browser
>navigate the App Url
>wait 6sec
>Enter Email address into Email or Phone textbox
How to use it in the Selenium Code ?
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Locator_className {

public static void main(String[] args) throws InterruptedException {


//open the Firefox Browser

WebDriver driver=new FirefoxDriver();

//Navigate the App Url

driver.get("https://www.facebook.com/?");

// wait 6sec

Thread.sleep(6000);

//Enter Email address into Email or Phone textbox

driver.findElement(By.className("inputtext")).sendKeys("KosmikTechnologies@gmail.co
m");

Solution 2:
>If no Id and name in your Html code of any element. Then we preferred className
locator.
>If The className attribute value with spaces then we preferred cssSelector and
xpath Expression locators.Here className locator doesn’t work to identify the
element.

Html Code Ex :
<input id="u_0_p" class="inputtext _58mg _5dba _2ph-" type="text" aria-label="First
name" placeholder="" aria-required="true" value="" name="firstname" data-
type="text" aria-describedby="js_6p" aria-invalid="true">
Test Steps :
>open the firefox browser
>navigate the App Url
>wait 6sec
>Enter The First Name
How to use it in the Selenium Code ?
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Locator_className {

public static void main(String[] args) throws InterruptedException {


//open the Firefox Browser

WebDriver driver=new FirefoxDriver();

//Navigate the App Url

driver.get("https://www.facebook.com/?");

// wait 6sec

Thread.sleep(6000);

//Enter The First Name

driver.findElement(By.className("inputtext _58mg _5dba


_2ph-")).sendKeys("Hanumanth");

Don’t forget:
We might find situations where we cannot use the className attribute due to the
following reasons:

> If no className in your Html code of any element.

>If The className attribute value are dynamically generated.

>If The className attribute value with spaces.

7.cssSelector:
8. Xpath Locator:

OPERATIONS ON WEB ELEMENTS

Selenium performs various operations on the webelements using the following methods

1. Click():- This is used to Clicks on a target element (e.g. a link, button,


checkbox, or radio button).
2. Sendkeys():- This is used for entering the text into input fields.
3. Clear():- this is used to clear the input fields
4. getText():- This is used to capture the visible text of a webelement
5. getAttribute():- This is use to capture the property of the webelement.
6. isDisplayed():- This is used to find an element is visible or hidden.
7. isEnabled():- This will tell us whether an element is enabled or disabled.
8. isSelected():- This will tell us if radio button is selected, checkbox is
selected, an option in dropdown is selected.

HTML STATEMENTS

Component HTML Tag Mandatory field Optional field


Link a Href id,name,class
Text fields Input Type=’text’ id,name,class
Password fields Input Type=’password’ id,name,class
Check box Input Type=’checkbox’ id,name,class
Radio button Input Type=’radio’ id,name,class
Submit buttons Input Type=’submit’ id,name,class
Email field Input Type=’email; id,name,class
Dropdown Select None id,name,class
Element in dropdown Option None id,name,class
Images Img Src id,name,class
Frames Frame,iframe None id,name,class
Webtable Table None id,name,class
Rows in a webtable Tr None id,name,class
Columns in a webtable Td None id,name,class
Text P None id,name,class
Boldtext B None id,name,class
Headers h1 – h6 None id,name,class

Loops in JAVA

Loops:- A loop statement allows us to execute a statement or group of statements


multiple times.

While loop: Repeats a statement or group of statements while a given condition is


true. It tests the condition before executing the loop body.

do...while loop :Like a while statement, except that it tests the condition at the
end of the loop body.

for loop : Execute a sequence of statements multiple times and abbreviates the code
that manages the loop variable.

Java Program to print Selenium 10 times

public class WhileLoop {

public static void main(String[] args) {


int i=1;
while(i<=10)
{
System.out.println(“Selenium”);
i=i+1
}
}
}

Java Program to print even numbers between 1 to 10


public class WhileLoop {
public static void main(String[] args) {
int i=2;
while(i<=10)
{
System.out.println(i);
i=i+2
}
}
}

Program to Print 2 table

public class WhileLoop {

public static void main(String[] args) {


int i=1;
int j=2;
while(i<=10)
{
System.out.println(j+"*"+i+"="+j*i);
i=i+1;
}
}
}

Nested Loops : Program to Print multiplication tables from 1 to 10

public class WhileLoop {

public static void main(String[] args) {


int i=1;
while(i<=10)
{
int j=1;
while(j<=10)
{
System.out.println(i+"*"+j+"="+j*i);
j++;
}
i++;
}

Java Program Pyramid 1 Example


public class JavaPyramid1 {

public static void main(String[] args) {

for(int i=1; i<= 5 ;i++){

for(int j=0; j < i; j++){


System.out.print("*");
}
//generate a new line
System.out.println("");
}
}
}

Output of the above program would be

*
**
***
****
*****

Java Program Pyramid 2 Example

public class JavaPyramid2 {

public static void main(String[] args) {

for(int i=5; i>0 ;i--){

for(int j=0; j < i; j++){


System.out.print("*");
}
//generate a new line
System.out.println("");
}
}
}

Output of the example would be


*****
****
***
**
*

Java Program Pyramid 3 Example


public class JavaPyramid3 {

public static void main(String[] args) {

for(int i=1; i<= 5 ;i++){

for(int j=0; j < i; j++){


System.out.print("*");
}

//generate a new line


System.out.println("");
}

//create second half of pyramid


for(int i=5; i>0 ;i--){

for(int j=0; j < i; j++){


System.out.print("*");
}

//generate a new line


System.out.println("");
}

}
}

Output of the example would be

*
**
***
****
*****
*****
****
***
**
*

Selenium WebDriver First Program :

Pre-requisite -

 Make sure you have already installed Firefox in ur local system.


 Make sure you have already installed JDK 1.8 or above in ur local system.
 Make sure you have already installed Eclipse IDE.
 Make sure you have already configured Selenium-java .jar file with your java
project.
 Make sure you have downloaded the latest version of Selenium-java.jar file.
Otherwise, you will get a compiler error.
 Make sure you have downloaded the geckodriver for Firefox.

Point to note -
• If your browser version is 47+, then you have to download 'geckodriver.exe'.
If it is below 47, then no need to download.

TestSteps:
 Open the firefox browser
 Navigate the application url
 Get the Title of the WebPage
 Print the title of the webpage
 Verify Title of the WebPage
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Dashboard Text
 Print the Dashboard Text
 To verify whether the welcome page successfully opened or not
 Clicking On Logout Button
 Close the current Firefox Browser

Selenium Code :
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SampleClass {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/
eKart/admin/");

//Get the Title of the WebPage

String title=driver.getTitle();

//print the title of the webpage

System.out.println(title);

//Verify Title of the WebPage

if (title.equals("Administration")) {
System.out.println("title verified successfully");
} else {
System.out.println("title not verified successfully");
}

// Enter the username

driver.findElement(By.name("username")).sendKeys("Kadmin");

// Enter the password

driver.findElement(By.name("password")).sendKeys("K@admin");

// Clicking On Login Button

driver.findElement(By.xpath("//*[@id='content']/div/div/div/div/div[2]/form/
div[3]/button")).click();

// Identify and get the Dashboard Text

String text =
driver.findElement(By.xpath("//*[@id='content']/div[1]/div/h1")).getText();

// Print the Dashboard Text

System.out.println(text);
// To verify whether the welcome page successfully opened or not

if (text.equals("Dashboard")) {
System.out.println("Welcome page verified successfully");
} else {
System.out.println("Welcome page not verified successfully");
}

// Clicking On Logout Button

driver.findElement(By.xpath("//*[@id='header']/ul/li[3]/a")).click();

// Close the current Firefox Browser

driver.close();

SELENIUM | BROWSER COMMANDS :

1.get() : This will be used to navigate the application url

Syntax : driver.get("appURL”);

2.getTitle() : This will be used to get the title of the current Webpage.

Syntax : driver.getTitle();

3.findElement() : By using this we can identify single webelement On a webpage.

Ex : Button, checkbox,radio button etc.

Syntax : driver.findElement(By.Locator("Locator-Value"));

4.findElements() : By using this we can identify list of webelements On a webpage.

Ex :

a. Suppose if you want to identify dropdown values at a time then we use


findElements method.

b. Suppose if you want to identify list of frames in a webpage then we use


findElements method.

c. Suppose if you want to identify list of links in a webpage then we use


findElements method.

Syntax :

List<WebElement> total_Links = driver.findElements(By.tagName("a"));

5.sendKeys() : If you want to give the value to the input field(textbox,text area)
then we use sendkeys method.

Syntax :

driver.findElement(By.locator("locator-value")).sendKeys("text");

6.getText() : If you want to get the particular text in a webpage then we use
getText method.
Syntax :

String PageText=driver.findElement(By.Locator(“Locator-value”)).getText();

7.click() :Is there any click operation in your application then we use click().

Syntax :

driver.findElement(By.Locator("Locator-value")).click();

8.close() : This will be used to close the current browser window.

Syntax : driver.close();

Important Interview Questions :

1.How to Identify WebElement in selenium webdriver?


A )By using firebug and firepath we can Identify WebElement.
2.Can we use firebug and firepath for chrome and Ie ?
No,
A )Suppose if u want to identify the WebElement In chrome and ie here no need to
install firebug and firepath.Becoz chrome and ie have its won developer tool to
identify the webElement.

3,What is the default package of selenium ?


A) org.openqa.selenium
4.What is the difference between findElement() and findElements()?

>findElement() : By using this we can identify single webelement On a webpage.

Ex :

> Button, checkbox,radio button etc.

Syntax :

> driver.findElement(By.Locator("Locator-Value"));

TestSteps :

 open the firefox browser


 navigate the application url
 Enter the username
 Close the current Firefox Browser

Selenium Program :

package seleniumProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findElementMethod {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/eKart/
admin/");

// Enter the username


driver.findElement(By.name("username")).sendKeys("Kadmin");

// Close the current Firefox Browser

driver.close();

>findElements() : By using this we can identify list of webelements at a time On a


webpage.

Ex :

> Suppose if you want to identify dropdown values at a time then we use
findElements method.

> Suppose if you want to identify list of frames at a time in a webpage then we
use findElements method.

> Suppose if you want to identify list of links at a time in a webpage then we
use findElements method.

Syntax :

>List<WebElement> elementName = driver.findElements(By.Locator("LocatorValue"));

TestSteps :

 open the firefox browser


 navigate the application url
 Identify all the links and store into total_Links variable
 Print the total Links on a webpage
 Close the current Firefox Browser window

Selenium Program :
package seleniumProject;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findElementsMethod {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/
eKart/admin/");

//Identify all the links and store into total_Links variable

List<WebElement> total_Links = driver.findElements(By.tagName("a"));

//Print the total Links on a webpage


System.out.println(total_Links.size());

// Close the current Firefox Browser

driver.close();

Note:
>WebElement is an in-built interface in selenium which is used to store anything
captured from the web application, it works like a datatype and it can be used to
store information about links, images, buttons, radio button, etc.

5.How to verify particular text on a webpage using selenium webdriver? (Or)


How to verify successful message on a webpage using selenium webdriver ?
TestSteps :

 open the firefox browser


 navigate the application url
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Dashboard Text
 Print the Dashboard Text
 To verify whether the welcome page successfully opened or not
 Clicking On Logout Button
 Close the current Firefox Browser

Selenium Program :
package seleniumProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SampleClass {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser
WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/eKart/
admin/");

// Enter the username


driver.findElement(By.name("username")).sendKeys("Kadmin");

// Enter the password

driver.findElement(By.name("password")).sendKeys("K@admin");

// Clicking On Login Button

driver.findElement(By.xpath("//*[@id='content']/div/div/div/div/div[2]/form/
div[3]/button")).click();

// Identify and get the Dashboard Text

String text =
driver.findElement(By.xpath("//*[@id='content']/div[1]/div/h1")).getText();

// Print the Dashboard Text

System.out.println(text);
// To verify whether the welcome page successfully opened or not

if (text.equals("Dashboard")) {
System.out.println("Text matched");
} else {
System.out.println("Text not matched");
}

// Clicking On Logout Button

driver.findElement(By.xpath("//*[@id='header']/ul/li[3]/a")).click();

// Close the current Firefox Browser

driver.close();

6.What is a webDriver ?

Here webDriver is a interface in between selenium automation test script and


application.

Here driver instance of the webDriver.


Syntax : WebDriver driver = new FirefoxDriver();

Control statements :

Syntax :
If(Actual_value.equals(Expected_value))
{

//Execute the code if condition is true

}else
{
//Execute the code if condition is false
}

Actual_value : Take the text from Testing Application.

Expected_value : client requirement

6.Difference between close() and quit() in selenium webdriver ?


Driver.close() : By using this we can close the current browser window.
I.e Single window on which driver is having focus that will be closed only
.
Driver.quit() : Every associated browser will be closed
I.e closed all the windows opened by the driver.

7.What is the purpose of public static void main() in java ?


public :
Since, main() should be available to JVM.It should be declared as public .If we
don’t use main() as a public then it doesn’t make itself available to JVM and JVM
can not execute it.

Static :
We should be call the main() without creating an object,such methods are called
static methods and we should be declared as static.
Void :
If main() it does not written any value then you have to put void(no value) before
the main().
main():
If main() is not written in the java program then jvm will not execute the
program.main() is the starting point for JVM to start execution of java.
8.Why we will import the packages ?

A)We will import the packages which contain some specific classes to use their
methods in the script.

What are the pre-requisites to run the selenium webdriver ?


1. JDK 1.8 (or)above
2. Eclipse IDE
3. Selenium JAR file
4. Testing Application
5. Browser
What is a frame?
Frame is just like as a container where few elements can be grouped.
How to identify frame inside a webpage?
There are different ways to identify frame inside a webpage
Way 1:
 Open webpage in a browser.
 Right click on webelement in a webpage

Way 2:
 Open webpage in a browser.
 Right click on webelement in a webpage
 Open source code(Html Code) of the webpage by clicking inspect element with
firebug option see below image.

How to handle an element inside the frame ?


There are 4 ways to handles frames in selenium webdriver.
Switch to frame by using index :
Method 1 :
Suppose if there is single frame in a webpage then we can switch to the iframe by
using index.
Here is the sample code:

Syntax : driver.switchTo().frame(int index);

Example : driver.switchTo().frame(0);

Note : By default single frame index value ‘ 0’.That means when webpage has only
one frame then the index will be zero.
Method 2 :
Suppose if there are 3 frames in a webpage then we can switch to the iframe by
using index.
Here is the sample code:
Syntax :

List<WebElement> framelist=driver.findElements(By.tagName("iframe"));

driver.switchTo().frame(framelist.get(int index));

Example :
List<WebElement> framelist=driver.findElements(By.tagName("iframe"));

//switchTo 1st frame by using index

driver.switchTo().frame(framelist.get(0));

//switchTo 2nd frame by using index

driver.switchTo().frame(framelist.get(1));

//switchTo 3rd frame by using index

driver.switchTo().frame(framelist.get(2));

Switch to frame by using Id or Name :

We can also use Name and Id attributes of iframe through which we can switch to
iframes.
Here is the sample code:
Syntax 1:
driver.switchTo().frame(“Id of the element”);

Html code :
Example : driver.switchTo().frame(“rightMenu”);
Syntax 2:
driver.switchTo().frame(“Name of the element”);

Html code :

Example : driver.switchTo().frame(“rightMenu”);

Switch to frame by using WebElement :

We can also switch to the frame using webelement.


Here is the sample code:
Syntax :
driver.switchTo().frame(WebElement);

Html code :

Example : driver.switchTo().frame(driver.findElement(By.name(“rightMenu”)));

How to get all the frames in a webpage ?

Html code :
Open notepad and type the below Html code and save as frames.html

<html>
<body>
<iframe src="http://www.seleniumhq.org/download/" width="200" height="200"
name="selenium">
<p>Your browser does not support iframes.<p>
</iframe>

<iframe src="http://127.0.0.1/orangehrm-2.5.0.2/login.php" width="200" height="200"


name="selenium">
<p>Your browser does not support iframes.<p>
</iframe>
<br>
<iframe src="http://testng.org/doc/index.html" width="200" height="200"
name="selenium">
<p>Your browser does not support iframes.<p>
</iframe>
<br>
<a class="gb_P" data-ved="0EMIuCBMoAA" href="https://mail.google.com/mail/?tab=wm"
data-pid="23">Click on Gmail</a>
</body>
</html>

Example :
package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class getTotalFrames {

public static void main(String[] args) {

// Open Firefox Browser

WebDriver driver = new FirefoxDriver();

// Open AppURL In Browser

driver.get("file:///C:/Users/Hanumanthu/Downloads/frames.html");

// count all the frames on a webpage

List<WebElement> total_frames=driver.findElements(By.tagName("iframe"));

System.out.println(total_frames.size());

//close the current browser window

driver.close();

}
}

How to verify TestNg text inside 3rd frame?

Selenium Sample Code :


package seleniumProject;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class getTotalFrames {


public static void main(String[] args) {

// Open Firefox Browser


WebDriver driver = new FirefoxDriver();
// Open AppURL In Browser
driver.get("file:///C:/Users/Hanumanthu/Downloads/frames.html");
//count all the frames on a webpage
List<WebElement> total_frames=driver.findElements(By.tagName("iframe"));
System.out.println(total_frames.size());
//Switch to 3rd Frame by using Index
driver.switchTo().frame(total_frames.get(2));
//Identify and get the text and store into testNg_text variable
String testNg_text=driver.findElement(By.xpath("html/body/h2[1]")).getText();
//print the text from 3rd frame
System.out.println(testNg_text);
//verify the text from 3rd frame
if(testNg_text.equals("TestNG"))
{
System.out.println("TestNG text verified successfully");
}else
{
System.out.println("TestNG text not verified successfully");
}
//How switch back to main window from inside any frame ?
driver.switchTo().defaultContent();
//Close the Firefox Browser
driver.close();

}
}
Note :

1.Switch to 3rd Frame by using Index

Syntax : driver.switchTo().frame(total_frames.get(index));
Example : driver.switchTo().frame(total_frames.get(2));

2.Switch to 3rd Frame by using Id

Syntax : driver.switchTo().frame(“Id of the element”);


Example : driver.switchTo().frame(“selenium”);
If no id then go for Name.

3.Switch to 3rd Frame by using Name

Syntax : driver.switchTo().frame(“Name of the element”);


Example : driver.switchTo().frame(“selenium”);

4.Switch to 3rd Frame by using WebElement

Syntax : driver.switchTo().frame(WebElement);
Example : driver.switchTo().frame(driver.findElement(By.name(“selenium”);

How switch back to main window from inside any frame ?


Syntax : driver.switchTo().defaultContent();

Java For Loop

The Java for loop is used to iterate a part of the program several times. If the
number of iteration is fixed, it is recommended to use for loop.

Java Simple For Loop

The simple for loop is same as C/C++. We can initialize variable, check condition
and increment/decrement value.

Syntax:

for(initialization;condition;incr/decr){
//code to be executed
}

Example:

public class ForExample {


public static void main(String[] args) {
for(int i=1;i<=10;i++){
System.out.println(i);
}
}
}

How to handle frame in selenium webdriver using java

TestSteps:
Open Firefox Browser
Open AppURL In Browser
Get the Title of WebPage
Verify Title of WebPage
Enter the username
Enter the password
Clicking On Login Button
Identify and get the Welcome selenium text
Verify Welcome selenium text
Switch to frame
Handle DropDown in Selenium
a) How to print all the dropdown values
b) How to Select the dropdown value inside a frame
c) verify selected value from dropdown
d) How to Verify dropdown values
Again switch back to main window from frame
Clicking On Logout Button
Close the Firefox Browser
Selenium Code :
package com.tests;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class OrangeHRM_login {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the AppUrl

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

//Get the Title of WebPage

String title=driver.getTitle();

//print the title of the webpage

System.out.println(title);

//Verify Title of the WebPage


if (title.equals("OrangeHRM - New Level of HR Management")) {
System.out.println("title is verified successfully");
} else {
System.out.println("title is not verified successfully");
}

// Enter the username

driver.findElement(By.name("txtUserName")).sendKeys("selenium");

// Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

// Clicking On Login Button

driver.findElement(By.name("Submit")).click();

// Identify and get the Welcome selenium text and store into text variable
String text =
driver.findElement(By.xpath("//*[@id='option-menu']/li[1]")).getText();

// Print the welcome selenium text

System.out.println(text);

// To verify whether the welcome page successfully opened or not

if (text.equals("Welcome selenium")) {

System.out.println("Welcome selenium is verified successfully");


} else {
System.out.println("Welcome selenium is not verified
successfully");
}

// Switch to Frame by ID

driver.switchTo().frame("rightMenu");

System.out.println("****How to print all the dropdown values inside a frame****");

// Identify the dropdown

WebElement dropdown = driver.findElement(By.id("loc_code"));

// Identify dropdown values and store into droplist variable

List<WebElement> droplist = dropdown.findElements(By.tagName("option"));

// How to print all the dropdown values

for (inti = 0; i<droplist.size(); i++) {


System.out.println(droplist.get(i).getText());
}
System.out.println("*****How to Select the dropdown value inside a frame*****");

/*
If u want to select the dropdown value then we need to create the
select object for that dropdown
*/

Select s = new Select(dropdown);

// Select the dropdown value by using index

s.selectByIndex(2);

//s.selectByVisibleText("Emp. First Name");


//s.selectByValue("1");

System.out.println("****verify selected value from dropdown inside a frame


*****");

//get the selected value and store into selected_value variable

String selected_value=s.getFirstSelectedOption().getText();

//print selected value

System.out.println("selected_value :"+selected_value);

//verify selected value from dropdown

if (selected_value.equals("Emp. First Name")) {


System.out.println("selected value verified successfully");
} else {
System.out.println("selected value not verified successfully");
}

// How switch back to main window from inside any frame

driver.switchTo().defaultContent();

// Clicking On Logout Button

driver.findElement(By.xpath("//*[@id='option-menu']/li[3]/a")).click();

// Close the Firefox Browser

driver.close();

}
Working with popups – 3

In this chapter, we will cover:


1. How to Handling Web-Based alert Popup/Javascript Alert Popup.
2. How to Handling modal popup window.
3. How to Handling multiple windows.

Introduction:
Javascript Alerts Popup, Confirmation Popup and Prompt Popup are very regularly
used elements of any software webpage and you must know how to handle all these
kind of popups In selenium webdriver software automation testing tool.First of
all, Let me show you all three different popup types to remove confusion from your
mind and then we will see how to handle them In selenium webdriver.
It is nothing but a small box .Here alert box speaks about error message or some
information.
How to Handling Web-Based alert Popup/Javascript Alert Popup.

TestSteps :

 open the firefox browser


 Navigate the url
 Enter the Username
 Enter the password
 click on login button
 click on logout button
 switchTo alert ,get the alert text and store the alert text into alert_text
variable
 verify alert text
 click on ok button
 close the browser

Selenium code :

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class WebBasedAlertPopup_JavascriptAlertPopup {

public static void main(String[] args) throws InterruptedException {

// open the firefox browser


WebDriver driver = new FirefoxDriver();

// Navigate the url

driver.get("http://demo.guru99.com/v4/");

// Enter the Username

driver.findElement(By.xpath("html/body/form/table/tbody/tr[1]/td[2]/
input")).sendKeys("mngr193544");

// Enter the password

driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td[2]/
input")).sendKeys("EbepYgE");

// click on login button

driver.findElement(By.xpath("html/body/form/table/tbody/tr[3]/td[2]/
input[1]")).click();

// Wait 5sec

Thread.sleep(5000);

// click on logout button

driver.findElement(By.xpath("html/body/div[3]/div/ul/li[15]/a")).click();

// Wait 5sec

Thread.sleep(5000);

// switchTo alert ,get the alert text and store the the alert text in
alert_text
// variable

String alert_text = driver.switchTo().alert().getText();

System.out.println("Print alert text :" + alert_text);

// verify alert text

if (alert_text.equals("You Have Succesfully Logged Out!!")) {


System.out.println("alert text verified successfully");
} else {
System.out.println("alert text not verified successfully");
}

// click on ok button

driver.switchTo().alert().accept();

// click on cancel button

// driver.switchTo().alert().dismiss();
// close the browser

// Wait 5sec

Thread.sleep(5000);

// close the browser window

driver.close();

}
Note :
1.Until you do not handle alert you cannot perform any action in the parent
window.
2. Web-Based alert and Java Script alerts are same so do not get confused.
How to handle single popup window or Modal popup window ?

TestSteps :
 Open the firefox browser
 Navigate the Application Url
 Wait for 3sec
 Print the title of the current webpage
 1.Switch to modal popup window
 Wait for 3sec
 2.Do some action on modal popup window based on your requirement
 3.Identify and click on popup window
 Do some action on main window based on your requirement
 close the current browser window
Selenium Program :
package seleniumProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Handle_Modal_Popup_window {
public static void main(String[] args) throws InterruptedException {
/ /Open the firefox browser
WebDriver driver = new FirefoxDriver();

//Navigate the Application Url


driver.get("http://www.rcreddyiasstudycircle.com/");

//Wait for 3sec


Thread.sleep(3000);
//Print the title of the current webpage
System.out.println(driver.getTitle());

//1.Switch to modal popup window


driver.switchTo().window(driver.getWindowHandle());

//Wait for 3sec


Thread.sleep(3000);

//2.Do some action on modal popup window based on your requirement

//3.Identify and click on popup window


driver.findElement(By.xpath("html/body/div[6]/div/div/div/div")).click();

//Do some action on main window based on your requirement

//close the current browser window


driver.close();

}
How to handle multiple windows in Selenium WebDriver?
Practice site :
https://www.cleartrip.com/trains
Point to Note : -
1. We can handle multiple windows in selenium webdriver using Switch To methods
which will allow us to switch control from one window to another window.
2. If you are working with web applications then you must have faced this
scenario where you have to deal with multiple windows.
3. If you have to switch between tabs then also you have to use the same
approach. Using switch To method we can also handle frames and alerts with easy
methods. I will focus on multiple windows as of now.
Before starting this section I will recommend you watch ArrayList in Java which
will help you to understand this concept in details.

ArrayList : -
1.By creating ArrayList,we can store no of windows at dynamically.
2. By creating ArrayList,dynamically we can increase the memory size when new
window store into ArrayList (Java Collection Object).
3. ArrayList is type of Java Collection Object useful to store duplicate objects.
4. ArrayList Elements are stored in index based.
5. ArrayList allow duplicate elements.

There are two methods in Selenium WebDriver to handle multiple windows -

 driver.getWindowHandle() – This method is used to get the current opened


window.

Syntax : -

//Get the current opened window

String currentWindow = driver.getWindowHandle();

Return type – String

 driver.getWindowHandles() - This method is used to get all the opened windows


in a Set.

Syntax : -

//Get all the opened windows in a Set

Set<String> all_openedwindows = driver.getWindowHandles();

Return Type - Set<String>

If there are multiple windows opened then follow below syntax.


1. The user wants to go to main window, Follow below syntax.

Syntax : - driver.switchTo().window(parentWindow);

Ex : - driver.switchTo().window(AllWindowHandles.get(0));

Note – By default main window index value ‘0’

2. The user wants to go to child1 window, Follow below syntax.

Syntax : - driver.switchTo().window(child1 Window);

Ex : - driver.switchTo().window(AllWindowHandles.get(1));

3. The user wants to go to child2 window, Follow below syntax.

Syntax : - driver.switchTo().window(child2 Window);

Ex : - driver.switchTo().window(AllWindowHandles.get(2));

In some applications, you will get some Popups that is nothing but separate
windows.

Scenario -
TestCase_ID Test Steps Step Description
TC_09 Step 1 Launch firefox Browser

TC_ Step 2 Navigate the Application Url

TC_ Step 3 Enter the username

TC_ Step 4 Enter the password

TC_ Step 5 Click on login button

TC_ Step 6 click on feedback

TC_ Step 7 Get total windows and store into windows variable

TC_ Step 8 print total windows

TC_ Step 9 By creating ArrayList object u can store no of window based


popups dynamically

TC_ Step 10 Switch to new child window

TC_ Step 12 print the child window title

TC_ Step 13 Do some action on child window based on your requirement

TC_ Step 14 close the child window

TC_ Step 15 Wait for 3sec

TC_ Step 16 Switch to main or parent window

TC_ Step 17 print the parent window title


TC_ Step 18 Do some action on main window based on your requirement
TC_ Step 19 close the Parent window

Complete program to handle multiple windows in selenium webdriver ?


First, we will switch to child window (pop up window) then we will close it and
then we will switch to the parent window.

package seleniumProject;
import java.util.ArrayList;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Handle_Multiple_Windows {

public static void main(String[] args) throws InterruptedException {

//Open the firefox browser


WebDriver driver = new FirefoxDriver();

//Navigate the Application Url


driver.get("http://kosmiktechnologies.com/seleniumLiveProject/kosmik-
hms/");

//Enter the username


driver.findElement(By.name("username")).sendKeys("kosmik");

//Enter the password


driver.findElement(By.name("password")).sendKeys("kosmik");

//Click on login button


driver.findElement(By.name("submit")).click();

//click on feedback
driver.findElement(By.xpath(".//*[@id='navigation']/li[3]/a")).click();

//Get total windows and store into windows variable


Set<String> windows=driver.getWindowHandles();

//print total windows


System.out.println(windows.size());

//By creating ArrayList object u can store no of window based popups


dynamically
ArrayList<String> AllWindowHandles = new ArrayList<String> (windows);

1. new ArrayList<String> ();

2. new ArrayList<String> (windows);

3. ArrayList<String> AllWindowHandles = new ArrayList<String> (windows);

//Switch to new child window


driver.switchTo().window(AllWindowHandles.get(1));

//print the child window title


System.out.println(driver.getTitle());

// Do some action on child window based on your requirement

//close the child window


driver.close();

//Wait for 3sec


Thread.sleep(3000);

//Switch to main or parent window


driver.switchTo().window(AllWindowHandles.get(0));

//print the parent window title


System.out.println(driver.getTitle());

// Do some action on main window based on your requirement

//close the Parent window


driver.close();
}
}
Working
with checkbox,Listbox – 4

In this chapter, we will cover:


1. How to verify single checkbox in a webpage using selenium?
2. How to verify multiple checkboxes in a webpage using sselenium?
3. How to Verify Multiple selections are allowed or Not from a list box.

How to verify single checkbox in a webpage using selenium?

TestSteps

 Open the Firefox browser


 Navigate the AppUrl
 Identify Checkbox1
 Select Checkbox1
 Verify Checkbox1
 Close the current Browser window

Selenium Code :

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SingleCheckbox {


public static void main(String[] args) {
//open the firefox browser
WebDriver Driver = new FirefoxDriver();
//navigate the AppUrl
Driver.get("http://demo.guru99.com/test/radio.html");
// Identify Checkbox1
WebElement CheckBox1= Driver.findElement(By.id("vfb-6-0"));
//Select Checkbox1
CheckBox1.click();
//Verify Checkbox1
if (CheckBox1.isSelected())
{
System.out.println("Checkbox1 Selected");
} else
{
System.out.println("Checkbox1 not Selected");
}
//Close the current Browser window
Driver.close();
}
}

How to verify multiple checkboxes in a webpage using sselenium?


TestSteps :

 Open the firefox browser


 Navigate the AppUrl
 Identify all Checkboxes and store into checkBoxes variable
 Print the total checkboxes
 Select multiple checkboxes one by one
 Verify multiple checkboxes one by one
 Close the current Browser window

Selenium Code :

package seleniumProject;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Verify_Multiple_Checkboxes {

public static void main(String[] args) {

//open the firefox browser


WebDriver driver = new FirefoxDriver();

//navigate the AppUrl


driver.get("http://demo.guru99.com/test/radio.html");

// Identify all Checkboxes and store into checkBoxes variable


List<WebElement> checkBoxes =
driver.findElements(By.xpath("//input[@type='checkbox']"));
//print the total checkboxes
System.out.println(checkBoxes.size());

for(int i=0; i<checkBoxes.size(); i++)


{
//select multiple checkboxes one by one
checkBoxes.get(i).click();

//verify multiple checkboxes one by one


if(checkBoxes.get(i).isSelected()){

System.out.println(i+" checkBox is selected ");

}else{

System.out.println(i+" checkBox is not selected ");

//Close the current Browser window


driver.close();

}
}

Verify Multiple selections are allowed or Not from a list box.

TestSteps :
1.Launch the web browser
2.Navigate the url
3.Identify the Lisbox
4.select multiple options from a list box.
5.Verify Multiple selections are allowed or Not from a list box.

Selenium Code :
package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class IsMultiple {

public static void main(String[] args) {


//1. Launch the web browser
WebDriver driver=new FirefoxDriver();

//3. Navigate the url


driver.get("https://apps.fas.usda.gov/esrquery/esrq.aspx");

//identify the listbox


WebElement
listbox=driver.findElement(By.xpath("//*[@id='MainContent_lbCountry']"));

//create select object for that listbox


Select Countries=new Select(listbox);
//select multiple options from a list box.

// Selecting an option using ‘selectByVisibleText’


Countries.selectByVisibleText("AFGHANISTAN");

// Selecting an option using ‘selectByVisibleText’


Countries.selectByVisibleText("ARGENTINA");

//Verify Multiple selections possible or not


if(Countries.isMultiple())
{
System.out.println("Multiple selections allowed");
}
else{
System.out.println("Multiple selections not allowed");
}

SELENIUM | BROWSER COMMANDS :

isSelected(): By using this we can verify particular checkbox is selected or not on


a webpage.

isMultiple() : By using this we can verify Multiple selections are allowed or Not
from a list box.

Handling keyboard and mouse events 4

In this chapter, we will cover:


1. How to perform dragAndDrop operation in selenium webdriver ?
2. How to perform doubleClick operation in selenium webDriver ?
3. How to perform rightClick operation in selenium webDriver ?
4. How to perform Mouse hover operation in selenium webDriver ?

While performing test automation some actions can not be performed directly in
webdriver, in such a case we need to use some tricky ways. Some of such scenarios
are sending keyboard inputs to your test or mouse operations on web-elements, etc.

Special keyboard and mouse events are performed using the Advanced User
Interactions API. It contains the Actions and the Action classes that are needed
when executing these events.

We need to create new action builder instance by passing the webdriver instance.
The following are the most commonly used keyboard and mouse events provided by the
Actions class.

Following are some example selenium methods of action class to handle such
scenarios.

Action Class :

By using Action Class, You can perform all actions on a web page.
To handle the mouse movements and keyboard events then we use Actions class
in selenium.
To use Actions class in our code, First we need to create the Actions class
object for that driver.

Where exactly we can use action class?

For Ex :Suppose If u want to perform mouse hover ,drag and drop,Rihgt click and
doubleClick etc..in this kind of situation we need to use Action class.

perform() :Execute the action on that webelement

Note : For each action we need to perform()


Chord : One of the nice feature in selenium webdriver is it allows us to simulate
pressing of multiple keys using a method called "chord"

1.How to perform Drop & Drag operation in Selenium ?


Many times, We have the web application where we need to drag an item from one
location to another location. To handle this kind of actions we need Action class
in selenium

Test steps :
 Open the firefox browser
 Navigate the AppUrl
 Identify the drag element
 Identify the drop element
 Create action class object for that driver
 Performing Drag and Drop operation
 Identify and get the Dropped! text and store into dropped_text variable
 To verify whether the dragAndDrop operation successfully performed or not
 Close the current browser window

Selenium code :

package SeleniumPack;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class DragAndDrop {

public static void main(String[] args) {

//Open the firefox browser

WebDriver driver = new FirefoxDriver();


//Navigate the AppUrl

driver.get("http://jqueryui.com/resources/demos/droppable/default.html");

//Identify the drag element

WebElement draggable =
driver.findElement(By.xpath("//*[@id='draggable']"));

//Identify the drop element

WebElement droppable = driver.findElement(By.xpath("//*[@id='droppable']"));

/*
Note :

To handle the mouse movements and keyboard events then we use Actions class.

To use action class in our code we need to create action class object for
that

driver first.

*/

//create action class object for that driver

Actions oAction = new Actions(driver);

//Performing Drag and Drop operation

oAction.dragAndDrop(draggable, droppable).perform();

//Identify and get the Dropped! text and store into dropped_text variable

String dropped_text=
driver.findElement(By.xpath("//*[@id='droppable']/p")).getText();

//To verify whether the dragAndDrop operation successfully performed or not

if(dropped_text.equals("Dropped!"))
{
System.out.println("dragAndDrop operation verified successfully");

}else
{
System.out.println("dragAndDrop operation not verified
successfully");
}

//Close the current browser window

driver.close();
}
}

2.How to perform Mouse hover in selenium?


Test steps :
 Open the firefox browser
 Navigate the AppUrl
 Get the Title of WebPage
 Print the title of the webpage
 Print the title of the webpage
 Enter the username
 Enter the password
 Clicking On Login Button
 Identify and get the Welcome selenium text and store into text variable
 Print the welcome selenium text
 To verify whether the welcome page successfully opened or not
 Create action class object for that driver
 Mouse hover on PIM main module
 Click on Add Employee submenu
 Wait 5sec
 Switch to frame by using Id
 Identify and get the Add Employee text and store into addEmp variable
 Print the Add Employee text
 To verify whether the Add Employee page successfully opened or not
 Switch back to main window
 Click on Logout
 Wait 5sec
 Close the current browser window

Selenium Code :

package ActionClassPack;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class MouseMovement {

public static void main(String[] args) throws InterruptedException {


// open the firefox browser

WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();
// navigate the AppUrl

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

// Get the Title of WebPage

String title = driver.getTitle();

// print the title of the webpage

System.out.println(title);

// Verify Title of the WebPage

if (title.equals("OrangeHRM - New Level of HR Management")) {


System.out.println("title is verified successfully");
} else {
System.out.println("title is not verified successfully");
}

// Enter the username

driver.findElement(By.name("txtUserName")).sendKeys("selenium");

// Enter the password

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

// Clicking On Login Button

driver.findElement(By.name("Submit")).click();

// Identify and get the Welcome selenium text and store into text
variable
String text =
driver.findElement(By.xpath("//*[@id='option-menu']/li[1]")).getText();

// Print the welcome selenium text

System.out.println(text);

// To verify whether the welcome page successfully opened or not

if (text.equals("Welcome selenium")) {

System.out.println("Welcome selenium is verified successfully");

} else {
System.out.println("Welcome selenium is not verified
successfully");
}

//create action class object for that driver

Actions act = new Actions(driver);

//mouse hover on PIM main module

act.moveToElement(driver.findElement(By.id("pim"))).perform();

// click on Add Employee submenu

driver.findElement(By.xpath("//*[@id='pim']/ul/li[2]/a")).click();

//wait 5sec
Thread.sleep(5000);

//Switch to frame by using Id

driver.switchTo().frame("rightMenu");

// Identify and get the Add Employee text and store into addEmp
variable

String addEmp =
driver.findElement(By.xpath("/html/body/form/div/div[1]/div[2]/div[1]/
h2")).getText();

// Print the Add Employee text

System.out.println(addEmp);

// To verify whether the Add Employee page successfully opened or not

if (addEmp.equals("PIM : Add Employee")) {


System.out.println("Add Employee page verified successfully");
} else {
System.out.println("Add Employee page not verified
successfully");
}

//switch back to main window

driver.switchTo().defaultContent();

//Click on Logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

//wait 5sec

Thread.sleep(5000);

//close the current browser window

driver.close();

3.To verify whether the DoubleClick operation successfully performed or Not?

TestSteps :
 Open the firefox browser
 Navigate the AppUrl
 Identify copyText button element
 Create action class object for that driver
 Double click on copyText button
 Identify and get the text from input field2 and store into entered_text
variable
 To verify whether the double click operation successfully performed or not
 Close the current browser window

Selenium Code :

package SeleniumPack;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class DoubleClick {

public static void main(String[] args) throws InterruptedException {

// Open the firefox browser

WebDriver driver = new FirefoxDriver();

// Navigate the AppUrl

driver.get("file:///C:/Users/Hanumanthu/Downloads/doubleClickMe.html");

/*
* How to handle exception in selenium ?
*
* A) By using try - catch block
*
*/

try {
// identify copyText button element

WebElement element =
driver.findElement(By.xpath("html/body/button"));

// Create action class object for that driver

Actions action = new Actions(driver);

// double click on copyText button

action.doubleClick(element).perform();

System.out.println("After performing double click will


allowed");

/*
Note :

We can retrieve value which we have typed or already typed


in text box/text area. It will be useful when we want to verify if correct value is
typed or to know existing value in text box/text area.

To retrieve value from text box/textarea, we need to use


getAttribute() method.

*/

// Identify and get the text from input field2 and store into
entered_text variable

String entered_text =
driver.findElement(By.id("field2")).getAttribute("value");

// to verify whether the double click operation successfully


performed or not
if (entered_text.equals("Hello World!")) {
System.out.println("Entered text verified successfully");
} else {
System.out.println("Entered text not verified
successfully");
}

} catch (Exception e) {
System.out.println("Unable to perform doubleClick operation");
}

// Close the current browser window

driver.close();
}

4.To verify whether the rightClick operation successfully performed or Not?And How
to Click on Open Link In New Window.

TestSteps :

 Open the firefox browser


 Navigate the AppUrl
 Identify about element
 Create action class object for that driver
 Rightclick on about element
 Wait 5sec
 Click on Open Link In New Window
 Close the current browser window

Selenium Code :

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Context_Click {

public static void main(String[] args) {

//Open the firefox browser

WebDriver driver = new FirefoxDriver();

//Navigate the AppUrl

driver.get("https://www.google.co.in/");

//Identify about element

WebElement about = driver.findElement(By.linkText("About"));


try {
//Create action class object for that driver

Actions action = new Actions(driver);

// Rightclick on about element

action.contextClick(about).perform();

System.out.println("Sucessfully Right clicked on the About


element");

//wait 5sec

Thread.sleep(5000);

} catch (Exception e) {

System.out.println("Unable to perform Right click on About


element");
}

//Close the current browser window

driver.close();
}
}

To Verify whether the file uploaded or not


Practice Website :
https://uk.designerexchange.com/index.php/sell/quote
There are different ways to handle file upload with Selenium Webdriver.

1.sendkeys() :If u want to upload the file then we need to use sendkeys().
2.AutoIt tool :Some times selenium did not find the window based elements then
we need to use AutoIt.

1.By using sendkeys()

The First and the Easy way is simple case of just finding the element and typing
the absolute path of the image file into it.

NOTE: This works only when the textbox is enabled. So please make sure that the
input element is visible.

The OTHER WAY to Handle File Upload

Some times sendkeys() it doesn ‘t work at that time u need to follow AutoIt tool.
If there is no text box / input tag to send the file path using Sendkeys method at
that time u need to follow Autoit tool.

You will have only a button (Customized button) and when click on browse button,
browser opens a window popup and to select the file from windows, And as we know
selenium will not support window based applications.
Why we are using AutoIT in Selenium?
1-While automating web-application many times you will get window based activity
like- file upload, file download pop up, window authentication for secure sites
etc.
In this case Selenium fails and will not be able to handle desktop elements to
avoid this we will use AutoIT script that will handle desktop or windows elements
and will combine AutoIT script with our Selenium code.
Introduction to AutoIT tool
1-AutoIt is freeware automation tool that can work with desktop application too.
2-It uses a combination of keystrokes, mouse movement and window/control
manipulation in order to automate tasks in a way not possible or reliable with
other languages (e.g. VBScript and SendKeys).
For more info about AutoIT, you can visit their Official Website AutoIt Official
Website

How to write script in AutoIT?


For AutoIt scripting you should have three things ready.
1-AutoIt Editor- Editor help us to write AutoIt scripts.
2-Tool Finder (Same as firebug on Firefox) – It will help us to identify the
element and check their Attributes.
3- AutoIt Help section- This help you to understand about AutoIt functions and what
are the parameter it accepts.
Let’s start with Downloading first
Step 1– Navigate to AutoIt official
website https://www.autoitscript.com/site/autoit/downloads/ and go to download
section or Click here Download AutoIt
Step 2– Click on Download AutoIt and Install
Step 3– Click on Download Editor and Install.

Step 4– Once both installed in your machine check all is installed correctly.
Note- Generally it goes to C:\Program Files\AutoItv3 location if you do not change
it

Step5– Open SCiTE folder and Click on SciTE this will open AutoIt Editor

Once all Installed Let’s see how we can write script


Upload File in Selenium Webdriver using Autoit

To upload a file in Selenium Webdriver we will create AutoIT script, which will
handle file-uploaded window, and then we will combine Selenium script with AutoIt
scripts.
Click on Upload button you will get file uploader we will handle the same using
AutoIt.
Step 1– Open Editor and Finder Tool

Step 2– We need to write script to upload file so we will use some methods of
AutoIt.

Each method will have some own functionality.

ControlFocus-This will give focus on the window.


ControlSetText-This will set the file path.
ControlClick-This will click on open button.
Step 1-
Click on Browse button , new window will open now open finder tool and Click on
Finder tool and drag to the file name as I shown in below screenshot.

This will give all the detail about that window and file name Section info : we
will use only some attribute like window title, class and instance.
Open AutoIt Editor and Write Script

In ControlClick method we will give control id of open button


Step 2-
Save the script to a particular location with some unique name.
Note- By default script will be saved as .au3 extension
Step 3– Now Compile the script so for compiling right click on file and Select
compile script this will generate .exe file of the file.

Step 4- Now write Selenium program and add this .exe file and run your program.
TestSteps :
 Open the firefox browser
 Navigate the AppUrl
 wait 3sec
 Identify UserName element
 Identify Password element
 Click on Login
 Identify and get the Welcome Admin text and store into text variable
 Print Welcome Admin text
 Verify Welcome Admin page
 Create action class object for that driver
 Mouse hover on PIM Module
 Wait 5sec
 Mouse hover on AddEmployee and click
 Wait 5sec
 Enter first name
 Enter the last name
 click on Browse element
 Upload file
 Wait 10sec
 Click on save button
 Wait 10sec
 Identify and get the sai honey text and store into saiHoney_text variable
 Print saiHoney_text
 verify saiHoney_text
 click on Welcome Admin
 Click on Logout
 Wait 5sec
 Close the current browser window

Selenium Code :

package seleniumProject;

import java.awt.AWTException;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
public class FileUpload {

public static void main(String[] args) throws AWTException,


InterruptedException, IOException {

//Open the firefox browser

WebDriver driver = new FirefoxDriver();

//Navigate the AppUrl


driver.get("https://opensource-demo.orangehrmlive.com/");

//wait 3sec

Thread.sleep(3000);

//Identify UserName element

driver.findElement(By.id("txtUsername")).sendKeys("Admin");

//Identify Password element

driver.findElement(By.id("txtPassword")).sendKeys("admin");

//Click on Login

driver.findElement(By.id("btnLogin")).click();

//Identify and get the Welcome Admin text and store into text variable

String text=driver.findElement(By.id("welcome")).getText();

//Print Welcome Admin text

System.out.println(text);

//Verify Welcome Admin page

Assert.assertEquals(text, "Welcome Admin");

//Create action class object for that driver

Actions act=new Actions(driver);

//Mouse hover on PIM Module

act.moveToElement(driver.findElement(By.xpath("//*[@id='menu_pim_viewPimModule']"))
).perform();

//Wait 5sec

Thread.sleep(5000);

//Mouse hover on AddEmployee and click


act.moveToElement(driver.findElement(By.xpath("//*[@id='menu_pim_addEmployee']"))).
click().perform();

//Wait 5sec

Thread.sleep(5000);

//Enter first name

driver.findElement(By.id("firstName")).sendKeys("sai");

//Enter the last name

driver.findElement(By.id("lastName")).sendKeys("honey");

//click on Browse element

driver.findElement(By.id("photofile")).click();

//driver.findElement(By.id("photofile")).sendKeys("C:\\Users\\Public\\
Pictures\\Sample Pictures\\Desert.jpg");

//Upload file

Runtime.getRuntime().exec("D:\\Autoit\\AutoFileupload.exe");

//Wait 10sec

Thread.sleep(10000);

//Click on save button

driver.findElement(By.id("btnSave")).click();

//Wait 10sec

Thread.sleep(10000);

//Identify and get the sai honey text and store into saiHoney_text
variable

String saiHoney_text=driver.findElement(By.xpath("//*[@id='profile-pic']/
h1")).getText();

//Print saiHoney_text

System.out.println(saiHoney_text);

//verify saiHoney_text

if(saiHoney_text.equals("sai honey"))
{
System.out.println("sai honey text verified successfully");
}else
{
System.out.println("sai honey text not verified successfully");
}
//click on Welcome Admin

driver.findElement(By.id("welcome")).click();

//Click on Logout

driver.findElement(By.xpath("//*[@id='welcome-menu']/ul/li[2]/a")).click();

//Wait 5sec

Thread.sleep(5000);

//Close the current browser window

driver.close();

}
}

Introduction to TestNg testing Framework


 Overview
 Install TestNg and Verify TestNg into Eclipse
 Create First TestNg Test Case
 Create Multiple Test Cases and Execute
I)Overview

 TestNG is a Testing Framework and it has been most popular with in short time
among test engineers.
 Testng inspired from junit(java platform) and Nunit(.Net platform).
 TestNG has advance features compared to junit
 TestNg is a most powerful tool,stronger and easy to use functionalities.
 TestNG is a open source Testing framework,whr NG stands for Next Generation
 You can use any one either junit or testng but both are not required .
Requirements :
TestNG requires JDK 7 or higher.

Why we are using TestNG


By using TestNG,we can create the selenium automation test cases, execute the
selenium automation test cases and generate test Reports and also generate the log
files
Note :
 1.Selenium IDE generate test reports but no detail.
 2.Selenium RC OutDated
 Here Selenium webDriver it does not generate the test reports .selenium
webDriver with the help of testng will generate the test Reports.
Advantages of TestNG
 TestNG Annotations are very easy to create test cases.
 TestNG support prioritized testing and group testing.
 Parallel test execution is possible.
How to Install TestNG step by step into Eclipse:
Way : 1

We will follow the below steps to install TestNG in Eclipse IDE .

Step 1:
In Eclipse, on top menu bar, Under Help Menu, Click on "Install new Software" in
help window.

Step 2:
Enter the URL (http://beust.com/eclipse/) at Work With field and click on "Add"
button.

Step 3:
Once you click on "Add", it will display the screen, Enter the Name as "TestNG".

Step 4:
After clicking on "OK", it will scan and display the software available with the
URL which you have mentioned.
Now select the checkbox at TestNG and Click on "Next" button.

Step 5:
It will check for the requirement and dependencies before starting the
installation.
If there is any problem with the requirements/dependencies, it will ask you to
install them first before continuing with TestNG. Most of the cases it will
successfully get installed nothing to worry about it.

Step 6:
Once the above step is done, it will ask you to review the installation details. If
your are ready or Ok to install TestNG, click on "Next" to continue.

Step 7:
Accept the Terms of the license agreement and Click on "Finish" button.

Thats it... It will take few minutes to get installed.


Finally once the installation is done, you can if the TestNG is installed properly
or Not.
Go to Windows Menu bar, and Mouse Over on "Show View" and Click on "Other" at the
last as in the below screen shot.

Expand Java folder and see if the TestNg is available as in the below screen shot.

Way : 2
Configuring TestNG

1. Open Eclipse  Click on Help Menu  Click on Eclipse Market Place


2. Goto Find  Type TestNG  Click on Go button

3. Click on TestNG for eclipse  Click on Install


4. Check TestNG and uncheck TestNG M2E integration.

5. Click on Next.
6. Accept the license Agreement  Click on Finish.

7. Goto the security window Click on OK

8. Click on Restart Now.


Checking TestNG configured or not

1. Open Eclipse
2. Click on Window Menu
3. Click on Show View
4. Click on Other
5. Expand JAVA
6. Check for TestNG

TestNG does not require main() , instead it uses certain annotations.

Important Annotations in TestNG

Annotation Description
@Test This represent the testcase, the functionality that has to be automated is
given as “@Test”
@BeforeMethod Run before each test case in the current class.

@AfterMethod Run after each test case in the current class.


@BeforeClass Run before all the test case in the current class.

@AfterClass Run after all the test case in the current class.

@BeforeTest Run before all the test cases that belongs to classes
@AfterTest Run after all the test cases that belongs to classes
@parameters This is used to pass parameters to the test cases from a file called
TestNG.xml

Add TestNG library for that Project.


For adding TestNG library,
• Right click on your project-> Properties -> Java Build Path -> Libraries Tab.
• Click on Add Library button -> Select TestNG from Add Library popup and then
click on Next and Finish buttons.

It will add TestNg library in your project as shown in bellow image. Now click on
OK button to close that window.

Creating TestNG class :


Here 1St we need to Create Manual test cases .Based on manual test cases we need
to Create the selenium Automation test script.
Manual test cases :
Test Case name : Verify title of the webpage
Test Steps:
1. Launch Browser
2. Navigate to Application URL
3. VerifyTitle :
Compares the actual page title with an expected page title.
4.Close Browser
Expected page title = OrangeHRM - New Level of HR Management
Actual page title= OrangeHRM - New Level of HR Management
Status: Pass/Fail

Creating TestNG class(Selenium Automation Test Case)


Now that we have done all the basic setup to get started with the test script
creation using TestNG. Let’s create a sample script using TestNG.
Step 1: Expand the “DemoTestNG” project and traverse to “src” folder. Right click
on the “src”package and navigate to New -> Other..

Step 2: Expand TestNG option and select “TestNG” class option and click on the
“Next” button.

Step 3: Furnish the required details as following. Specify the Source folder,
package name and the TestNG class name and click on the Finish button. As it is
evident from the below picture, user can also check various TestNG notations that
would be reflected in the test class schema. TestNG annotations would be discussed
later in this session

Now that we have created the basic foundation for the TestNG test script, let us
now inject the actual test code.

Scenario:
• Launch the browser and open “http://127.0.0.1/orangehrm-2.5.0.2/login.php”.
• Verify the title of the page and print the verification result.
• Close the web browser.
Code:

public class FirstProgrm {

WebDriver driver;

//@BeforeClass defines this Test has to run before every @Test methods in
the current class/program

@BeforeClass
public void openbrowser() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
}

@Test
public void VerifyTitle() {

String title = driver.getTitle();


System.out.print("Current page title is : "+title);
Assert.assertEquals(title, "OrangeHRM - New Level of HR Management");

//@AfterClass defines this Test has to run after every @Test methods in the
current class/program
Note :
 By default,TestNg generate Html Reports .
 TestNg generate emailable-report also.
 You just copy emailable-report and past into desktop.You can attach
emailable-report for your email.
 In java we need to use main method but in testNG no need to use main method
 TestNg Programs contains only methods .
 If u don’t mention @Test Annotations then the method is not going to be
executed.

Code Explanation with respect to TestNG


1) @Test – @Test is one of the TestNG annotations. This annotation lets the program
execution to know that method annotated as @Test is a test method. To be able to
use different TestNG annotations, we need to import the package “import
org.testng.annotations.*”.
2) There is no need of main() method while creating test scripts using TestNG. The
program execution is done on the basis of annotations.
3) In a statement, we used Assert class while comparing expected and the actual
value. Assert class is used to perform various verifications. To be able to use
different assertions, we are required to import “import org.testng.Assert”.
Executing the TestNG script
The TestNG test script can be executed in the following way:
=> Right click anywhere inside the class within the editor or the java class within
the package explorer, select “Run As” option and click on the “TestNG Test”.

TestNG result is displayed into two windows:


• Console Window
• TestNG Result Window
Refer the below screencasts for the result windows:

(Click on image to view enlarged)

HTML Reports
TestNG comes with a great capability of generating user readable and comprehensible
HTML reports for the test executions. These reports can be viewed in any of the
browser and it can also be viewed using Eclipse’s build –in browser support.
To generate the HTML report, follow the below steps:
Step 1: Execute the newly created TestNG class. Refresh the project containing the
TestNG class by right clicking on it and selecting “Refresh” option.
Step 2: A folder named as “test-output” shall be generated in the project at the
“src” folder level. Expand the “test-output” folder and open on the “emailable-
report.html” file with the Eclipse browser. The HTML file displays the result of
the recent execution.

Step 3: The HTML report shall be opened with in the eclipse environment. Refer the
below image for the same.
Refresh the page to see the results for fresh executions if any.

Introduction Of testng.xml File

In TestNG framework, We need to create testng.xml file to create and handle


multiple test classes. testng.xml is the file where we can configure our webdriver
software automation test, set software test dependency, include or exclude any
software test method or class or package, set priority etc..
Creating testng.xml File
• First of all Create a project and webdriver test case as described in my
PREVIOUS POST.
• To create testng.xml file, Right click on project folder and Go to TestNG ->
Convert to testNG as shown in bellow given image. It will open New File wizard.

Now your testng.xml file will looks like bellow.

In above testng.xml code,


• <suite> : suite tag defines the TestNG suite. You can give any name to your
suite using 'name' attribute. In above given example, We have given "Suite One" to
our test suite.
• <test> : test tag defines the TestNG test. You can give any name to your test
using 'name' attribute. In above given example, We have given "Test One" to our
test.
• <classes> : classes tag defines multiple class. We can multiple test class
under classes tag. In our example we have only one class.
• <class> : class tag defines the class name which you wants to consider in
test execution. In above given example,

Structure of TestNG.XML file

<suit>
<test>
<Classess>
<class>packagename.classname</class>
</classes>
</test>
</suit>

Executing testng.xml File


To Run
Right click on testng.xml file -> Run As -> Select TestNG Suite as shown in bellow
given image.

It will start execution of defined software test class

When execution completed. Test execution HTML report will looks like bellow.
Working with Excel Files

In java Project ,If u want to work with excel then We need to download and
configure poi.jar file for that project.

In Maven Project ,If u want to work with excel then We need to set the poi
dependency for that project.

poi: poi is a program interface for Microsoft Excel, Which allow user to read
and write input data from excel sheets

Where to download poi.jar file:

Go to google search for POI 4.0.1.jar


Follow below url
https://poi.apache.org/
After find search
click on Download POI 4.0.1.jar Save jar file into drive.

Where to download POI dependency file

Go to google search for maven repository


Follow below url

https://mvnrepository.com/
After find search

Enter POI into search box and search it


Click on first link Save POI dependency into poi.xml

EXCELL Operations :
To perform read and write operations in excel we require third party JAR files
like “Apache-POI”.

Apache-POI:- works on all xls and .xlsx files.

XSSFWorkbook:- This is an in built class in apache-POI, using which we can handle


the complete excel file.

XSSFSheet:- This is an in built class in apache-POI, for handling one sheet in an


excel file.

ROW:- This is an interface in the apache-POI, which is used to handle one row in
the excel sheet.

Cell:- This is an interface in apache-POI, which is used to handle one cell in a


row.

Important methods In Apache-POI

getLastRowNum() : This is used to capture the last row no in the excel file.

getCellNum(): This is used to capture the last Cell No, in the row.
getSheet(): This is used to capture specific sheet in the excel workbook.

Createsheet():- This can create an additional sheet in the excel workbook.


getRow():- This will capture one complete row in the excel file.

CreateRow():- This will create a new row in the sheet.

getCell():- This will capture one cell in a row.

CreateCell():- This will create a new cell in an existing row.

getStringValue():- This will capture string data present in a cell.

getNumericValue():- This will capture numeric data present in a cell.

setCellValue():- This is used to write the data into the cell.

Write():- This is used to save the excel file.

How to Login_With_XlsFile_using_POI :

package excl;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeClass;

import java.io.FileInputStream;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class NewTest {

WebDriver driver;

@Test
public void LoginTest() throws Exception {

//Navigate the application Url

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

/*
FileInputStream – A FileInputStream is an inputstream for reading data
from a Excel File.

FileOutputStream – A FileOutputStream is an outputstream for writing data


into a Excel File.
*/

//Now access the Excel file

FileInputStream fis = new FileInputStream("D:\\Login_Excel.xls");

//Get the workbook from Excel


HSSFWorkbook workbook = new HSSFWorkbook(fis);

//Get the sheet from Workbook

HSSFSheet sheet = workbook.getSheet("Result");

//read the data from sheet

//Read the username from excel sheet and store into username variable

String username=sheet.getRow(1).getCell(0).getStringCellValue();

//Read the password from excel sheet and store into password variable

String password=sheet.getRow(1).getCell(1).getStringCellValue();

//Enter the username

driver.findElement(By.name("txtUserName")).sendKeys(username);

//Enter the password

driver.findElement(By.name("txtPassword")).sendKeys(password);

//Click on Login

driver.findElement(By.name("Submit")).click();

//wait 3sec

Thread.sleep(3000);

//Identify Welcome Selenium text and get the text and store into
displaysuccess variable

String
text=driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

//print Welcome selenium

System.out.println(text);

// verify welcome page( Welcome Selenium text)

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified
successfully");
}

//click on logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();

}
@BeforeClass
public void startup() {

//Open the Firefox browser

driver = new FirefoxDriver();


}

@AfterClass
public void afterClass() {

//close the browser

driver.close();
}

How to Login_With_XlsxFile_using_POI :

package excl;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeClass;

import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;

public class Login_With_XlsxFile_Using_POI {

WebDriver driver;

@Test
public void LoginTest() throws Exception {

//Navigate the application Url

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

/*
FileInputStream – A FileInputStream is an inputstream for reading data
from a Excel File.

FileOutputStream – A FileOutputStream is an outputstream for writing data


into a Excel File.
*/

//Now access the Excel file

FileInputStream fis = new FileInputStream("D:\\Login_Excel1.xlsx");


//Get the workbook from Excel

XSSFWorkbook workbook = new XSSFWorkbook(fis);

//Get the sheet from Workbook

XSSFSheet sheet = workbook.getSheetAt(0);

//read the data from sheet

//Read the username from excel sheet and store into username variable

String username=sheet.getRow(1).getCell(0).getStringCellValue();

//Read the password from excel sheet and store into password variable

String password=sheet.getRow(1).getCell(1).getStringCellValue();

//Enter the username

driver.findElement(By.name("txtUserName")).sendKeys(username);

//Enter the password

driver.findElement(By.name("txtPassword")).sendKeys(password);

//Click on Login

driver.findElement(By.name("Submit")).click();

//wait 3sec

Thread.sleep(3000);

//Identify Welcome Selenium text and get the text and store into
displaysuccess variable

String
text=driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

//print Welcome selenium

System.out.println(text);

// verify welcome page( Welcome Selenium text)

if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified
successfully");
}

//click on logout

driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();
}
@BeforeClass
public void startup() {

//Open the Firefox browser

driver = new FirefoxDriver();


}

@AfterClass
public void afterClass() {

//close the browser

driver.close();
}

How to Verify Dropdown Values Using _xls ?

Verify dropdown values


Dropdown Excel
1.Get the dropdown size 1.Get the Excel size
2.Create Arraylist object for that dropdown.
Arraylist ddvalues=new Arraylist(); 2.Create Arraylist object for that Excel.
Arraylist xlvalues=new Arraylist();
3.Store dropdown values in an ddvalues variable.See below

4.Compare dropdown size and Excel size 3.Store Excel values in an xlvalues
variable .See below

5. Compare dropdown values and Excel values one by one

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Verify_DropdownValues_Using_xls {


WebDriver driver;

@BeforeClass
public void setUp()
{
//Launch Firefox browser

driver = new FirefoxDriver();

//Maximize the browser window

driver.manage().window().maximize();
}

@Test
public void Verify_DropdownValuesTest() throws IOException,
InterruptedException, BiffException {

//Navigate the Application Url

driver.get("http://www.tizag.com/htmlT/htmlselect.php");

//wait 3sec

Thread.sleep(3000);

//Identify dropdown

WebElement dropdown=driver.findElement(By.name("selectionField"));

//Identify dropdown values and store into dropdownCount variable

List<WebElement>
dropdownCount=dropdown.findElements(By.tagName("option"));

//Print total dropdown values.

System.out.println("Total dropdown values are : "+dropdownCount.size());

/*
FileInputStream – A FileInputStream is an inputstream for reading
data from a Excel File.

FileOutputStream – A FileOutputStream is an outputstream for writing


data into a Excel File.
*/

//Now access the Excel file

FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\


Xls_File.xls");

//Get the workbook from Excel

HSSFWorkbook workbook=new HSSFWorkbook(fis);

//Get the sheet from Workbook


HSSFSheet sheet=workbook.getSheetAt(1);

//Get total rows from excel sheet

int total_Rows=sheet.getLastRowNum()+1;

System.out.println("Total excel rows are : "+total_Rows);

//Get total columns from excel sheet

int total_Columns=sheet.getRow(0).getLastCellNum();

System.out.println("Total excel Columns are : "+total_Columns);

//Create ArrayList object for that excel values

ArrayList xlvalues=new ArrayList();

/*

As you know,some times we need to perform same action with multiple


times at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for(int i=0;i<total_Rows;i++)
{

//Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}

//Create ArrayList object for that excel values

ArrayList ddvalues=new ArrayList();

//Using for loop, we can iterate till the j value is true

for(int j=0;j<dropdownCount.size();j++)
{

ddvalues.add(dropdownCount.get(j).getText());
}

//Check for the required elements by Text and display


matched elements and unmatched elements

if(total_Rows!=dropdownCount.size())
{
System.out.println("Size Not matched");
}
else{
for(int k=0;k<total_Rows;k++)
{
if(xlvalues.get(k).equals(ddvalues.get(k)))
{
System.out.println("Excel Data is
Matching with Application Data");
}
else
{
System.out.println("Excel Data is not
Matching with Application Data");
}

}
}

@AfterClass
public void tearDown()
{
//close the browser

driver.quit();
}

How to Verify Dropdown Values Using _xlsx ?

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Verify_DropdownValues_Using_xlsx {

WebDriver driver;

@BeforeClass
public void setUp()
{
//Launch Firefox browser

driver = new FirefoxDriver();


//Maximize the browser window

driver.manage().window().maximize();
}

@Test
public void Verify_DropdownValuesTest() throws IOException,
InterruptedException, BiffException {

//Navigate the Application Url

driver.get("http://www.tizag.com/htmlT/htmlselect.php");

//wait 3sec

Thread.sleep(3000);

//Identify dropdown

WebElement dropdown=driver.findElement(By.name("selectionField"));

//Identify dropdown values and store into dropdownCount variable

List<WebElement>
dropdownCount=dropdown.findElements(By.tagName("option"));

//Print total dropdown values.

System.out.println("Total dropdown values are : "+dropdownCount.size());

/*
FileInputStream – A FileInputStream is an inputstream for reading
data from a Excel File.

FileOutputStream – A FileOutputStream is an outputstream for writing


data into a Excel File.
*/

//Now access the Excel file

FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\


Xlsx_File.xlsx");

//Get the workbook from Excel

XSSFWorkbook workbook=new XSSFWorkbook(fis);

//Get the sheet from Workbook

XSSFSheet sheet=workbook.getSheetAt(1);

//Get total rows from excel sheet

int total_Rows=sheet.getLastRowNum()+1;

System.out.println("Total excel rows are : "+total_Rows);


//Get total columns from excel sheet

int total_Columns=sheet.getRow(0).getLastCellNum();

System.out.println("Total excel Columns are : "+total_Columns);

//Create ArrayList object for that excel values

ArrayList xlvalues=new ArrayList();

/*

As you know,some times we need to perform same action with multiple


times at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for(int i=0;i<total_Rows;i++)
{

//Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}

//Create ArrayList object for that excel values

ArrayList ddvalues=new ArrayList();

//Using for loop, we can iterate till the j value is true

for(int j=0;j<dropdownCount.size();j++)
{

ddvalues.add(dropdownCount.get(j).getText());
}

//Check for the required elements by Text and display


matched elements and unmatched elements

if(total_Rows!=dropdownCount.size())
{
System.out.println("Size Not matched");
}
else{
for(int k=0;k<total_Rows;k++)
{
if(xlvalues.get(k).equals(ddvalues.get(k)))
{
System.out.println("Excel Data is
Matching with Application Data");
}
else
{
System.out.println("Excel Data is not
Matching with Application Data");
}

}
}

@AfterClass
public void tearDown()
{
//close the browser

driver.quit();
}

How to Verify AutoSearch Results_xlsFile ?

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class HowtoVerifyAutoSearchResults_xlsFile {

WebDriver driver;

@BeforeClass
public void setUp() {
// Launch Firefox browser

driver = new FirefoxDriver();

// Maximize the browser window

driver.manage().window().maximize();
}

@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {

// Navigate the Application Url

driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");
//Enter i into textbox field

driver.findElement(By.id("myInput")).sendKeys("i");

//Identify AutoSuggets and store into AutoSuggets variable

List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));

//Print Size of the AutoSuggets

System.out.println("Size of the AutoSuggets is : " +


AutoSuggets.size());

//create ArrayList object for that AutoSuggets

ArrayList AutoSugget_values = new ArrayList();

System.out.println("************Application_AutoSearchResult*******");

/*

As you know,some times we need to perform same action with multiple times
at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for (int i = 1; i <= AutoSuggets.size(); i++) {

//Identify AutoSugget and get the text and store into value
variable

String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();

//print the AutoSugget

System.out.println(value);

//Store AutoSugget value into AutoSugget_values variable

AutoSugget_values.add(value);
}

//Now access the Excel file

FileInputStream fis = new FileInputStream("E:\\SeleniumSoftware dump\\


AutoSuggest_xlsFile.xls");

//Get the workbook from Excel

HSSFWorkbook workbook=new HSSFWorkbook(fis);


//Get the sheet from Workbook

HSSFSheet sheet=workbook.getSheet("Sheet5");

//Get total rows from excel sheet

int total_Rows=sheet.getLastRowNum()+1;

System.out.println("Total excel rows are : "+total_Rows);

//create ArrayList object for that Excel values

ArrayList xlvalues=new ArrayList();

/*

As you know,some times we need to perform same action with multiple


times at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for(int i=0;i<total_Rows;i++)
{

//Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());

//Check for the required elements by Text and display matched elements
and unmatched elements

if(total_Rows!=AutoSuggets.size())
{
System.out.println("Size Not matched");
}
else{
for(int k=0;k<total_Rows;k++)
{
if(xlvalues.get(k).equals(AutoSugget_values.get(k)))
{
System.out.println("Excel Data is Matching with
Application Data");
}
else
{
System.out.println("Excel Data is not Matching with
Application Data");
}

}
}
}

@AfterClass
public void closeBrowser()
{
//close the browser

driver.quit();
}
}

How to Verify AutoSearch Results_xlsxFile ?


package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class HowtoVerifyAutoSearchResults_xlsxFile {

WebDriver driver;

@BeforeClass
public void setUp() {
// Launch Firefox browser

driver = new FirefoxDriver();

// Maximize the browser window

driver.manage().window().maximize();
}

@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {

// Navigate the Application Url

driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");

//Enter i into textbox field

driver.findElement(By.id("myInput")).sendKeys("i");
//Identify AutoSuggets and store into AutoSuggets variable

List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));

//Print Size of the AutoSuggets

System.out.println("Size of the AutoSuggets is : " +


AutoSuggets.size());

//create ArrayList object for that AutoSuggets

ArrayList AutoSugget_values = new ArrayList();

System.out.println("************Application_AutoSearchResult*******");

/*

As you know,some times we need to perform same action with multiple times
at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for (int i = 1; i <= AutoSuggets.size(); i++) {

//Identify AutoSugget and get the text and store into value
variable

String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();

//print the AutoSugget

System.out.println(value);

//Store AutoSugget value into AutoSugget_values variable

AutoSugget_values.add(value);
}

//Now access the Excel file

FileInputStream fis = new FileInputStream("E:\\SeleniumSoftware dump\\


AutoSuggest_xlsxFile.xlsx");

//Get the workbook from Excel

XSSFWorkbook workbook=new XSSFWorkbook(fis);

//Get the sheet from Workbook

XSSFSheet sheet=workbook.getSheet("Sheet1");

//Get total rows from excel sheet


int total_Rows=sheet.getLastRowNum()+1;

System.out.println("Total excel rows are : "+total_Rows);

//create ArrayList object for that Excel values

ArrayList xlvalues=new ArrayList();

/*

As you know,some times we need to perform same action with multiple


times at that time we need to follow - forloop

*/

//Using for loop, we can iterate till the i value is true

for(int i=0;i<total_Rows;i++)
{

//Read the data from excel sheet

xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());

//Check for the required elements by Text and display matched elements
and unmatched elements

if(total_Rows!=AutoSuggets.size())
{
System.out.println("Size Not matched");
}
else{
for(int k=0;k<total_Rows;k++)
{
if(xlvalues.get(k).equals(AutoSugget_values.get(k)))
{
System.out.println("Excel Data is Matching with
Application Data");
}
else
{
System.out.println("Excel Data is not Matching with
Application Data");
}

}
}

@AfterClass
public void closeBrowser()
{
//close the browser

driver.quit();
}
}

How to Verify_MultipleWebTableValues_Using_xlsFile ?

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Verify_MultipleWebTableValues_Using_xls {

WebDriver driver;

@BeforeClass
public void openWebSite() {

//open the browser


driver = new FirefoxDriver();

//navigate the application url


driver.get("file:///C:/Users/Hanumanthu/Downloads/webtable.html");

@Test
public void CountRowsTest() throws IOException, BiffException {

//To calculate the number of rows in a table


int allRows = driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);

// To calculate the number of columns


int allCols =
driver.findElements(By.xpath("html/body/table/tbody/tr[1]/td")).size();

// Get Total columns in a Table


System.out.println("Total columns in a Table -- " + allCols);

//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xls_File.xls");

//Get the Workbook from excel file


HSSFWorkbook w=new HSSFWorkbook(fis);

//Get the Sheet from Workbook


HSSFSheet sheet=w.getSheet("Sheet6");

//count the total rows from excel sheet


int total_rows=sheet.getLastRowNum()+1;

System.out.println("Total rows from excel sheet :"+total_rows);

//count the total rows from excel sheet


int total_columns=sheet.getRow(0).getLastCellNum();

System.out.println("Total rows from excel sheet :"+total_columns);

//create the ArrayList object for that excel


ArrayList xlvalues=new ArrayList();

System.out.println();
System.out.println("**************Excel data*****************\n");

//Using for loop, we can iterate till the i value is true


for(int i=0;i<sheet.getLastRowNum()+1;i++)
{

//Using for loop, we can iterate till the j value is true


for(int j=0;j<sheet.getRow(0).getLastCellNum();j++)
{

//print the excel data


System.out.print(sheet.getRow(i).getCell(j).getStringCellValue()+" ");

//read the data from excel sheet and store excel values in an xlvalues
ref_variable through add function
xlvalues.add(sheet.getRow(i).getCell(j).getStringCellValue());

}
System.out.println();
}

//create the ArrayList object for that Webtable


ArrayList Wvalues=new ArrayList();

System.out.println();
System.out.println("**************WebTable data*****************\n");

//Using for loop, we can iterate till the m value is true


for(int m=1;m<=total_rows;m++)
{
//Using for loop, we can iterate till the n value is true
for(int n=1;n<=total_columns;n++)
{
String data =
driver.findElement(By.xpath("html/body/table/tbody/tr["+m+"]/td["+n+"]")).getText()
;

//print the WebTable data


System.out.print(data+" ");

//store webtable values in an Wvalues ref_variable through add function


Wvalues.add(data);

}
System.out.println();
}
System.out.println();

int total_rows_columns = total_rows*total_columns;

System.out.println(" **************Compare WebTable data with Excel


data***************** "+"\n");
//Using for loop, we can iterate till the k value is true
for(int k=0;k<total_rows_columns;k++)
{

if(Wvalues.get(k).equals(xlvalues.get(k)))
{
System.out.println(Wvalues.get(k)+" is Matching with "+xlvalues.get(k)+"\
n");
}
else
{
System.out.println(Wvalues.get(k)+" is not Matching with
"+xlvalues.get(k)+"\n");
}

}
@AfterClass
public void tearDown()
{
//close the browser
driver.quit();
}
}

How to Verify_MultipleWebTableValues_Using_xlsxFile ?

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

import jxl.read.biff.BiffException;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

public class Verify_MultipleWebTableValues_Using_xlsx {

WebDriver driver;

@BeforeClass
public void openWebSite() {

//open the browser


driver = new FirefoxDriver();

//navigate the application url


driver.get("file:///C:/Users/Hanumanthu/Downloads/webtable.html");

@Test
public void CountRowsTest() throws IOException, BiffException {

//To calculate the number of rows in a table


int allRows = driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);

// To calculate the number of columns


int allCols =
driver.findElements(By.xpath("html/body/table/tbody/tr[1]/td")).size();
// Get Total columns in a Table
System.out.println("Total columns in a Table -- " + allCols);

//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xlsx_File.xlsx");

//Get the Workbook from excel file


XSSFWorkbook w=new XSSFWorkbook(fis);

//Get the Sheet from Workbook


XSSFSheet sheet=w.getSheet("Sheet6");

//count the total rows from excel sheet


int total_rows=sheet.getLastRowNum()+1;

System.out.println("Total rows from excel sheet :"+total_rows);

//count the total rows from excel sheet


int total_columns=sheet.getRow(0).getLastCellNum();

System.out.println("Total rows from excel sheet :"+total_columns);

//create the ArrayList object for that excel


ArrayList xlvalues=new ArrayList();

System.out.println();
System.out.println("**************Excel data*****************\n");

//Using for loop, we can iterate till the i value is true


for(int i=0;i<sheet.getLastRowNum()+1;i++)
{

//Using for loop, we can iterate till the j value is true


for(int j=0;j<sheet.getRow(0).getLastCellNum();j++)
{

//print the excel data


System.out.print(sheet.getRow(i).getCell(j).getStringCellValue()+" ");

//read the data from excel sheet and store excel values in an xlvalues
ref_variable through add function
xlvalues.add(sheet.getRow(i).getCell(j).getStringCellValue());

}
System.out.println();
}
//create the ArrayList object for that Webtable
ArrayList Wvalues=new ArrayList();

System.out.println();
System.out.println("**************WebTable data*****************\n");

//Using for loop, we can iterate till the m value is true


for(int m=1;m<=total_rows;m++)
{
//Using for loop, we can iterate till the n value is true
for(int n=1;n<=total_columns;n++)
{
String data =
driver.findElement(By.xpath("html/body/table/tbody/tr["+m+"]/td["+n+"]")).getText()
;

//print the WebTable data


System.out.print(data+" ");

//store webtable values in an Wvalues ref_variable through add function


Wvalues.add(data);

}
System.out.println();
}
System.out.println();

int total_rows_columns = total_rows*total_columns;

System.out.println(" **************Compare WebTable data with Excel


data***************** "+"\n");
//Using for loop, we can iterate till the k value is true
for(int k=0;k<total_rows_columns;k++)
{

if(Wvalues.get(k).equals(xlvalues.get(k)))
{
System.out.println(Wvalues.get(k)+" is Matching with "+xlvalues.get(k)+"\
n");
}
else
{
System.out.println(Wvalues.get(k)+" is not Matching with
"+xlvalues.get(k)+"\n");
}

}
@AfterClass
public void tearDown()
{
//close the browser
driver.quit();
}
}

How to Verify_Multiple WebTableValues_Using_xlsFile ?

package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

public class Verify_MultipleWebTableValues_Using_xls {

WebDriver driver;

@BeforeClass
public void openWebSite() {

//open the browser


driver = new FirefoxDriver();

//navigate the application url


driver.get("file:///C:/Users/Hanumanthu/Downloads/webtable.html");

@Test
public void CountRowsTest() throws IOException {

//To calculate the number of rows in a table


int allRows = driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);

// To calculate the number of columns


int allCols =
driver.findElements(By.xpath("html/body/table/tbody/tr[1]/td")).size();

// Get Total columns in a Table


System.out.println("Total columns in a Table -- " + allCols);

//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xls_File.xls");

//Get the Workbook from excel file


HSSFWorkbook w=new HSSFWorkbook(fis);

//Get the Sheet from Workbook


HSSFSheet sheet=w.getSheet("Sheet6");

//count the total rows from excel sheet


int total_rows=sheet.getLastRowNum()+1;

System.out.println("Total rows from excel sheet :"+total_rows);

//count the total rows from excel sheet


int total_columns=sheet.getRow(0).getLastCellNum();

System.out.println("Total rows from excel sheet :"+total_columns);

//create the ArrayList object for that excel


ArrayList xlvalues=new ArrayList();

System.out.println();
System.out.println("**************Excel data*****************\n");

//Using for loop, we can iterate till the i value is true


for(int i=0;i<sheet.getLastRowNum()+1;i++)
{

//Using for loop, we can iterate till the j value is true


for(int j=0;j<sheet.getRow(0).getLastCellNum();j++)
{

//print the excel data


System.out.print(sheet.getRow(i).getCell(j).getStringCellValue()+" ");

//read the data from excel sheet and store excel values in an xlvalues
ref_variable through add function
xlvalues.add(sheet.getRow(i).getCell(j).getStringCellValue());

}
System.out.println();
}

//create the ArrayList object for that Webtable


ArrayList Wvalues=new ArrayList();

System.out.println();
System.out.println("**************WebTable data*****************\n");

//Using for loop, we can iterate till the m value is true


for(int m=1;m<=total_rows;m++)
{
//Using for loop, we can iterate till the n value is true
for(int n=1;n<=total_columns;n++)
{
String data =
driver.findElement(By.xpath("html/body/table/tbody/tr["+m+"]/td["+n+"]")).getText()
;

//print the WebTable data


System.out.print(data+" ");

//store webtable values in an Wvalues ref_variable through add function


Wvalues.add(data);

}
System.out.println();
}
System.out.println();

int total_rows_columns = total_rows*total_columns;

System.out.println(" **************Compare WebTable data with Excel


data***************** "+"\n");
//Using for loop, we can iterate till the k value is true
for(int k=0;k<total_rows_columns;k++)
{

if(Wvalues.get(k).equals(xlvalues.get(k)))
{
System.out.println(Wvalues.get(k)+" is Matching with "+xlvalues.get(k)+"\
n");
}
else
{
System.out.println(Wvalues.get(k)+" is not Matching with
"+xlvalues.get(k)+"\n");
}

}
@AfterClass
public void tearDown()
{
//close the browser
driver.quit();
}
}

How to Verify_Multiple WebTableValues_Using_xlsxFile ?


package seleniumProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

public class Verify_MultipleWebTableValues_Using_xlsx {

WebDriver driver;

@BeforeClass
public void openWebSite() {

//open the browser


driver = new FirefoxDriver();

//navigate the application url


driver.get("file:///C:/Users/Hanumanthu/Downloads/webtable.html");

@Test
public void CountRowsTest() throws IOException {

//To calculate the number of rows in a table


int allRows = driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);

// To calculate the number of columns


int allCols =
driver.findElements(By.xpath("html/body/table/tbody/tr[1]/td")).size();

// Get Total columns in a Table


System.out.println("Total columns in a Table -- " + allCols);

//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xlsx_File.xlsx");
//Get the Workbook from excel file
XSSFWorkbook w=new XSSFWorkbook(fis);

//Get the Sheet from Workbook


XSSFSheet sheet=w.getSheet("Sheet6");

//count the total rows from excel sheet


int total_rows=sheet.getLastRowNum()+1;

System.out.println("Total rows from excel sheet :"+total_rows);

//count the total rows from excel sheet


int total_columns=sheet.getRow(0).getLastCellNum();

System.out.println("Total rows from excel sheet :"+total_columns);

//create the ArrayList object for that excel


ArrayList xlvalues=new ArrayList();

System.out.println();
System.out.println("**************Excel data*****************\n");

//Using for loop, we can iterate till the i value is true


for(int i=0;i<sheet.getLastRowNum()+1;i++)
{

//Using for loop, we can iterate till the j value is true


for(int j=0;j<sheet.getRow(0).getLastCellNum();j++)
{

//print the excel data


System.out.print(sheet.getRow(i).getCell(j).getStringCellValue()+" ");

//read the data from excel sheet and store excel values in an xlvalues
ref_variable through add function
xlvalues.add(sheet.getRow(i).getCell(j).getStringCellValue());

}
System.out.println();
}

//create the ArrayList object for that Webtable


ArrayList Wvalues=new ArrayList();

System.out.println();
System.out.println("**************WebTable data*****************\n");
//Using for loop, we can iterate till the m value is true
for(int m=1;m<=total_rows;m++)
{
//Using for loop, we can iterate till the n value is true
for(int n=1;n<=total_columns;n++)
{
String data =
driver.findElement(By.xpath("html/body/table/tbody/tr["+m+"]/td["+n+"]")).getText()
;

//print the WebTable data


System.out.print(data+" ");

//store webtable values in an Wvalues ref_variable through add function


Wvalues.add(data);

}
System.out.println();
}
System.out.println();

int total_rows_columns = total_rows*total_columns;

System.out.println(" **************Compare WebTable data with Excel


data***************** "+"\n");
//Using for loop, we can iterate till the k value is true
for(int k=0;k<total_rows_columns;k++)
{

if(Wvalues.get(k).equals(xlvalues.get(k)))
{
System.out.println(Wvalues.get(k)+" is Matching with "+xlvalues.get(k)+"\
n");
}
else
{
System.out.println(Wvalues.get(k)+" is not Matching with
"+xlvalues.get(k)+"\n");
}

}
@AfterClass
public void tearDown()
{
//close the browser
driver.quit();
}
}

what are the common Exceptions In selenium webdriver ?


We always face the Exceptions while automating.Lets see few Exceptions and what’s
the Reason
Timeout Exception :
Test Steps :

open the browser


Navigate the url
Enter the username
Enter the password
click on login button

//wait for Maximum time 5sec to open the welcome page

Thread.sleep(5000);

verify text
close the browser

1.suppose here Maximum time 5sec,so test method successfully executed with in 5sec.
so i.e pass
2.suppose here Maximum time 5sec,your test method execution didn't finish with in
5sec.so i.e fail

in this case ur selenium webdriver will throw " Timeout Exception. "

WebDriver Exception:

While passing url in selenium we have to pass protocals as well There are many
protocals available like

FTP,HTTPS,SMTP etc.

driver.get("https://www.google.co.in/?gfe_rd=cr&ei=7A8RVuzLD8Ol8weGyIaQAg");---pass

driver.get("www.google.co.in/?gfe_rd=cr&ei=7A8RVuzLD8Ol8weGyIaQAg");---fail

in this case ur selenium webdriver will throw " WebDriver Exception. "

Ex :
----

package com.tests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Login {

public static void main(String[] args) {

WebDriver driver=new FirefoxDriver();

driver.get("127.0.0.1/orangehrm-2.5.0.2/login.php");

driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");

driver.findElement(By.name("Submit")).click();
}

}
NoSuchElement Exception :
This exception occurs when WebDriver is unable to identify the elements during
run time. i.e Due to enter Invalid Locator or Invalid Locator value.

Syntax :
driver.findElement(By.Locator("Locator value")).click();

Examples:

1. driver.findElement(By.validLocator ("Invalid Locator value ")).click();


2. driver.findElement(By.InvalidLocator ("valid Locator value ")).click();

so in this case ur selenium webdriver will throw " NoSuchElement Exception . "

Selenium Code :

package com.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Login {

public static void main(String[] args) {

WebDriver driver=new FirefoxDriver();

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");

driver.findElement(By.InvalidLocator ("valid Locator value ")).click();


//driver.findElement(By.validLocator ("Invalid Locator value ")).click();

ElementNotVisible Exception :

suppose some elemets takes some time to appear when browser is loading in this case
ur selenium webdriver test case will failure . so in this case ur selenium
webdriver will throw " elementNotVisible Exception. "

//wait 15 sec till the element is visible once element is visible then do some
action on facebook link on a webpage
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//
input[@id='text']")));

Ex :
----
package com.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class VisibilityofElement {

public static void main(String[] args) {


WebDriver driver = new FirefoxDriver();

driver.navigate().to("http://www.ebay.in/?aff_source=Google_cpc");

driver.manage().window().maximize();

//wait 15 sec till the element is visible once element is visible then
do some action on facebook link on a webpage
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//
input[@id='text3']")));

if(driver.findElement(By.xpath("//*[@id='gf-BIG']/table/tbody/tr/td[3]/ul/
li[2]/a")).isDisplayed())
{

driver.findElement(By.xpath("//*[@id='gf-BIG']/table/tbody/tr/td[3]/ul/
li[2]/a")).click();
System.out.println("Element is displayed");

}else
{
System.out.println("Element is not displayed");
}

NoAlertPresent Exception :

This exception will be generated when webdriver switch


to alert popup but there Is no any alert present on page.
so in this case ur selenium webdriver will throw "NoAlertPresent Exception. "

package com.tests;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Login {

public static void main(String[] args) {


WebDriver driver=new FirefoxDriver();

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

driver.findElement(By.name("txtUserName")).sendKeys("selenium");
// driver.findElement(By.name("txtPassword")).sendKeys("");

driver.findElement(By.name("Submit")).click();

//wait 15 sec till the element is visible on a webpage


WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.alertIsPresent());

String str=driver.switchTo().alert().getText();
System.out.println(str);

if(str.equals("Password not given!"))


{
System.out.println("alert text is verified");
}else
{
System.out.println("alert text is not verified");
}
driver.switchTo().alert().accept(); //To click ok
// driver.switchTo().alert().dismiss(); //To click cancel

driver.findElement(By.name("txtPassword")).sendKeys("selenium");

driver.findElement(By.name("Submit")).click();
driver.close();

Selenium will wait 5 seconds until the Alert element is present and once Alert
element is present, Selenium will perform an action and will move to the next
step.
Xpath(is defined as xmlPath) in Selenium
If there is no any alternative way like id, class, name, etc. then XPath is
used to find an element on the web page .
Xpath is complete address of the Element
By using xpath we can identify the narmal webelements and dynamic
webelements.
Xpath-types
1. Absolute XPath
2. Relative Xpath

Absolute XPath :

It is the direct way to find the element, but the disadvantage of the absolute
XPath is that if there are any changes made in the path of the element then that
XPath gets failed.

The key characteristic of XPath is that it begins with the single forward
slash(/) ,which means you can select the element from the root node.
Below is the example of an absolute xpath expression of the element shown in the
below screen.

Absolute xpath:
Ex:- html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/
div[1]/div/h4[1]/b

Relative xpath :

For Relative Xpath the path starts from the middle of the HTML DOM structure. Its
start with the double forward slash (//), which means it can search the element
anywhere at the webpage.
You can starts from the middle of the HTML DOM structure and no need to write long
xpath.
Below is the example of a relative XPath expression of the same element shown in
the below screen. This is the common format used to find element through a relative
XPath.

Relative xpath:
syntax: //tagName[@Attributename='value']
Htmlcode : <input id=”abc” name =”xyz”>
Ex : // input [@id=’abc’]

Note:- in xpath ‘//’ represents search in the entire page single ‘/’ represents
search in the current node. On the left hand side of the ‘/’ we have parent
element, on the right hand side we have child element.
By constructing our own xpaths it is possible to use a combination of a locator to
identify elements.
This will help us in identifying the elements more quickly and uniquely.

<input id=”abc” name =”xyz”>

Using Id : driver.findelement(By.id(“abc))
Using Name: driver.findelement(By.name(“xyz”))
Using both Name and ID:- driver.findelement(By.Xpath(“//input[@id=’abc’ and
@name=’xyz’]))

Diff b/w Absolute XPath and Relative Xpath


Absolute XPath Relative Xpath

It takes the xpath from(/)tag or html tag to identify WebElement. It takes the
xpath from(//) to identify WebElement insteady of writing from root tag(/).
How to generate Absolute XPath.

Let us see : To generate the absolute XPath, you need to follow the following steps

1. Open your browser.


2. Open firebug using firebug icon.
3. Click on Firepath in firebug interface.
4. Select the option ‘Absolute XPath’.
How to generate Relative Xpath

Let us see : To generate the Relative Xpath , you need to follow the following
steps

1. Open your browser.


2. Open firebug using firebug icon.
3. Click on Firepath in firebug interface.
4. Select the option ‘show Entire Dom’.

This is a long length xpath This is a short length xpath


Syntax :
/html/head/body/div/input
Ex html/body/div[1]/div[2]/div[2]/form/input[18]

Syntax: //tagName[@attributeName=’value’]
Ex: //input[@name='uid']

it identifies the element very fast. it will take more time in identifying the
element as we specify the partial path not (exact path).

Note:
Beacuse in future any of the webelement when added/Removed then Absolute Xpath
changes. So Always use Relative Xpaths in your Automation.

• Here First we need to install firepath


• After Install firepath we will get the option like below image

• Here firebug and firepath these two add-on’s only for firefox .
• By using firebug and firepath we can identify the WebElement
• Suppose if u want to identify the WebElement
In chrome and ie here no need to install firebug and firepath.

Becoz chrome and ie have its won developer tool to identify the webElement.
Follow Html code :
<html>
<body>
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="middlename" placeholder="Middle Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="submit">
</body>
</html>
Note : Copy above html code and paste into notepad and save as frames.html formate.

How to handle Dynamic webElement(or)object in selenium ?


a)Many web sites create dynamic element on their web pages where Ids of the
elements gets generated dynamically. Every reload id gets generated differently. So
to handle this situation we use some JavaScript functions like starts-with and
contains .

starts-with
1)We can use this function when ID in starting is constant then dynamic.
2)if your (Loginbutton)dynamic element ids have the format where button
id="continue-12345", id="continue-12346" and id="continue-12347" where 12345,
12346 and 12347 is a dynamic numbers you could use the following

Where Dynamic id

< button id="continue-12345" >


< button id="continue-12346" >
< button id="continue-12347" >

XPath:------ //button[starts-with(@id, 'continue-')]

Where Dynamic name


< button name="continue-12345" >
< button name ="continue-12346" >
< button name="continue-12347" >

XPath:------ //button[starts-with(@name, 'continue-')]

Where Dynamic class

< button class ="continue-12345" >


< button class ="continue-12346" >
< button class ="continue-12347" >

XPath:------ //button[starts-with(@class, 'continue-')]


ends-with
1)We can use this function when ID in ending is constant then before dynamic.
2)if your (Loginbutton)dynamic element ids have the format where button
id="12345-continue", id="12346-continue" and id="12347-continue" where 12345,
12346 and 12347 is a dynamic numbers you could use the following

Where Dynamic id

< button id="12345-continue" >


< button id="12346-continue" >
< button id="12347-continue" >

XPath:------ //button[ends-with(@id, 'continue')]

Where Dynamic name

< button name="12345-continue " >


< button name ="12346-continue " >
< button name="12347-continue " >

XPath:------ //button[ends-with(@name, 'continue')]

Where Dynamic class

< button class ="12345-continue " >


< button class ="12346-continue " >
< button class ="12347-continue " >

XPath:------ //button[ends-with(@class, 'continue')]

contains

1.We can use this function when Id contain any fixed value at any place
2.Sometimes an element gets identfied by a value that could be surrounded by other
text, then contains function can be used.

Where Dynamic id

< button id="continue-12345-old" >


< button id="break-12345 -new”>
< button id="continue-12345-old" >

XPath:----- // button [contains(@id, '-12345-')].


Where Dynamic name

< button name ="continue-12345-old" >


< button name ="break-12345 -new”>
< button name ="continue-12345-old" >

XPath:------- // button [contains(@name, '-12345-')].

Where Dynamic class

< button class ="continue-12345-old" >


< button class ="break-12345 -new”>
< button class ="continue-12345-old" >

XPath: ------// button [contains(@class , '-12345-')].

Selenium Code :

package tests;

import java.util.ArrayList;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SampleClass {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();

//Navigate the url

driver.get("https://www.ryanair.com/gb/en/useful-info/help-centre/faq-
overview/My-ryanair-mandatory-sign-in");

Thread.sleep(10000);
//click on Login

driver.findElement(By.xpath(".//*[@id='myryanair-auth-login']/a/span")).click();
Thread.sleep(10000);

//switch to popup window


driver.switchTo().window(driver.getWindowHandle());
Thread.sleep(10000);

//Enter the Email address


driver.findElement(By.id("email235")).sendKeys("bhavya203@gmail.com");

//Enter the password

driver.findElement(By.xpath("//*[starts-
with(@id,'password')]")).sendKeys("K2@urapati");
//click on login
driver.findElement(By.className("core-btn-primary")).click();
Thread.sleep(10000);

//verify welcome page


String text=driver.findElement(By.className("username")).getText();

System.out.println(text);

if(text.equals("Bhavya"))
{
System.out.println("Bhavya successfully Logged in");
}else
{
System.out.println("Bhavya not successfully Logged in");
}

driver.findElement(By.className("username")).click();
Thread.sleep(5000);

//Click on logout
driver.findElement(By.xpath(".//*[@id='menu-container']/ul[2]/li[1]/
div/ul/li[9]/a")).click();
Thread.sleep(5000);

//close the browser


driver.quit();
}

}
DYNAMIC XPATH

In some applications we have elements whose xpaths constantly change, they are
called as dynamic xpaths and they can be handled using 3 different JavaScript
functions.

1. Starts-with()
2. Ends-with()
3. Contains()

Start-with function (): Start-with function finds the element whose attribute value
changes on refresh or on any operation on the webpage. In this expression, match
the starting text of the attribute is used to find the element whose attribute
changes dynamically. You can also find the element whose attribute value is static
(not changes).

Syntax:-//*[starts-with(@attribute, ‘starting point of value which does not


change’)]

Ends-with function ():We can use this function when ID in ending is constant then
before dynamic.

Syntax:- //*[ends-with(@attribute, ‘ending point of value which does not change’)]


Contains ():is a method used in XPath expression. It is used when the value of any
attribute changes dynamically.

Syntax:- //*[contains(@attribute, ‘some portion of value which does not change’)]


TestCase_ID Test Step Step Description
TC_23 Step 1 Launch firefox
TC_23 Step 2 Naivgate to yahoo.com
TC_23 Step 3 Send selenium into the search box
TC_23 Step 4 Click on SeleniumIDE from the auto generated suggestions

Program 26:-Program to Launch FireFox browser and Navigate to yahoo.com, Send


selenium into the search box,Click on Selenium IDE from the auto generated
suggestions.

Xpath of selenium IDE captured for the first time


.//*[ id="yui_3_10_0_1_1476363551351_415" ]/li[1]/a

Xpath of selenium IDE captured for the Second time


.//*[@id='yui_3_12_0_1_1476365226719_819']/li[1]/a

Xpath of selenium IDE captured for the Third time


.//*[@id='yui_3_12_0_1_1476365295923_850']/li[1]/a

To overcome the above situations we need to use the above said JavaScript
functions.

Xpath created using JavaScript Function


(//*[@id,'yui_3_12_0_1_1476365)]/li[1]/a

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.server.browserlaunchers.Sleeper;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class DynamicXpath {


FirefoxDriver driver;
@BeforeTest
public void setUp()
{
driver=new FirefoxDriver();
driver.get("https://yahoo.com");
}
@Test
public void xpathTest()
{
driver.findElement(By.id("UHSearchBox")).sendKeys("Selenium");
Sleeper.sleepTightInSeconds(3);
driver.findElement(By.xpath("//*[starts-
with(@id,'yui_3_12_0_1_14740')]/li[1]/a")).click();

}
}
How to use functions in xpath in selenium ?

Automation using selenium is a great experience. It provides many way to identif an


object or element on the web page.
But sometime we face the problems of idenfying the objects on a page which have
same attributes.
When we get more than one element which are same in attribute and name like
multiple checkboxes with same name and same id.
More than one button having same name and ids. There are no way to distingues those
element. In this case we have problem to instruct selenium to identify a particular
object on a web page.
I am giving you a simple example . In the below html source there are 6 checkboxes
are there having same type and same name.
It is really tough to select third or fifth.

Open notepad and type the below and save as .html file

input type='checkbox' name='chk' ----first


input type='checkbox' name='chk' ----second
input type='checkbox' name='chk' ----third
input type='checkbox' name='chk' ----forth
input type='checkbox' name='chk' ----fifth
input type='checkbox' name='chk' ----sixth

XPath Types : Functions


last(), position()

I will show you how we can use some of these above functions in xpath to identify
the objects.

Functions : last()
In the above html file there are six checkboxes and all are having same attributes
(same type and name)
How we can select the last checkbox based on the position. We can use last()
function to indentify the last object among all similar objects.
Below code will check or uncheck the last checkbox.
driver.findElement(By.xpath("//input[@type='checkbox'][last()]"));

How we can select the second last checkbox and third last checkbox. We can use
last()- function to indentify the last object among all similar objects.
Below code will check or uncheck the second last checkbox and thrid last checkbox
respectively.
driver.findElement(By.xpath("//input[@type='checkbox'][last()-1]"));
driver.findElement(By.xpath("//input[@type='checkbox'][last()-2]"));

Functions : position()
If you want to select any object based on their position using xpath then you can
use position() function in xpath.
You want to select second checkbox and forth checkbox then use below command
driver.findElement(By.xpath("//input[@type='checkbox'][position()=2]"));

driver.findElement(By.xpath("//input[@type='checkbox'][position()=4]"));

above code will select second and forth checkbox respectively.

Java script :
1. Suppose ur web page element is in hidden and disabled mode in this kind of
situation selenium will not work at that time we can use Selenium’s
JavascriptExecutor interface which executes JavaScript through Selenium driver. It
has “executeScript” methods, to run JavaScript on current browser.

1. If u want to work with selenium ,then compulsory Element should not be hidden
and disabled mode
2. Selenium with help of javascript to handle hidden and disabled type elements.
3. By using javascript, u can Enabled Element at runtime

click operation using 'Javascript':

WebElement Login_buttont= driver.findElement(By.name("Submit"));


((JavascriptExecutor) driver).executeScript("arguments[0].click();",Login_buttont);
I have two submit buttons with same names on webpage.now I want to click second
submit button.

WebElement second_submit_buttont= driver.findElement(By.name("button"));


((JavascriptExecutor) driver)
.executeScript("arguments[1].click();",second_submit_button);

Note:
Where arguments[1] means second element which has same name.

How to send the text to the username textbox field using JS


WebElement username=driver.findElement(By.name("txtUserName"));

((JavascriptExecutor) driver).executeScript("arguments[0].value =
'selenium';",username);

Note :By default every single(username,password ,login etc.) webelemt has


arguments[0]

Maven :

>Maven is a project build tool formally known as build tool.

>It provides the concept of a project object model (pom) file to manage project
build, dependency and documentation.

>Maven has its own repository where it keeps all plugins, jars etc..

>We can create maven project for writing scripts and create dependency using
pom.xml. once dependency set maven will download all the dependent jar files
automatically.

Part 1 :

1. Install maven into eclipse


2. Verify maven successfully install or not on ur eclipse

Part 2 :

Create Maven Project :

3. Go to Eclipse and click on JavaEE


4. File -> New -> Other->Maven->Select Maven Project
5. Check the check box Create a Simple Project
6. Give Group Id and Artifact
7. Click on Finish
So let us create some sample selenium scripts with maven project.

We need to create build first .if u want to create build then we require some
plugins

GroupId
• domainName
ArtifactId
• project name as artifactId
Version
• 0.0.1

Node Description
groupId This is an Id of project's group. This is generally unique amongst an
organization or a project. For example, a banking group com.company.bank has all
bank related projects.
artifactId This is an Id of the project.This is generally name of the project. For
example, consumer-banking. Along with the groupId, the artifactId defines the
artifact's location within the repository.
version This is the version of the project.Along with the groupId, It is used
within an artifact's repository to separate versions from each other. For example:

com.company.bank:banking:1.0
com.company.bank:banking:1.1.

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>STTP</groupId>
<artifactId>SeleniumMavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Compiler plug-in -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

</plugin>

<!-- Below plug-in is used to execute tests -->


<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>

<configuration>

<suiteXmlFiles>
<!-- TestNG suite XML files -->

<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>

</configuration>

</plugin>

</plugins>

</build>

</project>

Apache-MAVEN
What Is Maven? Why Do We Use Maven In Selenium?
What Is Maven?
Apache Maven Is Powerful Java project management and build management tool. That
means we can manage java project builds very easily using maven. Maven can helps
you to minimize your project and build management time and efforts. It Is fine to
manage project manually If It Is small. But If project Is very large or there are
many projects then It Is very hard for developer to manage each of them manually.

Using maven build tool, you can setup all those things which required running your
project code independently. Maven provides common platform to generate source code,
compiling and packaging code.

Main objectives of maven build tool are as bellow.


• It makes project build process easy.
• It provides easy and uniform build system.
• It provides quality project document Information.
• Managing project dependencies.
• Provides guild lines for better project management practices.
• Facilitate easy and transparent migration to new features.
• It allows to build project using project object model (POM).
• It downloads required dependency's jar files automatically from Maven central
repositories.
Why To Use Maven In Selenium Project?
As Maven Is build management tool, It will helps you to manage your selenium
project's build easily. If you are thinking that you will get some extra functions
from maven to write selenium automate test cases then you are thinking wrong. It Is
build management tool and It will manage your selenium test project's build
compilation, documentation and other related project tasks It self. It will helps
you to create right project structure, add and manage jar files In project's build
path etc..

Maven uses POM.xml configuration file which kept all project configuration related
Information. For selenium, You need to provide selenium webdriver version related
Information In POM.xml file and then It will download all required jar files
automatically and store It In local repository called m2. Later on If you wants to
change version of selenium webdriver then you need to modify version In POM.xml
file only. Then maven will download new version jar files automatically and store
In local repository. That means If you upgrade any dependency's version In POM.xml
file, First It will check that version's jar files are available or not In local
repository. If available then fine else It will download them from maven central
repository.

We will learn more about usage of maven In selenium project In my upcoming posts.
You will understand Its actual usage and usefulness once you will use It In your
project. Read my next post to know how to Install maven In Eclipse IDE.

How To Download And Install Maven In Eclipse Step By Step


We learnt what Is maven and why to use It In selenium project In previous . Now Its
time to Install maven In eclipse. Follow the steps as described bellow to Install
Maven In Eclipse.

Installing Maven In Eclipse

Step 1 : Open eclipse IDE and go to Help -> Install New Software menu as shown In
bellow Image. It will open new software Installation window.

Step 2 : Add bellow given URL In Work with text field of eclipse and press keyboard
ENTER button. It will search for maven software to Install.

URL = http://download.eclipse.org/technology/m2e/releases

Step 3 : On search completion, It will show "Maven Integration For Eclipse" check
box as shown In bellow Image.

Select that check box and click on Next button as shown In above Image. It will
start processing as bellow. It can take 1 to 2 minutes.
Step 4 : When above process completed, Install Remediation page will display as
bellow. Click on Next On that screen.

Step 5 : Next screen will be Install Detail. Click on Next on It.

Step 6 : Next screen will be Review licenses. Select "I accept the terms of the
licenses agreement." radio button and click on Finish.

It will start Installing maven In eclipse as bellow and It can take 5 to 20 minutes
to complete Installation. You can run It In background too.

Step 7 : At the end of maven Installation, It will show you message to restart
eclipse. Click on Yes button as shown bellow. It will restart your eclipse.

How to confirm Maven Is Installed In your eclipse


To confirm that maven Is Installed properly or not In your eclipse, You need to
open eclipse preferences window from menu Item -> Window -> preferences as bellow.
It will show you Maven In tree as bellow on preferences window. It means maven Is
Installed

You are done with maven Installation


Create New Maven Project In Eclipse For Selenium WebDriver + TestNG
Before creating maven project In eclipse IDE for selenium webdriver, You must be
aware about maven and It should be Installed properly In your eclipse IDE. Earlier
we learnt about what Is maven and how to download and Install maven So If maven Is
Installed In eclipse then you are ready to create new maven project as described In
bellow given steps.

Steps to create new maven project

Step 1 : First of all, Open eclipse IDE and go for creating new project from New ->
Other as shown In bellow Image.

It will open new project creation window.

Step 2 : Expand Maven folder In new project creation wizard window and select Maven
Project and then click on Next button as shown In bellow Image.

It will take you to project name and location selection screen.

Step 3 : On project name and location selection screen, You can choose work space
location for maven project by clicking on browse button. If wants to use default
work space location then select that check box and click on Next button as bellow.
It will take you to Archetype selection screen.

Steps 4 : On Archetype selection screen, Select Maven-archetype-quickstart option


as bellow and click on Next button.

Step 5 : On next screen, Enter Group Id = STTA, Artifact Id = MavenProject and


Package = STTA.MavenProject as shown In bellow Image. Then click on Finish button.

It will create new maven project In eclipse as bellow.

Now your maven project Is created. You can see there Is pom.xml file under your
project as shown above.

Step 6 : Now you need to add selenium webdriver and TestNG dependencies with latest
version In pom.xml file. Open pom.xml file and copy-paste bellow given code In It
and then save It.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>STTP</groupId>
<artifactId>SeleniumMavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
<!-- Compiler plug-in -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

</plugin>

<!-- Below plug-in is used to execute tests -->


<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>

<configuration>

<suiteXmlFiles>
<!-- TestNG suite XML files -->

<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>

</configuration>

</plugin>

</plugins>

</build>

</project>

Current latest version of selenium webdriver Is 2.44.0. TestNG latest version Is


6.8.8. You can change It If version updated version release In future.

Step 7 : Delete existing AppTest.java file from src/testjava folder package and
create new class file under same package with name = WebDriverTest.java as bellow.

Now copy-paste bellow given code In that WebDriverTest.java file and save It.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class WebDriverTest {

WebDriver driver;
//@BeforeClass - Run before Executing all test cases in the current
class/program
@BeforeClass
public void openbrowser() {
driver = new FirefoxDriver();

driver.manage().window().maximize();
driver.get("https://www.google.co.in/?
gfe_rd=cr&ei=yfXxV8TwDaPv8wei9ICICg&gws_rd=ssl");
}

//@AfterClass- Run After Executing all test cases in the current


class/program
@AfterClass
public void closebrowser() {
System.out.print("\nBrowser close");
driver.quit();
}

@Test
public void verifyTitle() {
String title = driver.getTitle();
System.out.print("Current page title is : "+title);
Assert.asserEquals(title,"Google");
}
}
Above file will show you errors as we do not have Included selenium and testng jar
files In project's build path. Here maven will do It automatically for us.

When you save It, It will start building work space by downloading required jar
files from maven central repository and store In local repository based on your
selenium webdriver and TestNG versions as bellow. It can take 5 to 20 minutes based
on your Internet speed.

Running webdriver project from pom.xml file


When above process get completed, You can run your project from pom.xml file. To
run It, Right click on pom.xml file and select Run As -> Maven test as shown In
bellow Image.

It will start executing webdriver test WebDriverTest.java file. This Is the way to
create and run webdriver test In eclipse using maven and testng

1.What is a Framework
Framework is a s/w which contains some set of programs .By using these programs we
can do our work very easily.
2.What is Data Driven Framework
Data Driven framework is focused on separating the test scripts logic and the test
data from each other. Allows us to create test automation scripts by passing
different sets of test data. The test data set is kept in the external files or
resources such as MS Excel Sheets, The test scripts connect to the external
resources to get the test data. By using this framework we could easily make the
test scripts work properly for different sets of test data.
3.Why Data Driven Framework
Usually, we place all our test data in excel sheets which we use in our test runs.
Assume, we need to run a test script (Say, login test) with multiple test data. If
we run the same test with multiple test data sets manually is time-consuming, and
error-prone. In the next section, we see a practical example.
In simple words, we adopt Data Driven Framework when we have to execute the same
script with multiple sets of test data.

4.Advantages of using Data Driven Test Framework


1. Faster script development
2. Reuse the script
3. Well organized code
4. Test data management
5. Easy of reporting and logging
6. Easy of maintenance.
5. where we can use data driven framework
 By using this u can control all ur data by external files like xls
 Suppose we need to test the login/Register/ Any form with multiple input
fields with 100 different data sets.

Means that :

Case 1 : Suppose if u want to test the login with multiple input fields with 100
different data sets then we need to use data driven framework.
Case 2 : Suppose if u want to test the Register with multiple input fields with
100 different data sets then we need to use data driven framework.

Case 3 : Suppose if u want to test the Any form with multiple input fields with
100 different data sets then we need to use data driven framework.
6.How to work on Data Driven Framework in Selenium Using poi
Selenium automates browsers. It’s a popular tool to automate web-based
applications. To handle excel sheets to read and write data using Selenium we do
use poi.
Assume, you need to test login form with 50 different sets of test data
1. As a manual tester, you do log in with all the 50 different sets of test data
for 50 times
2. As an automation tester, you create a test script and run 50 times by
changing the test data on each run or you create 50 test scripts to execute the
scenario
Note : Data Driven testing helps here and save a lot of time of us.
7.How To Create Data Driven Framework in Selenium Using poi
Here I will take OpenCart Application to showcase implementation of Data Driven
Framework in Selenium with Java using poi
1.Scenario: Open OpenCart and do log in and log out.
 suppose you are working with Log In function with 100 different usernames and
passwords to check which username and password Is valid and which Is Invalid or
wrong.
So now we are going to create this kind of Selenium WebDriver data driven Framework
step by step.

Follow below steps to Implement Data Driven framework.

First, we see how to read test data from excel sheet and then we see how to write
the result in the excel sheet.
8.Prerequisites to implement Data Driven Framework:
1. Eclipse IDE
2. TestNG
3. Selenium jars
4. poi dependency
5. Microsoft Excel
The structure of my project (Data Driven Project with Maven) is as follows:

Main Intention of creating separate packages for different file types Is It will be
very easy for us to find and manage any file.
Supposing if you wants to change something In .xls file then directly you can go
to "com.stta.ExcelFiles" package folder and update the file.
9.Create Bellow Given Packages Under the Project
1. com.stta.ExcelFiles :- To store .xls files.
2. com. stta.Logging :- To store .log file.
3. com. stta.property :- To store .properties files.
4. com. stta.TestSuiteBase :- To store base class file.
5. com. stta.utility :- To store utility files.
6. com. stta.xslt :- To store testng-results.xsl file.

Step 1: Open Eclipse and configure poi jar files – Download POi jar.
Note: If you are using Maven Project then you could include the dependencies in the
pom.xml

Must Read: How to create Maven Project

Step 2: Open Excel Sheet and create some test data. Here I have saved my excel
sheet on my D Drive.

Step 3: Create a Java Classes under your Project

Config.property:
This file will hold all are configuration info
For ex:

1. Property file is case sensitive in property file suppose you have (S is a


capital letter) ScreenshotPath = “Screenshot location”
but in ur selenium code (s is a small letter) at the time of getproperty so null is
print.

2. If u don’t want ScreenshotPath = “Screenshot location” property right now


then u simply give #ScreenshotPath = “Screenshot location” just lik as a
comment.May be it will be help in future.

In java, if you want to give the comment for single line then we need to give
double slash(//).
In Property file, if you want to give the comment for single line then we need to
give hash(#).
3. It doesn’t require space after the parameter value in property file
OR.property
1. O.R is a place where we can store all the object(element) info.
2. And it acts as a interface in b/w testscript and application in order to
identify the element during execution.
3. And it is a centralized location of the Object and their properties.
O.R file will hold all the xpath of the elements of the application.

Test base:
This class will responsible for initializing everything it will be basically super
class of the all sub classes which we create in this test base Reading
configuration parameters and xpath from property file.

System.getProperty(“user.dir”) Mean:->
Suppose if you want copy the same project in some other location or in some other
system then run the script then wat will happen? Then error is coming why becoz u
are working directory has been changed here possible to change the location but it
takes time.
My intension is we have to create System.getProperty(“user.dir”) in FileInputStream
constructor that’s mean u are working with current directory.
Now its possible copy the same project in some other location or in some other
system then run it wat will happen?then u can happily execute the script there may
be no need change the location.

How to Reading_Properties_Files ?

package com.Banking.UtilityFiles;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Reading_Properties_Files {

//@BeforeClass defines this Test has to run before every @Test methods in
the current class/program

public static Properties config;


public static Properties OR;
public static WebDriver driver;

@BeforeClass
public void intilize() throws IOException{
//create Properties object for that config.properties file
config=new Properties();

FileInputStream fis=new
FileInputStream(System.getProperty("user.dir")+"\\src\\main\\java\\com\\Banking\\
Property\\config.properties");
//load config property file
config.load(fis);
// //create Properties object for that OR.properties file
OR=new Properties();

FileInputStream fiss=new
FileInputStream(System.getProperty("user.dir")+"\\src\\main\\java\\com\\Banking\\
Property\\OR.properties");
//load xpath
OR.load(fiss);

if(config.getProperty("browser").equals("Firefox"))
{
driver=new FirefoxDriver();

}else
{

System.out.println("Unable to launch the Firefox browser");

}
//Maximize the browser window
driver.manage().window().maximize();

@Test
public void Login() throws Exception {

driver.get(config.getProperty("TestSiteName1"));

driver.findElement(By.name(OR.getProperty("username"))).sendKeys("selenium");;

driver.findElement(By.name(OR.getProperty("password"))).sendKeys("selenium");;

driver.findElement(By.name(OR.getProperty("login"))).click();

Thread.sleep(3000);

driver.findElement(By.xpath(OR.getProperty("logout"))).click();

@AfterClass
public void closebrowser() {
driver.close();

}
How to write the data into excel ?

package com.Banking.tests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class WriteXLSX {

public static void main(String[] args) throws IOException {


FileInputStream fis = new FileInputStream("D:\\test1.xls");
HSSFWorkbook readable_workbook = new HSSFWorkbook(fis);
HSSFSheet readable_sheet = readable_workbook.getSheetAt(0);
//Create First Row
HSSFRow row1 = readable_sheet.createRow(0);
HSSFCell r1c1 = row1.createCell(0);
r1c1.setCellValue("Emd Id");
HSSFCell r1c2 = row1.createCell(1);
r1c2.setCellValue("NAME");
HSSFCell r1c3 = row1.createCell(2);
r1c3.setCellValue("AGE");

//Create Second Row


HSSFRow row2 = readable_sheet.createRow(1);
HSSFCell r2c1 = row2.createCell(0);
r2c1.setCellValue("1");
HSSFCell r2c2 = row2.createCell(1);
r2c2.setCellValue("sai");
HSSFCell r2c3 = row2.createCell(2);
r2c3.setCellValue("4");

//Create Third Row


HSSFRow row3 = readable_sheet.createRow(2);
HSSFCell r3c1 = row3.createCell(0);
r3c1.setCellValue("2");
HSSFCell r3c2 = row3.createCell(1);
r3c2.setCellValue("Akki");
HSSFCell r3c3 = row3.createCell(2);
r3c3.setCellValue("3");

File file=new File("D:\\test2.xls");


FileOutputStream writable_Excel =new
FileOutputStream(file);
readable_workbook.write(writable_Excel);
writable_Excel.close();
System.out.println("Save the readable workbook into writable_Excel");
}
}
Inheritance :

What is Inheritance?
Create new class from existing class .The sub class acquired all the features of
super class then it is called inheritance .
Advantage of inheritance ?
The sub class reuse the super class code without rewriting it.so the developing
class becomes very easy and programmer productivity is also increased.
I. Application development time is very less.
II. Redundancy (repetition) of the code is reducing. Hence we can get less memory
cost and consistent results.
III. Instrument cost towards the project is reduced.
IV. We can achieve the slogan write one’s reuse/run anywhere (WORA) of JAVA

JAVA Super-Class Program for Inheritance

public class Car {


int price;
public void start()
{
System.out.println("This is to start the car");
}

JAVA sub-Class Program for Inheritance

public class Audi extends Car{

String model;
public void stop()
{
System.out.println("This is to stop the car");
}
public static void main(String[] args) {
Audi a=new Audi();
a.model="A4";
a.stop();
a.start();
a.price=1111;

Mainly why we are using inheritance ?


Using Inheritance,
1. For method overriding.
2. we can reuse the code of parent class In to child class so that size of code
will decrease. Maintenance of code will be also very easy.

extends keyword Is used to Inherit child class from parent class

Creating Single Or Multiple Tests For Multiple Classes In WebDriver

• "SuperClass" will be used for initializing and closing webdriver instance,


and also reusable functions.
• "SubClass" will be used as selenium automation test cases.
What is a Method in Java?

• Method is a group of statements which is created to perform some actions or


operations when your java code call it from main method.
• Inside a method u can not be execute by itself.
• To execute that method,you need to call from main method block.

Methods (or) Functions: - Methods are used to create re-usable code.


Advantage : Code reusability.
public class MethodsOrFunctions {

public static void main(String[] args) {


int a=10,b=20,c=30;
int r=sumAll(a,b,c);
System.out.println(r);
r=sumAll(100,200,300);
System.out.println(r);
}

public static int sumAll(int i,int j,int k)


{
int temp=i+j+k;
return temp;
}

Capturing ScreenShots

TestCase_ID Test Step Step Description


TC_15 Step 1 Launch firefox
TC_15 Step 2 Naivgate to google
TC_15 Step 3 Take a screenshot

Program 19:-Program to Launch FireFox browser and Navigate to google.com,and take


screenshot of the page.

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Screenshots {

public static void main(String[] args) throws IOException {


1. FirefoxDriver driver=new FirefoxDriver();
2. driver.get("http://google.com");

3. TakesScreenshot scr=(TakesScreenshot)driver;
4. File srcFile=scr.getScreenshotAs(OutputType.FILE);
5. FileUtils.copyFile(srcFile,new File("C:\\Hanumanth.png"));

Explanation of Above Program

Step3:- Driver object which belongs to FireFoxDriver type is converted (Typecasted)


into takesscreenshot type. This takesscreenshot is an in-built interface in
selenium, once the type casting is done we storing it into a variable called
screen. This screen belongs takesscreenshot type.
Step4:-using the screenshot object we are calling the method getScreenshotAs and
specifying that the output should come in file format.

Step5:-This screenshot should be saved in our system using an in-built class in


java called FileUtils. This class has a method copy file which accepts two
arguments.
1. The file that should be copied
2. The location where it should be copied.
OR
The screen shot can also be captured using the below code.

1. File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
2. FileUtils.copyFile(srcFile,new File("C:\\Hanumanth.png"));

Exception Handling: this is the process of overcoming an exception or error and


remain the execution of the remaining steps in the program.

The section of code which might generate an error should be given in the try block.
If it generates an error the control comes into the catch block. The program
overcomes that error and continues the execution of remaining code.

JAVA Program

public class ExceptionHandling {

public static void main(String[] args) {


System.out.println("Selenium");
try
{
System.out.println(100/0);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("Jmeter");
}

Priority Testing
Prioritization testing in TestNG

? I have multiple test cases in the same class.when i run this by


default,these(@Test) annotations are execute alphabetically.
? So at that time u can use prioritizing test.
? By using prioritizing test,u can execute the test cases in order.
? Based on the priority u can execute the test cases in order.
? U can give priority at method level
? If you don't mention the priority, it will take all the test cases as
"priority=0" bydefault.

public class PriorityTesting {

@Test
public void login()
{
System.out.println("Login successful");
}
@Test
public void checkEmail()
{
System.out.println("check email successful");
}
@Test
public void search()
{
System.out.println("search successful");
}
@Test
public void logout()
{
System.out.println("Logout successful");
}

Test Case execution Flow(As per Alfa bytical order):


check email successful
Login successful
Logout successful
search successful

public class PriorityTesting {

@Test(priority=0)
public void login()
{
System.out.println("Login successful");
}
@Test(priority=1)
public void checkEmail()
{
System.out.println("check email successful");
}
@Test(priority=2)
public void search()
{
System.out.println("search successful");
}
@Test(priority=3)
public void logout()
{
System.out.println("Logout successful");
}

Test Case execution Flow(As per priority):


Login successful
check email successful
search successful
Logout successful

Group of Testing :
With the help of Grouping, you can make the groups of Test cases like you can
divide the test cases into multiple groups
like Smoke, Sanity, and Regression. You can also execute specified test group using
TestNG.

Create & Execute Test Groups in TestNG


Here we are taking an example, In which we will create the two class “GroupTest1 ”
and “GroupTest2”.

We can execute the Test Groups using “testng.xml” file. To execute the Test group,
you need to include the group in the testng.xml file.

Let’s see our Test Classes —>

TC_1 :
------
package RunMultipleGroups;

import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class GroupTest1 {

@Test(groups = "Smoke",priority=0)
public void login_Account() {
System.out.println("Account Login");
}

@Test(groups = "Smoke",priority=1)
public void checkMail() {

Assert.assertEquals("OrangeHRM","OrangeHRM");

System.out.println("Checking Mail in the Inbox");


}

@Test(groups = "Sanity",priority=1)
public void checkDrafts() {
System.out.println("Checking Drafts");
}

TC_2 :
-----=
package RunMultipleGroups;

import org.junit.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class GroupTest2 {

@Test(groups = "Sanity",priority=1)
public void checkPromotions() {
System.out.println("Checking Promotions");
}

@Test(groups = "Sanity",priority=2)
public void checkAccountDetails() {
System.out.println("Checking Account Details");
}

@Test(groups = "Smoke",priority=2)
public void composeMail() {

Assert.assertEquals("OrangeHRM","OrangeHRM");
System.out.println("Send a Mail ");
}

@Test(groups = "Smoke",priority=3)
public void deleteMail() {
System.out.println("Delete a Mail");
}
@Test(groups = "Sanity",priority=3)
public void logout_Account() {
System.out.println("Account Logout");
}

Execute Smoke Testing:


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

<suite name="Suite">

<test name="Smoke Testing" >


<groups>
<run>
<include name="Smoke" />
</run>
</groups>

<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>

</test>

</suite> <!-- Suite -->


Execute Sanity Testing:
---------------------------

<suite name="Suite">

<test name="Sanity Testing" >


<groups>
<run>
<include name="Sanity" />
</run>
</groups>

<classes>

<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>

</classes>
</test>

</suite> <!-- Suite -->

Execute Multiple Test Groups:


TestNg.xml
--------------

<suite name="Suite">

<test name="Smoke Testing" >


<groups>
<run>
<include name="Smoke" />
</run>
</groups>

<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>
</test>
<test name="Sanity Testing" >
<groups>
<run>
<include name="Sanity" />
</run>
</groups>

<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>

</classes>

</test>

</suite> <!-- Suite -->

Including and excluding groups:


--------------------------------------------
<include >:--> It tells testng.xml file that which group we need to execute.
< exclude > :-->It tells testng.xml file that which group we need to skip.

Simple way to execute failed test cases using Selenium

Most of the time we have faced this question in interviews that Can we execute only
failed test cases in Selenium or can we identify only failed test cases in Selenium
and re-run them.

I really love this feature of TestNG that you can run only failed test cases
explicitly without any code. This can be easily done by running one simple testng-
failed.xml.
Execute Failed test cases using Selenium

Real-time Example

Take an example that you have one test suite of 100 test cases and once you start
execution of test suite there are a number of chances that some test cases will
fail.Consider 15 test cases are failing out of 100 now you need to check why these
test cases are failing so that you can analyze and find out the reason why they
have failed.

Note- Your script can fail due to so many reasons some of them are

1- Some locator has been changed in application because the application is getting
new feature- so in this case you need to modify your script in other words you have
to refine your script.

You can not avoid maintenance of test script you always have to maintain your
scripts 😉

2- Either functionality has been broken- in this case, you have to raise a defect
and assign to the respective person.

Execute Failed test cases using Selenium


Steps

1-If your test cases are failing then once all test suite completed then you have
to refresh your project . Right click on project > Click on refresh or Select
project and press f5.

2-Check test-output folder, at last, you will get testng-failed.xml

3- Now simply run testng-failed.xml.an be easily done by running one simple testng-
failed.xml.

How to run testng-failed.xml

We don’t have to perform any other activity once you will get testng-failed.xml
double click on this and analyze which test case are failing and why . Then modify
your script and run it.

To run above xml simple right click on xml then Select run as then TestNG Suite.

Generating XSLT reports through WebDriver ,Ant and TestNG

To generate XSLT reports, We have to use Apache Ant. Apache Ant Is open source
command-line tool which will help us to generate XSLT reports for our selenium
webdriver .
XSLT stands for XML Style-sheet language for transformation, It provide very rich
formatting report using TestNG framework
We will configure our project and system to generate XSLT reports. Configuration
Includes Java Installation, ANT Installation, adding build.xml file In project and
also verify that all other required files are configured and placed at proper place
or not.

Why need XSLT reports


Till now, We have generated testng reports as described In previous. But testng
reports are not so much Interactive and we can not send this kind of reports to our
manager or client. XSLT reports are very Interactive and easy to understand them.

ANT Installation For XSLT reports


First of all you have to configure ant In your system to generate XSLT reports. And
to configure ant, Latest java version should be Installed In your system.I have
also described how to verify that ant Is configured properly or not on that page.

Steps for generating reports:

Let us Generate XSLT Report in Selenium WebDriver

1.Add build.xml File Under Your Project


You have to create build.xml file under your project because ant understand only
build.xml file's execution pattern. You can download ready made build.xml file from
bellow given link page to Include It In your project.
• Go To This
Page(https://drive.google.com/drive/folders/0B5v_nInLNoquV1p5YWtHc3lkUkU) and
Download the XSLT report package
Step 1): Download the XSLT report package

Unzip the above folder you will get below items:

• lib
• build.xml
• testng-results.xsl

Step 2): Unzip the folder and copy all files and paste at the project home
directory as shown in below screen.

3. Create build.xml

Here
1.verify paths in build.xml file
2.Confirm required jar files added in project build path

<project name="TestAutomation" basedir=".">


<property name="LIB" value="${basedir}/lib" />
<property name="BIN" value="${basedir}/bin" />
<path id="master-classpath">
<pathelement location="${BIN}" />
<fileset dir="${LIB}" includes="*.jar"/>
</path>

<target name="generateReport">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/test-output/testng-results.xml"
style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"
/>
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS"
name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="master-classpath">
</classpath>
</xslt>
</target>

</project>

3.Before generating XSLT reports,you need to run your test suite from “
Testng.xml ” file first becoz XSLT reports are generated using “ Testng-
results.xml “ file .

4. Create testng.xml file in your project with the following script for TestNG
execution
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Ant Suite">
<test name="Ant Test">
<classes>
<class name=" XSLT_ReportsPack. xsltReports " ></class>
</classes>
</test>
</suite>

Next I want to generate the Ant xslt reports

Step 3): In this step run the build.xml file from eclipse as shown below:

Right click on the build.xml then click on run as Ant build.

Then a new window opens. Now select option 'generateReport'.

Click on Run button. It should generate the report.


Verifying XSLT Report
Once build is successful and moved to project home directory and refresh then You
will find the testng-xslt folder.

Inside this folder you will find index.html file as shown below:

Now open this HTML file in any browser like Firefox or Chrome, which support
javascript. You will find the report as shown in below screen. The pie chart report
represents test status more clearly. The filter feature allows the user to filter
the result as per the set criteria.

We will get results like below image

Parameterization in TestNG using testng.xml


You can use parameter annotations through the testng.xml file to pass values to
test methods as arguments. However, at times it is required to pass values to test
methods, especially during the run time. It can be done in the same way as the
username and password are passed through testng.xml instead of hard coding it in
test methods or as the browser name is passed as a parameter to execute in a
specific browser.

Let us now try to understand parameterization with a basic example.

package com.parameterization;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestParameters {
@Parameters({ “browser” })
@Test
public void testCaseOne(String browser) {
System.out.println(“browser passed as :- ” + browser);
}
@Parameters({ “username”, “password” })
@Test
public void testCaseTwo(String username, String password) {
System.out.println(“Parameter for User Name passed as :- ” + username);
System.out.println(“Parameter for Password passed as :- ” + password);
}
}
In the above class, two parameters ‘username’ and ‘password’ are passed as input to
test method ‘testCaseOne’.
The following is the testng.xml file, in which we need to pass the parameter values
for the test method.

<! DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>


<suite name="Parameterization Test Suite">
<test name="Testing Parameterization">
<parameter name="browser" value="Firefox"/>
<parameter name="username" value="selenium"/>
<parameter name="password" value="selenium123"/>
<classes>
<class name="com.parameterization.TestParameters" />
</classes>
</test>
</suite>

Parallel Testing :

1. Browser compatibility software testing Is most Important thing for any software
web application and generally you have to perform browser compatibility testing
before 1 or 2 days of final release of software web application

2. In such a sort time period, you have to verify each Important functionality
In every browsers suggested by client.

3.If you want to run multiple tests In different browsers one by one then It will
take too much time to complete your software tests and you may not complete It
before release the project.

4. In this kind of situation, I want to run multiple tests In different browsers


parallely at the same time within sort time and will helps you to save your time
efforts.

Test_Parallel.java

package SampleTestCases;

package seleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Test_Parallel {

public WebDriver driver;


@BeforeClass
//I have used @Parameters annotation to pass parameter In method
//parameter value will retrieved from testng.xml file's <parameter> tag.
@Parameters ({"browser"})
public void setup(String browser){
//Method will pass value of parameter.
if (browser.equals("FFX")) {
//If value Is FFX then webdriver will open Firefox Browser.
System.out.println("Test Starts Running In Firefox Browser.");

driver = new FirefoxDriver();

}else if (browser.equals("CRM")){
//If value Is CRM then webdriver will open chrome Browser.
System.out.println("Test Starts Running In Google chrome.");

System.setProperty("webdriver.chrome.driver","C:\\Users\\Hanumanthu\\Downloads\\
chromedriver.exe");
driver = new ChromeDriver();
}
else if (browser.equals("IE")){
//If value Is CRM then webdriver will open chrome Browser.
System.out.println("Test Starts Running In IE.");

System.setProperty("webdriver.ie.driver","C:\\Users\\Hanumanthu\\Downloads\\
IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
driver.manage().window().maximize();
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
}
//Both bellow given tests will be executed In both browsers.
@Test
public void verify_title(){
String title = driver.getTitle();
Assert.assertEquals("OrangeHRM - New Level of HR Management", title);
System.out.println("Title Is Fine.");
}
@AfterClass
public void closebrowser(){
driver.close();
}
}

testng.xml
----------

<suite name="Parallel Testing" parallel="tests">


<test name="Test In FireFox" >
<parameter name="browser" value="FFX" />
<classes>
<class name="seleniumProject.Test_Parallel"/>
</classes>
</test>

<test name="Test In Google Chrome" >


<parameter name="browser" value="CRM"></parameter>
<classes>
<class name="seleniumProject.Test_Parallel"/>
</classes>
</test>

<test name="Test In IE" >


<parameter name="browser" value="IE"></parameter>
<classes>
<class name="seleniumProject.Test_Parallel"/>
</classes>
</test>

</suite>

Install Chropath Addon for Chrome Browser

>ChroPath is the best alternative for the deprecated/discontinued FireBug Add-on


and Firepath Add-on.
>ChroPath Add-on is mainly used for auto-generating the XPath Expressions and CSS
Selectors Locators for identifying the elements on a web page.
>ChroPath Add-on can be installed on both Chrome and Firefox Browsers, I personally
recommend it using it on the Chrome Browser.
Now I am going to explain the steps for installing the ChroPath Add-on on the
Chrome Browser.
Let’s get started.
Follow the below steps for installing ChroPath Add-on on Chrome Browser:
1) Open Chrome browser> go to google search >Enter ChroPath then search it> click
on the link ChroPath – Google Chrome as shown below:

2) Click on ‘Add to Chrome’ button as shown below:

3) Click on ‘Add Extension’ Button as shown below:

4) Observe that ChroPath has been added to Chrome as shown below:

5) Also, the ChroPath Add-on got added to the Chrome Browser as shown below:

Hence, we have successfully installed ChroPath in Chrome Browser.

Install Chropath Addon for Firefox Browser


Note: ChroPath Add-on can be installed on both Chrome and Firefox Browsers
This is for the Firefox fans, who are interested in using ChroPath Add-on on the
Firefox Browser.
Let’s get started.
Follow the below steps for installing ChroPath Add-on on Firefox Browser:
1) Open Firefox browser> go to google search >Enter ChroPath then search it> click
on the link ChroPath for Firefox as shown below:

2) Click on ‘Add to Firefox’ button as shown below:

3) Click on ‘Add’ button as shown below:

4) Observe that The ChroPath has been added to Firefox as shown below

Hence, we have successfully installed ChroPath in Firefox Browser.

How to use Chropath add-on in Chrome Browser?

Pre-requisite : Install Chropath Add-on on Chrome Browser as explained in the


previous topic.

FireBug and Firepath add-ons got deprecated and hence discontinued. Hence we need
to use Chropath add-on in place of them. In this topic, I will explain, how to use
Chropath in Chrome browser in a step by step manner. Please follow the below steps
to understand.
1. Launch Chrome Browser and browse any site say www.google.com

2. Press 'F12' key on your keyboard, then you will get the developer tool in Chrome
Browser as shown below.

3.Select 'Elements' tag and then select the 'Chropath' option as shown below.

4. Click on the 'Inspect Element' option on the Chrome Developer tool Options as
shown below, select any UI element on the page say 'Google Logo' and ensure that
the source code of the selected UI element (i.e. Google Logo in this example) is
highlighted as shown below.

Also, observe that the XPath Expressions and CSS Selectors locators got auto-
generated as shown below (The usage of these locators are explained in previous
topic).

5. Observe that the above highlighted source code is in html format. We may need
this source code to identify the properties of the selected UI element (i.e. Google
Logo in this example).

6. For example if we want to know the id property details of the selected UI


element Google Logo. First we need to inspect the Google Logo by following the
above 4 steps and copy the 'id' details from the highlighted source code as shown
below.

7. You can also copy the XPath Expressions and CSS Selectors locators that are
auto-generated by Chropath as shown below.

Introduction
• Jenkins is an open-source, continuous integration tool developed by Hudson
lab.
• It is cross-platform and can be used on Windows, Linux, Mac OS environments.
• Jenkins is written in Java.
• Jenkin’s used to automate the built of your projects at a scheduled time or
when a trigger is raised or when the user requests it.
• The automated, continuous build can help a lot in increasing the productivity
and reducing conflicts.

Prerequisites
• Ecllipse with TestNG
• Create XML file and Run Script
• Convert XML file to .bat file

What is the Use of Jenkins in Selenium

Scenario:
Suppose your Boss or Team lead assigns you 200 testcase to execute in a day.So how
you will do this.If your team lives in different areas.One is in Banglore,Other is
in Noida Third one is in Us.
By using Jenkins you can do this.We will create our testcases and deploy on A
Repository.Here What Jenkins will do?Jenkins will run those test cases which are on
repository.
Repository is a central hub where you all will store your Test case.
We can run our testcase using BatchFile .

One of the most important feature of jenkins is Scheduling


We can schedule our build periodically.
Suppose you need to run build1 at 10 pm

How To Download And Install Jenkins


Step 1: Download Jenkins
Step 2: Install Jenkins
To download Jenkins, Go to ‘https://jenkins.io/index.html‘ and download correct
package as per your OS.

I have downloaded Jenkins version 2.60.2


Unzip Jenkins to a specified folder. Right click on ‘jenkins.msi’ file and click on
‘Install’

Click on ‘Next‘ button

Click on ‘Next‘ button

Click on ‘Install‘ button to install Jenkins.

Click on Finish button.

Once the installation is done, navigate to the Jenkins Dashboard


(http://localhost:8080 by default) in the browser window.
Copy the password from initialAdminPasswordfile and paste it. In my case the
location is “C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword”

Click on ‘Install Suggested Plugins‘

Create an Admin user by giving Username, Password, Full Name , Email Address of
your preference
and save and finish then you will get Jenkins dashboard.
This way we could Install Jenkins in Windows.

Jenkins is running so we are almost done.So next go to structure

1. First run multiple test cases indually from Eclipse


2. Run multiple test cases from xml file
3. Run xml file from cmd prompt
Create library folder under the project (inside library we have all libraries)see
below.

Run the xml file from command prompt


Before executing the xml file let me set the class path like
Open command prompt and navigate to project home directory and set the classpath-

Home directory > set classpath=D:\workspace\WebDrivertest\bin;D:\workspace\


WebDrivertest\library\*;
Enter
Home directory > java org.testng.TestNG jenkintestng.xml
Note- Please make the changes as per your system
4.Run xml file from .bat file
Open notepad and type the below command and save as .bat file

In the above line of code, at the end of a batch file, we have added 'pause'
statement to prevent auto-closing of console after the execution, which will print
a nice message as 'Press any key to continue . . . ' so that we can view the
output. Or, if we don't want "Press any key to continue . . ." message you can just
ignore that.
In my case I have saved as run.bat

Run xml file from .bat file


Just double click on bat file

Run .bat file from Jenkin


Go to jenkin
Create Jenkins Project:
1. Go to the Jenkins dashboard and Click on New Item
2. In the next screen, enter the Item name, for example JenkinProject. Choose
the ‘Freestyle project option’ and click OK
3. It will be redirected to configuration page where you can specify the details
of the job
4. Now go to Advanced->Click-on use custom workspace and give the workspace path
in directory

Then go to Build and Click-on Execute Windows Batch Command here we needs to .bat
file->Click on Apply and save Buttons

5. Once saved, you can click on the Build Now option and build is scheduled, it
will run.

The Build history section shows that a build is in progress.


6. The build is completed, a status of the build will show if the build was
successful or not. Click on the #1 in the Build history to bring up the details of
the build ->Console Output link to see the details of the build

How to Generate TestNG Reports Using Jenkins.


we need to have the following.

Step 1: Creating TestNG Project.


Step 2: Installing Jenkins.
We have TestNG Project and Jenkins ready.
Step 3: Installing TestNG Reports Plugin In Jenkins
Open Jenkins (localhost:8080) and click on ‘Manage Jenkins‘ and click on ‘Manage
Plugins‘

Click on ‘Available‘ tab and search TestNG Results Plugin and select the check box
against ‘TestNG Results Plugin‘ and click on ‘Install Without Restart‘

Open the ‘JenkinProject ‘Job which we have created earlier. Refer this How To
Create JenkinProject on Jenkins.
Click on ‘Configure’ and scroll down to ‘Post Build Actions’ and click on ‘Add Post
Build Actions’ drop down list.

Select ‘Publish TestNG Results‘

Enter TestNG XML Report Pattern as ‘**/testng-results.xml‘ and click on ‘Save‘


button

We have created a new project ‘JenkinProject‘ with the configuration to run TestNG
Tests and also to generate TestNG Reports after execution using Jenkins.
Let’s execute it now by clicking on ‘Build Now‘ button. It will invoke testng.xml
from the batch file.
Right click on Build Number (here in my case it is #1) and click on Console Output
to see the result.

Once the execution is completed, we could see a link to view ‘TestNG Results’.

This way, we could generate TestNG Reports using Jenkins.


How To Execute Maven Project Using Jenkins :
we need to have the following.
1. Maven – Check this Installation of Maven.
2. Maven Project – Check this Creating Maven Project.
3. Jenkins – Check this Installation of Jenkins.
Firstly install Maven in Eclipse IDE and create a Maven Project. Next, open Jenkins
and create a new Job to execute Maven Project using Jenkins.
Execute Maven Project Using Jenkins:

Click on New Item link to create a job on Jenkins

Enter an item name (here I am adding a name ‘MavenProject’) and click on FreeStyle
Project and click on OK

Scroll down to ‘Build‘ option. Click on ‘Add Build Step‘ and choose the value
‘Invoke top-level Maven targets‘ from the drop down list.
Enter Goals “clean install”
Enter POM path (in my case the path is E:\SeleniumSoftware dump\
SeleniumMavenProject\pom.xml)
Click on ‘Apply‘ and ‘Save‘

We have created a new project ‘MavenBankingProject‘ with the configuration to


execute MavenBankingProject using Jenkins. You could see in the below screenshot.

Let’s execute it now. Click on ‘Build Now‘ button. It will invoke pom.xml.

Right click on Build Number (here in my case it is #10) and click on Console Output
to see the result.

You could see Build Status ‘failure’ on Console Output.

This way, we could execute Maven Project using Jenkins.

Schedule your build in Jenkins for periodic execution


Jenkins comes with very good functionality in which we can schedule jobs which we
created
You can schedule build for existing jobs which already created and while creating
new project also we can specify the same.
Let’s schedule the job. Refer the below screenshot
Step 1-
Open job which we created now and Click on configure > select the check box build
periodically

Step 2-
Specify the time here we need to careful about the syntax
Jenkins works on Cron pattern for more info aboy cron refer cron
linkhttp://en.wikipedia.org/wiki/Cron
Jenkins will accept 5 parameter lest discuss one by one
* * * * *
Here first parameter- specify minute and range will vary from 00-59
Here second parameter- specify hours and range will vary from 0-23
Here third parameter- specify day and range will vary from 0-6 here 0 and 6 will be
Sunday
Here fourth parameter- specify month and range will vary from 0-11
Here fifth parameter- specify year so here you can specify *
Example 1- if you specify 00 22 * * * it means your build will run daily @ 10
PM

Finally, we have executed our test case successfully.

IMPORTENT Questions :

IMPORTENT Questions :

 What is default package of selenium?


 Maximizing Browser Window?
 What are the prerequisites to run selenium webdriver?
 What are the flavors of selenium ?
 Diff b/w Verify and Assert ?
 How to Verify Element is visible or not?
 How to Verify Element is Enable or disable?
 What is the diff b/w findelement and findelements in selenium?
 Verify Single checkbox/radio button is selected or Not ?
 Verify Multiple checkboxes/ radio buttons are selected or Not ?
 How to handle Popup window ?
 How to handle multiple windows ?
 How to perform dragAndDrop operation in selenium webdriver ?
 How to handle multiple actions at a time in selenium?
 How to perform double click in selenium?
 How to select dropdown value inside a frame?
 How to get all the frames on webpage ?
 How to handle Nested frames(frame inside frame) using selenium ?
 How Switch back to Main page from Frame ?
 Suppose I have two submit buttons with same names on Webpage, here how can
u click on 1st submit button.
 Some times click() method it doesn’t work then how to perform click operation
in selenium?
 Some times sendKeys() method it doesn’t work then how to enter the value into
input field using selenium?
 How to verify particular text in a webpage ?or
How to verify successful message in selenium?
 Diff b/w driver.getwindowhandle() and driver.getwindowhandles()?
 Which Programming Languages Supported By Selenium WebDriver To Write Test
Cases?
 Which Different Element Locators Supported By Selenium WebDriver?
 What Is XPath and what Is use of It In WebDriver?
 xpath types and diff b/w them in selenium ?
 Can you tell me a difference between driver.get() and driver.navigate().to()
methods?
 Which Programming Languages Supported By Selenium WebDriver To Write Test
Cases?
 How to handle Web Based Popups/javascript alerts/handle alerts in selenium?
 Can we automate window based application's using selenium WebDriver?
 why should we go for javascript in selenium ?
 How to handle hidden and disable mode of the webelements in selenium ?
 How to verify successful message in a webpage ?
 How do you identify the Xpath of element on your browser ?
 What is the difference between absolute XPath and relative XPath?
 How To Handle Dynamic Changing IDs In XPath. ?

Example :
Xpath= //div[@id='post-body-3647323225296998740']/div[1]/form[1]/input[1]

In this XPath "3647323225296998740" Is changing every time when reloading the page.
How to handle this situation?
 What is the diff b/w close() and quit()?
 What Is the syntax to get value from text box and store It In variable. ?
 How to capture screenshot when test case failure In selenium webdriver ?
 Tell me any 5 webdriver common exceptions which you faced during software
test case execution. ?
 What is Difference between getAttribute() and getText()?
 To verify whether the particular text is present/exist or not on the page ?
 Difference between selenium and qtp ?
 Tell me about the brief introduction of selenium ?
 Does selenium support mobile application testing ?
 How to identify webelement in selenium ?
 when we will go for xpath in selenium ?
 How to handle dynamic objects in selenium ?
 what are the locators available in selenium ?
 what is the default timeout for selenium ?
 Difference between findelement() and findelements() in selenium ?
 How to handle the Expected alerts in webdriver ?
 How to handle the UnExpected alerts in webdriver ?
 what is isDisplayed in selenium ?
 How to select the dropdown values in selenium ?
 Implicit and Explicit Wait (Test Synchronization) in selenium?
 How to perform drag and drop operation in selenium webdriver ?
 Explain your Roles and Responsibilities in your project ?
 which tool did you use for reporting ?
 What is the alternate way to send text into textbox of webpage with out using
sendKeys() method ?
 If any button is hidden/disabled then how to click on button using selenium ?
 How do you launch IE/chrome browser?
 How to perform right click using WebDriver?
 How do you simulate browser back , forward and refresh?
 What is the difference between ‘/’ and ‘//’ ?
 What is the use of AutoIt tool ?
 Why should we use javascript in selenium?
 How to count the number of checkboxes checked in selenium webdriver ? or How
to select multiple check box and verify ?
 What are the benefits of automation testing.
 Does Selenium WebDriver Support Record And Playback Facility?
 Selenium WebDriver Is Paid Or Open Source Tool? Why you prefer to use It?
 How to press ENTER key button on text box In selenium webdriver?
 Can you tell me the alternative driver.get() method to open URL In browser?
 Do you have faced any technical challenges with Selenium WebDriver software
test automation?
 Tell me a scenario which we can not automate In selenium WebDriver.
 What are the advantages of TestNG over JUnit.
 When we can use Actions class In Selenium WebDriver test case?

TestNg :

 What is TestNg ?What is the use.?


 What is Annotation ? How many Annotations are there in TestNg ?
 Difference between junit and TestNg ?
 what is the difference between verify and assert command ?
 Is it possible to write to multiple test cases in single class ?
 How to create test suites(or xml file) in testng ?
 what is the library file of testng or what is the default package of testng?
 How to set priority of @Test method? What Is Its usage?
 What Is the usage of testng.xml file?
 Where we can create the testng.xml file?
 How to run the xml file in testng?
 Why need Ant-xslt-reports ?
 What is the meaning of system.getProperty("user.dir") in selenium ?
 How to run smoke testing in selenium ?
 How to run sanity testing in selenium ?
 How to run both smoke and sanity testing in selenium ?
 What is a parallel testing ?
 Why it is required parallel testing in selenium?
 How to run only failure test cases in selenium?
 How to scedule the job using jenkin ?
 how to email the test reports for test lead through Jenkin using selenium?
 How to run xml file from command prompt?
 How to create the batch(.bat) file in selenium?
 What is a log files?
 Why it is required log files in selenium?
 What is your project build tool?
 where we can use Data driven framework in selenium?
 Diff b/w javaproject and maven project.
 How to read and write the data from Excel file using poi?
 How to get the string type cell value from excel sheet using poi jar?
 How to get the Numaric type cell value from excel sheet using poi jar?
 How to compare one excel data with another excel data ?
 How to covert double type value into string ?
 How to print the 3rd column data from webtable in selenium?
 How to print the 3rd column and 2nd row data from webtable in selenium?

Java :

 What is inheritance in java?


 what is a method(or)function in java?
 why we are using method or function in selenium?
 whatis diff b/w List and ArrayList in selenium ?
 What is diff b/w local and global variable in java ?
 What is a type casting in java ?
 Can we declare string as a data type?
 Write synatax for Nested if-else in java ?
 Why we are using for-loop ?
 How to reverse string in java?
 Write a program to reverse a string without using reverse function.

package JAVAExamples;

public class StringReverse {


public static void main(String[] args) {
//String to reverse.
String str = "This Is String.";
String revstring = "";

for (int i = str.length() - 1; i >= 0; --i) {


//Start getting characters from end of the string.
revstring += str.charAt(i);
}

System.out.println(revstring);
}
}

 Write program to print fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21,...

 int x=10 and y=20. Swap both variable values without using any temp variable.
 int x=10 and y=20. Swap both variable values with using any temp variable.
 Write a program to print below given pattern.

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
 How to convert integer value into string type?
 What are the access modifiers in java?
 what is the difference between == and equals() in java
 How to handleException Handling in Java ?

1.Open the Firefox browser


2.Navigate the AppURL
3.Maximize the browser window
4.scroll till the target element(News)
5.click on target element(News)

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();",
element);

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Can we perform scroll operation into selenium directly ?


*************************************************************
Ans : NO, but we can perform scroll operation in selenium with the help of
javascript code

How to scroll Vertically UP / Down in selenium ?


*****************************************************
Here Selenium with the help of Javascript code to scroll Vertically UP / Down

How to scroll Vertically Down in selenium javascriptExecutor Interface?


**************************************************************************

Syntax
***********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Example
**************

//scroll Vertically Down by 500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");

Program
************

How to scroll Vertically Up in selenium javascriptExecutor Interface?


**************************************************************************

Syntax
***********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Example
**************

//scroll Vertically UP by -500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-500)");

Program
************
How to scroll Horizontally Left / Right in selenium ?
*****************************************************
Here Selenium with the help of Javascript code to scroll Horizontally Left / Right

How to scroll Horizontally Right in selenium javascriptExecutor Interface?


*****************************************************

Syntax
***********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Example
**************

//scroll Horizontally Right by 500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(500,0)");

program
***********

How to scroll Horizontally Left in selenium javascriptExecutor Interface?


*****************************************************

Syntax
***********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Example
**************

//scroll Horizontally Left by -250 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(-250,0)");

program
***********
//scroll Horizontally Right by 500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(500,0)");

//wait 5 sec

Thread.sleep(5000);

//scroll Horizontally Left by -250 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(-250,0)");

How to scroll to a particular element/target element using selenium


javascriptExecutor?
**********************************************************************

Manual Steps
*************
Selenium Javascript code
***********************

scrollIntoView() : By using this we can scroll till the target element

What are the common exceptions u faced in ur project ?


***********************************************************

1.TimeOut exception
2.NoSuchElement exception
3.InvalidOrgumentException / webdriver exception
4.NoAlertPresent exception
5.elementNotVisible exception

1.NoSuchElement exception
**************************
2.InvalidOrgumentException / webdriver exception
*************************************************

3.elementNotVisible exception
*********************************
case 1:

How to verify particular element is visible or not in selenium ?


*******************************************************************
Case 2:

if(driver.findElement(By.linkText("News")).isDisplayed())
{

driver.findElement(By.linkText("News")).click();

System.out.println("News element is visible");


}else
{
System.out.println("Unable to locate the News element");
}

Case 3 :

//wait 10 sec
Thread.sleep(10000);
School project
*****************

Case 1
*************

abstract class
*****************

//concreate methods

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})

//abstract method

4.fee-------------50%-----incomplete knowledge (abstract void fee();)

Case 2
*************

//concreate class
*************************
//concreate methods

1.Teacher---------100%-----complete knowledge (void teacher(){})


2.Student---------100%-----complete knowledge (void student(){})
3.chortboard------100%-----complete knowledge (void chortboard(){})
4.fee-------------100%-----complete knowledge (void fee(){})

Case 3
*************
interface concept
**********************

//abstract methods

1.Teacher---------50%-----complete knowledge (abstract void teacher();)


2.Student---------50%-----complete knowledge (abstract void student();)
3.chortboard------50%-----complete knowledge (abstract void chortboard();)
4.fee-------------50%-----complete knowledge (abstract void fee();)

Interface in java ?
***********************
When we will go for interface in java and selenium ?
*******************************************************
Ans :

Example
************
Manual Steps
***************
1.Create Interface(Animal)
2.Create Subclass(Cat) from Interface(Animal)
3.Create Mainclass
abstract void atm();

Java code
***********

1.
2.
3.
4.
5.

Difference betweeen extends keyword and implements keyword in java ?


***********************************************************************

extends keyword : By using this ,we can inherit the subclass from superclass

implements keyword : To implement an interface in child class we must use


implements keyword

Note :
**********
>We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented inteface)

>We can create object for that implemented class

class and object in java ?


******************************
class and object examples
*****************************
Class : Vehicles Objects : car,bus,auto etc.
Class : Animals Objects : cat,dog,elephant etc.
Class : Furniture Objects : table,chair,cot etc.
Class : Fruits Objects : mango,orange,apple etc.

What is a object in java ?


****************************
Ans : It exists really / physically

Examples : car,cat,table,mango etc.

In general, object(Student) has two things


***********************************************8
1.state / properties
2.Behavior / Actions

What is a class in java ?


******************************
Ans : It doesn't exist really /physically

Example : Vehicles,Animals,Fruits,Furniture etc.

>Here class is a blueprint or Template or structure or design from which individual


objects a*a

are created
>Here always created from class to object,not object to class

In general car is a object and it has two things


**************************************************

1.state / properties
2.Behavior / Actions

Object syntax
*****************

Student S = new Student();

Object syntax Explanation


****************************

>Student()===>This is called Student constructor

>Here new is called keyword

Why we are using new keyword ?


********************************
Ans : By using new keyword,we can create Student object(new Student();)

>Here S is called object reference variable

>Here Student is called class

Class syntax
****************

class <classname>
{

//1.state / properties-----------vairables

<datatype> variablename 1;
<datatype> variablename 2;

//2.Behavior / Actions------------methods /functions

return-type methodname1()
{

}
return-type methodname2()
{

main()
{

}
}
class and object Example
**************************

Difference betweeen class and object in java ?


*********************************************
Class
*********
1.It doesn't exist really /physically

Example : Vehicles,Animals,Fruits,Furniture etc.

2.Why we are using class keyword ?


***************************************
Ans : By using class keyword,we can create class

3.In program,we can create class only once

4.Here memory space is not allowed when class is created

5.A class can contain variables and methods

Object
**********
1.It exists really / physically

Examples : car,cat,table,mango etc.

2.Why we are using new keyword ?


********************************
Ans : By using new keyword,we can create Student object(new Student();)

3.In program,we can create objects in multiple times

4.Here memory space is allowed when object is created

5.And object also can contain variables and methods

What are the different element Locators to identify the element in selenium ?
******************************************************

1. id----------1
2. Name---------2
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName---------3
7. cssSelector
8. Xpath---------------4

tagName locator in selenium ?


******************************

Ans :
Examples
************
1.
2.
************

How to count total links in a webpage ?


******************************************
Example
**********
Manual Steps
**************
1.Identify all the links
2.count total links in a webpage

Selenium Java code


**********************
//1.Identify all the links

List<WebElement> totalLinks = driver.findElements(By.tagName("a"));

System.out.println("totalLinks : "+totalLinks.size());//3

3.How to count total frames in a webpage ?


******************************************

Manual Steps
**************

1.Identify all the frames


2.count total frames in a webpage

Selenium Java code


**********************

//1.Identify all the frames

List<WebElement> totalFrames =
driver.findElements(By.tagName("iframe"));

System.out.println("totalFrames : "+totalFrames.size());//3

className locator in selenium ?


***********************************
Example
***********
Manual Steps
***************
1.Identify textbox(Enter keyword)
2.Enter text into textbox(Enter keyword)

Selenium Java code


**********************
WebDriver driver=new FirefoxDriver();

//Navigate the App Url


driver.get("https://www.facebook.com/");

//Identify and Enter the text into Enter keyword textbox

driver.findElement(By.className("inputtext _55r1
_6luy")).sendKeys("*********@gmail.com");

LinkText and partialLinkText locators in selenium ?


*****************************************************

Ans :

LinkText locator
***********

Syntax :
*************

driver.findElement(By.linkText("Entire text"));

Example
**********
driver.findElement(By.linkText("Verified Rights Owner (VeRO) Program"));

Program
***********

partialLinkText locator
***************************

Syntax :
*************

driver.findElement(By.partialLinkText("partial text"));

Example
**********
driver.findElement(By.partialLinkText("Owner (VeRO)"));

Program
***********

Multiple inheritance in java ?


*********************************

Here java doesn't support multiple inheritance (That means A class can't extend
multiple
classes)

Syntax:
*********
class Superclass1
{

}
class Superclass2
{

}
class Subclass extends Superclass1,Superclass2
{

Example
***********
class Father
{

}
class Mother
{

}
class Son extends Father,Mother
{

A class can implement multiple interfaces

Syntax:
**********

interface Interface1
{

}
interface Interface2
{

}
class Childclass implements Interface1,Interface2
{

}
Example
**********

interface Father
{

}
interface Mother
{

}
class Son implements Father,Mother
{

Program
*****
Manual Steps
*****************
1.Create Interface1(Father)
2.Create Interface2(Mother)
3.Create Child class(Son) from multiple
interfaces(Interface1(Father),Interface2(Mother))
4.Create Mainclass

Java code
************
1.
2.
3.
4.
5.

CAn we call the variable from interface ?


*****************************************
Ans : Yes

Syntax : Interfacename.variablename

CAn we call the variable from class ?


*****************************************
Ans : Yes

Syntax : classname.variablename

Note :
*********
>Here we can't create object for that interface but we can create reference for
that interface

Son S = new Son();//valid

Father S = new Son();//valid

Mother S = new Son();//valid

Father S = new Father();//invalid

Mother S = new Mother();//invalid

Flow-control in java ?
************************

Selection statements
************************
1.If statement
2.if-else statement
3.ladder if-else statement
4.switch statement

1.If statement
*********************

Syntax :
***********

if(condition-part / Testing-part) //here must be boolean condition


{

//if block
}

Syntax Explanation:
***********************

1.
2.

Example 1
*************
public class If_Statement {

public static void main(String[] args) {

int cat_age=5;
int dog_age=7;

if(cat_age==dog_age)
{

System.out.println("Animals age matched");


}

}
>Here if the condition is true then JVM will execute if block.
>Here if the condition is false then JVM will print nothing output
>But my requirement if the condition is true then JVM will execute if block,

if the condition is false then JVM has to print something in the console .so in
this

kind of situation we are going to use else part.

Example 2
*************
public class If_Statement {

public static void main(String[] args) {

int cat_age=5;
int dog_age=7;

if(cat_age==dog_age)
{

System.out.println("Animals age matched");


}else
{

System.out.println("Animals age not matched");


}

Conclusion
**************
1.Suppose if u want to check only true condition then we have to go if statement

2.Suppose if u want to check true /false condition then we have to go if-else


statement

Example 3
*************
public class If_Statement {

public static void main(String[] args) {

int A=100;

if(A) //here must be boolean condition


{

System.out.println("Hello");
}else
{

System.out.println("Hanumanth");
}

Code Explanation :
********************
>if(A)==>if(100)-->Here JVM will expecting boolean value not integral literal value
and

floating-point literal value.


>

Found : int
Required : boolean

Example 4
*************
public class If_Statement {

public static void main(String[] args) {

int A=100;

if(A>50) //here must be boolean condition


{

System.out.println("A is greater than 50");


}else
{

System.out.println("A is less than 50");


}

Example 5
*************
public class If_Statement {

public static void main(String[] args) {

int x=10;

if(x=20) //here must be boolean condition


{

System.out.println("Hello");
}else
{

System.out.println("Hanumanth");
}

}
>int x=10;//now onwards x value will become 20
>if(x),here x means what 20

>if(20)==>

F : int
R : boolean

Example 6
*************
public class If_Statement {

public static void main(String[] args) {

int x=10;

if(x==20) //here must be boolean condition


{

System.out.println("Hello");
}else
{

System.out.println("Hanumanth");
}

==-------->By using this,we can compare values / references / boolean value


=--------->By using this,we can assigning the value into variable

Example 7
*************
public class If_Statement {

public static void main(String[] args) {

boolean b=true;

if(b=false) //here must be boolean condition


{

System.out.println("Hello");
}else
{

System.out.println("Hanumanth");
}

}
>boolean b=true;now onwards b value will become false
>if(b),here means what false

>if(false)

F : boolean
R : boolean

Example 8
*************
public class If_Statement {
public static void main(String[] args) {

boolean b=false;

if(b==false) //here must be boolean condition


{

System.out.println("Hello");
}else
{

System.out.println("Hanumanth");
}

switch statement
*********************
>Suppose if u want to check one more conditions then we have to go switch statement

Syntax :
************

switch(Expression value){

case value1 : statement1--->code to be execute;

break;

case value2 : statement2--->code to be execute;

break;

case value3 : statement3--->code to be execute;

break;

default : statement4--->Here default case will be executed


when expression value
is not matched with
any case value;

Syntax Explanation:
************************

1.
2.
3.
4.
5.
6.

Example 1
**********
public class Switch_Statement {

public static void main(String[] args) {

int x=0;

switch(x){

System.out.println("Hanumanth");//error

}
>In switch block,every statement should be under case value or case label and
default case

>In switch block,independent statement is not allowed

Example 2
**********
public class Switch_Statement {

public static void main(String[] args) {

int x=0;

int y=1;

switch(x){

case 0 : System.out.println("Hello");//valid

case y : System.out.println("Hanumanth");//invalid

>In switch block,every case value should be constant not variable

Example 3
**********
public class Switch_Statement {

public static void main(String[] args) {

int x=10;

switch(x){

case 10 : System.out.println("Hello");//valid
case 11 : System.out.println("Hanumanth");//invalid

case 11 : System.out.println("Hanumanth");//invalid
}

}
>In switch block,duplicate case value not required

Example 4
**********
public class Switch_Statement {

public static void main(String[] args) {

//local variables

int x=0;

final int y=1;

switch(x){

case 0 : System.out.println("Hello");//Hello

case y : System.out.println("Hanumanth");//valid

What are the access modifiers in java ?


******************************************
Ans :

1.private
2.public
3.protected
4.default

Example 5
**********
public class Switch_Statement {

public static void main(String[] args) {

//local variables

byte b=10; // min -128 to max 127

switch(b){

case 10 : System.out.println("Hello");//valid
case 100 : System.out.println("Hi");//valid

case 1000 : System.out.println("Hanumanth");//invalid


}

}
>Here byte type variable can store in the range of the values min -128 to max 127

>Here case 10 is allowed in the range of the values min -128 to max 127

>Here case 100 is allowed in the range of the values min -128 to max 127

>Here case 1000 is not allowed in the range of the values min -128 to max 127

>In switch block,every case value should be in the range of argument type

Case value rules


********************
1.>In switch block,every case value should be constant not variable
2.>In switch block,duplicate case value not required
3.>In switch block,every case value should be in the range of argument type

fall-through inside switch block


*************************************
Definition :
***************
>Here expression value is matched with any case value,from that case onwards all
the statements

will be executed automatically until break statement then this concept is called
fall-through

Example 6
**********
public class Switch_Statement {

public static void main(String[] args) {

//local variables

int x=0;

switch(x){

case 0 : System.out.println("Hello");//

case 1 : System.out.println("Hi");//

break;

case 2 : System.out.println("Hanumanth");//
default : System.out.println("Kosmik");
}

Example 6
**********
public class Switch_Statement {

public static void main(String[] args) {

//local variables

char ch='r';

switch(ch){

case 'g' : System.out.println("green");//

case 'r' : System.out.println("Red");//

break;

case 'y' : System.out.println("yellow");//

default : System.out.println("no color");


}

default case rules


**********************
1.Here default case will be executed when expression value is not matched with any

case value

2.In switch block,we can write default case only once

3.In switch block,we can write default case anywhere but switch is recommended to
write

at last.

Example 7
**********
public class Switch_Statement {

public static void main(String[] args) {

//local variables

int furniture=0;

switch(furniture){
default : System.out.println("no furniture");

case 0: System.out.println("table");//

break;

case 1 : System.out.println("chair");//

case 2 : System.out.println("cot");//

Here why we are using break statement inside switch block ?


****************************************************

Ans : To stop the fall-through

Loops in java
*****************

Why we are using loops in java ?


*************************************
Ans : Here loops are used to execute a group of statements repeatedly as long as
the condition is true

Example
************
public class Loops_Statement {

public static void main(String[] args) {

System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");
System.out.println("Hanumanth");

types of loops
*************

3.forloop

Where exactly we can use forloop in java ?


**********************************************
Ans : Sometimes we need to perform same action with multiple times so at that time
we need to follow forloop

Syntax
***********

for(initialization-part ; condition-part/Testing-part ; increment/decrement-


part)
{
//loop body

Syntax Explanation
********************
1.
2.

Example 2
*************
Hpw to print (starting)1-10(ending) nos ?
****************************
1
2
3
4
5
...10

public class Switch_Statement {

public static void main(String[] args) {

for(int i=1;i<=10;i++)
{
System.out.println(i);

i++

i=i+1
i=1+1
i=2
-------------
i++

i=i+1
i=2+1
i=3

Example 3
**************

public class Switch_Statement {

public static void main(String[] args) {

int j=1; //local variable

for(int i=1;i<=5;i++)
{
System.out.println(i);

System.out.println(j);

System.out.println(i);

System.out.println(j);

Nested forloop(forloop inside another forloop) in java ?


***********************************************************

Syntax :
**************

for(initialization-part ; condition-part/Testing-part ; increment/decrement-part)


{

for(initialization-part ; condition-part/Testing-part ;
increment/decrement-part)
{

//Inner forloop body

}//Inner forloop end

//Outer forloop body

}//Outer forloop end

Syntax Explanation:
*********************

Example
**********

Output
*********
0 1 2
3 4 5
6 7 8

Difference betweeen print() and println() in java ?


*****************************************************
print() :
************

>By using this, we can print the text (Hello---)and the curser waits on the same
line to

print the next text

Example
***********
System.out.print("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
*********
Hello---Hi---
Hanumanth
println() :
************
>By using this, we can print the text and the curser move to next automatically

Example
***********
System.out.println("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
*********
Hello---
Hi---
Hanumanth

System.out.println(); // go to new line or next line


Selenium Automation Testing
*****************************

What is a Testing ?
*******************
Ans : To verify whether the functionality works well or not .i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure

Difference betweeen defect,error,failure ?--IQ


**************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

Types of Testing
*********************
1.Functional Testing
2.Non-functional Testing

Types of functional automation tools


**************************************
1.opensource
===============
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.sahi
4.badboy
5.ruby
6.watir etc.

2.commercial
===============
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen Selenium and Qtp ?--IQ


*********************************************
Selenium
**********
1.opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here Selenium + Appium----->Mobile app

Here Selenium + Autoit or sikuli or robot class--------->desktop app

Qtp
*********
>Commercial(paid tool)
>Vbscript
>FF,IE and chrome
>windows
>Webapp ,mobile app and desktop app

History of Selenium
*********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 toos

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium Webdriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium Webdriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium Webdriver + Extra features) + Selenium Grid


>2019

Selenium Components---IQ
************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

--------------------part 1
Java for selenium(core java enough)--------------part 2
********************

Java,

80%----------------->selenium webdriver +java(java oops concepts + collections)

TestNG---------part 3
**********

TestNG(latest)-------Junit(old)

Why we are using TestNG ?


*********************************
Ans :By using TestNG,we can create selenium automation test cases,execute the
selenium automation test cases,

it generate Test Reports and also generate log files.

Mainly Why we are using TestNG ?


*********************************
1.Selenium IDE generate Test Reports, but no details
2.Selenium RC outdated(old)
3.Selenium webDriver doesn't generate Test reports and here selenium webDriver with

the help of TestNG will generate the Test Reports.

Add three parts


********************

1 + 2 + 3----------->Selenium Webdriver + Java + TestNG

AutoIT
logs
grid
Git
jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework

TestNg(Next generation)
**************************

TestNg(latest)----Junit(old)
Why we are using TestNg ?
***************************
Ans : By using Testng,we can create selenium automation test cases,execute the
selenium automation test cases,

it generate Test Reports and also generate log files.

Mainly Why we are using TestNg ?


***************************
1.Selenium IDE generate the Test Reports but no details
2.Selenium Rc outdated(old)
3.Selenium webdriver doesn't generate the Test reports and here selenium webdriver

with the help of TestNG will generate the Test reports.

part 1
**********
1.Install TestNG into Eclipse
2.Verify TestNG successfully install or not into Eclipse
3.Add TesNG library files
4.Create TestNg class(Selenium Automation test case)

What is the default package of selenium ?


*******************************************
Ans :

What is the default package of TestNG ? or What is the TestNG library file ?
****************************************************************************
Ans : org.testng.annotations

i.e @Test--->

TestSteps
***************
>Open browser
>Navigate the App URL
>Verify OrangeHRM Login Page Title
>close the browser

Ant-XSLT-Reports(advanced html reports)


****************

>Convert Testng html reports into Ant-XSLT-Reports


>Email the Ant-XSLT-Reports(advanced html reports) for ur Test Lead and project
manager

Why we are using xml file ? or Why we are using Test suite ?
***************************************************************
Ans :
Where we can create xml file ?
***********************************
Ans :

How to create the xml file under package ?


**********************************************
Ans :

How to run xml file ?


***********************
Ans :

ArrayList in java ?(collection topic)


*************************

Why we are using arraylist in java ?


****************************************
Ans :

Example
***********

>Suppose if u want to store only integer values in an arrayList then we should


follow below syntax

ArrayList<Integer> arraylist = new ArrayList<Integer>();

arraylist.add(10);//store 10 in an arraylist through add()


arraylist.add(20);//store 20 in an arraylist through add()
arraylist.add(30);//store 30 in an arraylist through add()
arraylist.add(40);//store 40 in an arraylist through add()

>Suppose if u want to store only float values in an arrayList then we should follow
below syntax

ArrayList<Float> arraylist = new ArrayList<Float>();

arraylist.add(10.1f);//store 10 in an arraylist through add()


arraylist.add(20.2f);//store 20 in an arraylist through add()
arraylist.add(30.3f);//store 30 in an arraylist through add()
arraylist.add(40.4f);//store 40 in an arraylist through add()

>Suppose if u want to store only double values in an arrayList then we should


follow below syntax

ArrayList<Double> arraylist = new ArrayList<Double>();

arraylist.add(10.1);//store 10 in an arraylist through add()


arraylist.add(20.2);//store 20 in an arraylist through add()
arraylist.add(30.3);//store 30 in an arraylist through add()
arraylist.add(40.4);//store 40 in an arraylist through add()

>Suppose if u want to store only String values in an arrayList then we should


follow below syntax
ArrayList<String> arraylist = new ArrayList<String>();

arraylist.add("Sai");//store 10 in an arraylist through add()


arraylist.add("Akki");//store 20 in an arraylist through add()
arraylist.add("Hanu");//store 30 in an arraylist through add()
arraylist.add("Kosmik");//store 40 in an arraylist through add()
>Suppose if u want to store only boolean values in an arrayList then we should
follow below syntax

ArrayList<Boolean> arraylist = new ArrayList<Boolean>();

arraylist.add(true);//store 10 in an arraylist through add()


arraylist.add(true);//store 20 in an arraylist through add()
arraylist.add(false);//store 30 in an arraylist through add()
arraylist.add(true);//store 40 in an arraylist through add()

>Suppose if u want to store only character values in an arrayList then we should


follow below syntax

ArrayList<Character> arraylist = new ArrayList<Character>();

arraylist.add('a');//store 10 in an arraylist through add()


arraylist.add('b');//store 20 in an arraylist through add()
arraylist.add('c');//store 30 in an arraylist through add()
arraylist.add('d');//store 40 in an arraylist through add()

>Suppose if u want to store int,float,double,string,boolean, character values in an


arrayList then we should follow below syntax

ArrayList arraylist = new ArrayList();

arraylist.add(10);//store 10 in an arraylist through add()


arraylist.add(10.3f);//store 20 in an arraylist through add()
arraylist.add(2.5);//store 30 in an arraylist through add()
arraylist.add("Sai");//store 40 in an arraylist through add()
arraylist.add(true);//store 30 in an arraylist through add()
arraylist.add('d');//store 40 in an arraylist through add()

Can we store duplicate values in an arrayList ?


*****************************************************
Ans : Yes

CAn we remove 20 in an arralist ?


*************************************
Ans : Yes

Syntax:
*********

arraylist.remove(index);

Example
***********

arraylist.remove(1);//removed 20 in the position of 1

Program
**********
Can we replace 20 with 50 in an arrayList ?
*************************************************
Ans : Yes

Syntax :
***********
arraylist.set(int index,Object obj);

Example
*********

arraylist.set(1,50); // replace 20 with 50 in the position of 1

Program
***********

Can we insert / add 50 in the position of 1 ?


*************************************************
Ans : Yes

Syntax :
***********

arraylist.add(int index,Object obj);

Example
*********

arraylist.add(1,50); //insert / add 50 in the position of 1

Program
************

Can we remove all the values present in the arrayList ?


*********************************************************
Ans : Yes

Syntax:
************

arralist.clear();

Example
************

arraylist.clear();//remove all the values present in the arrayList

Program
*********
Verify arraylist has empty or not ?
***************************************

>If arraylist has empty then it returns true


>If arraylist has not empty then it returns false

Syntax :
***************
arraylist.isEmpty();

Example
***********

arraylist.isEmpty();//Verify arraylist has empty or not

How to login with xls file using poi jar ?


****************************************

How to login with xlsx file using poi jar ?


****************************************

Difference betweeen == and equals() in java ?


***********************************************

Student S1 = new Student("Hanumanth");

Student S2 = new Student("Hanumanth");

>equals() : By using this ,we can compare strings / content

>== : By using this, we can compare references / values

System.out.println(S1==S2);//false

System.out.println(S1.equals(S2));//true

>= :By using this, we can assigning the value into variable

int x=10;

How to Verify Random Dropdown Values Using _xlsFile ?


*************************************************

0 1 2
2 3 4
5 6 7

Selenium 1st class


**********************

How to Verify multiple rows and columns of the Webtable data Using _xlsFile?
**************************************************************
Company Contact Country

Selenium 1st class


**********************

1 + 2 + 3------->Selenium Webdriver + Java + TestNG

What are the prerequisites to run the selenium webdriver ?--IQ


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

Ans :

1.JDK file
2.Eclipse IDE / oxygen
3.Selenium Jar files
4.Testing Application
5.Browser(Firefox)

Part 1
**********
1.Create new Javaproject
2.Create new package
3.Create new Class
4.Add selenium java jar files for that project
5.Download / Add geckoDriver for that project

Why we are using selenium java jar files ?


************************************************
Ans :

Where we can get the selenium java jar files ?


***************************************************
Ans :

Handle popups :

************************
1. How to Handling Web-Based alert Popup/Javascript Alert Popup ?
2. How to Handling modal popup window ?
3. How to Handling multiple windows ?

How to Handling Web-Based alert Popup/Javascript Alert Popup ?


******************************************************************
diagram:
************
Manual Steps
***************
>switch to alert
>Verify Alert text
>click on ok

Selenium Java code


*********************

//switch to alert

Alert alt = driver.switchTo().alert();

//-----------Verify Alert text----------------------

//---------------------------------------------------------Operation
code

String alert_text = alt.getText();

System.out.println(alert_text);//You Have Succesfully Logged Out!!

//---------------------------------------------------------Verification
code

if(alert_text.equals("You Have Succesfully Logged Out!!"))


{
System.out.println("Alert text verified successfully");
}else
{
System.out.println("Alert text not verified successfully");
}

//click on ok

alt.accept();

2. How to Handling modal popup window ?


*********************************************

diagram:
************

Manual Steps
***************
>Switch to model popup window
>Do some action
>click on model popup window

Selenium Java code


*********************
//>Switch to model popup window
driver.switchTo().window(driver.getWindowHandle());

//>Do some action

//>click on model popup window

driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();

3. How to Handling multiple windows ?


*******************************************

Data driven framework in selenium


************************************

What is a default package of selenium ?


**********************************************
Ans : org.openqa.selenium

Why we will import the packages ?


*************************************
Ans :

get() :

How to verify title of the webpage ?


****************************************
Testing = operation code + verification code

Manual Steps
***************
>Get the Title of the WebPage
>Print tile of the WebPage
>verify title of the webpage

Selenium Java code


********************

//-------------------verify title of the webpage-------------------------

//---------------------------------------------------------operation code

// Get the Title of the WebPage

String title = driver.getTitle();

//Print tile of the WebPage

System.out.println(title);//OrangeHRM - New Level of HR Management


//---------------------------------------------------------verification code

//verify title of the webpage

if(title.equals("OrangeHRM - New Level of HR Management"))


{

System.out.println("Title verified successfully");


}else
{
System.out.println("Title not verified successfully");

Selenium WebDriver
***********************

1.By using this,we can identify element / object

2.After identify the element then do some action on that element

Difference betweeen findElement() and findelements() in selenium ?


******************************************************************
Ans :

sendkeys() :

getText() :

return-type : String

getTitle() :

return-type : String

How to verify particular text in a webpage ? or

How to verify successfull message in selenium ?


*****************************************************

Testing = operation code + verification code

Manual Steps
***************
 Identify and get the Welcome Selenium Text
 Print the Welcome Selenium Text
 To verify whether the welcome page successfully opened or not

Selenium java code


*******************
//-----------------verify successfull message---------------------------

//---------------------------------------------------------operation
code
// Identify and get the Welcome Selenium Text

String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();

System.out.println(text);//Welcome selenium

//-----------------------------------------------------------verification
code

if(text.equals("Welcome selenium"))
{

System.out.println("Welcome page verified successfully");


}else
{
System.out.println("Welcome page not verified successfully");
}

How to Handle multiple windows in selenium?


************************************************

Manual Steps
*************

1.Count total windows


****************************
//----------------------1.Count total windows---------------------

Set<String> totalWindows = driver.getWindowHandles();

System.out.println("totalWindows : "+totalWindows.size());//2

2.Handle child windows


**************************
Manual Steps
*******************
a. switch to child window
b. do some action
c. close the child window

selenium java code


***************
//----------------------2.Handle child windows---------------------

//switch to child window


driver.switchTo().window(allWindowsHandle.get(1));

//do some action

System.out.println(driver.getTitle());

//close the child window

driver.close();

3.Handle Main windows


**************************
Manual Steps
*******************
a. switch to main window
b. do some action
c. close the main window

Selenium Java code


**********************

//-----------------------3.Handle Main windows-------------------------

//switch to main window

driver.switchTo().window(allWindowsHandle.get(0));

//do some action

System.out.println(driver.getTitle());

//close the main window

driver.close();

Handling Frames
******************
1.How to handle single frame ?
2.How to handle multiple frames ?
3.How to handle Nested frames(Frame inside another frame)

1.How to handle single frame ?


*********************************
a) How to print all the dropdown values ?
*********************************************
//---------------------How to get the dropdown size ------------------------------

Manual Steps
*****************
>First,get the dropdown size or count dropdown values

1.First,Identify dropdown
2.Next,Identify all the values from this dropdown

Selenium java code


*******************
//---------------------How to get the dropdown size ------------------------------

List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));

System.out.println("droplist size : "+droplist.size());//3

>print all the dropdown values


************************************

Selenium Java code


***********************

//---------------------How to get the dropdown size ------------------------------

List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));

System.out.println("droplist size : "+droplist.size());//3

//---------------------print all the dropdown values------------------------

for(int i=0;i<droplist.size();i++)
{

System.out.println(droplist.get(i).getText());

b) How to Select the dropdown value inside a frame


*****************************************************
diagram :
************

Manual Steps
*****************
>Switch to frame
>Identify dropdown
>Select the dropdown value

Selenium Java code


*********************

// Switch to frame by index

driver.switchTo().frame(0);

//1.First,Identify dropdown
WebElement dropdown = driver.findElement(By.id("loc_code"));

//>Select the dropdown value

Select S = new Select(dropdown);

S.selectByIndex(1);

c) verify selected value from dropdown


*****************************************
Manual Steps
****************

>get the selected value


>Verify selected value

Selenium Java code


*********************

//----------------verify selected value from dropdown--------------------

//-----------------------------------------------------operation code
//>get the selected value

String selected_value = S.getFirstSelectedOption().getText();

System.out.println("selected_value : "+selected_value);//Emp. Id

//----------------------------------------------------Verification code

if(selected_value.equals("Emp. Id"))
{

System.out.println("selected_value verified successfully");


}else
{
System.out.println("selected_value not verified successfully");
}

Action class in selenium


*************************

1.How to perform Drop & Drag operation in Selenium ?


********************************************************

Manual Steps
****************

Selenium Java code


***********************

2.How to perform Mouse hover in selenium?


********************************************
Manual Steps
****************
Selenium Java code
***********************

3.To verify whether the DoubleClick operation successfully performed or Not?


******************************************************************************
Manual Steps
****************

Selenium Java code


***********************

4.How to perform rightClick operation in selenium?


******************************************************

Action class in selenium


*****************************

1.How to perform Drop & Drag operation in Selenium ?


********************************************************
Manual Steps
***************

Selenium Java code


**********************

2.How to perform Mouse hover in selenium?


*********************************************

Manual Steps
***************

Selenium Java code


**********************

3.To verify whether the DoubleClick operation successfully performed or Not?


***********************************************************************

Manual Steps
***************

Selenium Java code


**********************

4.How to perform rightClick operation in selenium?


*******************************************************

Mouse actions in selenium


******************************

1.dragAndDrop()
2.moveToElement()
3.doubleClick()
4.contextClick()

Keyboard actions in selenium


******************************

1.sendKeys()
2.keyDown()-->perform the keypress without release
3.keyUp()--->perform the key release

Where exactly we can use sendKeys() in Action class?


*********************************************************
Ans : Suppose if u want to perform single action then we use sendKeys().

Examples:
***************

keyDown,keyUp,Enter,Delete,F11 ...etc

Action class code examples


******************************
1.sendKeys(Keys.ARROW_DOWN)
2.sendKeys(Keys.ARROW_UP)
3.sendKeys(Keys.ENTER)
4.sendKeys(Keys.F11)
5.sendKeys("a")
6.sendKeys(Keys.DELETE)

Where exactly we can use keyDown() and keyUp() in Action class?


*********************************************************
Ans : Suppose if u want to perform multiple actions at a time then we use
keyDown() and keyUp().

Examples
************

Ctrl +a,Ctrl +c,Ctrl +v,Alt+N,Shift +a,Ctrl+F11 ....etc.

Action class code examples


******************************

Ctrl +a = Ctrl press + press a + ctrl release

Ctrl +a = keyDown(Keys.CONTROL) + sendKeys("a") + keyUp(Keys.CONTROL)

Shift +a = Shift press + press a + Shift release


Shift +a = keyDown(Keys.SHIFT) + sendKeys("a") + keyUp(Keys.SHIFT)

How to perform Ctrl +a in selenium


************************************

Constructor in java
**********************
This is similar to method

Why need constructor in java ?


**********************************
Ans :

Types of constructors
**********************
1.default constructor
2.parameterized constructor

1.default constructor
************************
Syntax :
*************

Student()
{

2.parameterized constructor
******************************
Student(int i)
{

>Here constructor doesn't return any value not even void

In method,return-type is mandatory ?
**************************************
Ans :Yes

Example
***********
void m1()
{

When default constructor will be called ?


********************************************
Ans : Whenever u create an object by default default constructor will be called
When parameterized constructor will be called ?
********************************************
Ans : Whenever u create an object and passing the values then parameterized
constructor will be called

When function will be called ?


***********************************
Ans : Whenever u create an object after function will be called

In default constructor,how to initialize the values for that instance variables ?


***********************************************************************************
Student()
{
name = "Sai";
rollno = 101;

}
Example
**************

In parameterized constructor,how to initialize the values for that instance


variables ?
***********************************************************************************

Student(String Akki,int 102)


{

name = Akki;

rollno = 102;

Example
**************

3.A method is called and executed multiple times from single object
**********************************************************************88

Example
**********

4.A constructor is called and executed only once from single object .
*************************************************************************

Example
************

In java,constructor overloading is possible ?


***********************************************
Ans : Yes
What is a constructor overloading in java ?
************************************************
Ans : Here constructor name same but with different argument types then this
concept is called

constructor overloading .

>Here instance variable and local variable both are not same in this case this
keyword an optional
***********************************************************************************
**

Example
**********

>Here instance variable and local variable both are same in this case we have to
create this keyword

Example
**********

this keyword in java ?


***********************
Example 1
*************

How to call the instance variable from this keyword ?


*********************************************************
Syntax : this.variablename

How to call the default constructor from this keyword ?


*********************************************************
Syntax : this();

How to call the parameterized constructor from this keyword ?


*********************************************************
Syntax : this(value1,value2);

How to call the method from this keyword ?


*********************************************************
Syntax : this.methodname();

Example 2
*************

Calling parameterized constructor and method from default constructor


**************************************************************************

Calling default constructor from parameterized constructor


***********************************************************

Calling parameterized constructor from parameterized constructor


*******************************************************************

xpath in selenium
**********************
1.
2.
3.

xpath types
*************
1.Absolute xpath
2.Relative xpath

How to get the Absolute xpath and Relative xpath in firefox ?


**************************************************************
Ans : By using selectorsHub

How to install selectorsHub into firefox ?


**********************************************
Ans :

Absolute xpath
*******************
/html[1]/body[1]/div[1]/div[3]/form[1]/div[1]/div[1]/div[1]/div[1]/div[2]/input[1]

Relative xpath
****************

//input[@title='Search']

How to get the Absolute xpath and Relative xpath in chrome ?


**************************************************************
Ans : By using selectorsHub

How to install selectorsHub into chrome ?


**********************************************
Ans :

Absolute xpath
****************
/html[1]/body[1]/div[1]/div[3]/form[1]/div[1]/div[1]/div[1]/div[1]/div[2]/input[1]

Relative xpath
******************
//input[@title='Search']

How to get the Absolute xpath and Relative xpath in IE ?


**************************************************************
Ans : By using Fire-ie- browser tool

How to download Fire-ie- browser tool ?


*******************************************
Ans :

Absolute xpath
****************
/html[1]/body[1]/div[1]/div[3]/form[1]/div[1]/div[1]/div[1]/div[1]/div[2]/input[1]
Relative xpath
******************
//input[@title='Search']

Difference betweeen Absolute xpath and Relative xpath in selenium ?


******************************************************************

How to handle dynamic elements / objects in selenium ?


*************************************************

Here Selenium(Relative xpath) + xpath functions(starts-with()) ------>to handle


dynamic elements / objects

//input[starts-with(@name,'btnchkavail')]

driver.findElement(By.xpath("//input[starts-with(@name,'btnchkavail')]")).click();

Relative xpath syntax:


*************************

//tagName[@Attributename='value']

//button[starts-with(@id,'continue')]

//button[ends-with(@id,'continue')]

//button[contains(@id,'188')]

driver.findElement(By.xpath("//button[contains(@id,'188')]")).click();

What are the xpath functions in selenium ?


***********************************************

>starts-with(),ends-with(),contains(),text(),position()

text()
***********
1.
2.

Element : Welcome to Hanumanth

Html code
**********

<h1>Welcome to Hanumanth</h1>

Syntax :
***********
//tagName[text()='value']

Example
***********

//h1[text()='Welcome to
HanumanthsahgdjhasgjkdhasjkhdjkahskdjhaskjdhkjaHDSLKJAHkjshAKJHSKJahskjhAS']

Program
**********

xpath function : contains()


*****************************
1.
2.

Html code
**********

<h1>Welcome to
HanumanthsahgdjhasgjkdhasjkhdjkahskdjhaskjdhkjaHDSLKJAHkjshAKJHSKJahskjhAS</h1>

Syntax :
***********

//tagName[contains(text(),'value')]

Example
*********

//h1[contains(text(),'Hanumanth')]

Program
**********

xpath function : position()


*****************************

Example 1
*********

//h1[contains(text(),'Hanumanth')][position()=2]

Example 2
*********

How to handle same name of the element/objects ?


***************************************************

Here Selenium(Relative xpath) + xpath function(position())------>to handle same


name of the element/objects
Relative xpath Syntax
************************

//tagName[@attributeName='value']

xpath function
*****************
position()

Example
***********

//input[@name='chk'][position()=5]

How to write the absolute xpath and relative xpath in manually ?


************************************************************************

How to write the Relative xpath for that password ?


******************************************************

Element : Password

Html code
**************

<input type="text" name="password">

Syntax :
**********

//tagName[@attributeName='value']

Example
**********

//input[@name='password']

Program
***********

How to write the Relative xpath for that Gmail ?


******************************************************
Element : Gmail

Html code
**************

<a class="gb_f" data-pid="23" href="https://mail.google.com/mail/?


authuser=0&amp;ogbl" target="_top">Gmail</a>

Syntax :
**********

//tagName[@attributeName='value']

Example
**********

//a[@class='gb_f']

Program
***********

How to write the absolute xpath for that username ?


******************************************************

write the absolute xpath for that Gmail : follow the red line

/html/body/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/a

How to write the absolute xpath and relative xpath in manually ?


*******************************************************************

How to write the absolute xpath password ?


*******************************************

How to write the absolute xpath for that Username ?


*******************************************

write the absolute xpath for that Username : Follow the Red line

How to write the absolute xpath for that Gmail ?


**********************************************

write the absolute xpath for that Gmail : Follow the Red line

/html/body/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/a

How to write the Relative xpath for that Username ?


*******************************************

Element : Username
Html code
**************

<input type="text" name="username">

Syntax :
***********

//tagName[@attributeName='value']

Example
********

//input[@name='username']

Program
**********

// Open the firefox browser

WebDriver driver = new FirefoxDriver();

// Navigate the application url

driver.get("file:///E:/Browser%20Elements/Browser%20Element.html");

driver.findElement(By.xpath("//input[@name='username']")).sendKeys("selenium");

How to write the Relative xpath for that Password ?


*******************************************

Element : Password

Html code
**************

<input type="text" name="password">

Syntax :
***********

//tagName[@attributeName='value']

Example
********

//input[@name='password']

Program
**********

// Open the firefox browser

WebDriver driver = new FirefoxDriver();


// Navigate the application url

driver.get("file:///E:/Browser%20Elements/Browser%20Element.html");

driver.findElement(By.xpath("//input[@name='password']")).sendKeys("selenium123");

How to write the Relative xpath for that Gmail ?


*******************************************

Element : Gmail

Html code
**************

<a class="gb_f" data-pid="23" href="https://mail.google.com/mail/?


authuser=0&amp;ogbl" target="_top">Gmail</a>

Syntax :
***********

//tagName[@attributeName='value']

Example
********

//a[@class='gb_f']

Program
**********

// Open the firefox browser

WebDriver driver = new FirefoxDriver();

// Navigate the application url

driver.get("file:///E:/Browser%20Elements/Browser%20Element.html");

driver.findElement(By.xpath("//input[@name='password']")).sendKeys("selenium123");

How to read the property files or How to with property files?


*****************************************************************

What is a Inheritance ?
****************************
Ans :
What are the advantages of inheritance ?
******************************************
Ans :

1.
2.
3.
4.

Syntax:
***********
class Superclass
{

}
class Subclass extends Superclass
{

Example
**********
Manual Steps
***************
1.Create Superclass(TestBaseClass)
2.Create Subclass(MultipleCustomersLoginTest) from Superclass(TestBaseClass)

Selenium Java code


********************

In superclass
****************

common code + Additional code(optional)

common code
**************
1.Open the browser(@B.C)
2.close the browser(@A.C)
3.Reusable functions

In subclass
***************

Additional code(mandatory)

>In this i will be keeping all the selenium automation test cases

@Test--->

How to verify xpath is valid or not into Firefox ?


******************************************************
Syntax :
***********

$x("path")

Example
**********

$x("//input[@name='q'")

How to verify xpath is valid or not into chrome ?


******************************************************

How to handle dynamic element/objects in selenium ?


*****************************************************
Ans : Here Selenium(Relative xpath) + xpath functions(starts-with,ends-
with,contains)--->to handle dynamic element/objects

How to handle same name of the element/objects in selenium ?


*************************************************************
Ans : Here Selenium (Relative xpath)+ xpath function(position())--->to handle same
name of the element/objects

How to handle hidden/disabled mode of the element/objects in selenium ?


************************************************************************
Ans : Here selenium + Javascript---->to handle hidden/disabled mode of the
element/objects

Why should we go for javascript in selenium ?


*************************************************
Ans :

javascript syntax
*******************

(javascriptExecutor)driver.executeScript(script,argument);

Syntax Explanation
*********************

>(javascriptExecutor)driver==>Convert driver object variable into


javascriptExecutor

>javascriptExecutor==>Here javascriptExecutor it's an interface,which will help us

to execute the javascript code through selenium webdriver.

>executeScript==>Here javascriptExecutor can contain executeScript(),by using


this(executeScript())

we can execute the javascript code.

>script==>This is a javascript code


>argument==>This is a argument to the javascript code

javascript syntax
*******************

(javascriptExecutor)driver.executeScript(script,argument);

Example
***************

((JavascriptExecutor) driver).executeScript("arguments[0].value =
'selenium';",driver.findElement(By.name("frame")));

Note :
********

By default javascript,it understand arguments[0] for that every single element

CAn we perform scroll operation in selenium directly ?


***********************************************************
Ans : No,but we can perform scroll operation with the help of javascript

How to verify xpath is valid or not into firefox?


***************************************************

Element : SearchBox

Html code
************

<input class="gLFyf gsfi" jsaction="paste:puy29d;" maxlength="2048" name="q"


type="text" aria-autocomplete="both" aria-haspopup="false" autocapitalize="none"
autocomplete="off" autocorrect="off" autofocus="" role="combobox"
spellcheck="false" title="Search" value="" aria-label="Search" data-
ved="0ahUKEwjdlfLigPPxAhXVyzgGHbJdCB0Q39UDCAQ">

Syntax
**********

$x("xpath")

Example
********

$x("//input[@name='q']")

How to verify xpath is valid or not into chrome?


***************************************************

Element : SearchBox

Html code
************
<input class="gLFyf gsfi" jsaction="paste:puy29d;" maxlength="2048" name="q"
type="text" aria-autocomplete="both" aria-haspopup="false" autocapitalize="none"
autocomplete="off" autocorrect="off" autofocus="" role="combobox"
spellcheck="false" title="Search" value="" aria-label="Search" data-
ved="0ahUKEwjdlfLigPPxAhXVyzgGHbJdCB0Q39UDCAQ">

Why should we go for javascript in selenium ?


************************************************
Ans :

1.
2.

How to handle dynamic element/objects in selenium ?


*********************************************
Ans : Here selenium(Relative xpath)+ xpath functions(starts-with,ends-
with,contains)--->to handle dynamic element/objects

How to handle same name of the element/objects in selenium ?


**************************************************************
Ans :Here selenium(Relative xpath)+ xpath function(position())--->to handle same
name of the element/objects

How to handle hidden/disabled mode of the element/objects in selenium ?


********************************************************************
Ans : Here Selenium +javascript---->to handle hidden/disabled mode of the
element/objects in selenium ?

javascript syntax
*******************

(javascriptExecutor)driver.executeScript(script,argument);

Syntax Explanation
***********************

>(javascriptExecutor)driver==>Convert driver object variable into


javascriptExecutor

>javascriptExecutor==>Here javascriptExecutor it's an interface,which will be help


us

to execute javascript code through selenium webDriver

>executeScript==>Here javascriptExecutor can contain executeScript(),by using


this(executeScript())

we can execute the javascript code.

>script==>This is a javascript code

>argument==>This is a argument to javascript code

Example
***********
Note :
*********
By default javascript,it understand arguments[0] for every single element

1.How to read the properties files ? or How to work with properties files ?
******************************************************************************

Why need property files ?


***************************
Ans :

Example
***********
Manual Steps
************

Selenium Java code


*********************

Read the config.properties file


**********************************

1.Create properties object for that config.properties file

Properties config = new Properties();

2.How to access the config.properties file into working environment

FileInputStream fis = new FileInputStream("E:\\Selenium Files\\


com.Banking.OpenCart\\src\\main\\java\\com\\Banking\\PropertyFile\\
config.properties");

3.Store config.properties file in an memory location

config.load(fis);

Read the OR.properties file


**********************************

1.Create properties object for that OR.properties file

Properties OR = new Properties();

2.How to access the OR.properties file into working environment

FileInputStream fiss = new FileInputStream("E:\\Selenium Files\\


com.Banking.OpenCart\\src\\main\\java\\com\\Banking\\PropertyFile\\OR.properties");
3.Store OR.properties file in an memory location

OR.load(fiss);

Selenium Automation Testing


****************************

What is a Testing ?
***********************
Ans : To verify whether the functionality works well or not . i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure

Difference betweeen defect,error and failure ?--IQ


****************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

Types of Testing
****************
1.Functional Testing
2.Non-functional Testing

Types of functional Automation tools


***************************************
1.opensource
===============
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.sahi
4.badboy
5.ruby
6.watir etc.

2.commercial
===============
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference between selenium and Qtp ?--IQ


**************************************
selenium
***********
1.Opensource(free of cost)
2.Java,c#,python,ruby,perl and php
3.FF,IE,Chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app only

Here Selenium + Appium--->mobile app

Here Selenium + AutoIT or sikuli or robot class---->desktop app

QTP
********
1.commercial(paid tool)
2.Vbscript
3.FF,IE and chrome
4.Windows
5.Webapp , mobile app and desktop app

History of selenium
**********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium Webdriver + Selenium Grid


>It was came into 2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium Webdriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium Webdriver+Extra features) + Selenium Grid


>2019

Selenium Components---IQ
***************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

-------------------------------------part 1

Java for selenium(core java enough) -------------part 2


**********************

Java,
80%------------>selenium WebDriver + java(java oops concepts + collections)

TestNG----------part 3
************************

TestNG(latest)---Junit(old)

Why we are using TestNG ?


****************************
Ans : By using TestNG,We can create selenium automation test cases,execute the
selenium automation test cases,

It generate Test Reports and also generate log files.

Mainly Why we are using TestNG ?


****************************
1.Selenium IDE generate the Test Reports but no details
2.Selenium Rc outdated(old)
3.Selenium WebDriver doesn’t generate the Test Reports and here selenium webDriver

with the help of TestNG will generate the Test Reports.

Add three parts


******************

1+ 2+ 3------------->Selenium WebDriver + Java + TestNG

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework

How to write the data into excel ?


*************************************

Can we perform scroll operation in selenium directly ?


********************************************************
Ans : No,but we can perform scroll operation in selenium with the help of
javascript code

How to scroll Vertically Up/Down in selenium javascriptExecutor?


****************************************************************
Syntax:
**********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Example
**********

//scroll Vertically Down by 1000 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,1000)");

//scroll Vertically Up by -500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-500)");

Program
**********

How to scroll Horizontally left/right in selenium javascriptExecutor?


****************************************************************

Syntax:
**********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");

Example
**********

//scroll Horizontally right by 1000 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(1000,0)");

//scroll Horizontally left by -500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(-500,0)");

program
***********

How to scroll to particular / target element using selenium JavascriptExecutor ?


*********************************************************************************

Manual Steps
*****************

What are the common exceptions u faced in ur project ?


********************************************************

1.NoSuchElement exception
2.TimeOut exception
3.ElementNotVisible exception
4.WebDriver exception / Invalid orgument exception
5.NoAlertPresent exception
1.NoSuchElement exception
******************************
2.WebDriver exception / Invalid orgument exception
**************************************************
3.NoAlertPresent exception
***************************
Manual Steps
**************
1.Open the FF browser
2.Navigate the app Url
3.Enter the Username
4.Password not given
5.Click on login
6.Wait for (Thread.sleep(15000))15 sec to open the alert box(10 sec)
7.switch to alert box
8.click on ok button

4.ElementNotVisible exception
********************************
case 1
********

Case 2
**********
How to verify particular element is visible or not ?
*******************************************************
if(driver.findElement(By.linkText("News")).isDisplayed())
{

driver.findElement(By.linkText("News")).click();

System.out.println("News element is visible");

}else
{

System.out.println("Unable to locate the News element");


}

case 3
**********
1.Why this type of error is coming
2.How to resolve this type of error

Thread.sleep(10000);

tagName locator in java ?


***************************

1.
2.
3.

Ex 1
******
How to count total links in a webpage ?
****************************************
Manual Steps
**************

Selenium Java code


**********************

Ex 2
******
How to count total frames in a webpage ?
****************************************
Manual Steps
**************

Selenium Java code


**********************

Ex 2
******
Difference betweeen linkText and partialLinkText locators ?
**************************************************************

>
linkText locator
*******************

>

Syntax :
***********

driver.findElement(By.linkText("Entire text"));

Example
*********
driver.findElement(By.linkText("Verified Rights Owner (VeRO)
sadfasgdgasjgdasgdjgasjjasgjagjkaHLKDHalkjsdfasgdjhagsjdhgjasgdjasProgramfxhgcgshj"
));

program
**********

partialLinkText locator
*******************

>

Syntax :
***********

driver.findElement(By.partialLinkText("partial Text"));

Example
*********

driver.findElement(By.partialLinkText("Owner (VeRO)"))

program
**********
Today 2nd class
******************

>Suppose if u want to access the java and selenium then we need to download
JDK(Java Development Kit) file first

Part 1
********

1.download JDK(Java Development Kit) file first


2.Install JDK(Java Development Kit) file into ur local system
3.Verify JDK(Java Development Kit) file successfully install or not into ur local
system
4.Download Eclipse IDE/oxygen
5.Directly open the Eclipse IDE/oxygen and here no need to install Eclipse
IDE/oxygen

Part 2
*********

1.Create New JavaProject


2.Create new package
3.Create new class

Datatype in java ?
*********************

int x=10;

What is a variable in java ?


********************************
Ans : Variable is a memory location and here variable x can store some data based
on datatype

then it is called variable.

7386467494

Today 2nd class


****************

>Suppose if u want to access the java and selenium then we need to download
JDK(java Development kit) file first

Part 1
*********

1.download JDK(java Development kit) file first


2.Install JDK(java Development kit) file into ur local system
3.Verify JDK(java Development kit) file successfully install or not into ur local
system
4.Download Eclipse IDE/oxygen
5.Directly open the Eclipse IDE/oxygen and here no need to install Eclipse
IDE/oxygen

Part 2
********

1.Create new JavaProject


2.Create new package
3.Create new class

Datatypes in java ?
**********************

int x=10;

What is a variable in java ?


******************************
Ans : Variable is a memory location and here variable x can store some data based
on datatype

then it is called Variable.


>Here we can use datatypes in our selenium webDriver to prepare the selenium
automation test script

>In java or other programming languages,we know we need variables to store some
data based on datatype

>In java, every variable and every expression should a datatype

types of datatype
******************
1.primitive datatype
2.Non-primitive datatype

What are the integral integer datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


**************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long,float,double,char,boolean

What are the non-primitive datatypes in java ?--IQ


**************************************************
Ans : String ,array,set,list etc.

byte datatype in java ?


***************************
>This will be used to store +ve and -ve nos
>Here byte datatype variable can store in the range of the values min -128 to max
127

Example 1
***********

byte b= 125; //valid byte type value

System.out.println(b);//

Code Explanation
******************
>Here providing value 125
>Here expected value is byte type
>min -128 to max 127

Found : byte type value


Required : byte

Java compiler work


********************
>compile the java code line by line(That means checking the java code line by line
whether it is currect code or not )

JVM(Java virtual machine)


*******************************

>Simply execute the java code

Example 2
***********

byte b= "Hanumanth"; // invalid string type value

System.out.println(b);//

Code Explanation
******************

>We can say this("Hanumanth") is a String type value

>Here string mean collection of characters

Examples
************

"HYD" or "H" or "123" or "HYD123" or "%^%^&^*&&()("

>Here everything in double-quotes it's a string


>Here string always must be in double-quotes

F : string type value


R : byte

Example 3
***********

byte b= true; // invalid boolean

System.out.println(b);//

Code Explanation
******************

>We can say this(true) is a boolean type value

>Here boolean mean true / false

F : boolean
R : byte

Example 4
***********

byte b= 127; // valid byte type value

System.out.println(b);//
Code Explanation
******************
>127
>byte type value
>min -128 to max 127

F : byte
R : byte

Example 5
***********

byte b= 127L; // invalid

System.out.println(b);//

What are the integral integer datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


**************************************************
Ans : float and double

What are the primitive datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long,float,double,char,boolean

What are the non-primitive datatypes in java ?--IQ


**************************************************
Ans : String ,array,set,list etc.

Example 5
***********

byte b= 127L; // invalid long

System.out.println(b);//

F : long
R : byte

>We can say this(127L) is a long type value by suffixed with 'l' or 'L'

>Here suffixed with 'l' or 'L' is a mandatory for that long type value ?
*************************************************************************
Ans : Yes

Datatype rules
*****************

byte(least) < short < int < long < float < double(highest)
1.We can assign left-side datatype value into any right-side datatype variable.

2.We can't assign right-side datatype value into any left-side datatype variable.

3.Here if u are trying to assign right-side datatype value into any left-side
datatype variable

then we required TypeCasting.

Example 6
***********

byte b= 10.5F; // invalid float

System.out.println(b);//

>Here we can say this (10.5F) is a float type value by suffixed with 'f' or 'F'

>Here suffixed with 'f' or 'F' is a mandatory for that float type value ?
****************************************************************************
Ans : Yes

F : float
R : byte

Example 7
***********

byte b= 10.5; // invalid double

System.out.println(b);//

F : double
R : byte

What are the integral floating-point literal values ?


**************************************************
Ans : float and double

>Here we can specify floating-point literal value(float and double) only in decimal
form

Float examples
*****************

10.5F,2.5f,10.1111f...etc.

double examples
*****************

10.5,2.5,10.1111...etc.

Example 8
***********
byte b= 300; // invalid int

System.out.println(b);//

F : int
R : byte

Code Explanation
******************
>128
>byte type value
>min -128 to max 127

What are the integral integer datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


**************************************************
Ans : float and double

Note :
**********
1.Datatype rules

2.By default every integral literal value is what type int type

3.By default every floating-point literal value is what type double type

Short datatype in java ?


**************************
>+ve and -ve nos
>min -32768 to max 32767

Example 1
***********

short s= 32767; //valid short

System.out.println(s);//

F : short
R : short

Code Explanation
******************
>32767
>short type value
>min -32768 to max 32767

Example 2
***********

short s= 32.767; // invalid double

System.out.println(s);//

F : double
R : short

Example 3
***********

short s= 32767L; // invalid long

System.out.println(s);//

Example 4
***********

short s= 32768; // invalid int

System.out.println(s);//

F : int
R : short

>32768
>short type value
>min -32768 to max 32767

What are the integral integer datatypes in java ?--IQ


**************************************************
Ans : byte,short,int,long

What are the integral floating-point datatypes in java ?--IQ


**************************************************
Ans : float and double

Int datatype in java ?


**************************

Testing = operation code + verification code

1.How to select multiple options from listbox?


**************************************************

//.Identify the Lisbox

WebElement listbox =
driver.findElement(By.id("ctl00_MainContent_lbCountry"));

//select multiple options from a list box.

Select S = new Select(listbox);

S.selectByIndex(3);
S.selectByVisibleText("ARGENTINA");
2.Verify Multiple selections are allowed or Not from a list box.?
*********************************************************************
//----------------------------------------------- operation code
//.Identify the Lisbox

WebElement listbox =
driver.findElement(By.id("ctl00_MainContent_lbCountry"));

//select multiple options from a list box.

Select S = new Select(listbox);

S.selectByIndex(3);
S.selectByVisibleText("ARGENTINA");

//---------------------------------------------------------verification
code

if(S.isMultiple())
{
System.out.println("Multiple selections are allowed");
}else
{
System.out.println("Multiple selections are not allowed");
}

How to verify single checkbox in a webpage using selenium?


**************************************************************
diagram :
************

Manual Steps
************
>Identify Checkbox1
>Click Checkbox1
>Verify Checkbox1

Selenium java code


********************
//---------------------verify single checkbox-----------------

//-------------------------------------------------operation code
// Identify Checkbox1

WebElement checkbox1 = Driver.findElement(By.id("vfb-6-0"));

// Click Checkbox1

checkbox1.click();

//-------------------------------------------verification code

// Verify Checkbox1

if(checkbox1.isSelected())
{
System.out.println("checkbox1 selected");
}else
{

System.out.println("checkbox1 not selected");

How to Verify multiple checkboxes ?


***************************************

xpath syntax
**************

//tagName[@attributeName='value']

Example
*********

//input[@type='checkbox']

Program
**********
//-----------------------------------------------------operation code

// Identify all Checkboxes

List<WebElement> totalCheboxes =
driver.findElements(By.xpath("//input[@type='checkbox']"));

System.out.println("totalCheboxes: "+totalCheboxes.size());//3

//---------------------------------------------------------verification code
// Verify multiple checkboxes one by one

for(int i=0;1<3;i++)
{

totalCheboxes.get(1).click();

if(totalCheboxes.get(1).isSelected())
{
System.out.println("Checkbox selected");
}else
{
System.out.println("Checkbox not selected");
}

int datatype in java ?


***************************
>+ve and -ve
>min -2147483648 to max 2147483647

Example 1
**********

int i= 2345; //valid int

System.out.println(i);//

Code Explanation
******************
>2345
>int type value
>min -2147483648 to max 2147483647

Found : int
Required : int

Example 2
**********

int i= 23.45F; // invalid float type value

System.out.println(i);//

F : float type value


R : int

Example 3
**********

int i= 2345L; // invalid long

System.out.println(i);//

long datatype in java ?


***************************

>+ve and -ve nos


> min -9223372036854775808 to max 9223372036854775807

Example 1
**********

long l= 127L; // valid long

System.out.println(l);//

Example 2
**********

long l= 128; // valid int

System.out.println(l);//

F : int
R : long
What are the integral literal values ?
*****************************************
Ans : byte,short,int,long

What are the integral floating-point literal values ?


*****************************************
Ans : float and double

min -128 to max 127

Example 3
**********

long l= 100; // invalid double

System.out.println(l);//

String datatype in java ?


****************************
>This will be used to store single character and group of characters

>Here range not applicable for string datatype

Examples
***********

"HYD" or "H" or "123" or "HYD123" or "%&^*&(*_)(_)" or "true"

>Here everything in double-quotes it's a string

>Here string mean collection of characterss

>Here string always must be in double-quotes

Example 1
**********

String S= 10; // invalid int

System.out.println(S);//

Example 2
**********

String S= "true"; // valid String

System.out.println(S);//

Example 3
**********

String S= Hanumanth; // invalid

System.out.println(S);//
Example 4
**********

String S= "Hanumanth"; // valid

System.out.println(S);//

Why should we go for javascript in selenium ?


**********************************************

Ans :

1.
2.

How to handle hidden and disable mode of the element/objects in selenium ?


***************************************************************************
Ans : Here Selenium + Javascript--------->to handle hidden and disable mode of the
element/objects

Javascript Syntax
********************

(javascriptExecutor)driver.executeScript(script,argument);

Syntax Explanation
*********************

>(javascriptExecutor)driver==>Convert driver object variable into


javascriptExecutor

>javascriptExecutor==>Here javascriptExecutor it's an interface which will help us

to execute the javascript code through selenium webDriver.

>executeScript==>Here javascriptExecutor ,it contain executeScript ,by using this


we can execute the javascript code

>script==>This is called javascript code

>argument==>This is a argument to the javascript code

Note :
**********

By default javascript,it understand arguments[0] for that every single element

Javascript part 2
*******************
Can we perform scroll operation in selenium directly ?
*********************************************************
Ans :No,but we can perform scroll operation with the help of javascript code

Handle popups
***************
1. How to Handling Web-Based alert Popup/Javascript Alert Popup.
2. How to Handling modal popup window.
3. How to Handling multiple windows.

1. How to Handling Web-Based alert Popup/Javascript Alert Popup.


*******************************************************************
diagram
*********

Manual Steps
***************

1.switch to alert
2.verify alert text
3.click on ok

Selenium Java code


********************

Testing = operation code + verification code

//1.switch to alert

Alert alt = driver.switchTo().alert();

//---------------------2.verify alert text------------------

//------------------------------------------------------operation code

String alert_text = alt.getText();

System.out.println(alert_text);//You Have Succesfully Logged Out!!

//--------------------------------------------------verification code

if(alert_text.equals("You Have Succesfully Logged Out!!"))


{
System.out.println("Alert text verified successfully");
}else
{
System.out.println("Alert text not verified successfully");
}

//3.click on ok

alt.accept();

2. How to Handling modal popup window.


******************************************

diagram:
**********

Manual Steps
***************
1.switch to modal popup
2.close the modal popup
Selenium Java code
*******************
//1.switch to modal popup

driver.switchTo().window(driver.getWindowHandle());

//>click on model popup window

driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();

3. How to Handling multiple windows.


*****************************************

1.Count total windows


**************************

//--------------------1.Count total windows--------------------

Set<String> totalWindows = driver.getWindowHandles();

System.out.println("totalWindows : "+totalWindows.size());//2

2.Handle child window


**************************
a.switch to child window
b.do some action
c.close the child window

3.Handle Main window


**************************
a.switch to Main window
b.do some action
c.close the Main window

boolean datatype in java ?


***************************
>This will be used to store only boolean value such as true/false

>Here range not applicable for boolean datatype

Example 1
*************

boolean b = 0; // invalid int

System.out.println(b);

F :int
R : boolean

Example 2
*************

boolean b = "true"; // invalid String

System.out.println(b);

F : String
R : boolean

Example 3
*************

boolean b = True; // invalid

System.out.println(b);

>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'

Example 4
*************

boolean b = true; // valid boolean

System.out.println(b);

float datatype in java ?


****************************

>This will be used to store +ve and -ve decimal value

>min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>Here we can specify floating-point literal value(float and double) only in decimal
form

Example 1
*************

float f = 10.5F; // valid float

System.out.println(f);

Example 2
*************

float f = 10.5; // invalid double

System.out.println(f);

Example 3
*************

float f = 10.111111111F; // 9 1's valid float

System.out.println(f);
Note :
*******

>Here float type vairable can store only decimal value upto 6 digits after decimal

Example 4
*************

float f = 25F; // valid float

System.out.println(f);

Example 5
*************

float f = 25; // valid

System.out.println(f);

double datatype in java ?


***************************

>>This will be used to store +ve and -ve decimal value


>min -1.7976931348623157e308d to max 1.7976931348623157e308D

>Here we can specify floating-point literal value(float and double) only in decimal
form

Example 1
*************

double d = 234.5; // valid double

System.out.println(d);

Example 2
*************

double d = 10.1111111111111111; // 16 1's valid double

System.out.println(d);

Note :
*******

>Here double type vairable can store only decimal value upto 14 digits after
decimal

Example 3
*************

double d = 10.11111D; // valid double

System.out.println(d);

Char datatype in java ?


*************************

if()
{

}else
{

Assert.asserEquals(act,exp);

How to handle exception in java/selenium ?


***************************************

Syntax :
************
try
{

}catch(Exception e)
{

How to take the screenshort when test case failure?


******************************************************
Manual Steps
*****************
>Create screenshort location where our screenshort need to be generate

>take the screenshort

>Now i want to copy screenshort to desired location

Selenium Java code


*********************

Difference betweeen Verify and assert ?


********************************************

Verify
********
if(condition)
{

}else
{

}
Assert
************

Assert.assertEquals(act, exp);

Java oops concept


**********************

Why should we go for Inheritance in java ?


******************************************
Ans :

Without inheritance
************************

Manual Steps
*************
1.Create Teacher class
2.Create Student class
3.Create MainClass

Java code
**************

what is a inheritance in java ?


************************
Ans :

>
What are the advantages of inheritance ?
****************************************
Ans : By using Inheritance,

1.We can reduce the code size


2.We can reduce the development time
3.We can avoid the duplicate code

What is the main advantage of inheritance ?


****************************************
Ans : code reusability

Syntax :
**********

class Superclass
{

}
class Subclass extends Superclass
{

Example
*********
Manual Steps
*****************
1.Create Superclass(Teacher class)
2.Create Subclass(Student) from Superclass(Teacher class)
3.Create MainClass

Java code
***********

In superclass
****************

common code + Additional code(optional)

In subclass
***************

Additional code(Mandatory)

Types of inheritance
***********************
1.Single inheritance
2.Multi-Level Inheritance
3.Hierarchical inheritance

1.Single inheritance
**********************
Example 2
************
Manual Steps
****************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
************
Case 1
**********
Child C = new Child();

C.m1();//call the m1()----valid


C.m2();//call the m2()----valid

Case 2
**********
Parent C = new Child();

C.m1();//call the m1()----valid


C.m2();//call the m2()-----invalid

Case 3
*********
Parent C = new Parent();

C.m1();//call the m1()----valid


C.m2();//call the m2()-----invalid

Multi-Level Inheritance
*****************************

Selenium Automation Testing


*******************************

What is a Testing ?
***********************
Ans : To verify whether the functionality works well or not . i.e Testing or

>Simply we can say to find the defect or to find the error or to find the failure

Difference betweeen defect,error and failure ?--IQ


*************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

Types of Testing
*********************
1.Functional Testing
2.Non-functional Testing

Types of functional automation tools


**************************************
1.opensource
==================
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.sahi
4.badboy
5.Ruby
6.watir etc.

2.commercial
================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen selenium and qtp ?--IQ


*********************************************
Selenium
**********
>opensource(free of cost)
>Java,c#,python,ruby,perl and php
>FF,IE,chrome,opera,safari and Edge
>Windows,linux and mac os
>Web app only

Here Selenium + Appium ----->mobile app

Here Selenium + Autoit or sikuli or robot class----->desktop app

Qtp
***********
>commercial(paid tool)
>FF,Ie and chrome
>Vbscript
>Windows
>Web app,mobile app and desktop app

History of selenium
**********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium WebDriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium WebDriver+Extra features) + Selenium Grid


>2019

Selenium components---IQ
****************************
1.Selenium IDE
2.Selenium Rc
3.Selenium Webdriver
4.Selenium Grid

-----------------------part 1

Java for Selenium(core java enough)------------part 2


******************

Java,

80%-----------------selenium webDriver + java(Java oops concepts + collections)

TestNG------------part 3
*********

TestNG(Latest)---------Junit(old)

Why we are using TestNG ?


****************************
Ans : By using TestNG,we can create selenium automation test cases,execute the
selenium automation test cases,

it generate the Test Reports and also generate log files.


Mainly Why we are using TestNG ?
****************************

1.Selenium IDE generate Test Reports but no details

2.Selenium RC outdated(old)

3.Selenium WebDriver doesn't generate the Test Reports and here selenium webDriver

with the help of TestNG will generate the Test Reports.

Add three parts


*****************

1 + 2 + 3------>Selenium WebDriver + Java + TestNG

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-xslt-reports

Data-Driven framework
Keyword driven framework
Hybrid framework
page object modal

CAn we perform scroll operation in selenium directly ?


******************************************************
Ans : NO,but we can perform scroll operation with the help of javascriptExecutor

How to scroll Vertically Up/Down in selenium javascriptExecutor ?


******************************************************************

Syntax:
***********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis pixels,y-axis


pixels)");

Example
**********

//Scroll Vertically Down by 1000 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,1000)");
//Scroll Vertically Up by -500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-500)");

program
********

How to scroll Horizontally left/right in selenium javascriptExecutor ?


******************************************************************

Syntax:
***********

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis pixels,y-axis


pixels)");

Example
***********
//Scroll Horizontally right by 1000 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(1000,0)");

//Scroll Horizontally left by -500 pixels

((JavascriptExecutor) driver).executeScript("window.scrollBy(-500,0)");

program
***********

How to scroll till the particular /target element/object using selenium


javascriptExecutor??
**********************************************************************************

What are the common exceptions u faced in ur project ?


********************************************************

1.NoSuchElement Exception
2.TimeOut Exception
3.ElementNotVisible Exception
4.Webdriver Exception / InvalidOrgumentException
5.NoAlertPresent Exception

1.NoSuchElement Exception
****************************
2.Webdriver Exception / InvalidOrgumentException

3.NoAlertPresent Exception
********************************

1.open the ff browser


2.Navigate the app Url
3.Enter the Username
4.Password not given
5.click on login
6.After click on login wait for 15sec to open the alert box
7.switch to alert box(16 sec)
8.click on ok

ElementNotVisible Exception
******************************

case 1
*********

CAse 2
*********

How to verify particular element is visible or not ?


*****************************************************
if(driver.findElement(By.linkText("News")).isDisplayed())
{

driver.findElement(By.linkText("News")).click();

System.out.println("News element is visible");

}else
{

System.out.println("Unable to locate the News element");


}

Case 3
**********
1.Why this type of error is coming
2.How to resolve this type of error

Today 2nd class


******************

>Suppose if u want to access the java and selenium then we need to download
JDK(Java development kit)file first

Part 1
********
1.download JDK(Java development kit)file first
2.Install JDK(Java development kit)file into ur local system
3.Verify JDK(Java development kit)file successfully install or not into ur local
system
4.Download Eclipse IDE/oxygen
5.Directly open the Eclipse IDE/oxygen and here no need to install Eclipse
IDE/oxygen
Part 2
*********
1.Create new JavaProject
2.Create new package
3.Create new Class

Datatype in java ?
**********************

int x = 10;

What is a variable in java ?--IQ


**********************************
Ans : Variable is a memory location and here variable x can store some data based
on

datatype then it is called variable.

>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script

>In java or other programming languages,we know we need variables to store some
data based on

datatype.

>In java,every variable and every expression should have a datatype

Types of datatypes
*******************
1.primitive datatypes
2.Non-primitive datatypes

Whar are the integral integer datatypes in java ?--IQ


*****************************************************
Ans : byte,short,int,long

Whar are the integral floating-point datatypes in java ?--IQ


*****************************************************
Ans : float and double

Whar are the primitive datatypes in java ?--IQ


*****************************************************
Ans : byte,short,int,long,float,double,boolean,char

Whar are the non-primitive datatypes in java ?--IQ


*****************************************************
Ans : String,array,set,list etc.

byte datatype in java ?


***************************

7386467494
boolean datatype in java ?
****************************
>This will be used to store only boolean value such as true/false

>Here range not applicable for boolean datatype

Example 1
*************

boolean b = 100; //invalid int

System.out.println(b);

Example 2
*************

boolean b = "true"; // invalid String

System.out.println(b);

Example 3
*************

boolean b = True; // invalid

System.out.println(b);

Example 4
*************

boolean b = true; // valid boolean

System.out.println(b);

float datatype in java ?


***********************

>This will be used to store +ve and -ve decimal value

>min -3.4028235e38F to max 3.4028235e38F

Here e mean exponential form

>Here we can specify floating-point literal value(float and double) only in decimal
form

Example 1
*************

float f = 10.5F; // valid float

System.out.println(f);

Example 2
*************

float f = 10.5; // invalid double


System.out.println(f);

Example 3
*************

float f = 10.111111111F; // 9 1's valid float

System.out.println(f);

Example 4
*************

float f = 25F; // valid float

System.out.println(f);

Example 5
*************

float f = 25; // valid int

System.out.println(f);

double datatype in java ?


***************************

>This will be used to store +ve and -ve decimal value

>min -1.7976931348623157e308d to max 1.7976931348623157e308D

Here e mean exponential form

>Here we can specify floating-point literal value(float and double) only in decimal
form

Example 1
*************

double d = 10.5; // valid double

System.out.println(d);

Example 2
*************

double d = 10.1111111111111111; // 16 1's valid double

System.out.println(d);

Example 3
*************

double d = 10.1111D; // valid doub

System.out.println(d);

char datatype in java ?


**************************
3.How to handle multiple windows in selenium?
*************************************

Diagram:
************

Manual Steps
**************
1.Count total windows
*************************
Set<String> totalWindows = driver.getWindowHandles();

System.out.println("totalWindows : "+totalWindows.size());//2

2.Handle child window


*************************
>switch to child window
>do some action
>close the child window

Selenium Java code


*********************
//switch to child window

driver.switchTo().window(allWindowHandles.get(1));

//do some action

System.out.println(driver.getTitle());

//close the child window

driver.close();

3.Handle Main window


*******************************
>switch to Main window
>do some action
>close the Main window

Selenium Java code


*********************

char datatype in java ?


*************************
>This will be used to store single character not group of characterss

>Here char datatype variable can store in the range of the values min 0 to max
65535

min 0 to max 65535(0 to 127)


Examples
**********

'c' or '5' or '@' --------valid

'ABC' or '123' or '%&^*&&*&('------invalid

>Here everything in single quotes it's a character

Example 1
************

char ch = "C"; // invalid String

System.out.println(ch);//

Example 2
************

char ch = C; // invalid

System.out.println(ch);//

Example 3
************

char ch = 'C'; // valid char

System.out.println(ch);//

Example 4
************

char ch = 65; // valid the ASCII value(65) of a character---'A'(char type


value)

System.out.println(ch);// A

What is the ASCII value(65) of a character ?


*******************************************
Ans : A

What is the ASCII value(97) of a character ?


*******************************************
Ans : a

What is the ASCII value(115) of a character ?


*******************************************
Ans : s

What is the ASCII value(125) of a character ?


*******************************************
Ans : }

Example 5
************

int i = 'S'; // valid the character('S') of ASCII value---83(int type value)

System.out.println(i);// 83

What is the character('S') of ASCII value ?


******************************************
Ans : 83

What is the character('g') of ASCII value ?


******************************************
Ans : 103

Char datatype in java?


*************************
>This will be used to store single character not group of characterss

>min 0 to max 65535(0 to 127)

Examples
************
'C' or '5' or '@'---------valid

'Cdshfds' or '1235' or '@KUIIIUIO'---------invalid

>Here everything in single quotes it's a character

>Here char value always must be in single quotes

Example 1
************

char ch = "C" ; //invalid String

System.out.println(ch);

Example 2
************

char ch = C ; // invalid

System.out.println(ch);

Example 3
************

char ch = 'C' ; // valid char

System.out.println(ch);

Example 4
************

char ch = 65 ; // valid the ASCII value(65) of a character---'A'(char type


value)

System.out.println(ch);
What is the ASCII value(65) of a character ?
******************************************
Ans : 'A'

What is the ASCII value(97) of a character ?


******************************************
Ans : 'a'

What is the ASCII value(115) of a character ?


******************************************
Ans : 's'

Example 5
************

int i = 'S' ; // valid the character('S') of ASCII value---83(int type value)

System.out.println(i);//

What is the character('S') of ASCII value ?


******************************************
Ans : 83

What is the character('g') of ASCII value ?


******************************************
Ans : 103
What is a Variable in java ?
******************************

int x = 10;

Ans :

Types of variables
********************
1.Instance variables
2.Local variables
3.Static variables

What are the Instance variables in java ?


*******************************************
Ans :

1.The values of the name and rollNo are different from student to student such type
of variables

are called instance variables.

2.The values of the name and rollNo are different from object to object such type
of variables

are called instance variables.

Where we can create instance variables ?--IQ


*******************************************
Ans : Inside the class or outside the method or outside the constructor or outside
the block(

if,if-else,ladder if-else,switch,forloop,while,do-while,static)

Example 1
**************

public class FirstProgram {

//instance variable

String name="Sai";

public static void main(String[] args)


{

System.out.println(name);//error

CAn we access the instance variable into static area directly ?


******************************************************************
Ans : No,we can't access

What is a Variable in java?


**********************
Ans :

int x= 10;

Types variables
******************
1.Instance variables
2.Local variables
3.Static variables

What is a Instance variables in java ?


****************************************
Ans :

>The values of the name and rollno are different from student to student such type
of

variables are called instance variables.

>The values of the name and rollno are different from object to object such type of

variables are called instance variables.

Where we can create instance variables ?


*******************************************
Ans : Inside the class or outside the method or outside the constructor or outside
the block(

if,if-else,ladder if-else,switch,while,do-while,forloop,static)

Example 1
************
public class FirstProgram {

//instance variable

String name = "Sai";

public static void main(String[] args)


{
System.out.println(name);//error

Can we access the instance variable into static area directly ?


*****************************************************************
Ans : No,we can't access

Example 2
************
public class FirstProgram {

//instance variable

String name = "Sai";

public static void main(String[] args)


{

System.out.println(name);//error

Object syntax
******************

Student S= new Student();

Object syntax Explanation


****************************

>Student()==>This is called Student constructor

>Here new is called keyword

Why we are using new keyword ?


**********************************
Ans : By using new keyword,we can create Student object(new Student())
>Here S is called object reference variable

>Here Student is called class

Can we access the instance variable into static area directly ?


*****************************************************************
Ans : No,but we can access through object reference

Example 3
************
public class FirstProgram {

//instance variable

String name = "Sai";

public static void main(String[] args)


{

System.out.println(name);//error

When function will be called ?


****************************
Ans : Whenever u create an object after function will be called

CAn we access the instance variable into instance area directly ?


*******************************************************************
Ans : Yes

Example 2
***********

public class Student {

//Instance variable

String name = "Sai";

public static void main(String[] args)


{
System.out.println(name);//error
}

Object Syntax
****************

Student S = new Student();

Object Syntax Explanation


*****************************

>Student()==>This is called Student constructor

>Here new is called keyword

Why we are using new keyword ?


******************************

Ans : By using new keyword, we can create Student object(new Student())

>Here S is called object reference variable

>Here Student is called class

CAn we access the instance variable into static area directly ?


********************************************************************
Ans :NO,but we can access through object reference

Example 3
***********

public class Student {

//Instance variable

String name = "Sai";

public static void main(String[] args)


{
System.out.println(name);//error
}

When function will be called ?


*******************************
Ans : Whenever u create an object after function will be called

CAn we access instance variable into instance area directly ?


****************************************************************
Ans : Yes

Example 4
***********

public class Student {

//Instance variable

int i=10;
String name;
boolean b;

public static void main(String[] args)


{

Student S = new Student();

System.out.println(S.i);//10
System.out.println(S.name);//null
System.out.println(S.b);//false
}

CAn we assign default values for that instance variables and static variables ?
*********************************************************************************
Ans : Yes

Example 5
***********

public class Student {

//Instance variable

private int i=10;


public String name;
protected boolean b;

public static void main(String[] args)


{

Student S = new Student();

System.out.println(S.i);//10
System.out.println(S.name);//null
System.out.println(S.b);//false
}
What are the access modifiers in java ?
****************************************
Ans :

1.private
2.public
3.protected
4.default

Can we assign access modifiers for that instance variables ?


***************************************************************
Ans : Yes

Can we access the instaance variable anywhere ?


*************************************************
Ans : No,but we can access through object reference

When instance variables will be accessible anywhere ?


********************************************************
Ans : At the time of object creation

How many ways we can access the instance variable anywhere ?


************************************************************
Ans : Only one way through object reference

Local variable in java ?


***************************

Example 1
************
class Test{

//create method

void m1()
{
int x=10; //local variable
}

//create Constructor

Test()
{
int y=20;//local variable

//create block

if()
{

int z=30;//local variable


}

Where we can create local variable ?


*************************************
Ans : Inside the method or inside the constructor or inside the block such type of
variables

are called local variables.

Example 2
************

TestNg(Next generation)
************************

TestNg(Latest)-------Junit(old)

Why we are using Testng ?


*****************************
Ans :

Mainly Why we are using Testng ?


*****************************
>
>
>

Part 1
*********
1.Install TesNG into Eclipse
2.Verify TestNG successfully install or not
3.Add TestNG libraries for that project
4.Create TestNG class (Selenium Automation test case)

What is the default package of TestNG ? or What is the TesNG library file ?
********************************************************************************
Ans : org.testng.annotations

i.e @Test------->It represents a selenium automation test case

TestSteps
***********
1.Open browser
2.Navigate the App URL
3.Verify OrangeHRM Login Page Title
4.close the browser

Selenium Java code


******************

Example 5
**************
public class Student {

//instance variables

private int a=10;


public String name;
protected boolean b;

public static void main(String[] args)


{
Student S = new Student();

System.out.println(S.a);//10
System.out.println(S.name);//null
System.out.println(S.b);//false
}
}

What are the access modifiers in java ?


*****************************************
Ans :

1.private
2.public
3.protected
4.default

CAn we assign access modifiers for that instance variables and static variables ?
*********************************************************************************
Ans : Yes
CAn we access the instance variables anywhere ?
**************************************************
Ans : No,but we can access through object reference

When instance variables will be accessible anywhere ?


********************************************************
Ans : At the time of object creation

How many ways we can access the instance variables anywhere ?


******************************************************************
Ans : Only one way through object reference

Local variable in java ?


*****************************
Example 1
**************
class Student{

//create method

void m1()
{

int x = 10;//local variable


}

//create constructor

Student()
{

int y = 20;//local variable


}

//create block

if()
{
int z = 30;//local variable

Where we can create local variable in java ?--IQ


**********************************************
Ans : Inside the method or inside the constructor or inside the block

Where we can create instance variables in java ?--IQ


**************************************************
Ans : Inside the class or outside the method or outside the constructor or outside
the block

Example 2
*************
public class Student {
public static void main(String[] args) {

int j = 1; //local variable

for(int i=1;i<3;i++)
{

System.out.println(i);//valid

System.out.println(j);//valid

System.out.println(i);//invalid

System.out.println(j);//valid

Example 3
*************
public class Student {

public static void main(String[] args) {

//local variables

int i;
int j;

System.out.println(i);//error

System.out.println(j);//error

Note :
********
>When i run this program by default JVM will not provide default values for that
local variables.
Here compulsory we have to initialize the values for that local variables.

CAn we assign default values for that instanace variables and static variables ?
********************************************************************************
Ans : Yes

CAn we assign default values for that local variables ?


*******************************************************
Ans : No

local variables examples


****************************
int i;//invalid
int i=0;//valid
int i=10;//valid

Instance variables examples


****************************

int i;//valid
int i=0;//valid
int i=10;//valid

Static variables examples


****************************

static int i;//valid


static int i=0;//valid
static int i=10;//valid

Example 3
*************
public class Student {

public static void main(String[] args) {

//local variables

private byte b=10; //invalid


public String name="Sai";//invalid
protected boolean b=false;//invalid

int i=10; //valid

final int y = 15; //valid

>Here final is called modifier

>Here final means what constant

>Here y is called constant variable.So constant variable value never be changed


that

mean on increment and no decrement.So always y is 15.

>Here can we assign final modifier for that local variable ,instance
variable,static variable?
****************************************************************
Ans : Yes

What are the access modifiers in java ?--IQ


****************************************
Ans :

1.private
2.public
3.protected
4.default

CAn we assign access modifiers for that local variables ?


************************************************************
Ans :NO

CAn we assign access modifiers for that instance variables and static variables?
************************************************************
Ans :Yes

CAn we access the local variable anywhere ?


*********************************************
Ans :No,we can access inside the methods or inside the constructor or inside the
block

When local variables will be accessible ?


*********************************************
Ans : While execute the methods or constructors or block

Static variable in java ?


*****************************
Definition:
************
>The name of the college is same from student to student such type of variable is
called

static variable.

>The name of the college is same from object to object such type of variable is
called

static variable.

Where we can create instance variable and static variable ?


*****************************************
Ans : Inside the class or outside the method or outside the constructor or outside
the block

Example 1
************
How to work with xls file ?
*******************************

How to login with xls file using poi jar file ?


********************************

How to login with xlsx file using poi jar file ?


********************************

Manual Steps
**************

Selenium Java code


*********************

Static variable in java ?


****************************
Example 1
***********
public class Student {

//static variable

static String name = "Sai";

public static void main(String[] args)


{
System.out.println(name);//Sai

}
}

Can we access the static variable into static area directly ?


***************************************************************
Ans : Yes

Example 2
***********
public class Student {

//static variable

static String name = "Sai";

public static void main(String[] args)


{

System.out.println(name);//Sai

}
}

Can we access the static variable into static area through object reference ?
***************************************************************
Ans : Yes

Example 3
***********
public class Student {

//static variable

static String name = "Sai";

public static void main(String[] args)


{

System.out.println(name);//Sai

}
}

Can we access the static variable into static area through classname ?
***************************************************************
Ans : Yes

Syntax : classname.variablename

Example 4
***********
public class Student {

//static variable

static String name = "Sai";


public static void main(String[] args)
{

System.out.println(name);//Sai

}
}

How many ways we can access the static variable ?


***************************************************
Ans : 3 ways

1.Directly we can access


2.Through object reference
3.Through classname

When static variable will be accessible ?


***********************************
Ans :

instance variable part 2


**************************

static variable part 2


**************************

@Test ---2
***********

Manual Steps
***************
1.
2.
3.
Selenium Java code
*********************

can we enter numeric value,date type value into textbox directly by using
sendkeys()?
********************************************************************************
Ans : NO

Convert intger type value into string type


********************************************

Example
**********
int i =10;

Syntax :
**********
String.valueOf(10);

"10"

driver.findElement(By.id()).sendKeys("10");

String s="Sai";

Note :
********

By using sendKeys we can enter only string type value into input field(textbox,text
area)

How to verify dropdown values ?


************************************

How to get he dropdown size ?


********************************
Manual Steps
***************
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown

Selenium java code


****************

// Identify dropdown

WebElement dropdown = driver.findElement(By.name("selectionField"));

// Identify dropdown values and store into dropdownCount variable

List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));

// Print dropdown size.

System.out.println("Dropdown size : " + dropdownCount.size());//3

>How to count total rows from excel.


*************************************
Manual Steps
*************
1.First,We need to access the Excel file into eclipse.
2. Get the workbook from Excel.
3. Get the sheet from Workbook.
4.Count total rows from excel sheet.

Selenium Java code


**********************

// Now access the Excel file into eclipse

FileInputStream fis = new FileInputStream("E:\\Selenium Files\\xls


Files\\Login_With_xlsFile.xls");

// Get the workbook from Excel

HSSFWorkbook workbook = new HSSFWorkbook(fis);

// Get the sheet from Workbook

HSSFSheet sheet = workbook.getSheet("Sheet2");

// Get total rows from excel sheet

int total_Rows = 2+1;

System.out.println("Excel size : " + total_Rows);//3

Instance variable part 2


*****************************

Part 1
***********
1.Print 1st Student details
2.print 2nd Student details
3.Print nth Student details

Part 2
***********
>Suppose if u want to Print 1st Student details then we need to create object for
that 1st Student

>Suppose if u want to Print 2nd Student details then we need to create object for
that 2nd Student

>Suppose if u want to Print nth Student details then we need to create object for
that nth Student

Part 3
**********
Print 1st Student details
******************************
>First,initialize the values for that instance variables
>Print 1st Student details

2.print 2nd Student details


********************************
>First,initialize the values for that instance variables
>Print 1st Student details

3.Print nth Student details


**********************************
>First,initialize the values for that instance variables
>Print 1st Student details

>If i change the 1st student marks then there are any effect for that remaining
student marks ?
************************************************************************
Ans :No effect

Instance variable part 2


****************************

>For every student a separate copy of name,rollno,marks will be created

>For every student a separate copy instance variables will be created

static variable part 2


*************************

>Create college name and share the collegeName for all the students

>Create single copy and share this copy for all the objects

driver.findElement(By.id("")).sendKeys("21");

String.valueOf(21);

"21"

Can we declare a string as a datatype?


****************************************
Ans : Yes

Example
************
String s="Sai";

Can we enter the Numeric value into input field(textbox,text area) using sendKeys()
?
***********************************************************************************
**
Ans : No
In this case we need to convert into String ,then after we can enter the String
value into input field(textbox,text area) using sendKeys()

Example
**********

driver.findElement(By.id("locator")).sendKeys(String.valueOf(Numeric value));

TypeCasting : Convert one datatype into another datatype

How to Convert Double to Integer in Java ?


******************************************

Ans : By Using typecasting: This way is a very simple and user friendly.

Example 1

double variable = 1234;


int i = (int)variable;

System.out.println(i);//Output : 1234

Example 2

double variable = 1234;

System.out.println(variable);//Output : 1234.0

float f = 500072; // 500072.0 int valid

Syso(f);

How to convert int to String ?


********************************
Ans : Convert using String.valueOf(int)

Example :
**********
Important methods In Apache-POI
*************************************
How to get boolean cell value from excel sheet ?
*************************************************
Ans : By using getBooleanCellValue()

How to get AlfaNumeric cell value from excel sheet ?


*************************************************
Ans : By using getStringCellValue()

How to get Date cell value from excel sheet ?


*************************************************
Ans : By using getDateCellValue()

How to get String cell value from excel sheet ?


*************************************************
Ans : By using getStringCellValue()

How to get Numeric cell value from excel sheet ?


*************************************************
Ans : By using getNumericCellValue()

How to verify Random dropdown values ?


****************************************

Difference betweeen == and equals() in java ?


*********************************************

Example
***********

Student S1 = new Student("Hanumanth");

Student S2 = new Student("Hanumanth");

System.out.println(S1==S2); //false

System.out.println(S1.equals(S2));//true

==----->By using this we can compare the references

equals()--->By using this we can compare the content / Strings

=---->By using this we can assigning the value into variable

What is a method/function in java ?


****************************
Ans :

1.
2.
3.

Syntax:
**********

return-type methodname(para1,para2,para3)
{
statement1;
statement2;
statement3;
}

Examples
*********

void add()
{
}

void addfunction()
{

}
void addFunction()
{

Write a program for a method,without return-type and without passing parameters ?


*****************************************************************************

When function will be called ?


********************************
Ans : Whenever u create an object after function will be called

Write a program for a method,with return-type and without passing parameters ?


*****************************************************************************

Write a program for a method,without return-type and with passing parameters ?


*****************************************************************************

Why we are using parameters ?


*******************************
Ans : By using these parameters,we can receive the data from outside into method

Write a program for a method,with return-type and with passing parameters ?


*****************************************************************************

Here A method can never return more than one value

Examples
************

return c; //valid
return a,b;//invalid
return a,return b;//invalid

What is a method / function in java ?


*****************************************
Ans :

1.
2.
3.

Syntax:
*********

return-type methodname(para1,para2,para3)
{
statement1;
statement2;
statement3;

Examples
***********
void add()
{

}
void addfunction()
{

}
void addFunction()
{

Write a program for a method ,without return-type and without passing parameters
***********************************************************************************

When function will be called ?


******************************
Ans: Whenever u create an object after function will be called

Write a program for a method ,without return-type and with passing parameters
***********************************************************************************

Why we are using parameters ?


********************************
Ans : By using these parameters,we can receive the data from outside into method

Write a program for a method ,with return-type and with passing parameters
***********************************************************************************

Here A method can never return more than one value

Examples
*************

return c; //valid
return a,b;//invalid
return a,return b;//invalid

//To verify whether the text exists/present or not on a webpage


*****************************************************************

boolean welcomepage=driver.getPageSource().contains("Welcome, kosmik");


if(welcomepage)
{

System.out.println("Patient Perminent Registration


successfully");
}else
{
System.out.println("Patient Perminent Registration not
successfully");
}

Selenium Automation Testing


****************************

What is a testing ?
**********************
Ans : To verify whether the functionality works well or not .i.e Testing or

>We can say to find the defect or to find the error or to find the failure

Difference betweeen defect,error and failure ?--IQ


******************************************************
1.Error : Developer
2.Defect : Test Engineer
3.Failure : Customer or User

Types of Testing
*******************
1.Functional Testing
2.Non-functional Testing

Types of functional automation tools


***************************************
1.Opensource
===============
1.Selenium RC(Remote controller)
2.Selenium WebDriver
3.Sahi
4.badboy
5.ruby
6.watir etc.

2.commercial
===============
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.

Difference betweeen Selenium and Qtp ?--IQ


******************************************
Selenium
*************
1.Opensource(free of cost)
2.Java c#,python,ruby,perl and php
3.FF,IE,chrome,opera,safari and Edge
4.Windows,linux and mac os
5.Web app

Here Selenium + Appium------>mobile app

Here Selenium + AutoIT or sikuli or robot class---->desktop app

QTP
*********
1.commercial tool(paid tool)
2.Vbscript
3.FF,IE and chrome
4.Windows
5.Webapp ,mobile app and desktop app

History of selenium
***********************
>It was came into 2004 by jason huggins

>Selenium 1 have 3 tools

>Selenium IDE + Selenium RC + Selenium Grid


>It was came into 2004

>Selenium 2 have 4 tools

>Selenium IDE + Selenium RC + Selenium Webdriver + Selenium Grid


>2011

>Selenium 3 have 3 tools

>Selenium IDE + Selenium Webdriver + Selenium Grid


>2016

>Selenium 4 have 3 tools

>Selenium IDE + (Selenium Webdriver+Extra features) + Selenium Grid


>2019

Selenium components---IQ
*********************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid

------------------------part 1

Java for selenium(core java enough)--------part 2


********************

Java,

80%-----------Selenium Webdriver+ java(oops concepts + collections)

TestNG-----------part 3
******

TestNG(latest)----Junit(old)
Why we are using TestNG ?
*******************************
Ans : By using TestNG,we xcan create selenium automation test cases,execute the
selenium automation test cases,

it generate Test Reports,and also generate log files.

Mainly Why we are using TestNG ?


*******************************

1.Selenium IDE generate Test Reports but no details


2.Selenium RC outdated(old)
3.Selenium WebDriver doesn't generate the Test Reports,and here selenium webdriver
with

the help of TestNG will generate the Test Reports.

Add three parts


******************

1+ 2 + 3 ----->Selenium WebDriver + Java + TestNG

AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports

Data driven framework


keyword driven framework
Hybrid framework
page object modal

What is a class and object in java ?


************************************

class and object examples


***************************
Class : Vehicles Objects : car,bus,auto etc.
Class : Animals Objects : cat,dog,elephant etc.
Class : Furniture Objects : table,chair,cot etc.
Class : Fruits Objects : mango,orange,apple etc.

What is a object in java ?


***************************
Ans : It exists really / physically

Examples : car,cat,table,mango etc.

Here object has two things


****************************

1.State / properties
2.Behavior / Actions

What is a class in java ?


****************************
Ans : It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

>
>

Here car is a object,and it has two things


**********************************************
1.State / properties
2.Behavior / Actions

Object syntax
*****************
Student S = new Student();

Object syntax Explanation


*****************
>Student()==>This is called Student constructor
>Here new is called keyword
Why we are using new keyword?
*********************************
Ans : By using new keyword,we can create Student object(new Student())

>Here S is called object reference variable

>Here Student is called class

class Syntax:
**************
class <classname>
{

//1.State / properties---------variables

<datatype> variable1;
<datatype> variable2;

//2.Behavior / Actions---------methods / functions

return-type methodname1()
{

}
return-type methodname2(datatype variblename)
{

main()
{
}

Example
**********
Difference betweeen class and object in java ?--IQ
*************************************************
Class
********
1.It doesn't exist really / physically

Examples : Vehicles,Animals,Furniture,Fruits etc.

2.In this program,we can create class only once

3.Why we are using class keyword ?


**********************************
Ans : By using class keyword,we can create class

4.We can create class without creating an object

5.Here memory space is not allowed when class is created

6.A class can contain variables and methods

Object
***********

1.It exists really / physically

Examples : car,cat,table,mango etc.

2.In this program,we can create objects multiple times

3.Why we are using new keyword?


*********************************
Ans : By using new keyword,we can create Student object(new Student())

4.We can't create object without class

5.Here memory space is allowed when object is created

6.And object also can contain variables and methods

Difference betweeen @BeforeTest and @AfterTest ?


*************************************************
@BeforeTest : @BeforeTest annotation run before all the test cases that belongs
classes
@AfterTest : @AfterTest annotation run After all the test cases that belongs
classes

Example
************
Create Baseclass(Superclass)
*******************************
class Baseclass
{
@BT
@AT

Reusable Functions(R.F)
}
Create Subclass1
*****************
class Subclass1 extends Baseclass
{

@Test-1
}
Create Subclass2
*****************
class Subclass2 extends Baseclass
{

@Test-2
}

xml file
*************
<suite name="Suite">
<test name="Test">
<classes>
<class name="com.Banking.Tests.Subclass1"/>
<class name="Registration.Subclass2"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

Output
*********
@BT

@Test-1
@Test-2
@AT

Difference betweeen @BeforeClass and @AfterClass ?


*************************************************
@BeforeClass : @BeforeClass annotation run before all the test cases in the current
class or program
@AfterClass : @AfterClass annotation run After all the test cases in the current
class or program

Create Test class


********************
class Test
{
@BC
@AC

Test-1
Test-2

Reusable Functions(R.F)

}
Output
***********
@BC

Test-1
Test-2

@AC

Difference betweeen @BeforeMethod and @AfterMethod ?


*************************************************
@BeforeMethod : @BeforeMethod annotation run before each test case in the current
class or program
@AfterMethod : @AfterMethod annotation run After all the test cases in the current
class or program

Create Test class


******************
class Test
{
@BM
@AM

Test -1
Test -2

Reusable Functions(R.F)

Output
********
@BM
Test -1
@AM

@BM
Test -2

@AM

nmr2627@gmail.com,---8am

65445 +7500

Flow-control in java?
************************

Selection statements
*********************
1.if
2.if-else
3.ladder if-else
4.switch
if statement
*****************

Syntax :
************

if(condition-part/Testing-part) // Here must be boolean condition


{

//body
}

Syntax Explanation
********************
>
>

Example 1
***********

public class Student {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}
}

Example 2
***********

public class Student {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}else
{
System.out.println("Animals age not matched");
}

}
}

Conclusion
************
>Suppose if u want to check only true condition then we have to go if statement
>Suppose if u want to check true/false condition then we have to go if-else
statement

Example 3
***********

public class Student {

public static void main(String[] args)


{
int A=100;

if(A) //Here must be boolean condition


{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}
>if(A)==>if(100)==>Here JVM will expecting boolean value not integral literal value
and floating-point literal value

F : int
R : boolean

Example 4
***********

public class Student {

public static void main(String[] args)


{
int A=100;

if(A>50) //Here must be boolean condition


{
System.out.println("A greater than 50");

}else
{
System.out.println("A less than 50");
}

}
}

Example 5
***********
public class Student {

public static void main(String[] args)


{
int x=10;

if(x=20) //Here must be boolean condition


{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

=------->By using this ,we can assigning the value into variable
==--------->By using this,we can compare the Numeric values or references or
boolean value

>int x=10; now onwards x value will become 20


>if(x),here x means what 20
>if(20)==>Here JVM will expecting boolean value not integral literal value and
floating-point literal value

F : int
R : boolean

Example 6
***********

public class Student {

public static void main(String[] args)


{
int x=10;

if(x==20) //Here must be boolean condition


{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

Example 6
***********

public class Student {


public static void main(String[] args)
{
boolean b=true;

if(b=false) //Here must be boolean condition


{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

>boolean b=true;now onwards b value will become false


>if(b),here b means what false
>if(false)==>

F : boolean
R : boolean

Example 7
***********

public class Student {

public static void main(String[] args)


{
boolean b=false;

if(b==false) //Here must be boolean condition


{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

Switch statement in java


****************************
>Suppose if u want to check one or more conditions then we have to go switch block

Syntax:
**********

switch(Expression value){

case value1 : statement1--->code to be executed;

break;
case value2 : statement2--->code to be executed;
break;
case value3 : statement3--->code to be executed;

break;
default : statement4--->Here default case will be executed when
expression value is not matched with any case value;

Syntax Explanation:
*********************
>
>
>
>
>
>
>
Example 1
************

Flow-control in java ?
**********************
Selection statements
**********************
1.if
2.if-else
3.ladder if-else
4.switch

If statement
****************

Syntax:
***********

if(condition-part/Testing-part) //Here must be boolean condition


{

//body
}

Syntax Explanation:
***********
1.
2.

Example 1
***********
public class Student {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}
}

Example 2
***********
public class Student {

public static void main(String[] args)


{
int cat_age=5;
int dog_age=5;

if(cat_age==dog_age)
{
System.out.println("Animals age matched");

}else
{
System.out.println("Animals age not matched");

}
}

Conclusion
**************
>Suppose if want to check only true condition then we have to go if statement.

>Suppose if want to check true /false condition then we have to go if-else


statement.

Example 3
***********
public class Student {

public static void main(String[] args)


{
int A=100;

if(A)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");
}

}
}

if(A)==>if(100)==>

Found : int
Required : boolean

Example 4
***********
public class Student {

public static void main(String[] args)


{
int A=100;

if(A>50)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

}
}

Example 5
***********
public class Student {

public static void main(String[] args)


{
int x=10;

if(x=20)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

}
}

>int x=10;now onwards x value will become 20

>if(x),here x means what 20

>if(20)==>
F : int
R : boolean

=----->By using this,we can assigning the value into variable


==---->By using this,we can compare Numeric values or Boolean values or references

Example 6
***********
public class Student {

public static void main(String[] args)


{
int x=10;

if(x==20)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

}
}

Example 7
***********
public class Student {

public static void main(String[] args)


{
boolean b=true;

if(b=false)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

}
}

>boolean b=true;now onwards b value will become false

>if(b),here b means what false

>if(false)

F : boolean
R : boolean

Example 8
***********
public class Student {

public static void main(String[] args)


{
boolean b=false;

if(b==false)
{
System.out.println("Hello");

}else
{
System.out.println("Hanumanth");

}
}

switch statement
********************

Ans : Suppose if u want to check one or more conditions then we have to go switch
statement

Syntax:
*********

switch(Expression value){

case value1 : statement1----->code to be executed;

break;

case value2 : statement2----->code to be executed;

break;

case value3 : statement3----->code to be executed;

break;

default : statement4----->Here default case will be


executed when expression value is not matched with any case value.

Syntax Explanation:
********************
1.
2.
3.
4.
5.
6.

Example 1
**********

Group Testing
*****************

1.Smoke Testing
2.Sanity Testing
3.How to run only failure test cases

Smoke Testing
*****************
>To verify whether the main functionalities of the application that is a smoke
Testing

Smoke Testing = Major functionalities + basic functionalities + Major


functionalities

Sanity Testing
*****************
>To verify whether the main functionalities of the application as well as optional
that is a Sanity Testing

Sanity Testing = Major functionalities + basic functionalities + Major


functionalities + optional

Test case execution flow(As per priority order)


**************************************************

Checking Drafts
Checking Promotions
Checking Account Details
Account Logout

Syntax :
************

//tagName[@Attributename='value']

//input[@name='clear']
$x("xpath")

$x("//input[@name='clear']")

R.x + xpath function(position())---->same name of the elements

//input[@name='clear'][position()]

//label[text()='CHARTS / VACANCY'][position()=1]

switch statement
*******************
Syntax :
***********
switch(Expression value){

case value1 :statement1-->Code to be executed;


break;
case value2 :statement2-->Code to be executed;
break;
case value3 :statement3-->Code to be executed;
break;
default :statement4--> Here default case will be executed when all the
case values are not matched with the expression value;
}

Example 1
**********

public class Student {

public static void main(String[] args)


{

int x=10;

switch(x){

System.out.println("Hanumanth"); // error
}
}
}

>In switch block,every statement should be under case value and default case

>In switch block,independent statement is not allowed

Example 2
**********

public class Student {

public static void main(String[] args)


{

int x=0;
int y=1;

switch(x){

case 0 : System.out.println("Hello"); // valid

case y : System.out.println("Hanumanth");// invalid

}
}
}

>In switch block,every case value should be constant, not variable

Example 3
**********

public class Student {

public static void main(String[] args)


{
//local variables

int x=0;
final int y=1; //Here Y is called constant variable

switch(x){

case 0 : System.out.println("Hello"); // valid

case y : System.out.println("Hanumanth");// valid

}
}
}

>Here final is called modifier

>Here final means what constant

>Here Y is called constant variable.Here constant variable value never be changed

that means no increment and no decrement.So always y is 1.

Example 4
**********

public class Student {

public static void main(String[] args)


{
//local variables
int x=1;

switch(x){

case 0 : System.out.println("Hello"); // valid

case 1 : System.out.println("Hanumanth");// invalid

case 1 : System.out.println("Hanumanth");//invalid
}
}
}

>In switch block,duplicate case value not required

Example 5
**********

public class Student {

public static void main(String[] args)


{
//local variables

short b=10; //min -32768 to max 32767

switch(b){

case 10 : System.out.println("Hello"); // valid

case 100 : System.out.println("Hi");// valid

case 1000 : System.out.println("Hanumanth");//invalid


}
}
}

>Here byte type variable can store in the range of the values min -128 to max 127

>Here case 10 is allowed in the range of the values min -128 to max 127

>Here case 100 is allowed in the range of the values min -128 to max 127

>Here case 1000 is not allowed in the range of the values min -128 to max 127

CAse value rules


**********************
1.In switch block,every case value should be constant, not variable

2.In switch block,duplicate case value not required

3.In switch block,every case value must be in the range of argument type(min -128
to max 127)
What is a fall-through(fall-down) inside switch block
*******************************************************

Definition :
**************

>Here expression value is matched any case value from that case onwards all the
statements

will be executed automatically until break statement this is called fall-through.

Why we are using break statement inside switch block ?


*********************************************************
Ans : To stop the fall-through concept

Example 6
**********

public class Student {

public static void main(String[] args)


{
//local variables

int x=0;

switch(x){

case 0 : System.out.println("Hello"); //

case 1 : System.out.println("Hi");//

case 2 : System.out.println("Hanumanth");//

default : System.out.println("Sai");
}
}
}

Name : palla Hanumanth

Education : Degree :B.SC(2006) Post-graduate : MCA(2009)

Expirence : Having 6.2 Years of experience in software testing using Manual and
Automation Testing in Healthcare, eCommerce and Insurance Domains.
Manual Testing : 3.2yrs

Automation Testing : 3yrs

Email id : hanumanthu.palla15@gmail.com

Ph no : 7386035382

Location : Guntur

CCTC : 7.2L

ECTC : 12L

Prefered location : Hyderabad

Ant-xslt-reports(Advanced TestNG Results)


*****************************************

>Convert TestNG Html reports(TestNG Results) into Ant-xslt-reports(Advanced TestNG


Results)

>Email the Ant-xslt-reports(Advanced TestNG Results) for ur TestLead and Project


manager

Data driven framework in selenium


**********************************

Advantages of inheritance
******************************
1.
2.
3.
4.

Syntax:
***********
class Superclass
{

}
class Subclass extends Superclass
{

Example
*********
Manual Steps
**************
1.Create SuperClass(TestBaseclass)
2.Create Subclass(MultipleCustomerLoginTest) from SuperClass(TestBaseclass)

Selenium Java code


********************

In SuperClass
***************

Common code + Additional code(optional)

Common code
***************
@BC
@AC

R.F's

In Subclass
***************

Additional code (Mandatory)


*****************************
@Test

1.How to read the property files ?


2.How to write the data into excel ?
3.How to take the screenshorts when test case failure ?

1.How to read the property files ?


***************************************

Example 7
**************
public class Student {

public static void main(String[] args)


{

char ch = 'r';

switch(ch){

case 'g' :System.out.println("green");

break;

case 'r' :System.out.println("red");

break;

case 'y' :System.out.println("yellow");

break;
default :System.out.println("no color");

}
}
}

default case rules


***********************
>Here default case will be executed when expression value is not matched with any
case value.

>In switch block,we can write default case only once

>In switch block,we can write default case anywhere

Example 8
**************
public class Student {

public static void main(String[] args)


{

int furniture=0;

switch(furniture){

default :System.out.println("no furniture");

case 0 :System.out.println("table");

break;
case 1 :System.out.println("chair");

case 2 :System.out.println("cot");

}
}
}

Why we are using break statement inside switch block ?


******************************************************

Ans : To stop the fall-through

Loops in java?
******************

Why we are using loops in java ?


************************************
Ans : Here loops are used to execute a group of statements repeatedly as long as
the condition

is true.
How to print Hanumanth 100 times ?
************************************
Example 1
************

types of loops
*****************

3.forloop

Where exactly we can use forloop ?


**************************************
Ans : Sometimes we need to perform same action with multiple times so at that time
we need to follow forloop.

Syntax :
***********

for(initialization-part ; condition-part/Testing-part ; increment/decrement-part)


{

//loop body
}

Syntax Explanation :
***********************
How to print 1(starting)-10(ending value) nos ?
******************************
1
2
3
4
5
........10

Example 2
************
public class Student {

public static void main(String[] args)


{

System.out.println("Hanumanth");

}
}

i++

i=i+1
i=1+1
i=2
-----------
i++
i=i+1
i=2+1
i=3

Example 3
************
public class Student {

public static void main(String[] args)


{

System.out.println("Hanumanth");

}
}

Nested forloop(forloop inside another forloop) in java ?


**********************************************************

What is a parameterized Testing ?


************************************

What is a Parallel Testing in selenium ?


*****************************************

2 years 1 months----1

1 years 0 months----2

2 years 1 months

Guntur - Hindu college - degree (B.Sc) - 2006

Chevella(Hyderabad)- New India college - Post-graduate (MCA) - 2009

Hi all,

Today no class

I have urgent work

Next class on saturday

Saturday : @5pm-8pm
Sunday : @5pm-8pm

Please consider

Today i will send u weekend class videos


How to verify webtable data in selenium ?
*******************************************

Company
Launch Pad

How to print 3rd column data ?


*********************************

// To calculate the number of rows in a table


int allRows =
driver.findElements(By.xpath("html/body/table/tbody/tr")).size();

// Get Total rows in the Table


System.out.println("Total rows in a Table -- " + allRows);

for (int m = 1; m <= allRows; m++) {

int n = 1;

String data =
driver.findElement(By.xpath("html/body/table/tbody/tr[" + m + "]/td[" + n +
"]")).getText();

System.out.println(data);

switch statement
******************

Syntax :
************
switch(Expression ){

case value1 :statement1-->Code to be executed;


break;
case value2 :statement2-->Code to be executed;
break;
case value3 :statement3-->Code to be executed;
break;
default :statement4-->Here default case will be execute when expression
value is not matched with any case value;
}

Example 1
**********
public class Student {

public static void main(String[] args)


{
int x=0;

switch(x){

System.out.println("HANUMANTH");//error

}
}
>In switch block,every statement should be under case value and default case
>In switch block,independent statement is not allowed

Example 2
**********
public class Student {

public static void main(String[] args)


{
int x=0;

int y = 10;

switch(x){

case 0 : System.out.println("Hello");//valid

case y : System.out.println("HANUMANTH");//invalid

}
}

>In switch block,every case value should be constant ,not variable

Example 3
**********
public class Student {

public static void main(String[] args)


{
//local variables

int x=0;//valid

final int y = 10;//valid

switch(x){

case 0 : System.out.println("Hello");//valid

case y : System.out.println("HANUMANTH");//valid

}
}

>
>
>

Example 4
**********
public class Student {

public static void main(String[] args)


{

//local variables

int x=0;//valid

switch(x){

case 0 : System.out.println("Hello");//valid

case 1 : System.out.println("HANUMANTH");//invalid

case 1 : System.out.println("HANUMANTH");//invalid

}
}

>In switch block,duplicate case value not required

Example 5
**********
public class Student {

public static void main(String[] args)


{
//local variables

short b=10;// min -32768 to max 32767

switch(b){

case 10 : System.out.println("Hello");//valid

case 100 : System.out.println("Hi");//valid

case 32767 : System.out.println("HANUMANTH");//invalid

}
}

>Here byte datatype variable can store in the range of the values min -128 to max
127

>Here case 10 is allowed in the range of the values min -128 to max 127

>Here case 100 is allowed in the range of the values min -128 to max 127

>>Here case 1000 is not allowed in the range of the values min -128 to max 127

CAse value rules


********************

>In switch block,every case value should be constant ,not variable

>In switch block,duplicate case value not required

>Here every case value should be in the range of argument type

What is a fall-through(fall-down) inside switch block?


***************************************************
Ans : Here expression value is matched any case value from that case onwards all
the statements

will be executed automatically until break statement then this concept is called
fall-through.

Example 6
**********
public class Student {

public static void main(String[] args)


{

//local variables
int x=0;

switch(x){

case 0 : System.out.println("Hello");//

case 1 : System.out.println("Hi");//

case 2 : System.out.println("HANUMANTH");//

default : System.out.println("Sai");//

}
}

Nested forloop(forloop inside another forloop) in java ?


*********************************************************

Difference betweeen print() and println() ?


***********************************************
print()
*********

>By using this ,we can print the text(Hello---) and the curser waits on the same
line
to print the next text.

Example
**********
System.out.print("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
*********
Hello---Hi---
Hanumanth

println()
************
>BY using this ,we can print the text and the curser move to next line
automatically

Example
**********
System.out.println("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");

Output
*********
Hello---
Hi---
Hanumanth

Nested forloop(forloop inside another forloop) in java ?


*********************************************************

Syntax:
***********

for(initialization-part; condition-part/Testing-part; increment/decrement-part)


{

for(initialization-part; condition-part/Testing-part; increment/decrement-


part)
{

//inner forloop body

}//inner forloop end

//outer forloop body

}//outer forloop end

Syntax Explanation
********************
Example
*********

Output
**********

0 1 2
3 4 5
6 7 8

transfer statements
***********************

1.break
2.continue
3.try-catch-final
4.return

1.break statement
*******************

Example 1
**************

public class Student {

public static void main(String[] args)


{
int x=10;

if(x)
{

break;//error
}

}
}
Where we can create break statement ?
****************************************
Ans : Inside the loops and switch block

Without break statement inside switch block


***********************************************

Example 6
**********
public class Student {

public static void main(String[] args)


{

//local variables

int x=0;

switch(x){

case 0 : System.out.println("Hello");//Hello

case 1 : System.out.println("Hi");//

case 2 : System.out.println("HANUMANTH");//

default : System.out.println("Sai");//

}
}

With break statement inside switch block


***********************************************

Example 6
**********
public class Student {

public static void main(String[] args)


{

//local variables
int x=0;

switch(x){

case 0 : System.out.println("Hello");//Hello

case 1 : System.out.println("Hi");//Hi

break;

case 2 : System.out.println("HANUMANTH");//

default : System.out.println("Sai");//

}
}

Without break statement inside forloop


***********************************************
How to print (starting)1-10(ending) nos ?
*******************************************
1
2
3
4
5
.......10

With break statement inside forloop


************************************

Syntax:
***********

for(initialization-part ; condition-part/Testing-part ; increment/decrement-


part)
{

if(condition to break)
{
break;

statements;
}

Synta Explanation
*********************
1.
2.
3.
4.

How to print 1-3 from 1-10 nos?


************************************
Example 4
************
public class Student {

public static void main(String[] args)


{

for(int i=1;i<=10;i++)
{
System.out.println(i);

}
}

page object model that is design pattern not framework,And it can be used in
framework

Types of page object model


***************************
1.without pageFactory
2.with pageFactory

continue statement
*********************

Example 1
*********
public class Student {

public static void main(String[] args)


{

int x=10;

if(x)
{
continue;//error

System.out.println("HANUMANTH");

}
}

Where we can create continue statement ?


******************************************
Ans : inside the loops only

Without continue statement inside forloop


***********************************************
How to print 1-10 nos ?
***************************
1
2
3
4
5
.........10

Example 2
*********
public class Student {

public static void main(String[] args)


{

for(int i=1;i<=10;i++)
{
System.out.println(i);

}
}

With continue statement inside forloop


***********************************************

Syntax:
*************

for(initialization-part; condition-part/Testing-part;
increment/decrement-part)
{

if(condition to continue)
{
continue;

statements;

Syntax Explanation:
********************

1.
2.
3.
4.

How to print 1-10 nos except 3 ?


***************************
Example 3
*********
public class Student {

public static void main(String[] args)


{

for(int i=1;i<=10;i++)
{

if(i==3)
{

continue;

System.out.println(i);

}
}

Why we are using continue statement inside forloop ?


*****************************************************
Ans : By using this, we can skip the value based on condition

Constructor in java ?
************************

>This is similar to method

Why need constructor in java ?


***********************************
Ans :

types constructor
********************
1.default constructor
2.parameterized constructor

1.default constructor
***************************

Student()
{

}
2.parameterized constructor
******************************
Student(para1,para2,para3)
{

>Here constructor doesn't return any value not even void

>In method, return-type is mandatory ?


**************************************
Ans : Yes

1.in default constructor ,how to initialize the values for that instance variables?
***********************************************************************************
Student()
{
name = "Sai";

rollno = 101;

2.In parameterized constructor,how to initialize the values for that instance


variables?
***********************************************************************************
**
Student(String Akki,int 102)
{
name = Akki;
rollno = 102;
}

Example
*********
When default constructor will be called ?
*********************************************
Ans : Whenever u create an object by default default constructor will be called

When function will be called ?


**********************************
Ans : Whenever u create an object after function will be called

When parameterized constructor will be called ?


*********************************************
Ans : Whenever u create an object and passing the values then parameterized
constructor will be called

3.A method is called and executed multiple times per single object
*********************************************************************

4.A constructor is called and executed only once per single object
********************************************************************

In java,constructor overloading is possible ?


**********************************************
Ans :Yes

What is a constructor overloading ?


**************************************
Ans :
Here constructor name same but with different argument types then this concept is
called constructor overloading

5.Here instance variable and local variable both are not same So in this case this
keyword an optional.
***********************************************************************************
*****

this keyword in java ?


************************

How to call the current class instance variable from this keyword ?
******************************************************
Syntax : this.instancevariablename

How to call the current class default constructor from this keyword ?
******************************************************
Syntax : this();

How to call the current class parameterized constructor from this keyword ?
******************************************************
Syntax : this(value1,value2);

How to call the current class method from this keyword ?


******************************************************
Syntax : this.methodname();

Example 2
***********

Calling parameterized constructor and method from default constructor


*********************************************************************
Example
*************
Calling default constructor from parameterized constructor
************************************************************
Example
*************

Calling parameterized constructor from parameterized constructor


*****************************************************************
Example
*************

Why need constructor in java ?


***********************************

Note :
*********
When i run this program by default JVM will provide default constructor and
initialize

the default values for that instance variables.

Student()
{
name = null;
rollno = 0;
}

Output
*********

Student name : null


Student rollno : 0

Page object model contains several packages, let's learn about each package and its
purpose in the framework.

base : base package will contain all the initialization files like opening browser,
initializing logging

constants : constants package will have all the constant files like CSS properties,
Attribute properties.

data : data package will have all the data handling java files like handling excel,
handling properties java files.

testData : In this package i will be keeping all the client requirement files like
excel files

pageObjects : In this pageObjects package will have all the page objects of java
classes

TestCases : The test package will have all the test cases in the framework.
What is pageFactory ?
**********************
PageFactory is a class in selenium.
It is used to achieve page factory design pattern,
it helps to initialize the page objects in the
class using initElements methods. When
I create an object from the page class,
pagefactory initializes the webelements
just before interacting this web element.
It means that once you call the element,
PageFactory class will immediately locate the element
and you will not get a staleElementReferenceException.

When a page object is created,


pagefactory driver (because of the constructor)
will be linked to weblements @findby in that page.

public LoginPage(){
PageFactory.initElements(Driver.get(), this);
}

//--------------Alternative way----------------------

PageFactory.initElements(driver, LoginPageObjects);

>Here PageFactory is a in-built class ,it contain initElements() by using


this(initElements())

we can initialize the page objects,when driver instance is created for the
LoginPage class.

>Or We can say simply that means ,every page object / element needs driver to
identify the elements.

>Suppose if u don't mention PageFactory.initElements(driver, LoginPageObjects);


then driver will not initiate.

Inheritance in java ?(java oops concept)


*****************************************
Why need inheritance in java ?
******************************
Ans :

Without inheritance
*********************
Example
***********

Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create MainClass

Java code
***********

What is a inheritance in java ?


*********************************
Ans :

advantages of inheritance
***************************
Ans : By using inheritance

1.We can reduce the code size


2.We can reduce the development time
3.We can avoid the duplicate code

Main advantages of inheritance


***************************
reuse the code

Syntax:
*********
class Superclas
{

}
class Subclass extends Superclas
{

Example
************
Manual Steps
***************
1.Create Superclass(Teacher class)
2.Create Subclass(Student class) from Superclass(Teacher class)
3.Create MainClass
Java code
***********

In Superclass
****************

common code + Additional code(optional)

In Subclass
**************

Additional code (mandatory)

types of inheritance
**********************

1.Single Inheritance
2.Multi-Level Inheritance
3.Hierarchical Inheritance

1.Single Inheritance
************************
Example 2
***********
Manual Steps
***************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass

Java code
*************
Case 1
*******
Child C = new Child();

C.m1();//call the m1()----valid


C.m2();//call the m2()------valid

Case 2
*******

Page object model part 2


******************************

>Page object Model is a one of the framework.


>In-Page Object Model, we will be working on Pages, and the “Page” refers to Java
classes, which would be storing web page corresponding locators and methods to
perform operations on those web pages.
>When we are working on a small test automation project, using Page Object Model
doesn’t matter, however, when we are working on test automation for a large growing
project, it is highly recommended to use Page Object Model. For large projects, our
test suite typically grows with the time. Hence it would become difficult to
maintain those test scripts if we are not following the Page Object Model.

Example: We have 20 scripts in our test suite for 20 different test cases, but they
do have common web elements interaction. Any change in these elements will force us
to change the locators in all 20 scripts, which would be time consuming and
challenging to maintain. Hence, it is recommended to use Page Object Model, where
we can store our locators at one single place so that they don't consume time when
any changes are required.

>Advantages of using the Page Object Model

Helps in easy maintenance of the test suite.


Develops scripts in a more readable format.
Makes scripts reusable. Efficient and reliable.

Page Object Model with Page Factory


**************************************
Page Factory Class is another way of implementing the Page Object Model.
Even here, our focus is to maintain separate classes for our locators and test
cases.
In this, we make use of @FindBy annotation to find our web elements.
To initialize web elements, Page Factory class provides a method called
initElements used along with parameters i.e., WebDriver reference and class name
storing the web locators.

@FindBy annotation can accept any Selenium locator as a property.

PageFactory.initElements(driver, LoginPageObjects);

>Here PageFactory is a in-built class ,it contain initElements() by using


this(initElements())

we can initialize the page objects,when driver instance is created for the
LoginPage class.

>Or We can say simply that means ,every page object / element needs driver to
identify the elements.

>Suppose if u don't mention PageFactory.initElements(driver, LoginPageObjects);


then driver will not initiate.

Case 1
********
Child C = new Child();

C.m1();//call the m1()----valid


C.m2();//call the m2()------valid

Case 2
********
Parent C = new Child();
C.m1();//call the m1()----valid
C.m2();//call the m2()------invalid

Case 3
********
Parent C = new Parent();

C.m1();//call the m1()----valid


C.m2();//call the m2()------invalid

Multi-Level Inheritance
**************************
Definition :
****************

Syntax:
***********
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Subclass1
{

}
Example 1
***********
Manual Steps
*****************
1.Create Superclass(GrandFather)
2.Create Subclass1(Father) from Superclass(GrandFather)
3.Create Subclass2(Son) from Subclass1(Father)
4.Create Mainclass

Java code
***********
Case 1
********
Son S = new Son();

S.rest();//call the rest()


S.work();
S.study();

Definition:
**************
Example 2
***********
Manual Steps
*****************
1.Create Superclass(Calculation)
2.Create Subclass1(Sum) from Superclass(calculation)
3.Create Subclass2(Subtraction) from Subclass1(Sum)
4.Create Mainclass

Java code
***********

Case 1
**********
Subtraction S = new Subtraction();

S.getData();//call the getData()

S.sum();

S.subtraction();

Hierarchical Inheritance
****************************
Definition:
***************

Syntax :
************
class Superclass
{

}
class Subclass1 extends Superclass
{

}
class Subclass2 extends Superclass
{

}
class Subclass3 extends Superclass
{

Example 1
*******
Manual Steps
***************
1.Create Superclas(Animal)
2.Create Subclass1(Dog) from Superclas(Animal)
3.Create Subclass2(Cat) from Superclas(Animal)
4.Create Subclass3(Cow) from Superclas(Animal)
5.Create Mainclass

Java code
*************
Case 1
*********
Dog D = new Dog();

D.eat();//call the eat()------valid


D.bark();//------valid

Case 2
*********
Animal D = new Dog();

D.eat();//call the eat()----valid


D.bark();//-------invalid

Example 2
********

What is the super() and this() ?


***********************************
Example 1
**************
public class Student {

Student()
{

System.out.println("Hanumanth");
super();//invalid

>Here super() must be in the 1st line in the constructor

Example 2
**************
public class Student {

Student()
{
super();//valid
System.out.println("Hanumanth");

>Here always super() must be in the 1st line in the constructor


Example 3
**************
public class Student {

Student()
{

System.out.println("Hanumanth");
this();//invalid

>Here always this() must be in the 1st line in the constructor

Example 4
**************
public class Student {

Student()
{
this();//valid
System.out.println("Hanumanth");

>Here always this() must be in the 1st line in the constructor

Example 5
**************
public class Student {

Student()
{
super();//valid-------1st place
this();//invalid----2nd place
System.out.println("Hanumanth");

>Here always this() must be in the 1st line in the constructor

Note :
**********

Example 6
**************
public class Student {

void student()
{
super();//invalid

System.out.println("Hanumanth");

}
Where we can create super() and this() ?
********************************************
Ans : Inside the constructor only

> How to call the superclass default constructor using super()?


******************************************************************
Example
********
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
*************

How to call the current class default constructor ?


****************************************************
Syntax :this();

How to call the current class parameterized constructor ?


****************************************************
Syntax :this(value1,value2);

How to call the superclass default constructor ?


****************************************************
Syntax :super();

Example
*********

How to call the superclass parameterized constructor ?


****************************************************
Syntax :super(value1,value2);

Example
***********
Manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangel) from Superclass(Shape)
3.Create MainClass
Java code
*************

Difference between super, this keywords?


****************************************
Why we are using super keyword ?
*********************************
Ans : By using super keyword,we can call the superclass members(variables +
methods)

How to call the superclass variable ?


***************************************
Syntax : super.variablename

Example
**************
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
*************

How to call the superclass method ?


***************************************
Syntax : super.methodname();

Example
**************
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass

Java code
*************
Why we are using this keyword ?
*********************************
Ans : By using this keyword,we can call the current class members(variables +
methods)

How to call the current class variable ?


***************************************
Syntax : this.variablename

How to call the current class method ?


***************************************
Syntax : this.methodname();

************************************************************* 1

http://www.kosmiktechnologies.com/seleniumLiveProject/eKart/admin/
http://makeseleniumeasy.com/2017/10/14/understanding-nullpointerexception-and-how-
to-avoid-it-in-javaselenium/

logs --->https://www.youtube.com/watch?v=Ed1OTpmDfR8

https://www.nexsoftsys.com/articles/page-object-model-factory-selenium.html--page
object model

https://kosmiktechnologies.com/seleniumLiveProject/kcart/index.php?
s=14d72110eb1d4242969fd52fa92d68d5
kadmin
Kkart7

http://kosmiktechnologies.com/seleniumLiveProject/kosmik-hms/

//tagName[text()='value']

//tagName[contains(text(),'value')]

(javascriptExecutor)driver.executeScript(script,argument);

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
//scroll till the target element(News)

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();",
driver.findElement(By.linkText("News")));

Sarath : MR_NO PR6041657208

<class name="Packagename.classname">
<methods>
<include name="testMethod"/>
<include name="testMethod"/>
<include name="testMethod"/>
<exclude name="testMethod"/>
</methods>

https://meet.google.com/bdz-uuyn-srk

[6:37 pm, 23/05/2021] Bhavani Selenium Kosmik: Hi sir,


new creditials for 8AM
Mail id: kosmiktech3607@gmail.com
Password:kosmik@1234

674-122-957

8AM Link:https://www.gotomeet.me/kosmiktech3607

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
New credentials:
Mail id:kosmiktech900@gmail.com
Password:kosmik@1234

8am,7pm,10:30am : Link:https://www.gotomeet.me/kosmiktech900
--------------------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
**************************************************************
Mail Id:kosmiktech664@gmail.com
Password:kosmik@1234
Link:
Link:https://www.gotomeet.me/kosmiktech664

Mail Id: kosmiktech935@gmail.com


Password:kosmik@456
9am--Link: https://www.gotomeet.me/kosmiktech935

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

For 9AM batch


Mail id:kosmiktech3608@gmail.com
Password : kosmik@1234

9Am Link:https://www.gotomeet.me/kosmiktech3608
---------------------------------------------------
Hanumanth SeleniumJavaTraining
hseleniumjavatraining@gmail.com
Asdfghjkl@123

Hanumanth SeleniumJavaRealTimeTraining's Meeting

Please join my meeting from your computer, tablet or smartphone.


https://www.gotomeet.me/hseleniumjavatraining

You can also dial in using your phone.


United States: +1 (408) 650-3123

Access Code: 349-247-485


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SeleniumJava Training
seleniumjavatraining3@gmail.com
Asdfghjkl@123

------------------------------------------------
SeleniumJava Training's Meeting

Please join my meeting from your computer, tablet or smartphone.


https://www.gotomeet.me/seleniumjavatraining3

You can also dial in using your phone.


United States: +1 (646) 749-3122

Access Code: 257-291-509

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Selenium training
trainingselenium9@gmail.com
Asdfghjkl@123
************************************************************

SeleniumJava Training's Meeting

Please join my meeting from your computer, tablet or smartphone.


https://www.gotomeet.me/trainingselenium9

You can also dial in using your phone.


United States: +1 (646) 749-3122

Access Code: 251-483-189

[6:35 am, 28/05/2021] Haritha Stud 2021: hanumanthseleniumjava@gmail.com


[6:37 am, 28/05/2021] Haritha Stud 2021: hanumanthseleniumtraining6@gmail.com
[6:39 am, 28/05/2021] Haritha Stud 2021: seleniumjavatraining1@gmail.com
[6:41 am, 28/05/2021] Haritha Stud 2021: testlinklabs1@gmail.com

hseleniumjavatraining@gmail.com------june,2021
hanumanth.selenium@gmail.com
hanumanthkt2020@gmail.com
hanumanthseleniumtraining@gmail.com

hanumanthseleniumjava@gmail.com----->Kalyan movva batch


hanumanthseleniumtraining6@gmail.com
seleniumjavatraining1@gmail.com
testlinklabs1@gmail.com

Imp Points
**************
>Cource Content--->Give me your Email id then I will send you Course Content
>Interview Questions and Answers on Java---->200+
>Interview Questions and Answers on Selenium--->200+
>Resume preparation --->After Course Complete
>Doubts sessions--->Daily
>Weekly Test --->Mon---Sat---->25+
>Job Assistance
>Mainly selenium and Java soft copy =low level students + average students + high-
level students

Selenium Java Training = Java Training + Selenium basic level + Selenium advance
level + Selenium Project level +

WhatsApp no : 7386467494

***************************************************************2

k57498445@gmail.com
Kosmik@5
New credentials sir
Link: https://www.gotomeet.me/k57498445

Mail Id:kosmiktech366@gmail.com
password:kosmik@1234
link:https://www.gotomeet.me/kosmiktech366
@7pm batch new credentials sir
ID: 805-800-109

Mail Id:kosmiktech344@gmail.com
password:kosmik@1234
Link:https://www.gotomeet.me/kosmiktech344

Mail Id:kosmiktech499@gmail.com
password:kosmik@1234
Link:https://www.gotomeet.me/kosmiktech499
@8AM new credentials

Mail Id:kosmiktech399@gmail.com
password:kosmik@1234
Link:https://www.gotomeet.me/kosmiktech399
@9AM new credentials

Mail id:kosmiktech600@gmail.com
Password:kosmik@1234
Link:https://www.gotomeet.me/kosmiktech600
New credentials @8AM batch sir
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Today demo link
*******************
Mail Id:kosmiktech664@gmail.com
Password:kosmik@1234

483-435-061

Link:https://www.gotomeet.me/kosmiktech664
New credentials of@9AM slot sir
****************************************************************

hanumanthselenium01@gmail.com
Asdfghjkl@123

https://www.gotomeet.me/hanumanthselenium01
Today u can join in this meeting@10am

Access Code: 492-254-917

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

SeleniumJava Training
seleniumjavatraining3@gmail.com
Asdfghjkl@123

https://www.gotomeet.me/seleniumjavatraining3

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hseleniumtraining@gmail.com
Asdfghjkl@123

https://gotomeet.me/hseleniumtraining

hanumanth.tester@gmail.com
Asdfghjkl@123

https://www.gotomeet.me/hanumanthtester7

U can join in this meeting daily

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
seleniumjavahanumanth@gmail.com
Asdfghjkl@123
Hanumanth SeleniumJava Training's Meeting

Please join my meeting from your computer, tablet or smartphone.


https://www.gotomeet.me/seleniumjavahanumanth

You can also dial in using your phone.


United States: +1 (408) 650-3123

Access Code: 338-168-349

You can join in this meeting

https://www.toolsqa.com/selenium-cucumber-framework/read-configurations-from-
property-file/

Advantages of Property file in Java

If any information is changed from the properties file, you don’t need to recompile
the java class.
In other words, the advantage of using properties file is we can configure things
that are prone to change over a period of time without need of changing anything in
code.

For E.g. We keep application Url in the property file, so in case you want to run
test from on other test environment, just change the Url in a property file and
that’s it. You do not require to build the whole project again.

https://www.youtube.com/watch?v=y8qjARHVScA ----------Git

************************************************************4
Selenium Automation Testing Demo-------->15685
xpath in selenium--->14014
What are the common Exception you faced in your project?----14394
What is a method in java?----14541
What is a constructor?----14914
this keyword------->15372
What is a class and object in java ?------>15730

103648---->

What are the different element Locators in selenium ?


******************************************************

1. id---------1
2. Name---------2
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName---------3
7. cssSelector
8. Xpath--------4
TestSteps:
************
Open Firefox Browser
Open AppURL In Browser
Get the Title of WebPage
Verify Title of WebPage
Enter the username
Enter the password
Clicking On Login Button
Identify and get the Welcome selenium text
Verify Welcome selenium text

Switch to frame

Handle DropDown in Selenium


****************************
a) How to print all the dropdown values

>First,get the dropdown size

1.First,Identify dropdown
2.Next,Identify all the values from this dropdown

>print all the dropdown values

b) How to Select the dropdown value inside a frame

>Switch to frame
>Identify dropdown
>Select the dropdown value

c) How to verify selected value from dropdown

>get the selected value


>Verify selected value

d) How to Verify dropdown values

Again switch back to main window from frame

Clicking On Logout Button


Close the Firefox Browser

Testing = operation code + verification code


http://register.rediff.com/register/register.php?FormName=user_details

https://www.kosmiktechnologies.com/seleniumLiveProject/kosmik-hms/

>Int datatype can store in the range of values min -2147483648 to max 2147483647

>Long data type can store in the range of values min -9223372036854775808 to max
9223372036854775807
--------------------------------------------------------------------

Button : Login

Html code : <input name=submit>

Selenium code : driver.findElement(By.id("submit")).click();


>How to work with disable textbox or password field. ?

file:///E:/Selenium%20Software%20dump%20files/Browser%20Elements/disabled.html
--------------------------------------------------------------------
//wait 15 sec until the See all element is visible on a webpage once the element is
visible then click on See all link on a webpage

WebDriverWait wait = new WebDriverWait(WebDriverReference,TimeDuration);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.Locator("LocatorValue")
));

until()==>wait for certain amount time until the See all element is visible on a
webpage

visibilityOfElementLocated==>It is used to check that an element is present on the


web page and visible also.

>Float datatype can store in the range of the values min -3.4028235e38F to max
3.4028235e38F

ASCII table

https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html

Imp Points
***********
>Cource Content--->Give me your Email id then I will send you Course Content
>Interview Questions and Answers on Java---->200+
>Interview Questions and Answers on Selenium--->200+
>Resume preparation --->After Course Complete
>Doubts sessions--->Daily
>Weekly Test --->Mon---Sat---->25+
>Job Assistance
>Mainly selenium and Java soft copy =Low level students + Average students + High-
level students

>Selenium Java Training = Java Training +Selenium basic level +Selenium advanced
level+ Selenium Project level +

WhatsApp No : 7386467494
How to scroll to particular / target Webelement using selenium javascript?
****************************************************************

Syntax :
**********

((JavascriptExecutor)
driver).executeScript("arguments[0].scrollIntoView();",targetelement);

>scrollIntoView()==>By using this we can scroll till the target Webelement

Rediff mail
***************

http://register.rediff.com/register/register.php?FormName=user_details

to call instance variable from this keyword ?


************************************************
Syntax :this.variable

How to call default constructor from this keyword?


------------------------------------------
Syntax : this()

How to call the parameterized constructor from this keyword?


------------------------------------------
Syntax : this(value)

How to call method from this keyword?


------------------------------------------
Syntax : this.methodname()
How to call the instance variable from this keyword ?
*****************************************************

Syntax : this.variable

How to call the default constructor from this keyword ?


***********************************************

Syntax : this()

How to call the parameterized constructor from this keyword ?


*************************************************************

Syntax :this(value)

How to call the method from this keyword ?


********************************************

Syntax : this.methodname()

To download Eclipse oxygen,Follow the Url

https://www.eclipse.org/downloads/packages/release/oxygen/3a

Follow the Steps


****************

1.Create Superclass(Animal)
2.Create subclass1(Dog) from Superclass(Animal)
3.Create Subclass2(Cat) from Superclass(Animal)
4.Create Subclass3(Cow) from Superclass(Animal)

Follow the Steps


****************

1.Create Superclass(College)
2.Create subclass1(Principal) from Superclass(College)
3.Create Subclass2(Teacher) from Superclass(College)
4.Create Subclass3(Student) from Superclass(College)

Manual TestSteps:
***************
> Open the firefox browser
> Navigate the application url
> Get the Title of the WebPage
> Print the title of the webpage
> Verify Title of the WebPage
> Enter the username
> Enter the password
> Clicking On Login Button
> Identify and get the Welcome Selenium Text
> Print the Welcome Selenium Text
> To verify whether the welcome page successfully opened or not
> Clicking On Logout Button
> Close the current Firefox Browser

What are the different element Locators to identify the element in selenium ?
******************************************************

1. id----------1
2. Name---------2
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName---------3
7. cssSelector
8. Xpath---------------4

https://www.kosmiktechnologies.com/new-batches/">

https://www.ebay.com/b/PDAs/38331/bn_1638584

Linktext-TestSteps :
********************
>open the Firefox Browser
>Navigate the App Url
> Click on New Batches footer link

Classname
**************
Test Steps :
>open the firefox browser
>navigate the App Url
>Enter Email address into Email or Phone textbox

https://www.kosmiktechnologies.com/new-batches/

https://www.facebook.com/?
min -128 to max 127

What are valid and invalid statements?--IQ


*****************************************

a) byte a=-128;
b) byte b=127;
c) byte c=128;
d) byte d=1.27;
e) byte e="kosmik";
f) byte f=125;
g) byte g=true;

>short data type can store in the range of values min -32768 to max 32767

>min -32768 to max 32767

What are valid and invalid statements?--IQ


*****************************************
short a = -32768;
short b = 32767;
short d = 3.2767;
short e = true;
short f = "Kosmik";

short b = 32768;

What are the integral literal values ?


*****************************************
Ans : byte value,short value,int value,long value

What are the floating-point literal value?


********************************************
Ans : float value and double value

>Int datatype can store in the range of values min -2147483648 to max 2147483647

min -2147483648 to max 2147483647

What are valid and invalid statements?--IQ


*****************************************

int a=-2147483648;

int b=2147483647;

int d=21.47483647;

int e=true;

int g=2147483647L;

int h="Kosmik";
>Long data type can store in the range of values min -9223372036854775808 to max
9223372036854775807

min -9223372036854775808 to max 9223372036854775807

What are valid and invalid statements?--IQ


*****************************************
long a=-9223372036854775808L ;

long b=9223372036854775807L;

long l=100;

long d=92.23372036854775807;

long e=true;

long f="Kosmik";

What are valid and invalid statements?--IQ


*****************************************

boolean a = 0;

boolean b = "true";

boolean c = True;

boolean d = true;

What are valid and invalid statements?--IQ


*****************************************

String str1 = "kosmiktech";

String str2 = "KOSMIKTECH";

String str3 = kosmiktech ;

String str4 = 10;

String str5 = true;

min -3.4028235e38F to max 3.4028235e38F

What are valid and invalid statements?--IQ


*****************************************

float a = 2.356f;

float b = -125.563f;

float d = -101.23;

float f=10.111111111f;

float f = 25f;
float g = 25;//25.0

>Here variable f can store in the range of values min -3.4028235e38F to max
3.4028235e38F

min -1.7976931348623157e308d to max 1.7976931348623157e308D

What are valid and invalid statements?--IQ


*****************************************

double a = 2.356;

double b = -125.563;

double d=10.1111111111111111;//16 1's

double d=10.1111d;

double h = true;
double h = "Hanumanth";

double i= 10.234f; //valid

>Double dataType can store in the range of values

byte(least) < short < int < long < float < double(highest)

char(least) < int < long < float < double(highest)

Note :
----------
Logical And (&&)

F&&F---F
T&&T---T
T&&F---F
F&&T---F

Logical OR (||)

F||F---F
T||T---T
T||F---T
F||T---T

Logical NOT(!)

!False=true
!True=false
---------------------------------------------------------
How to verify multiple checkboxes in a webpage using sselenium?
***********************************************************
Test steps
***********
 Open the firefox browser
 Navigate the AppUrl
 Identify all Checkboxes
 count total checkboxes
 Verify multiple checkboxes one by one
 Close the current Browser window

How to count total checkboxes in a webpage ?


**********************************************
Manual steps
***************
1.Identify all Checkboxes
2.count total checkboxes

Example
*********

List<WebElement> allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));

System.out.println("Total checkboxes : "+allchk.size());//3

How to Verify multiple checkboxes one by one ?


*************************************************

Manual steps
***************
1.Identify all Checkboxes
2.count total checkboxes
3.Verify multiple checkboxes one by one

Example
*********
List<WebElement> allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));

System.out.println("Total checkboxes : "+allchk.size());//3

//Verify multiple checkboxes one by one


for(int i=0;i<allchk.size();i++)
{

allchk.get(i).click();

if(allchk.get(i).isSelected())
{
System.out.println("checkbox selected successfully");
}else
{
System.out.println("checkbox not selected successfully");
}
}

Handling popups
*****************
1. How to Handling Web-Based alert Popup/Javascript Alert Popup.
2. How to Handling modal popup window.
3. How to Handling multiple popup windows.

How to Handling Web-Based alert Popup/Javascript Alert Popup.


************************************************************
Manual steps
***************
1.switch to alert box
2.get the alert text
3.click on ok button from alert box

Example
*********

//switch to alert box

Alert alert = driver.switchTo().alert();

String alet_text = alert.getText();

System.out.println(alet_text);//alert text verified successfully

//verify alert text

if(alet_text.equals("alert text verified successfully"))


{
System.out.println("Alert text vcerified successfully");
}else
{
System.out.println("Alert text not vcerified successfully");
}

//click on ok button

alert.accept();

Free Selenium Java Automation Training :

Free Recording Videos and Material:


*********************************
Selenium(Basics + Advanced)

>Material
>Videos
>Interview Questions

Core Java(Basics + Oops concepts + Collections)

>Material
>Videos
>Interview Questions

Who are inetrested plz join in this group :

https://chat.whatsapp.com/JJI9TKM6EcrCqStHw4cWSe

Whatsapp no : 7386467494

2. How to Handle modal popup window.


***************************************
 Open the firefox browser
 Navigate the Application Url
 1.Switch to modal popup window
 2.Do some action
 3.Identify and click on popup window

>Int datatype can store in the range of values min -2147483648 to max 2147483647
What are valid and invalid statements?--IQ
*****************************************
char a = 'd';
char b = d;
char c = "d";
char d = 'dd';
char e = 66;
int f = 'd';

1.Read the property files into the working environment

>Create the Properties object for that config. property file


>Read the config. property file into a working environment
>Store the config.property file in a memory location(a Config reference
variable)

>Create the Properties object for that OR.property file


>Read the OR.property file into the working environment
>Store the OR.property file in a memory location(an OR reference variable)

Handling Frames
*****************
1.How to handle single frame
2.How to handle multiple frames
3.How to handle Nested frames(frame inside a frame)

>Here variable s can store in the range of values min -32768 to max 32767
>Int datatype can store in the range of values min -2147483648 to max 2147483647

>Float datatype can store in the range of the values min -3.4028235e38F to max
3.4028235e38F

((JavascriptExecutor) driver).executeScript(script,argument);

Syntax :

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-pixels,y-pixels)");

((JavascriptExecutor)
driver).executeScript("arguments[0].scrollIntoView();",driver.findElement(By.linkTe
xt("News")));

scrollIntoView() : By using this we can scroll till the target element


Follow ASCII table in java

https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html

Chromedriver.exe
*****************

https://sites.google.com/a/chromium.org/chromedriver/

System.setProperty("webdriver.ie.driver","E:\\Selenium Software dump


files\\Seleniumworkspace\\Seleniumproject\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();

driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");

Note :
========
Logical And (&&)

F&&F---F
T&&T---T
T&&F---F
F&&T---F

Logical OR (||)

F||F---F
T||T---T
T||F---T
F||T---T

Logical NOT(!)

!False=true
!True=false

Send Email to TestLead


************************
Step 1: Log in to the Jenkins Homepage
Step 2: Install Email Extension Plugin
Step 3: Configure System
Step 4: Create Jenkins Job
Step 5: Send e-mail
Explicit wait:
**************
This will be used only for target element(See all)

Syntax :
*********
//wait 15 sec until the See all element is visible on a webpage once the element is
visible then click on See all link on a webpage

WebDriverWait wait = new WebDriverWait(WebDriverReference,TimeDuration);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.Locator("LocatorValue")
));

https://github.com/mozilla/geckodriver/releases

What are the different element Locators in selenium to identify the


element/object ?--IQ
******************************************************

1. id----1
2. Name---------2
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName-------3
7. cssSelector
8. Xpath----------4

//open the Firefox Browser


System.setProperty("webdriver.gecko.driver","F:\\Seleniumworkspace\\
SeleniumDemoProject\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();

How to call the instance variable from this keyword?


*********************************************************
Syntax : this.variablename
How to call the default constructor from this keyword?
*******************************************************

Syntax : this()

How to call the parameterized constructor from this keyword?


**************************************************************

Syntax :this(value)

How to call the method from this keyword?


*********************************************

Syntax : this.methodname()

Example
*************

short s=32768;//invalid

System.out.println(s);

Code Expla

Ex :
*****
1.Teacher--------100%-------complete knowledge (void teacher(){})
2.Student--------100%-------complete knowledge (void student(){})
3.Chort board----100%-------complete knowledge (void chortboard(){})

4.Fee-------50%---------incomplete knowledge (abstract void fee();)

1.Teacher--------50%-------incomplete knowledge (abstract void teacher();)


2.Student--------50%-------incomplete knowledge (abstract void student();)
3.Chort board----50%-------incomplete knowledge (abstract void chortboard();)
4.Fee-------50%---------incomplete knowledge (abstract void fee();)

@Tes-2
******************
Manual Steps
*****************
1.Read the property files
2.Open the FF
3.Navigate the app URL
----
----

>Create single customergroup


>To verify whether the single customergroup successfully created or not.
>Create multiple customergroups
>To verify whether multiple addcustomergroups successfully created or not
>Click on logout
>close the browser

Selenium Java code


**********************

@Test -3
*************

Manual Steps
*****************
1.Read the property files
2.Open the FF
3.Navigate the app URL
----
----

>Create single customer under kosmik 01


>To verify whether the single customer successfully created or not under kosmik 01.
>Create multiple customers under kosmik 01
>To verify whether multiple addcustomers successfully created or not under kosmik
01

>Click on logout
>close the browser

Selenium Java code


************************

class Superclass
{
@BT
@AT

R.F

}
class Subclass1 extends Superclass
{
@BT
@AT
R.F

@Test 1

class Subclass2 extends Superclass


{
@BT
@AT

R.F

@Test 2

<suite name="Suite" >


<test name="Test">
<classes>
<class name="com.Banking.Customer.Subclass1"/>

<class name="com.Banking.Customer.Subclass2"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

Output
*********
@BT

@Test 1
@Test 2

@AT

Output
*********
@BC
@Test 1

@AC

@BC

@Test 2

@AC

@BC
@Test 3

@AC
@BC

@Test 4

@AC

String S="Hanumanth";

1.How to convert int type value into string type ?


**************************************************

int x=125;

Syntax : String.valueOf(int type value);

String.valueOf(x);

String.valueOf(125);

"125"

2.CAn we declare a class as a data type ?


********************************************
Ans : Yes

3.Can we enter numeric value into input field(textbox,textarea) by using sendKeys()


?
*************************************************************
Ans : NO

@Tes-3
******************
1.Create single customer under kosmik1
2.To verify whether the single customer successfully created or not under kosmik1.
3.Create multiple customers under kosmik1
4.To verify whether multiple customers successfully created or not under kosmik1.
What is the super, this keywords?

Why we are using super keyword ?


Ans : By using this, we can call the superclass members(variables + methods)
How to call the superclass variable ?
Ans : super.variablename

How to call the superclass method ?


Ans : super.methodname();
Why we are using this keyword ?
Ans : By using this, we can call the current class members(variables + methods)
How to call the current class variable ?
Ans : this.variablename
How to call the currentclass method ?
Ans : this.methodname();

class Test{

@BC
@AC

@Test1
@Test2
@Test3

output
********

@BC

@Test1
@Test2
@Test3

@AC

class Superclass{

@BT
@AT

}
class Subclass1 extends Superclass{

@BT
@AT
@Test1

class Subclass2 extends Superclass{

@BT
@AT

@Test2

----------------------
@BT

@Test1
@Test2

@AT

Output
***********

@BT

@Test1
@Test2
@AT

What is the default package of selenium ?


*********************************************
Ans : org.openqa.selenium

get() :

getTitle() :

How to verify title of the webpage ?


***************************************
Manual Steps
**************
 Get the Title of the WebPage
 Print the title of the webpage
 Verify Title of the WebPage

Testing = operation code + verification code

Selenium Java code


***********************

//operation code

// Get the Title of the WebPage

String title = driver.getTitle();

// Print the title of the webpage

System.out.println(title);//OrangeHRM - New Level of HR Management

//verification code

// Verify Title of the WebPage

if(title.equals("OrangeHRM - New Level of HR Management"))


{
System.out.println("title verified successfully");

}else
{
System.out.println("title not verified successfully");
}

Selenium WebDriver
*********************

>By using this,we can identify element


>After identify the element then do some action on that element

Difference between findElement and FindElements ?


******************************************************
findElement() :

<class name="Packagename.classname">
<methods>
<include name="testMethod"/>
<include name="testMethod"/>
<include name="testMethod"/>
<exclude name="testMethod"/>
</methods>
</class>

Subject : Today’s status on 02-04-2021

Hanumanth lgit <hanumanth.lgit@gmail.com>

Chromedriver.exe
*****************

https://sites.google.com/a/chromium.org/chromedriver/

geckodriver.exe

https://github.com/mozilla/geckodriver/releases

How to download Fire IE Selenium


**********************************

https://code.google.com/archive/p/fire-ie-selenium/downloads

Subject : Today's status on 15-08-2021 10AM

Hi Hanumanth,

Please find below key notes of today's status

Key Notes :

1.Understanding requirements-2hours
2.Prepared the Test cases-2hours
3.Execute the Test cases-2hours
4.Meeting with Project manager-2hours

Please Let me know if you have any Queary

Thank You,

Venkat P
Company name
phno
Syntax :
**********

((JavascriptExecutor) driver).executeScript(script,argument);

((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis-pixels,y-axis-
pixels)");

((JavascriptExecutor)
driver).executeScript("arguments[0].scrollIntoView();",driver.findElement(By.linkTe
xt("News")));

scrollIntoView() : By using this we can scroll till the target element(news)

Data driven framework


*************************

Subject : Today’s status on 04-04-2021

Hi Rajasekhar,

Please find below key notes of today’s status.

Key Notes :

1.Understanding Requirements : 1hour


2.Prepared 5 Selenium Automation Test cases : 3hours
3.Meeting with Project manager : 2hours
4.Work with Opencart Project : 2hours

Let me know if you have any Query

Thank You,

Hanumanth. P,
Sr. Software Test Engineer,
Melstar Information Technologies,
ph no:+91- 7386467494
3157836470,

Hanumanth SeleniumTraining <hanumanthseleniumtraining6@gmail.com>

C/o Palla Hanumanthu


Hno : 4-1634/2/30/B,2nd floor
Allwyn colony - 2nd phase,
Near Jalakanya hotel,
kukatpally,
Hyderabad.
500072.

You might also like