Selenium Java Training
Selenium Java Training
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.
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 the Eclipse Oxygen, you can choose version Windows 32 bit or 64 bit based
on your OS
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
>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 :
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;
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
>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
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;
boolean b = "true";
System.out.println(b);
boolean c = True;
System.out.println(c);
boolean d = true;
System.out.println(d);
}
}
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
>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;
float b = -125.563f;//currect
System.out.println(b);
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;
double b = -125.563;//currect
System.out.println(b);
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
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;
}
}
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
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
//instance method
void m1()
{
System.out.println("Instance area "+name);//Sai
}
}
}
//instance variables
int i;
String str;
boolean b;
double d;
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
}
>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.
//create method
void m1()
{
//create constructor
Student()
{
int y=20;//local variable
//create if block
If(){
}
>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 {
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 {
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 {
//local variables
protected float=4.6f;//invalid
int x=10;//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
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 {
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 {
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
//instance method
void m1()
{
System.out.println("Instance area-->print student name through class
name :"+Student.name);//Sai
>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()
{
>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);
}
>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
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
Student.collegeName="Kosmik";
}
>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
Student.collegeName="Kosmik";
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
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;
void add() {
int a = 10;
int b = 20;
int c = a + b;
System.out.println(c);
Example 2
package MethodOnlineClassesExamples;
int add() {
int a = 10;
int b = 20;
int c = a + b;
return c;// 30
System.out.println(result);// 30
}
}
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;
System.out.println(c);//30
WithoutUsingReturnAndWithParameters objectRef=new
WithoutUsingReturnAndWithParameters();
}
Write a program for a method With return statement and with parameters:-
******************************************************************************
Example 4
package MethodOnlineClassesExamples;
return c;// 30
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 :
Example 1
int dog_age=5;
int cat_age=5;
if(dog_age==cat_age)
{
System.out.println("Animals age matched");
}
Example 2
int dog_age=7;
int cat_age=5;
if(dog_age==cat_age)
{
System.out.println("Animals age matched");
}
Note :
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 :
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;
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
Example 5
package Control_Flow;
int A=10;
if(A)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");
}
Code Explanation :
Found : int
Required : boolean
Example 6
package Control_Flow;
int x=10;
if(x=20)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");
}
}
}
Code Explanation :
Found : int
Required : boolean
Example 7
package Control_Flow;
int x=10;
if(x==20)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");
}
}
}
Code Explanation :
Found : boolean
Required : boolean
Note :
>java compiler compile the code (whether the code is correct or not).
>JVM will execute the code .
Example 8
package Control_Flow;
boolean b=true;
if(b=false)
{
System.out.println("Hello");
}else
{
System.out.println("Kosmik");//Output--Kosmik
}
}
}
Code Explanation :
Found : boolean
Required : boolean
Example 9
package Control_Flow;
boolean b=false;
if(b==false)
{
System.out.println("Hello");//Output--Hello
}else
{
System.out.println("Kosmik");
}
}
}
Code Explanation :
Found : boolean
Required : boolean
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
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
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
int x=10;//local
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;
switch(x)
{
case 10 : System.out.println(10);//valid
break;
switch(x)
{
case 10 : System.out.println(10);
break;
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
Example 6
***************
package Control_Flow;
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;
char ch='r';
switch(ch){
Example 7
***************
package Control_Flow;
int furniture=0;
switch(furniture){
case 0: System.out.println("table");
case 1: System.out.println("chair");
break;
case 2: System.out.println("cot");
}
}
}
Loops in java ?
********************
Example 1
************
public class Loops_Statement {
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
Syntax :
*********
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
//loop body
>
>
Example 1
*************
Example 2
************
public class Loops_Statement {
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;
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;
}
}
>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;
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?
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
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");
System.out.println("Hanumanth");
Example 2
public class ForLoop {
}
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 :
int k = 0;
k++;
System.out.println();
}
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 {
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{
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
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 {
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;
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;
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.
System.out.println(x);//
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;
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;
// instance variables
String name;
int rollno;
Student1() {
name = "Sai";
rollno = 100;
}
void stud_Details() {
System.out.println("Hi this is :" + name);
System.out.println("My rollno :" + rollno);
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.
String name;
int rollno;
Student2() {
name = "Sai";
rollno = 100;
name = Name;
rollno = Rollno;
void stud_Details() {
System.out.println("Hi this is :" + name);
System.out.println("My rollno :" + rollno);
}
}
Example :
Program :
package ConstructorPack;
// instance variables
String name;
int rollno;
// here default constructor is called and executed
Student() {
name = "Sai";
rollno = 100;
name = Name;
rollno = Rollno;
void stud_Details() {
System.out.println("Hi this is :" + name);
System.out.println("My rollno :" + rollno);
}
1.A method is called and executed multiple times per single object
Example :
package ConstructorExamples;
// instance variables
String name;
int rollno;
}
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;
Student3(String name) {
Student3(int id) {
}
}
4.If instance variable and local variable both are not same then in this case this
keyword an optional.
Example
package ConstructorExamples;
package ConstructorExamples;
// Instance variable
int a = 10;
void stud_Details() {
// local variable
int b = 20;
System.out.println(b);
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
//Instance variable
int a=10;
void stud_Details()
{
//local variable
int a=20;
Example 2
package ConstructorExamples;
// instance variable
int a = 10;
this.a = a;
void stud_Details() {
System.out.println(a);// 10
}
Calling parameterized constructor and method from default constructor
Example
package ThisKeywordExamples;
// instance variable
int a;
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
Student2() {
System.out.println("Hello Hanumanth");
}
Student2(int a) {
this();// call the default constructor
System.out.println(a);// 10
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
}
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;
return-type method_name1()
{
}
return-type method_name2()
{
main()
{
}
Example
package Method_Function;
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;
}
//instance variable
int id;
String name;
String address;
int marks;
>In this program,an object to Teacher class is created by JVM ,as shown below
System.out.println("*******Student details******");
>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;
>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
}
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)
In superclass(Teacher class)
//Common code
>setId()
>setName()
>setAddress()
>getId()
>getName()
>getAddress()
// Additional code(optional)
>setSal()
>getSal()
In subclass(Student class)
//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:
package JavaExamples;
//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;
}
package JavaExamples;
//instance variable
int 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;
System.out.println("*******Student details******");
}
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;
void m1()
{
System.out.println("Parent");//parent
}
Child(Subclass):
package Inheritance_Example2;
void m2()
{
System.out.println("Child");//child
MainClass
package Inheritance_Example2;
}
Case 1
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 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
void rest() {
System.out.println("rest");
}
}
Subclass1(Father)
package MultiLevelInheritance;
void work() {
System.out.println("work");
}
}
Subclass2(Son)
package MultiLevelInheritance;
void study() {
System.out.println("study");// study
}
MainClass
package MultiLevelInheritance;
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
// Instance variables
int x;
int y;
}
Subclass1(Sum)
package MultiLevelInheritance3;
// instance variable
int sum;
}
Subclass2(Subtraction)
package MultiLevelInheritance3;
// Instance varible
int sub;
}
Mainclass
package MultiLevelInheritance3;
Case 1
>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
Syntax :
class Superclass
{
}
class Subclass1 extends Superclass
{
}
class Subclass2 extends Superclass
{
}
class Subclass3 extends Superclass
{
}
Example 1
void eat()
{
System.out.println("Eating");
}
Subclass1(Dog)
package HierarchicalInheritance1;
void bark() {
System.out.println("Barking");
}
Subclass2(Cat)
package HierarchicalInheritance1;
void meow() {
System.out.println("Meowing");
}
Subclass3(Cow)
package HierarchicalInheritance1;
void moo() {
System.out.println("Mooing");
}
Mainclass
package HierarchicalInheritance1;
public class MainClass {
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
// Instance variables
int id;
String name;
String address;
int getId() {
return id;
}
String getName() {
return name;
}
String getAddress() {
return address;
}
Subclass1(Principal1)
package HierarchicalInheritanceExample3;
void evaluate() {
System.out.println("Evaluating");
}
Subclass2(Teacher1)
package HierarchicalInheritanceExample3;
// instance variable
int sal;
int getSal() {
return sal;
}
Subclass3(Student1)
package HierarchicalInheritanceExample3;
// Instance variable
int marks;
int getMarks() {
return marks;// 500
}
Mainclass
package HierarchicalInheritanceExample3;
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;
Animal()
{
System.out.println("Animal is created");//Animal is created
}
Subclass(Dog2)
package SuperThisExample;
Dog2() {
super();// call the super class default constructor.
Mainclass
package SuperThisExample;
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;
// Instance variables
int l;
int b;
Shape1(int l, int b) {
this.l = l;
this.b = b;
Subclass(Rectangle2)
package SuperThisExample2;
Rectangle2() {
Mainclass
package SuperThisExample2;
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 :
Ans: By using this, we can call the current class default constructor
Ans: By using this, we can call the current class parameterized constructor
1.Create superclass(Animal)
2.Create subclass(Cat6) from superclass(Animal)
3.Create Mainclass
Superclass(Animal)
package ThisSuperExample1;
// 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
MainClass
package ThisSuperExample1;
Example 2
1.Create superclass(Animal1)
2.Create subclass(Cat7) from superclass(Animal1)
3.Create Mainclass
Superclass(Animal1)
package ThisSuperExample2;
void meow()
{
System.out.println("This is a Animal class");
}
Subclass(Cat7)
package ThisSuperExample2;
void meow()
{
void display()
{
super.meow();//To call the super class meow()
Mainclass
package ThisSuperExample2;
Ans: Yes
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
Types of polymorphism
Example 1
************
package Methodoverloading3;
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);//
}
}
}
Definition 2
************
>Here method name same but with different method signature then it is called method
overloading
Example 2
package Methodoverloading3;
}
}
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;
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;
void car_color()
{
System.out.println("Child class method : Car color is Red");//Car color
is Red
}
}
Mainclass
package MethodOverridingExamples2;
>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)
{
}
Child class code
public class Child extends Parent {
}
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 :
>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
Example 2
Example 3
More Examples :
>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
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;
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
// Here every car will have brakes but different cars will have different
// breaking mechanism
}
2.Create Subclass1(Maruti) from Superclass(Abstract class(Car))
package AbstractExample;
Maruti(int regino) {
}
3.Create Subclass2(Santro) from superclass(Abstract class(Car))
package AbstractExample;
Santro(int regino) {
super(regino);
}
}
4.Create Mainclass
package AbstractExample;
System.out.println(M.regino);//10
System.out.println(S.regino);//20
}
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;
// Here every Animal make a sound but different animals make different
// sounds
// abstract method
}
2.Create subclass(Cat) from inteface(Animal)
package InterfaceExample;
System.out.println("Meow");// Meow
}
}
3.Create Mainclass
package InterfaceExample;
System.out.println(C.x);// 15
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
>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;
float HT = 6.2f;
}
2.Create Interface2(Mother)
package MultipleInheritance;
}
3.Create Childclass(Son) from multiple interfaces(Father,Mother)
package MultipleInheritance;
}
4.Create Mainclass
package MultipleInheritance;
Example 1
import java.util.ArrayList;
/*
>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(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 :
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 :
Example :
import java.util.ArrayList;
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
}
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
}
Syntax :
array_list.set(int index,Object obj);
Example
Example :
import java.util.ArrayList;
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
}
for(int i=0;i<array_list.size();i++)
{
}
}
}
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;
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
}
for(int i=0;i<array_list.size();i++)
{
}
}
}
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;
Example
array_list.isEmpty();//verify arratList has empty or not
Figure :
Example
import java.util.ArrayList;
/*
}
>Can we add empty data in an array_list?
Ans : Yes, we can add
Example :
import java.util.ArrayList;
for(int i=0;i<array_list.size();i++)
{
}
}
}
*******************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 )
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;
//Instance variable
WebDriver driver;
//Instance method
void openBrowser()
{
//Open the firefox browser
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
//Instance method
void loginTest()
{
//Identify the username and enter username
driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
driver.findElement(By.name("Submit")).click();
String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();
System.out.println(text);//Welcome selenium
if(text.equals("Welcome selenium"))
{
System.out.println("Welcome page verified successfully");
}else
{
System.out.println("Welcome page not verified successfully");
}
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
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))
{
}else
{
//Execute the code if condition is false
}
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.
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.
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"));
driver.switchTo().frame(framelist.get(0));
driver.switchTo().frame(framelist.get(1));
Html code :
Ex : driver.switchTo().frame(“rightMenu”);
Syntax 2:
driver.switchTo().frame(String name);
Html code :
Ex: driver.switchTo().frame(“rightMenu”);
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;
//Instance variable
WebDriver driver;
//Instance method
void openBrowser()
{
//Open the firefox browser
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
//Instance method
void loginTest()
{
//Identify the username and enter username
driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
driver.findElement(By.name("Submit")).click();
String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();
System.out.println(text);//Welcome selenium
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
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****");
for(int i=0;i<droplist.size();i++)
{
System.out.println(droplist.get(i).getText());
//S.selectByIndex(1);
S.selectByVisibleText("Emp. ID");
//S.selectByValue("6");
System.out.println(selected_value);
if(selected_value.equals("Emp. ID"))
{
System.out.println("Selected value verified successfully");
}else
{
System.out.println("Selected value not verified successfully");
}
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
}
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
TestSteps
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;
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?
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;
}
Working with popups :
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 :
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;
driver.get("http://demo.guru99.com/v4/");
driver.findElement(By.xpath("html/body/form/table/tbody/tr[1]/td[2]/
input")).sendKeys("mngr279617");
driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td[2]/
input")).sendKeys("gYpyqur");
driver.findElement(By.xpath("html/body/form/table/tbody/tr[3]/td[2]/
input[1]")).click();
// Wait 5sec
Thread.sleep(5000);
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();
// click on ok button
alt.accept();
// alt.dismiss();
// Wait 5sec
Thread.sleep(5000);
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 :
Manual steps
Example
//click on ok button
alert.accept();
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.
Syntax : -
Syntax : -
Syntax : - driver.switchTo().window(parentWindow);
Ex : - driver.switchTo().window(AllWindowHandles.get(0));
Ex : - driver.switchTo().window(AllWindowHandles.get(1));
3. The user wants to go to child2 window, Follow below syntax.
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 7 Get total windows and store into windows variable
//click on feedback
driver.findElement(By.xpath(".//*[@id='navigation']/li[3]/a")).click();
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());//
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.
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;
// instance variable
driver.get("https://jqueryui.com/resources/demos/droppable/default.html");
WebElement drag = driver.findElement(By.id("draggable"));
act.dragAndDrop(drag, drop).perform();
String dropped_text =
driver.findElement(By.xpath("//*[@id='droppable']/p")).getText();
System.out.println(dropped_text);
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;
driver.manage().window().maximize();
// navigate the AppUrl
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
System.out.println(title);
driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
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();
System.out.println(text);
} else {
System.out.println("Welcome selenium is not verified
successfully");
}
act.moveToElement(driver.findElement(By.id("pim"))).perform();
driver.findElement(By.xpath("//*[@id='pim']/ul/li[2]/a")).click();
//wait 5sec
Thread.sleep(5000);
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();
System.out.println(addEmp);
driver.switchTo().defaultContent();
//Click on Logout
driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();
//wait 5sec
Thread.sleep(5000);
driver.close();
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;
action.doubleClick(element).perform();
//wait 5 sec
Thread.sleep(5000);
System.out.println("double click operation
successfully performed");
/*
Note :
*/
if (entered_text.equals("Hello World!")) {
System.out.println("Entered text verified
successfully");
} else {
System.out.println("Entered text not verified
successfully");
}
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()
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;
driver.get("https://www.google.co.in/");
action.contextClick(about).perform();
driver.close();
}
}
Example 2
TestSteps :
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;
driver.get("https://www.google.co.in/");
action.contextClick(about).perform();
action.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).click().perform();
//wait 5sec
Thread.sleep(5000);
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)
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) {
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
driver.findElement(By.name("q")).sendKeys("webdriver");
action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).perform();
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;
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.findElement(By.name("q")).sendKeys("webdriver");
action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).sendKeys(Keys.DELETE
).perform();
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;
// Navigate to AppUrl
driver.get("https://www.kosmiktechnologies.com/jobs/");
act.sendKeys(EnterKeyword,"kosmik Technologies").perform();
// identify Go button
//Click on Go button
act.moveToElement(GO_button).sendKeys(Keys.ENTER).perform();
// 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.
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.
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
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
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.
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
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;
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
System.out.println(title);
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
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();
System.out.println(text);
if (text.equals("Welcome selenium")) {
} else {
System.out.println("Welcome selenium is not verified
successfully");
}
act.moveToElement(driver.findElement(By.id("pim"))).perform();
driver.findElement(By.xpath("//*[@id='pim']/ul/li[2]/a")).click();
// wait 5sec
Thread.sleep(5000);
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();
System.out.println(addEmp);
// To verify whether the Add Employee page successfully opened or not
// 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);
driver.switchTo().defaultContent();
// Click on Logout
driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();
// wait 5sec
Thread.sleep(5000);
driver.close();
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.
3) The downloaded file by default save in to the Download folder but still it
depends on your system settings.
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.
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.
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
Note :
But in IE browser there is no chance to verify whether the xpath is valid or not.
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
Where Dynamic id
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
XPath:------- //input[@name='btnchkavail']
Selenium Code :
package SeleniumJavaTests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
Diagram:
Absolute Xpath :
Program:
Absolute Xpath :
Program:
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();
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();
Html code
<input type="text" name="password">
Example
//input[@name='password']
Html code
<a class="gb_g" data-pid="23" href="https://mail.google.com/mail/?
authuser=0&ogbl" target="_top">Gmail</a>
Example
//a[@class='gb_g']
driver.get("https://www.google.com/");
driver.findElement(By.xpath("//a[@class='gb_g']")).click();
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
-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
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);
</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.
Expand Java folder and see if the TestNg is available as in the below screen shot.
Way : 2
Install TestNg into Eclipse:
5. Click on Next.
6. Accept the license Agreement Click on Finish.
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.
@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
>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
Figure 2
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;
//instance variable
WebDriver driver;
@Test
public void VerifyLoginPage() {
driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
//Click on Login
driver.findElement(By.name("Submit")).click();
String text =
driver.findElement(By.xpath("/html/body/div[3]/ul/li[1]")).getText();
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() {
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
@AfterClass
public void CloseBrowser() {
driver.close();
}
>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
2.TestNG Result Window : Refer the below screenshort for the result windows:
}
>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.
>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
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
Figure 2
Figure 3
>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;
WebDriver driver;
@Test
public void loginTest() throws IOException, InterruptedException {
//First we need to access the excel file into eclipse.
//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();
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();
System.out.println(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() {
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;
WebDriver driver;
@Test
public void loginTest() throws IOException, InterruptedException {
//First we need to access the excel file into eclipse.
//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();
driver.findElement(By.name("txtUserName")).sendKeys(username);
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();
System.out.println(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() {
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.
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.
4.Compare dropdown size and Excel size 3.Store Excel values in an xlvalues
variable .See below
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;
@Test
public void verifyDropdownValues() throws InterruptedException, IOException
{
driver.get("http://www.tizag.com/htmlT/htmlselect.php");
// wait 3sec
Thread.sleep(3000);
// Identify dropdown
List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));
/*
* 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.
*/
/*
*
* As you know,some times we need to perform same action with multiple
* times at that time we need to follow - forloop
*
*/
xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}
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()) {
} else {
System.out.println("Size Not matched");
}
@BeforeClass
public void OpenBrowser() {
@AfterClass
public void CloseBrowser() {
// close the browser
driver.close();
}
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;
@Test
public void verifyDropdownValues() throws InterruptedException, IOException
{
driver.get("http://www.tizag.com/htmlT/htmlselect.php");
// wait 3sec
Thread.sleep(3000);
// Identify dropdown
List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));
/*
* 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.
*/
/*
*
* As you know,some times we need to perform same action with multiple
* times at that time we need to follow - forloop
*
*/
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()) {
} else {
System.out.println("Size Not matched");
@BeforeClass
public void OpenBrowser() {
@AfterClass
public void CloseBrowser() {
// close the browser
driver.close();
}
}
>What is the difference betweeen == an equals() in java ?
Ans :
Example :
System.out.println(s1==s2);//false
System.out.println(s1.equals(s2));//true
Figure :
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.
4.Compare dropdown size and Excel size 3.Store Excel values in an xlvalues
variable .See below
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 {
@Test
public void verifyDropdownValues() throws InterruptedException, IOException {
driver.get("http://www.tizag.com/htmlT/htmlselect.php");
// wait 3sec
Thread.sleep(3000);
// Identify dropdown
List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));
/*
* 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.
*/
/*
*
* As you know,some times we need to perform same action with multiple
* times at that time we need to follow - forloop
*
*/
xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}
ddvalues.add(dropdownCount.get(j).getText());
}
// Check for the required elements by Text and display matched elements
if (total_Rows == dropdownCount.size()) {
// 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() {
@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;
WebDriver driver;
@BeforeClass
public void setUp() {
// Launch Firefox browser
driver.manage().window().maximize();
}
@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {
driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");
driver.findElement(By.id("myInput")).sendKeys("i");
List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));
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
*/
//Identify AutoSugget and get the text and store into value
variable
String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();
System.out.println(value);
HSSFSheet sheet=workbook.getSheet("Sheet5");
int total_Rows=sheet.getLastRowNum()+1;
/*
*/
for(int i=0;i<total_Rows;i++)
{
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();
}
}
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;
WebDriver driver;
@BeforeClass
public void setUp() {
// Launch Firefox browser
driver.manage().window().maximize();
}
@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {
driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");
driver.findElement(By.id("myInput")).sendKeys("i");
List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));
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
*/
//Identify AutoSugget and get the text and store into value
variable
String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();
System.out.println(value);
AutoSugget_values.add(value);
}
XSSFSheet sheet=workbook.getSheet("Sheet1");
int total_Rows=sheet.getLastRowNum()+1;
/*
*/
for(int i=0;i<total_Rows;i++)
{
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();
}
}
WebTable Excel
1.Get the Webtable size
4.Compare Webtable size and Excel size 3.Store Excel values in an xlvalues
variable .See below
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;
WebDriver driver;
@BeforeClass
public void openWebSite() {
@Test
public void CountRowsTest() throws IOException {
System.out.println();
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);
xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}
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
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
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;
WebDriver driver;
@BeforeClass
public void openWebSite() {
@Test
public void CountRowsTest() throws IOException {
System.out.println();
System.out.println("**************Excel data*****************\n");
// 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();
}
System.out.println();
System.out.println("**************WebTable data*****************\n");
}
System.out.println();
}
System.out.println();
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 :
>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 :
Part 2 :
>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>
<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
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.
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.
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>
<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>
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;
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/?");
}
@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.
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.
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.
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
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.load(fis);
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")) {
} 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;
r1c1.setCellValue("Emd Id");
r1c2.setCellValue("NAME");
r1c3.setCellValue("AGE");
r2c1.setCellValue("1");
r2c2.setCellValue("sai");
r2c3.setCellValue("4");
r3c1.setCellValue("2");
r3c2.setCellValue("Akki");
r3c3.setCellValue("3");
readable_workbook.write(writable_Excel);
System.out.println("Save the readable workbook into writable_Excel");
}
}
What is a Method in Java?
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
}
}
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(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">
<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>
</test>
<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>
</test>
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.
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.
• 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>
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
Step 3): In this step run the build.xml file from eclipse as shown below:
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.
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.
Parallel Testing :
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.
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;
}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>
Example 8
***************
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
***************
System.out.println(b);
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
Example 9
***************
System.out.println(b);
>129
>byte type
>min -128 to max 127
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
***************
System.out.println(s);
>32767
>short type
>min -32768 to max 32767
Example 2
***************
System.out.println(s);
Example 3
***************
System.out.println(s);
Example 4
***************
System.out.println(s);
1.break
2.continue
3.return
4.try-catch-final
1.break statement
********************
Example 1
**************
public class Break_Stament {
int x=10;
if(x)
{
break;//error
}
System.out.println("Hanumanth");
>
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 {
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
Example 4
**************
public class Break_Stament {
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 :
************
if(condition to break)
{
break;
statements;
Syntax Explanation :
***********************
1.
2.
3.
4.
Example 4
**************
public class Break_Stament {
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 {
int x=10;
if(x)
{
continue;//error
}
System.out.println("Hanumanth");
Example 4
**************
public class Break_Stament {
for(int i=1;i<=10;i++)
{
System.out.println(i);
}
}
With continue statement inside forloop ?
*******************************************
Syntax :
************
if(condition to continue)
{
continue;
statements;
Syntax Explanation :
*************************
1.
2.
3.
4.
Example 4
**************
public class Break_Stament {
for(int i=1;i<=10;i++)
{
if(i==3)
{
continue;
System.out.println(i);
}
}
DAtatypes in java ?
***********************
int x=10;
>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.
types of datatypes
**********************
1.primitive datatypes
2.Non-Primitive datatypes
Example 1
************
System.out.println(b);
Code Explanation :
***********************
>Here providing value is 125
>Here Expected value is byte type value
>min -128 to max 127
JVM work
*************
Ans : Just execute the java code
Example 2
************
System.out.println(b);
>127
>byte type value
>min -128 to max 127
Example 3
************
System.out.println(b);
Note :
********
>We can say this("Hanumanth") is a string type value
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
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");
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");
Java code
**************
Manual Steps
****************
1.Create Superclass(Shape)
2.Create Subclass(Rectangel) from Superclass
3.Create MainClass
Java code
**************
Example 1
************
int i=2345; // valid int type value
System.out.println(i);
>2345
>int type
>min -2147483648 to max 2147483647
Example 2
************
int i=23.45; //invalid double type value
System.out.println(i);
Example 4
***************
System.out.println(b);
Note :
***********
Example 5
***************
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
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
Example 7
***************
System.out.println(b);
Note :
**********
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.
byte b= 129; //
System.out.println(b);
Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.create SubClass(Cat) from Superclass(Animal)
3.Create Mainclass
Java code
***************
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)
Example
**********
Manual Steps
*****************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass
3.Create Mainclass
Java code
**************
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
Ex 2 : Here same name but with different sounds then it is called polymorphism.
types of polymorphism
*************************
Example
**********
void m1(int a)
void m1(String s)
void m1(long id)
Java program
****************
Example 2
*************
int i=23.45;//invalid double type value
System.out.println(i);
Example 3
*************
int i=2345L;//invalid long
System.out.println(i);
F : long
R : int
Example 1
*************
System.out.println(l);
Example 2
*************
System.out.println(l);
Example 3
*************
System.out.println(l);
F : float
R : long
String datatype in java ?
*****************************
Examples
*************
Example 1
*************
System.out.println(s);
F : int
R : String
Example 2
*************
System.out.println(s);
F : boolean
R : String
Example 3
*************
System.out.println(s);
Note :
**********
>Here this(Hanumanth ) is not applicable for any datatype
Example 4
*************
System.out.println(s);
F : String
R : String
>This will be used to store only boolean value such as true / false
Example 1
*************
System.out.println(b);
F : int
R : boolean
Example 2
*************
System.out.println(b);
Note :
*********
>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'
Example 3
*************
System.out.println(b);
F : boolean
R : boolean
constructor in java ?
**************************
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)==>
name="Sai";
rollno=101;
Example 1
**************
rollno = S_rollno;
Example 2
**************
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
**************
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.
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
Selenium WebDriver
**********************
What is a webdriver ?
**************************
Ans : webDriver it's an interface in betweeen selenium automation test script
TestNG------------------part 3
*******************
TestNG(latest)---Junit(old)
the selenium automation Test cases,it generate Test Reports and also generate
log files.
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
In superclass
******************
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();
Case 2
*********
Parent C = new Child();
Case 3
*********
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 ?
Manual Steps
***************
1.switch to alert
2.Verify alert text
3.click on ok
//**************************Verify alert
text*********************************
//------------------------------------------------------operation code
//2.Verify alert text
//----------------------------------------------------verification code
//3.click on ok
alt.accept();
Manual Steps
*****************
1.switch to model popup window
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
************
int x=10;
if(x)
{
break;//error
}
System.out.println("Hanumanth");
}
}
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");
}
}
}
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");
}
}
}
for(int i=1;i<=10;i++)
{
System.out.println(i);
}
}
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
if(condition to break)
{
break;
Statement;
Syntax Explanation :
***********************
1.
2.
3.
4.
Example 4
************
if(i==4)
{
break;
}
System.out.println(i);
}
}
Continue statement
*******************
Example 1
**************
public class Student {
if(x)
{
continue;//error
}
System.out.println("Hanumanth");
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
if(condition to continue)
{
continue;
Statement;
Syntax Explanation :
***********************
1.
2.
3.
4.
Example 2
**************
public class Student {
if(i==3)
{
continue;
System.out.println(i);
}
}
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
Types of Testing
**********************
1.Functional Testing
2.Non-functional Testing
2.commercial
***************
1.Qtp(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test
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 Components---IQ
*************************
1.Selenium IDE
2.Selenium RC
3.Selenium WebDriver
4.Selenium Grid
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
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
Selenium WebDriver
********************
What is a Webdriver ?
************************
-----------------part 1
Java,
TestNG----------part 3
***********************
TestNG(latest)---Junit(old)
the selenium automation Test cases,it generate Test Reports and also generate
log files.
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
Manual Steps
****************
1.switch to alert
2.Verify alert text
3.click on ok
//-------------------------------------------------------operation code
//2.Verify alert text
//------------------------------------------------------verification
code
//3.click on ok
alt.accept();
Manual Steps
*************
1.switch to model popup
2.do some action
3.click on model popup
driver.switchTo().window(driver.getWindowHandle());
//2.do some action
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
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
7386467494
Example 8
**************
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
Example 1
**************
System.out.println(s);
Example 2
**************
System.out.println(s);
Example 3
**************
System.out.println(s);
F : long
R : short
Example 1
**************
System.out.println(i);
Code Explanation :
***********************
>2345
>int type value
>min -2147483648 to max 2147483647
F : int
R : int
Example 2
**************
System.out.println(i);
F : long
R : int
Example 3
**************
System.out.println(i);
F : float
R : int
Example 2
***************
Definition 2:
********************
Ans : Here method name same but with different method signature then it is called
method overloading.
Program
**************
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.
Note :
*********
>When i run this program by default JVM will always call to child class
method(overriding method)
Case 1
***********
Child C = new Child();
>
>
Case 2
***********
>We can specify floating-point literal value(float value or double value) only in
decimal form
Example 1
*************
System.out.println(f);
F : float
R : float
Example 2
*************
System.out.println(f);
Example 3
*************
System.out.println(f);
Example 4
*************
System.out.println(f);
>We can specify floating-point literal value(float value or double value) only in
decimal form
Example 1
*************
System.out.println(d);
Example 2
*************
System.out.println(d);
Example 3
*************
System.out.println(d);
Examples
*************
Example 1
*************
System.out.println(ch);
Example 2
*************
System.out.println(ch);
Example 3
*************
System.out.println(ch);
Example 4
*************
System.out.println(ch);
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();
Example 1
*************
System.out.println(l);
F : long
R : long
Example 2
*************
long l=125; // valid int
System.out.println(l);
F : int
R : long
Example 3
*************
System.out.println(l);
Examples
**************
Example 1
***************
System.out.println(s);
F : int
R : String
Example 2
***************
System.out.println(s);
F : boolean
R : String
Example 3
***************
System.out.println(s);
System.out.println(s);
Example 1
***************
System.out.println(b);
Example 2
***************
System.out.println(b);
Example 3
***************
System.out.println(b);
Note :
*********
>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'
Example 4
***************
System.out.println(b);
Example
************
Manual Steps
****************
1.Create Parent class
2.Create Child class from Parent class
3.Create Mainclass
Java code
**************
CAse 1
*********
Case 2
********
Parent C = new Child();
CAse 3
**********
Parent C = new Parent();
Example 4
**************
System.out.println(ch);
Example 5
**************
System.out.println(i);
Variable in java
*******************
int x=10;
variable types
***************
1.Instance variable
2.Local variable
3.Static variable
>The values of the name and rollno are different from object to object such
Example 1
*************
//instance variable
String name="Sai";
System.out.println(name);//Error
Object Syntax :
********************
//create the object for that student class
Syntax Explanation :
************************
//instance variable
String name="Sai";
System.out.println(S.name);//Sai
Example
***********
Java code
**************
>
Syntax
**********
class Superclass
{
}
class Subclass extends Superclass
{
Example
************
Manual Steps
***************
1.Create Superclass(Teacher class)
2.Create Subclass(Student class) from Superclass
3.Create Mainclass
Java code
****************
In superclass
****************
Additional code(Mandatory)
>Here we can specify floating-point literal value(float value and double value)
only in decimal form
Example 1
**************
System.out.println(f);
F :float
R : float
Example 2
**************
System.out.println(f);
Example 3
**************
System.out.println(f);
Example 4
**************
System.out.println(f);
F : int
R : float
>Here we can specify floating-point literal value(float value and double value)
only in decimal form
Example 1
**************
System.out.println(d);
Example 2
**************
System.out.println(d);
Example 3
**************
System.out.println(d);
Examples
***************
'H' or 'h' or '5' or '@'---------valid
Example 1
**************
System.out.println(ch);
Example 2
**************
System.out.println(ch);
Example 3
**************
System.out.println(ch);
Example 4
**************
char ch=68; //
System.out.println(ch);
Example 5
**************
int i='D'; //
System.out.println(i);
Concreate method.
Example
*************
//Concreate method
void m1()
{
}
//Concreate method
void m1(int a)
{
//Concreate method
Example
*************
//Concreate method
}
//Concreate method
Example
*************
public abstract class Test { Unimplemented class
//Concreate method
}
//abstract method
>Here abstract method can be declared with abstract keyword such type of method
>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)
Example
*************
public abstract class Test { Unimplemented class
//Concreate method
}
//abstract method
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
***************
1.regino
2.FuelTank
3.Steering
4.Brakes
In subclass
**************
Additional code(Mandatory)
Example 3
*************
Example 4
**************
//Instance variable
Example 4
*************
//Instance variables
String name;
boolean b;
int i=10;
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
*************
//Instance variables
System.out.print.out.println(S.name);//null
System.out.print.out.println(S.b);//false
System.out.print.out.println(S.i);//10
class Test{
//method
void m1()
{
int x=10;//local variable
//constructor
Test()
{
int y=20;//local variable
//block
if()
{
int z=30;//local variable
Example 2
**************
public class Student {
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
int a; //invalid
int a=10;//valid
int a=0;//valid
int a; //valid
int a=10;//valid
int a=0;//valid
Example 4
**************
public class Student {
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
*********
Case 2
*********
Parent C = new Child();
Case 3
*********
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
*************
System.out.println(ch);//D
Example 5
*************
System.out.println(i);//71
Variable in java ?
**********************
Definition :
***************
int x=10;
Variable types
*****************
1.Instance variables
2.Local variables
3.Static variables
>The values of the name and rollno are different from student to student such
>The values of the name and rollno are different from object to object such
Example 1
*************
public class Student {
//Instance variable
String name="Sai";
Object syntax :
*********************
//create the object for that student class
Syntax Explanation :
***********************
Example 2
*************
public class Student {
//Instance variable
String name="Sai";
new Student();
System.out.println(name);// error
Example
***********
Manual Steps
****************
Java code
***************
School project
*****************
Abstract class
*******************
Example 4
*************
int x=10;//valid
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
*************
//static variable
Example 2
*************
//static variable
System.out.println(name);// Sai
}
Example 3
*************
//static variable
System.out.println(Student.name);// Sai
CAn we access the static variable into static area through classname ?
***************************************************************************
Ans : Yes
Syntax : classname.variablename
Example 4
*************
//static variable
System.out.println(Student.name);// Sai
>Here multiple subclasses acquired all the features of one superclass by using
extends
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();
>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();
>With Parent reference ,we can call the parent class method
>With Parent reference ,we can't call the child class method
Example 2
***************
Example 1
*************
class Test{
Test()
{
System.out.println("hanumanth");
super();//invalid
}
}
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
}
}
Example 4
*************
class Test{
Test()
{
this();//valid
System.out.println("hanumanth");
}
}
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");
}
}
Example 7
**************
Example
***********
manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create Mainclass
Java code
***********
Example
***********
manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangel) from Superclass(Shape)
3.Create Mainclass
Java code
***********
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
Types of Testing
********************
1.Functional Testing
2.Non-functional Testing
2.Commercial
================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4,Rft
5.Silk test etc.
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 components---IQ
**************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
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
Selenium Rc
*****************
>Selenium RC works with server but selenium webdriver doesn't work with server
Selenium WebDriver
*********************
------------part 1
Java,
TestNG----------part 3
**************************
TestNG(latest)---Junit(old)
selenium automation test cases,it generate the Test Reports and also generate
log files.
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
7386467494
Example 3
************
Example 4
*************
//Instance variable
int i=10;
double d;
boolean b;
System.out.println(S.i);//10
System.out.println(S.d);//0.0
System.out.println(S.b);//false
Example 5
*************
//Instance variable
System.out.println(S.i);//10
System.out.println(S.d);//0.0
System.out.println(S.b);//false
1.private
2.public
3.protected
4.default
Example 1
***********
class Test{
//create method
void m1()
{
//constructor
Test()
{
int y=20;//local variable
//create block
if()
{
Exzample 2
***********
//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.
Interface in java ?
************************
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
>We can't create object for that class abstract(Unimplemented class) class and
interface(Unimplemented interface)
extends keyword : By using extends keyword,we can inherit the subclass from
superclass
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(){})
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
**********************
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
2.Suppose if u want to print the 2st student details then we need to create
3.Suppose if u want to print the nth student details then we need to create
part 3
***********
Print 1st student details
**************************
If i change 1st stud1 marks then there are any effect for that remaining students
marks ?
**************************************************************************
Ans : No effect
>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
Example
***********
Manual Steps
****************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create Mainclass
Java code
*************
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)
polymorphism in java ?
**************************
poly---many
morphs---forms
Ex 2 : Here we have same name but with different sounds then it is called
polymorphism
types of polymorphism
*************************
Example
**********
Definition 2 :
*******************
>If u want to access the java and selenium then we need to download JDK(Java
development kit) file first
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
*********
Example 5
***********
//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
Ans : Here expression value is matched any case value from that case onwards
all the statements will be executed automatically until break statement then
Example 6
***********
public class FirstProgram {
//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
***********
//local variables
char ch='r';
switch(ch){
break;
case'y': System.out.println("yellow");//valid
Example 8
***********
//local variables
int furniture=0;
switch(furniture){
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;
>Here we can use datatypes in our selenium webdriver to prepare the selenium
automation test script
>In java , every variable and every expression should have a datatype
types of datatypes
***********************
1.primitive datatypes
2.Non-Primitive datatypes
7386467494
Example 4
************
//local variables
private byte b=10; //invalid
public String s="Hanumanth";//invalid
protected boolean b= false;//invalid
}
>Here final is called modifier
>Here final means what constant
>Here y is called constant variable,here variable y value never be changed
>CAn we assign final modifier for that local variable,instance variable and static
variable ?
**********************************************************************
Ans : Yes
CAn we assign access modifiers for that Instance variable and static variable ?
***********************************************************
Ans : Yes
1.private
2.public
3.protected
4.default
>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
System.out.println(name);//Sai
Example 2
*************
public class Student {
//Static variable
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
Can we access the static variable into static area through classname ?
****************************************************************
Ans : Yes
Syntax : classname.variablename
Example 4
*************
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()
{
Example 1
**************
System.out.println(b);
Code Explanation :
*********************
>Here we are providing value is 125
>Here Expected value is byte datatype
>min -128 to max 127
Example 2
**************
System.out.println(b);
Code Explanation :
**********************
>127
>byte type value
>min -128 to max 127
Example 3
**************
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 "%$^%&^^*&&"
Example 4
**************
System.out.println(b);
Note :
**********
>We can say this(true) is a boolean type value
Example 5
**************
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
Example 6
**************
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
**************
System.out.println(b);
Part 1
********
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
***********
If i change the 1st student marks then there are any effect for that remaining
students marks ?
**************************************************************************
Ans : No effect
>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
{
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
Syntax : classname.variablename
Examples
*************
1.State / properties
2.Behavior / Actions
What is a class in java ?
*****************************
Ans : It doesn't exist really / physically
>
1.State / properties
2.Behavior / Actions
Object syntax
*****************
Class Syntax :
********************
class <classname>
{
//1.State / properties-------variables
<datatype> variable1;
<datatype> variable2;
//2.Behavior / Actions-----methods
return-type methodname1()
{
}
return-type methodname2()
{
}
main()
{
Example
************
Class
**********
1.It doesn't exist really / physically
Object
********
1.It exists really / physically
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
**********
Program :
************
Example
***********
Manual Steps
****************
Java code
**************
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();
Case 2
*********
Case 3
*********
Example 8
*************
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:
*********
Example 9
*************
System.out.println(b);
>129
>byte type value
>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
Example 1
**************
System.out.println(s);
>32767
>short type value
>min -32768 to max 32767
F : short
R : short
Example 2
**************
System.out.println(s);
F : double
R : short
Example 3
**************
System.out.println(s);
F : long
R : short
Example 4
**************
System.out.println(s);
F : int
R : short
Example 1
**************
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()
{
Example
***********
When function will be called ?
********************************
Ans : Whenever u create an object after function will be called
Example
***********
Example
***********
Note :
**********
Here method can never return more than one value
Examples
**************
return c; //valid
return a,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
**************
CAse 1
********
Child C = new Child();
C.calculation(25.0);
C.calculation(25.0);
CAse 3
********
C.calculation(25.0);
1.concreate method
2.Concreate class
3.abstract method
4.abstract class
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()
{
}
}
Example
***********
//concreate method
//abstract method
>A method can be declared with abstract keyword then it is called abstract method
Note :
***********
//concreate method
//abstract method
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.
types of Testing
*********************
1.Functional Testing
2.Non-functional Testing
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
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 components---IQ
***************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
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.
Selenium Rc
**************
1.Selenium Rc works with server but selenium webdriver doesn't work with server.
Selenium WebDriver
*********************
What is a webdriver ?
************************
Ans : Webdriver it's an interface in betweeen selenium automation test script and
Testing Application.
----------------part 1
TestNG----------part 3
************************
TestNG(latest)---Junit(old)
selenium automation test cases,it generate Test Reports and also generate log
files.
7386467494
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
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
School project
*****************
Interface in java ?
**********************
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.
extends keyword : By using this, we can inherit the subclass from superclass
>We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented interface)
School project
*****************
CAse 1
*************
Abstract class
******************
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();)
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;
>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
Flow-control in java ?
***********************
Selection statements
************************
1.if
2.if-else
3.ladder if-else
4.switch
If statement
*****************
Syntax :
*************
//if body
}
Syntax Explanation :
*************************
will come of the if block and execute the statements that appear after if block.
Example 1
************
public class If_statement {
if(cat_age==dog_age)
{
But my requirement if condition is false then JVM has to print something in the
if(cat_age==dog_age)
{
}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 {
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
Found : int
Required : boolean
Example 4
************
public class If_statement {
}else
{
System.out.println("A is less than 50");
Example 5
************
public class If_statement {
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 {
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
Example 7
************
public class If_statement {
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
>if(false)==>
Found : boolean
Required : boolean
Example 8
************
public class If_statement {
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
switch statement
*******************
>If u want to check one or more conditions then we have to go switch statement.
ArrayList in java ?
*********************
Example 1
*************
Example
********
>Suppose if u want to store only float type values then we should follow below
syntax
Example
************
ArrayList<Float> arralist = new ArrayList<Float>();
>Suppose if u want to store only double type values then we should follow below
syntax
Example
************
Example
***********
ArrayList<Boolean> arralist = new ArrayList<Boolean>();
>Suppose if u want to store only String type values then we should follow below
syntax
Example
**********
ArrayList<String> arralist = new ArrayList<String>();
>Suppose if u want to store only character type values then we should follow below
syntax
Example
***********
Example
************
ArrayList arralist = new ArrayList();
Interface part 2
******************
>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
{
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
***************
Syntax : interfacename.variablename
Syntax : classname.variablename
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;
>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
types of datatypes
**********************
1.primitive datatypes
2.Non-Primitive datatypes
Example 1
*************
System.out.println(b);
Code Explanation :
***********************
>Here we are providing value is 125
>Compile the java code line by line(That means checking the java code line by line
whether it is currect code or not)
Example 2
*************
System.out.println(b);
Note :
**********
>We can say this("Hanumanth") is a string type value
>Here String mean collection of characterss
Examples
**************
Example 3
*************
System.out.println(b);
>127
>byte type value
>min -128 to max 127
Example 4
*************
System.out.println(b);
note :
*********
>We can say this(true) is a boolean type value
Example 5
*************
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
F : long
R : byte
Example 6
*************
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
*************
Switch statement
******************
>Suppose If you want to check one or more conditions then we will go for a switch
statement.
Syntax :
***********
switch(Expression value){
Syntax Explanation :
***********************
1.
2.
3.
4.
5.
6.
Example 1
*************
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
*************
int x=10;
int y=20;
switch(x){
case 0 : System.out.println("Hello");//valid
case y : System.out.println("Hanumanth");//invalid
}
}
Example 3
*************
//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
*************
//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
}
}
Example 4
*************
//local variables
switch(b){
case 10 : System.out.println("Hello");//valid
}
}
>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
>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 in the range of the argument type.
Example 5
*************
//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
*******************
Syntax :
*************
array_list.remove(index);
Example
**********
array_list.remove(1); //removed 20 in an arralist
Program
************
Syntax :
*************
Example
*************
array_list.set(1,50); //replaced 20 with 50 in the position of 1
Program
************
Syntax :
**************
Example
*********
Program
***********
can we remove all the values present in the arralist ?
**********************************************************
Ans : Yes
Syntax :
**********
array_list.clear();
Example
***********
Program :
*************
How to verify arralist has empty or not ?
*********************************************
Ans : By using isEmpty()
Syntax :
************
array_list.isEmpty();
Example
**********
Note :
**********
Program :
*************
Flow-control in java ?
**********************
1.Selection statement
*************************
1.if
2.if-else
3.ladder if-else
4.switch
If statement
*****************
Syntax :
*********
}
Syntax Explanation :
**********************
1.
2.
Example 1
***********
int cat_age=5;
int dog_age=5;
if(cat_age==dog_age)
{
System.out.println("Animals age matched");
Example 2
***********
int cat_age=5;
int dog_age=5;
if(cat_age==dog_age)
{
System.out.println("Animals age matched");
}else
{
Conclusion
**************
1.if
2.if-else
Example 3
***********
int A=100;
}else
{
System.out.println("Hanumanth");
}
1.
2.
Found : int
Required : boolean
Example 4
***********
int A=100;
}else
{
Example 5
***********
int x=10;
}else
{
System.out.println("Hanumanth");
}
>if(20)==>
F : int
R : boolean
Example 6
***********
int x=10;
}else
{
System.out.println("Hanumanth");
}
Example 7
***********
boolean b=true;
if(b=false) //here must be boolean condition
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
f : boolean
R : boolean
Example 8
***********
boolean b=false;
}else
{
System.out.println("Hanumanth");
}
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;
break;
case value 2 : statement3--->code to be executed ;
break;
Syntax Explanation :
*************************
1.
2.
3.
4.
5.
6.
Example 1
**************
public class Switch_Statement {
int x=10;
switch(x){
System.out.println("hanumanth");
1.In switch block,every statement should be under case value and default case
Example 2
**************
public class Switch_Statement {
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 {
int x=10;
int y=20;
switch(10){
case 10 : System.out.println("Hello");//invalid
case 10 : System.out.println("hanumanth");//invalid
}
Example 4
**************
public class Switch_Statement {
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 ?
*********************
Example
***********
>Suppose if u want to store only integer type values then we should follow below
syntax
Example
*********
>Suppose if u want to store only float type values then we should follow below
syntax
Example
*********
ArrayList<Float> arraylist = new ArrayList<Float>();
>Suppose if u want to store only double type values then we should follow below
syntax
Example
***********
ArrayList<Double> arraylist = new ArrayList<Double>();
>Suppose if u want to store only String type values then we should follow below
syntax
Example
********
ArrayList<String> arraylist = new ArrayList<String>();
>Suppose if u want to store only Boolean type values then we should follow below
syntax
Example
***********
ArrayList<Boolean> arraylist = new ArrayList<Boolean>();
>Suppose if u want to store only character type values then we should follow below
syntax
Example
***********
ArrayList<Character> arraylist = new ArrayList<Character>();
Example
************
ArrayList arraylist = new ArrayList();
Syntax :
***********
arraylist.remove(index);
Example
**********
Program
**********
Syntax :
***********
arraylist.set(int index,Object obj);
Example
***********
Syntax :
***********
Example
***********
Program
********
Syntax :
**********
arraylist.clear();
Example
***********
Program
************
Syntax :
***********
arraylist.isEmpty();
Example
************
Program :
**************
Example 8
*************
System.out.println(b);
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
*************
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
*************
System.out.println(s);
>32767
>short type value
>min -32768 to max 32767
F : short
R : short
Example 2
*************
System.out.println(s);
Example 3
*************
System.out.println(s);
Example 4
*************
System.out.println(s);
Example 1
*************
System.out.println(i);
>2345
>int type value
>min -2147483648 to max 2147483647
Example 2
*************
System.out.println(i);
Example 3
*************
System.out.println(i);
1.JDK file
2.Eclipse IDE/oxygen
3.Selenium jar files
4.Testing Application
5.browser
Example 1
**************
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
Required : byte
>Compile the java code line by line (That means checking the java code
Example 2
**************
System.out.println(b);
Note:
**********
>We can say this("Hanumanth") is a string type value
Examples
**************
Example 3
**************
byte b=127; // valid byte type value
System.out.println(b);
>127
>byte type value
>min -128 to max 127
Example 4
**************
System.out.println(b);
Note :
********
>We can say this(true) is a boolean type value
Example 4
**************
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
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
**************
System.out.println(b);
Example 1
*************
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
*************
System.out.println(l);
F : double
R : long
Example 3
*************
System.out.println(l);
F : int
R : long
Examples
*************
"HYD" or "H" or "123" or "HYD123" or "%$^%^&*&(*"
Example 1
*************
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
*************
System.out.println(s);
F : boolean
R : String
Example 3
*************
System.out.println(s);
Example 4
*************
System.out.println(s);
F : String
R : String
>This will be used to store only boolean value such as true /false
Example 1
*************
System.out.println(b);
Example 2
*************
System.out.println(b);
>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'
Example 3
*************
System.out.println(b);
Example 4
*************
System.out.println(b);
>Simply we can say to find the defect or to find the error or to find the failure.
types of Testing
******************
1.functional Testing
2.Non-functional Testing
2.commercial
================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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
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
*******************
Selenium Components---IQ
****************************
1.selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
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.
Selenium Rc
***************
>Here selenium RC works with server but selenium webdriver doesn't work with
server.
Selenium webdriver
*******************
What is a webdriver ?
************************
Ans : Webdriver it's an interface in betweeen selenium automation test script and
Testing Application.
----------------part 1
Java,
TestNG--------part 3
************************
TestNG(latest)----Junit(old)
the selenium automation test cases ,it generate Test Reports and also generate
log files
Example 3
**************
public class Test {
for(int i=1;i<3;i++)
{
System.out.println(i);
System.out.println(j);
}
System.out.println(i);
System.out.println(j);
}
Syntax :
**********
Syntax Explanation :
***********************
Example
************
Output
**********
0 1 2
3 4 5
6 7 8
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
***********
get() :
Manual Steps
***************
Get the Title of the WebPage
Print the title of the webpage
Verify Title of the WebPage
//--------------------------verification code
Loops in java ?
*********************
WHy we are using loops in java ?
************************************
Ans : Here loops are used to execute a group of statements repeatedly
Example 1
***************
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
Example 2
************
Syntax :
***************
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
//loop body
Syntax Explanation :
*********************
1.
2.
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) {
for(int i=1;i<=10;i++)
{
System.out.println(i);
System.out.println(j);
}
System.out.println(i);
System.out.println(j);
}
Output
**********
0 1 2
3 4 5
6 7 8
print():
***********
>By using this ,we can print the text and the curser waits on the same line
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
get() :
if(act.equals(exp))
{
}else
{
//-------------------------verification code
Example 7
*************
System.out.println(b);
F : double
R : byte
>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
*************
System.out.println(b);
F : int
R : byte
Note :
**********
>128
>byte type value
>min -128 to max 127
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
Example 1
*************
System.out.println(s);
Code Explanation :
*********************
>32767
>short type value
>min -32768 to max 32767
F : short
R : short
Example 2
*************
System.out.println(s);
F : double
R : short
Example 3
*************
System.out.println(s);
Code Explanation :
***********************
>32768
>short type value
>min -32768 to max 32767
F : int
R : short
Example 1
*************
System.out.println(i);
Example 2
*************
System.out.println(i);
Example 2
*************
System.out.println(i);
Example 1
*************
System.out.println(l);
Example 2
*************
long l=125; // valid int
System.out.println(l);
F : int
R : long
Examples
************
Example 1
*************
System.out.println(s);
Example 2
*************
System.out.println(s);
Example 3
*************
System.out.println(s);
Example 4
*************
System.out.println(s);
>Here we can specify floating-point literal value(float value and double value)
only in decimal form
Example 1
*************
System.out.println(f);
Example 2
*************
System.out.println(f);
Note :
********
>Here float datatype variable can store only decimal value upto 6 digits after
decimal.
Example 3
*************
System.out.println(f);
Example 4
*************
System.out.println(f);
Note :
*********
>When i run this program by default JVM will provide 25.0 instead of 25
Example 5
*************
System.out.println(f);
F : int
R : float
>Here we can specify floating-point literal value(float value and double value)
only in decimal form
Example 1
*************
System.out.println(d);
Example 2
*************
System.out.println(d);
Example 3
*************
System.out.println(d);
Examples
************
Example 1
*************
System.out.println(ch);
Example 2
*************
System.out.println(ch);
Example 3
*************
char ch='H'; // valid char
System.out.println(ch);
Example 4
*************
System.out.println(ch);
>If u want to access the java and selenium then we need to download JDK(Java
development kit) file first
Part 1
**********
Part 2
********
1.Create new JavaProject
2.Create new package
3.Create new class
Datatype in java ?
********************
int x=10;
>We can use datatypes in our selenium webdriver to prepare the selenium
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
********************
Example 1
*************
public class Break_statement {
int x=10;
if(x)
{
break; //error
}
System.out.println("Hanumanth");
Example 2
*************
int x=0;
switch(x){
case 0 : System.out.println("Hello");//Hello
case 1 : System.out.println("Hi");
case 2 : System.out.println("Hanumanth");
}
Example 3
*************
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");
}
Example 4
*************
for(int i=1;i<=10;i++)
{
System.out.println(i);
Example 5
*************
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");
}
Ans :
print():
**************
This will be used to print the text and the curser waits on the same line
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
*********************
sendKeys():
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"))
{
sendKeys() :
*************************************************
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
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"))
{
Syntax :
************
for(initialization-part ; conditional-part/testing-part ;increment/decrement-
part)
{
for(initialization-part ; conditional-part/testing-
part ;increment/decrement-part)
{
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
********************
Example 1
*************
int x=10;
if(x)
{
break;//error
}
System.out.println("Hanumanth");
Example 2
*************
int x=0;
switch(x){
case 0 : System.out.println("Hello");
case 1 : System.out.println("HI");
case 2 : System.out.println("Hanumanth");
Example 2
*************
int x=0;
switch(x){
case 0 : System.out.println("Hello");
case 1 : System.out.println("HI");
break;
case 2 : System.out.println("Hanumanth");
Example 1
**************
System.out.println(b);
Example 2
**************
System.out.println(b);
Example 3
**************
System.out.println(b);
>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'
Example 4
**************
System.out.println(b);
>We can specify floating-point literal value(float value and double value) only in
decimal form
Example 1
***************
System.out.println(f);
Example 2
***************
System.out.println(f);
>Here float type variable can store only decimal value upto 6 digits after decimal
Example 3
***************
System.out.println(f);
Note :
***********
When i run this program,by default JVM will provide 25.0 instead of 25 while
Example 4
***************
System.out.println(f);
>We can specify floating-point literal value(float value and double value) only in
decimal form
Example 1
***********
System.out.println(d);
Example 2
***********
System.out.println(d);
Example 3
***********
System.out.println(d);
Example 4
**************
char ch=68; //valid the ASCII value(68) of a character---'D'(char type value)
System.out.println(ch);//D
Example 5
**************
System.out.println(i);//71
Variable in java ?
**********************
int x=10;
Variable types
******************
1.Instance variable
2.Local variable
3.Static variable
>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
1.
2.
3.
4.
Example 1
*************
//Instance variable
String name="Sai";
System.out.println(name);//error
Object syntax
*****************
Syntax Explanation :
************************
Example 2
*************
//Instance variable
String name="Sai";
System.out.println(name);//error
Example 1
**************
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
Example 2
**************
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
Examples
************
"HYD" or "H" or "123" or "HYD123" or "$%^%&^*&(*&"
Example 3
**************
System.out.println(b);
>127
>byte type value
>min -128 to max 127
F : byte
R : byte
Example 4
**************
System.out.println(b);
Example 5
**************
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
Example 6
**************
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);
Syntax :
************
for(initialization-part ; conditional-part/testing-part
;increment/decrement-part)
{
if(condition to break)
{
break;
statements;
Syntax Explanation :
***********************
1.
2.
3.
4.
Example
***********
public class FirstProgram {
for(initialization-part ; conditional-part/testing-
part ;increment/decrement-part)
{
if(condition to break)
{
break;
}
statements;
Example 1
************
public class FirstProgram {
int x=10;
if(x)
{
continue; //error
}
System.out.println("Hanumanth");
}
Without continue statement inside forloop ?
*********************************************
Example 2
************
public class FirstProgram {
System.out.println(i);//1 2 3
}
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 {
System.out.println(i);//1 2 3
}
}
Constructor in java ?
***************************
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
Example 1
***************
Student()
{
name="sai";
rollno=101;
}
rollno = S_rollno;
}
Example
***********
Example 3
***************
System.out.println(d);
Examples
***********
Example 1
*************
System.out.println(ch);
Example 2
*************
System.out.println(ch);
Example 3
*************
System.out.println(ch);
Example 4
*************
System.out.println(ch);
Example 5
*************
System.out.println(i);//68
What is the character('D') of ASCII value ?
******************************************
Ans : 68
int x=10;
variables types
******************
1.Instance variables
2.Local variables
3.Static variables
>The values of the name and rollno are different fron student to student such
>The values of the name and rollno are different fron object to object such
1.
2.
3.
4.
(if,if-else,ladder if-else,switch,while,do-while,forloop,static)
Example 1
************
public class Student {
//Instance variable
String name="Sai";
System.out.println(name);// error
}
Object Syntax:
****************
//create student class 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();)
Example 2
************
public class Student {
//Instance variable
String name="Sai";
System.out.println(name);// error
Example 3
************
public class Student {
//Instance variable
String name="Sai";
System.out.println(name);// error
}
Example 7
************
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
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.
Example 1
************
System.out.println(s);
Code Explanation :
*********************
>32767
>short type value
>>min -32768 to max 32767
F : short
R : short
Example 2
************
System.out.println(s);
F : double
R : short
Example 3
************
System.out.println(s);
Example 4
************
System.out.println(s);
F : int
R : short
Example 1
************
System.out.println(i);
>2345
>int type value
>>min -2147483648 to max 2147483647
Example 2
************
System.out.println(i);
Example 3
************
System.out.println(i);
Example 3
**************
public class Student {
Example 4
************
public class Student {
//Instance variables
int i=10;
String name;
boolean b;
double d;
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
System.out.println(S.i);//10
System.out.println(S.name);//null
System.out.println(S.b);//false
1.private
2.public
3.protected
4.default
Can we assign access modifiers for that instance variables and static variables ?
*************************************************************************
Ans : Yes
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
Example 2
***********
public class Student {
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 {
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
*****************
Example 4
***********
public class Student {
int x=10;//valid
Example 1
**********
System.out.println(s);
F : int
R : String
Example 2
**********
System.out.println(s);
F : boolean
R : String
Example 3
**********
Example 4
**********
System.out.println(s);
Found : String
Required : String
System.out.println(b);
F : int
R : boolean
Example 2
*************
System.out.println(b);
Example 3
*************
System.out.println(b);
Note :
*********
>here boolean type variable can store obly boolean value by prefixed with 't' not
'T'
Example 4
*************
System.out.println(b);
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
****************
Example 3
*************
Can we access the instance variable into instance area directly ?
********************************************************************
Ans : Yes
Example 4
*************
//Instance vairable
int a=10;
boolean b;
double d;
System.out.println(S.a);//10
System.out.println(S.b);//false
System.out.println(S.d);//0.0
Example 5
*************
//Instance vairable
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
class Test{
//create method
void m1()
{
//create constructor
Test()
{
int y=20;//local variable
//create block
if()
{
int z=30;//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
***************
//local variable
int i;
int j;
System.out.println(i);//error
System.out.println(j);//error
}
int a; //invalid
int a=10;//valid
int a=0;//valid
int a; //valid
int a=10;//valid
int a=0;//valid
Example 1
*************
System.out.println(l);
Example 2
*************
System.out.println(l);
Found : float
Required : long
Example 3
*************
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
>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-------
Example 1
*************
System.out.println(f);
Example 2
*************
System.out.println(f);
Note :
******
Here float type variable can store only decimal value upto 6 digits after decimal
Example 3
*************
System.out.println(f);
Example 4
*************
float f=25; // valid int
System.out.println(f);
>
Example 1
*************
System.out.println(d);
Example 2
*************
System.out.println(d);
Example 3
*************
System.out.println(d);
Example 5
************
public class Student {
//Local variables
private byte b=10;//invalid
}
What are the access modifiers in java ?
*************************************
Ans :
1.private
2.public
3.protected
4.default
CAn we assign final modifier for that Instance variable and static variables ?
**********************************************************
Ans : Yes
>The name of the college is same from object to object such type of variable
Example 1
************
//static variable
System.out.println(name);//Sai
Example 2
************
//static variable
System.out.println(S.name);//Sai
Example 3
************
//static variable
Can we access the static variable into static area through classname ?
*************************************************************************
Ans : Yes
Syntax : classname.variablename
Example 4
************
//static variable
System.out.println(Student.name);//Sai
Example 5
**************
}
>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
>CAn we assign final modifier for that instance variable and static variable?
***********************************************************
Ans : yes
CAn we assign access modifiers for that instance variables and static variables ?
**********************************************************
Ans : Yes
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 Student {
//static variable
System.out.println(name);//Sai
}
Example 2
************
public class Student {
//static variable
System.out.println(S.name);//Sai
}
Example 3
************
public class Student {
//static variable
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
System.out.println(Student.name);//Sai
}
Examples
*************
'H' or 'h' or '5' or '@'----------valid
Example 1
**************
char ch="H";//invalid String
System.out.println(ch);
Example 2
**************
char ch=H;//invalid
System.out.println(ch);
Example 3
**************
System.out.println(ch);
Example 4
**************
System.out.println(ch);//D
Example 5
**************
System.out.println(i);//71
Variable in java ?
********************
Types of variables ?
***********************
1.Instance variables
2.Local variables
3.Static variables
>The values of the name and rollno are different from student to student such
>The values of the name and rollno are different from object to object such
1.
2.
3.
4.
(if,if-else,ladder if-else,switch,while,do-while,forloop,static)
Example 1
*************
//instance variable
String name="Sai";
System.out.println(name);//error
}
Example 2
*************
//instance variable
String name="Sai";
System.out.println(S.name);//Sai
}
Object Syntax :
*****************
Syntax Explanation :
**********************
Example 3
*************
//instance variable
String name="Sai";
System.out.println(S.name);//Sai
}
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);
Example 2
***********
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
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
>Suppose if u want to Print 2nd student details then we need to create object
>Suppose if u want to Print nth student details then we need to create object
Part 3
**********
If i change the 1st student marks then there are any effect for that remaining
students marks ?
*************************************************************************
Ans : No effect
>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
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
***********
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
Example 5
***********
//Instance variables
System.out.println(S.name);//Sai
System.out.println(S.b);//false
System.out.println(S.d);//0.0
}
1.private
2.public
3.protected
4.default
Can we assign access modifiers for that instance variables and static variables ?
**************************************************************************
Ans : Yes
class Test{
//crate method
void m1()
{
//create constructor
Test()
{
int y=20;//local variable
//create block
if()
{
int z=30;//local variable
Example 2
*************
public class Student {
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
*************
//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.
int a; //invalid
int a=10;//valid
int a=0;//valid
int a; //valid
int a=10;//valid
int a=0;//valid
Example 4
*************
//local variable
byte b=10;
Examples
***********
Object syntax :
********************
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;
return-type methodname1()
{
}
return-type methodname2()
{
main()
{
Example
***********
Object
*********
Example 4
************
public class Student {
//local variables
CAn we assign final modifier for that instance variables and static variables ?
*********************************************************
Ans : Yes
>The name of the college is same from object to object such type of
Example 1
***********
System.out.println(name);//Sai
Example 2
***********
//static variable
System.out.println(S.name);//Sai
CAn we access the static variable into static area through object reference ?
*****************************************************
Ans : Yes
Example 3
***********
//static variable
CAn we access the static variable into static area through classname ?
*****************************************************
Ans : Yes
Syntax : classname.variablename
Example 4
***********
//static variable
System.out.println(Student.name);//Sai
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
*********
If i change the 1st student marks then there are any effect for that remaining
students marks ?
**************************************************************************
Ans : No effect
>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
Without inheritance
**********************
Example
************
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create Mainclass
Java code
*************
With inheritance
**********************
Note :
**********
Advantages of inheritance
**************************
>By using inheritance,we can
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() :
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown
1
2
3
4
....10
Example
***********
public class Student {
System.out.println(i);
}
}
Syntax :
***********
if(condition to break)
{
break;
}
Syntax Explanation :
*********************
1.
2.
3.
4.
Example
***********
How to print 1-3 from 1-10 nos ?
**************************************
Example 1
**************
if(A>100)
{
continue;//error
System.out.println(A);
Example 2
**************
System.out.println(i);
}
}
Syntax :
***********
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
types of constructor
************************
1.default constructor
2.parameterized constructor
1.default constructor
************************
Syntax :
************
Student()
{
2.parameterized constructor
******************************
Syntax :
************
Student(para1,para2,para3)
{
1.In default constructor,how to initialize the values for that instance variables
****************************************************************************
Student()
{
name = "Sai";
rollno=101;
}
Example
*********
Handling frames
*****************
getText() :
return-type : String
diagram :
************
Manual steps
***************
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown
List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));
System.out.println(droplist.size());//3
for(int i=0;i<droplist.size();i++)
{
System.out.println(droplist.get(2).getText());
Output
*********
AA
BB
CC
>
>
>
Syntax :
*************
return-type methodname(para1,para2)
{
statement1;
statement2;
statement3;
}
Examples
*************
void add()
{
}
void addfunction()
{
}
void addFunction()
{
Example
*************
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
*************
How to write a program for a method,with return-type and with passing parameters
***************************************************************************
Example
*************
Examples
**************
return c; //valid
return a,b;//invalid
1.State/properties
2.Behavior / Actions
Examples : Vehicles,Animals,Furniture,Fruits
>
1.State/properties
2.Behavior / Actions
Object syntax
****************
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
***********
Syntax:
**********
return-type methodname(para1,para2,par3)
{
Statement1;
Statement2;
Statement3;
}
Examples
************
void add()
{
}
void addfunction()
{
}
void addFunction()
{
Examples
***********
return c; //valid
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
types of Testing
*********************
1.Functional Testing
2.NOn functional Testing
2.commercial
==============
1.Qtp(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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 Components---IQ
****************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
Manual Steps
****************
>Switch to frame
>Identify dropdown
>Select the dropdown value
driver.switchTo().frame("rightMenu");
//1.First,Identify dropdown
S.selectByIndex(2);
Manual Steps
******************
>get the selected value
>Verify selected value
//---------------------------------------------------operation code
//-----------------------------------------------------verification code
}else
{
System.out.println("Selected value not verified successfully");
}
2.Verify Multiple selections are allowed or Not from a list box.
********************************************************************
//-----------------------------------------------operation code
WebElement listbox =
driver.findElement(By.id("ctl00_MainContent_lbCountry"));
S.selectByIndex(3);
S.selectByVisibleText("ARGENTINA");
//------------------------------------------------verification code
//Verify Multiple selections are allowed or Not from a list box.
if(S.isMultiple())
{
Manual Steps
*****************
Identify Checkbox1
Click Checkbox1
Verify Checkbox1
checkbox1.click();
//-------------------------------------------------verification code
// Verify Checkbox1
if(checkbox1.isSelected())
{
System.out.println("checkbox1 selected");
}else
{
Manual Steps
****************
Identify all Checkboxes
Count total checkboxes in a webpage
Verify multiple checkboxes one by one
List<WebElement> Allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));
System.out.println(Allchk.size());//3
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']
rollno = S_rollno;
}
Example
***********
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
**********
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);
Example 2
*************
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
Class
*******
1.It doesn't exis really /physically
Object
*********
1.It exists really / physically
Flow-control in java ?
**************************
Selection statements
***********************
1.if statement / block
2.if-else
3.ladder if-else
4.switch
if statement
*****************
Syntax :
*************
Syntax Explanation :
**********************
1.
2.
Example 1
***************
public class Student {
int dog_age=5;
if(cat_age==dog_age)
{
}
}
>Here if the condition is false then JVM has to print something in the console.
Example 2
***************
public class Student {
int dog_age=5;
if(cat_age==dog_age)
{
}
}
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 {
if(A>50)
{
}
}
}
Example 4
***************
public class Student {
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
>if(A)===>if(100)==>
F : int
R : boolean
Example 5
***************
public class Student {
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
>if(20)==>
F : int
R : boolean
Example 6
***************
public class Student {
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 {
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
F : boolean
R : boolean
Example 8
***************
public class Student {
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){
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
Example 2
*************
public class Student {
int y=1;
switch(x){
case 0 : System.out.println("Hello");//valid
case y : System.out.println("hanumanth");//invalid
}
}
}
Example 3
*************
public class Student {
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 {
switch(1){
case 1 : System.out.println("Hello");//invalid
case 1 : System.out.println("hanumanth");//invalid
}
}
}
Example 5
*************
public class Student {
switch(x){
case 10 : System.out.println("Hello");//valid
}
}
>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
all the statements will be executed automatically until break statement then
Example 6
*************
public class Student {
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 {
switch(ch){
}
}
Example 8
*************
public class Student {
switch(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
Example 1
*************
types of loops
*****************
3.forloop
Syntax:
**********
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
//loop body
Statement1;
Statement2;
Statement3;
}
Syntax Explanation :
**********************
1.
2.
Example 1
*************
public class Student {
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 {
for(int i=1;i<=10;i++)
{
System.out.println(i);
System.out.println(j);
}
System.out.println(i);
System.out.println(j);
}
}
>By using this we can print the text and the curser waits on the same line
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
Syntax :
************
for(initialization-part ; conditional-part/testing-part ; increment/decrement-part)
{
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
Note : Here always created from class to object ,not object to class
Object syntax
*****************
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()
{
}
}
Object
***********
1.It exists really / physically
Flow-control in java ?
**************************
Selection statement
**********************
if statement / block
*************************
Syntax :
*************
//body
}
Syntax Explanation:
*************
1.
2.
Example 1
***********
public class Student {
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 {
if(A>50)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
}
Example 4
***********
public class Student {
}
}
>if(A)==>if(100)==>
F : int
R : boolean
Example 5
***********
public class Student {
if(x=20)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
}
F : int
R : boolean
Example 6
***********
public class Student {
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 {
if(b=false)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
}
F : boolean
R : boolean
Example 8
***********
public class Student {
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
****************
Definition:
***************
Here multiple subclasses acquired all the features of one superclass by using
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
************
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");
}
}
Example 3
***************
class Test{
Test()
{
System.out.println("Hanumanth");
this();//invalid
}
}
Example 4
***************
class Test{
Test()
{
this();//valid
System.out.println("Hanumanth");
}
}
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");
}
}
Manual Steps
****************
1.Count total windows
**************************
Set<String> totalWindows = driver.getWindowHandles();
System.out.println("totalWindows : "+totalWindows.size());//2
driver.switchTo().window(allwindowhandles.get(1));
System.out.println(driver.getTitle());
driver.close();
driver.switchTo().window(allwindowhandles.get(0));
System.out.println(driver.getTitle());
Without Inheritance
************************
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create Mainclass
Java code
***************
What is a inheritance in java ?
*******************************
Definition:
****************
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
***************
In subclass
***************
Additional code(mandatory)
Diagram:
************
Manual Steps
**************
1.Count total windows
*************************
Set<String> totalWindows = driver.getWindowHandles();
System.out.println("totalWindows : "+totalWindows.size());//2
Types of constructor
************************
1.default constructor
2.parameterized constructor
1.default constructor
***********************
Syntax:
***********
Student()
{
}
2.parameterized constructor
*****************************
Syntax:
***********
Student(para1,para2,para3)
{
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
name = Akki;
rollno =102;
}
In method,return-type is mandatory ?
*******************************************
Ans : Yes
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
>Here instance variables and local variables both are same so in this case
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);
Switch Statement
********************
Syntax:
***********
switch(Expression value){
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
Syntax Explanation :
**************************
1.
2.
3.
4.
5.
6.
Example 1
*************
int x=0;
switch(x){
System.out.println("Hanumanth");
}
>In switch block,every statement should be under case value and default case.
Example 2
*************
int x=0;
int y=1;
switch(x){
case 0 : System.out.println("Hello");//valid
case y : System.out.println("Hanumanth");//invalid
}
Example 3
*************
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
*************
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
*************
switch(b){
case 10 : System.out.println("Hello");//valid
case 100 : System.out.println("Hi");//valid
case 1000 : System.out.println("Hanumanth");//invalid
>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
all the statements will be executed automatically until break statement then this
concept
Example 6
*************
public class Student {
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;
>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
type of datatypes
******************
1.Primitive datatypes
2,Non primitive datatypes
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
**************
java code
************88
Example
***********
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
**************
Example
**********
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
**************
Action class
*************
Manual Steps
****************
Manual Steps
****************
Manual Steps
****************
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();
Case 2
**********
Parent C = new Child();
Case 3
**********
Parent C = new Parent();
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
***********
Manual Steps
**************
Manual Steps
**************
Example 2
**************
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
Example 7
************
public class Student {
switch(ch){
break;
case 'r' : System.out.println("Red");//Red
break;
case 'y' : System.out.println("yello");
to write at last
Example 7
************
public class Student {
switch(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
**************
types of loops
******************
3.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 {
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 {
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 1
************
System.out.println(b);
Code Explanation :
***********************
>Here providing value is 125
>Here Expected value is byte datatype value
>min -128 to max 127
Example 2
************
System.out.println(b);
Examples
***********
"HYD" or "H" or "123" or "HYD123" or "%^%^&^*&(*"
Example 3
************
System.out.println(b);
>127
>byte type value
>min -128 to max 127
Example 4
************
System.out.println(b);
Code Explanation :
*********************
Example 5
************
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
************
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
Ex 2 : Here same name but with different sounds then it is called polymorphism
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
Definition 1 :
*****************
Note :
**********
When i run this program by default JVM will always call to child class
method(overriding method)
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
print()
**********
>This will be used to print the text and the curser waits on the same line
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
Example
************
System.out.println("Hello---");
System.out.println("Hi---");
System.out.println("Hanumanth");
Output
*********
Hello---
Hi---
Hanumanth
Syntax:
**********
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
Syntax Explanation:
*********************
Example
**********
Output
********
0 1 2
3 4 5
6 7 8
Example 7
***********
System.out.println(b);
>We can specify floating-point literal value(float value and double value) only in
decimal form
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
***********
System.out.println(b);
Code Explanation :
*********************
>128
>byte type value
>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
R : byte
Example 1
************
System.out.println(s);
code Explanation :
********************
>32767
>short type value
>min -32768 to max 32767
Example 2
************
System.out.println(s);
F : double
R : short
Example 3
************
System.out.println(s);
F : long
R : short
Example 1
***********
System.out.println(i);
>2345
>int type value
>min -2147483648 to max 2147483647
Example 2
***********
System.out.println(i);
System.out.println(i);
F : double
R : int
Example 1
***********
System.out.println(l);
Example 2
***********
System.out.println(l);
F : int
R : long
Example 3
***********
System.out.println(l);
System.out.println(s);
byte,short,long,float,double
F : int
R : String
Example 2
***********
System.out.println(s);
Example 3
***********
System.out.println(s);
Example 4
***********
System.out.println(s);
Example 1
***********
System.out.println(b);
F : int
R : boolean
Example 2
***********
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
***********
System.out.println(b);
Diagram:
***********
Manual Steps
****************
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!"))
{
Examples
**********
sendKeys(Keys.ARROW_DOWN)
sendKeys(Keys.ARROW_RIGHT)
sendKeys(Keys.ENTER)
sendKeys(Keys.DELETE)
sendKeys("a")
Examples
************
Ctrl+a,Ctrl+c,Ctrl+v,Shift+a,Ctrl+F11 etc
LinkText locator
********************
Definition :
*****************
Syntax :
************
driver.findElement(By.linkText(locator value));
Example
***********
program
***********
Manual Steps
***************
partialLinkText Locators
****************************
Definition :
*****************
Syntax :
************
driver.findElement(By.patialLinkText(locator value));
Example
***********
driver.findElement(By.patialLinkText("Owner (VeRO)"));
program
***********
Manual Steps
***************
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
************
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
}
}
Example 4
***********
class Test
{
Test()
{
this();//valid
System.out.println("Hanumanth");
}
}
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");
}
}
Example 1
*************
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
***********8
Example 2
*************
Manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangle) from Superclass(Shape)
3.Create MainClass
Java code
***********8
Example
***************
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
***********8
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)
Transfer statement:
*********************
1.Break statement.
*******************
Example 1
**************
public class Student {
if(x)
{
break;//error
}
System.out.println(Hanumanth);
}
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);
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 2
**************
public class Student {
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 {
if(i==4)
{
break;
}
System.out.println(i);
Continue statement
**********************
Example 1
************
public class Student {
if(x)
{
continue;//error
System.out.println("Hanumanth");
for(initialization-part ; conditional-part/testing-part ;
increment/decrement-part)
{
if(condition to continue)
{
continue;
Statements;
Syntax Explanation:
********************
1.
2.
3.
4.
if(i==3)
{
continue;
}
System.out.println(i);
Constructor in java ?
*************************
>This is similar to method
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
name = Akki;
rollno = 102;
}
Example
*************
Example
***********
Example
************
>Here we can specify floating-point literal value(float value and double value)
only in decimal form
Example 1
***********
System.out.println(f);
Example 2
***********
System.out.println(f);
Example 3
***********
Note :
********
When i run this program by default JVM will provide 25.0 instead of 25 while
Example 4
***********
System.out.println(f);
>Here we can specify floating-point literal value(float value and double value)
only in decimal form
Example 1
***********
System.out.println(d);
Example 2
***********
System.out.println(d);
Example 3
***********
System.out.println(d);
Examples
***********
Example 1
***********
System.out.println(ch);
Example 2
***********
char ch = H; // invalid
System.out.println(ch);
Example 3
***********
System.out.println(ch);
Example 4
***********
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
************
>
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()
{
}
}
Ans : A method has declaration part but not implementation part such type of method
is called
abstract method.
Example 3
************
//concreate method
//abstract method
1.
2.
3.
4.
Note :
*******
>Here we can't create the object for that abstract class (Unimplemented class)
Ans : A class can contain concreate methods and abstract methods such type of class
is called
abstract class.
Example 4
************
//concreate method
//abstract method
abstract void m2(); //Unimplemented method
Inheritance in java
***********************
Without inheritance
*********************
Example
***********
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create MainClass
Java code
*************
With inheritance
*********************
Example
***********
Note :
******
Advantages of inheritance
*****************************
Ans : By using inheritance
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
*****************
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
*********
Case 3
*********
Parent C = new Parent();
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
//abstract method
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")
Examples
*************
Ctrl + a,Ctrl + c ,Ctrl +v,Shift + a,Alt+ F ,Ctrl + N, Ctrl + T, Ctrl + w---------
How to enter text into input field(textbox,text area) using action class ?
***********************************************************************
WebElement SearchBox = driver.findElement(By.name("q"));
action.sendKeys(SearchBox,"html").perform();
Polymorphism in java ?
*************************
Polymorphism------many forms
Ex 2 : Here same name but with different sounds then it is called polymorphism
types of polymorphism
**********************
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
************
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);
Example 2
**************
Example 4
***********
System.out.println(ch);
Example 5
***********
System.out.println(i);//68
Variable in java ?
***********************
int x=10;
Types of variables
*********************
1.Instance variables
2.Local variables
3.Static variables
>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.
if,if-else,ladder if-else,switch,while,do-while,forloop,static)
Example 1
************
public class Student {
//Instance variable
System.out.println(name);//error
Object Syntax:
***************
Syntax Explanation :
*********************
Example 2
************
public class Student {
//Instance variable
System.out.println(S.name);//Sai
Example 3
************
Hi Mam,
******I am waiting from last 2months Please help me mam for job*********
Thank you
Hanumanth.
Interface in java
*****************
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
3.
4.
5
Note :
***********
>We can't create object for that interface(Unimplemented interface) and abstract
class(Unimplemented class)
School project
***************
Case 1
***********
Abstract class
**********************
//concreate methods
//abstract method
Case 2
***********
Interface
***********************
//Abstract methods
Interface part 2
******************
AutoIT
**********
1.Download autoit
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
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
**************
Concreate method.
Example
**********
class Test
{
//concreate method
void m1()
{
}
//concreate method
void m1(int i)
{
//concreate method
main()
{
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()
{
Ans : A method has declaration part but not implementation part such type of method
is called
abstract method.
Example
**********
//concreate method
//abstract method
1.
2.
3.Here abstract method must be override in child class
Note :
*********
>We can't create object for that abstract class / Unimplemented class
Ans : A class can contain concreate methods and abstract methods such type of class
is called
abstract class.
Example
**********
//concreate method
//abstract method
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
*************
Example 1
*************
class Test{
Test()
{
System.out.println("Hanumanth");
super();//invalid
}
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
Example 4
*************
class Test{
Test()
{
this();//valid
System.out.println("Hanumanth");
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");
Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
*************
Example
************
Manual Steps
**************
1.Create Superclass(Shape)
2.Create Subclass(Rectangle) from Superclass(Shape)
3.Create MainClass
Java code
*************
Example
*****
Note :
***********
When i run this program by default JVM will provide default constructor and
initialize the default
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
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
Example 4
**************
//Instance variable
String name="Sai";
int i;
boolean b;
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
**************
//Instance variable
System.out.println(S.name);//Sai
System.out.println(S.i);//0
System.out.println(S.b);//false
}
1.private
2.protected
3.public
4.default
Can we assign access modifiers for that instance variables and static varibles ?
********************************************************************************
Ans : Yes
class Student
{
//create method
void m1()
{
int x=10;//local variable
}
//create Constructor
Student()
{
int y=20;//local variable
}
//create block
if()
{
Example 2
************
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
************
//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.
int i; //invalid
int i=0;//valid
int i=10;//valid
int i; //valid
int i=0;//valid
int i=10;//valid
Example 4
************
//local variables
Interface part 2
********************
>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
{
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
*************
Syntax : interfacename.variablename
Syntax : classname.variablename
Note :
********
>We can't create object for that interface(Unimplemented interface) and abstract
class(Unimplemented class)
1.
2.
3.
System.out.println("totalLinks : "+totalLinks.size());//3
System.out.println("totalFrames : "+totalFrames.size());//3
Example 1
************
xpath in selenium
*********************
Java code
*************
school project
******************
Abstract class
****************
//concreate methods
//abstract method
polymorphism in java ?
***************************
poly mean--------many
morphs-------forms
Ex 2 : Here same name but with different sounds then it is called polymorphism
Types of polymorphism
************************
Definition 2:
***************
Here method name same but with different method signature then this concept is
called method overloading
Example 2
*********
Here i am not satisfied with parent class method implementation(body) .so that in
child class i am
Example
*************
Manual Steps
*****************
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
When i run this by default JVM will always call to child class method (overriding
method)not parent class method(overridden method)
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
*****************
In Subclass
******************
Additional code(Mandatory)
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();
Case 2
**********
Parent C = new Child();
Case 3
**********
Parent C = new Parent();
>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
**********
//Static variable
static String name="sai";
System.out.println(name);//sai
Example 2
**********
//Static variable
System.out.println(S.name);//sai
Can we access the static variable into static area through object reference ?
****************************************************************
Ans : Yes
Example 3
**********
//Static variable
System.out.println(S.name);//sai
}
}
Can we access the static variable into static area through classname ?
****************************************************************
Ans : Yes
Syntax : classname.variablename
Example 4
**********
//Static variable
System.out.println(S.name);//sai
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> ();
>Suppose if u want to only float type value in an arralist then we should follow
below syntax
>Suppose if u want to only Double type value in an arralist then we should follow
below syntax
>Suppose if u want to only String type value in an arralist then we should follow
below syntax
>Suppose if u want to only boolean type value in an arralist then we should follow
below syntax
>Suppose if u want to only char type value in an arralist then we should follow
below syntax
Syntax :
***********
arralist.remove(index);
Example
*********
program
**********
Syntax :
***********
Example
*********
Program
***********
Syntax :
***********
Example
********
program
***********
arralist.clear();
Example
**********
program
************
Syntax :
************
arralist.isEmpty();
Example
**********
Sir, in array list if I store all data types then if I need to separate them while
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
**********
partial implementation
concreate method .
Example
*********
class Test
{
//concreate method
void m1()
{
//concreate method
void m1(int i)
{
//concreate method
main()
{
>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()
{
Example
*********
//concreate method
}
//abstract method
1.
2.
Note :
*********
>We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented interface)
Example
*********
//concreate method
//abstract method
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
***********
Types of xpath
***************
1.Absolute xpath
2.Relative xpath
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']
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']
Interface part 1
*******************
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.
extends keyword : By using this,we can inherit the subclass from superclass
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
Case 2
**********
interface
****************
//abstract methods
>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
{
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
Syntax : classname.variablename
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
***********
School Project
*****************
Abstract class
*******************
//concreate methods
//abstract method
//concreate methods
Interface
*************
//abstract methods
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.bark();//----valid
Case 2
********
Animal D = new Dog();
D.bark();//----invalid
Example 2
***********
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
2.commercial
****************
1.Qtp(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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
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 Components---IQ
***************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
no details
*************
>Selenium IDE reports are not effective to send the client ,TestLead and project
manager
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
Selenium WebDriver
*********************
What is a webdriver ?
**************************
Ans : Webdriver it's an interface in betweeen selenium automation test script and
Testing application
-------------part 1
Java,
TestNG------part 3
****************
TestNG(latest)-----Junit(old)
selenium automation test cases,it generate Test Reports and also generate log
files.
>Selenium RC outdated(old)
>Selenium Webdriver doesn't generate the Test Reports and here selenium webdriver
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
get() :
getTitle() :
return-type : String
Manual Steps
**************
1.Get the Title of the WebPage
2.Print the title of the webpage
3.Verify Title of the WebPage
//-----------------------------------------------------------operation code
//----------------------------------------------------------verification code
Selenium WebDriver
********************
1.By using selenium webdriver, we can identify element
2.After identify the element then do some action on that element
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
Manual Steps
****************
1.Identify and get the Welcome Selenium Text
2.Print the Welcome Selenium Text
3.Verify Welcome Selenium Text
//-----------------------------------------------------------operation code
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"))
{
Example 2
***********
Example 1
************
class Test{
Test()
{
System.out.println("Hanumanth");
super();//invalid
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
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
Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclas(Cat) from Superclass(Animal)
3.Create Mainclass
Java code
**************
Example
***********
Manual Steps
**************
1.Create Superclass(Shape)
2.Create Subclas(Rectangle) from Superclass(Shape)
3.Create Mainclass
Java code
**************
Example
***********
Manual Steps
**************
1.Create Superclass(Animal)
2.Create Subclas(Cat) from Superclass(Animal)
3.Create Mainclass
Java code
**************
>Suppose if u want to access the java and selenium then we need to download
JDK(Java development kit) file first
Part 1
**********
Part 2
***********
Datatype in java
********************
int x=10;
>Here we can use datatypes in our selenium webdriver to prepare the selenium
>In java or other programming languages,we know we need variables to store some
data
based on datatype.
types of datatype
********************
1.primitive datatype
2.Non-primitive datatype
Example 1
***********
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
Compile the java code line by line(That means checking the java code line by line
whether it is currect code or not)
Example 2
***********
System.out.println(b);
Code Explanation:
********************
>We can say this("Hanumanth") is a String type value
Examples
**************
Example 3
***********
System.out.println(b);
Code Explanation :
*******************
>127
>byte type value
>min -128 to max 127
F : byte
R : byte
Example 4
***********
System.out.println(b);
Code Explanation :
*********************
F : boolean
R : byte
Example 5
***********
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
F : long
R : byte
Example 6
***********
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
***********
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
Float Examples
********************
10.5f,10.1111f,2.6f,-123.456f...........
Double Examples
********************
10.5,10.1111,2.6,-123.456...........
Example 8
***********
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
//input[@title='Search']
Syntax :$x("xpath")
Example
*********
$x("//input[@title='Sear']")
Xpath : //button[starts-with(@id,'Submit')]
Code : driver.findElement(By.xpath("//button[starts-with(@id,'Submit')]")).click();
Xpath : //button[ends-with(@id,'Submit')]
Code : driver.findElement(By.xpath("//button[ends-with(@id,'Submit')]")).click();
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')]
//tagName[@attributeName = 'value']
//button[ends-with(@id,'Submit')]
driver.findElement(By.xpath("//button[starts-with(@id,'Submit')]")).click();
write the absolute xpath for that password : Follow Red line
/html/body/input[2]
write the absolute xpath for that Username : Follow Red line
/html/body/input[1]
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
Element : Username
Html code
************
Syntax :
************
//tagName[@attributeName='value']
Example
***********
//input[@name='username']
Program:
*************
--------------------------------------------------------
Element : Gmail
Html code
************
Syntax :
************
//tagName[@attributeName='value']
Example
***********
//a[@class='gb_f']
Program:
*************
Example
**********
>Suppose if u want to store only integer type values in an arralist then we should
follow below syntax
>Suppose if u want to store only float type values in an arralist then we should
follow below syntax
>Suppose if u want to store only double type values in an arralist then we should
follow below syntax
>Suppose if u want to store only boolean type values in an arralist then we should
follow below syntax
>Suppose if u want to store only String type values in an arralist then we should
follow below syntax
arraylist.remove(index);
Example
************
program
***********
Syntax :
*************
Example
************
Program :
************
Syntax :
*************
Example
************
Program :
**********
Syntax :
************
arralist.clear();
Example
************
arralist.clear();//remove all the values present in the arralist
Program :
***********
Syntax :
************
arralist.isEmpty();
Example
************
arralist.isEmpty();
Program :
************
1.
2.
Example
************
Manual Steps
***************
1.Create Superclas(Animal)
2.Create Subclass(Cat) from Superclas(Animal)
3.Create MainClass
Java code
*************
Polymorphism in java ?
***************************
morphs mean--------forms
polymorphism mean--------many forms
Ex 2 : Here same name but with different sounds then it is called polymorphism
Types of polymorphism
************************
method overloading.
Example
***********
>Here method name same but with different method signature then this concept is
called
method overloading.
Example 2
**************
Example
***********
Manual Steps
*****************
1.Create parent class
2.Create Child class from parent class
3.Create Mainclass
Java code
************
Example 1
*************
Syste.out.println(s);
Code Explanation :
**********************
>32767
>short type value
>min -32768 to max 32767
F : short
R : short
Example 2
*************
System.out.println(s);
F : long
R : short
Example 3
*************
System.out.println(s);
F : double
R : short
Example 4
*************
System.out.println(s);
F : int
R : short
Example 1
*************
System.out.println(i);
Code Explanation :
**********************
>2345
>int type value
>min -2147483648 to max 2147483647
Example 2
*************
System.out.println(i);
Example 1
*************
System.out.println(l);
Example 2
*************
System.out.println(l);
F : int
R : long
String datatype in java ?
*****************************
>This will be used to store single character and group of characterss
Example
************
"HYD" or "H" or "123" or "123HYD" or "$^%&^*O("
Example 1
*************
System.out.println(s);
Example 2
*************
System.out.println(s);
Example 3
*************
System.out.println(s);
Example 4
*************
System.out.println(s);
>This will be used to store only boolean value such as true / false
Example 1
*************
System.out.println(b);
Example 2
*************
boolean b="H"; // invalid String
System.out.println(b);
Example 3
*************
System.out.println(b);
Example 4
*************
System.out.println(b);
Handle Frames
******************
1.How to handle single frame
2.How to handle multiple frames
3.How to handle Nested frames(Frame inside another frame)
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"));
4.text()
**************
Example
**********
Html code
***********
<h1>Welcome to Hanumanth</h1>
Syntax :
**********
//tagName[text()='value']
Example
**********
//h1[text()='Welcome to Hanumanth
sjhdfkjsahfkjsahfkjashfkjjhaskjjfhkashfklaslkflkaskfgdsg']
contains()
***************
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
*************
Example
*********
//input[@name='chk'][position()=5]
program :
**************
Interface in java ?
*******************
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
extends keyword :By using this,we can inherit the subclass from superclass
Note :
********
1.We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented interface)
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
Case 2
**********
Concreate class
*********************
//concreate methods
Case 3
**********
interface concept
***********************
//abstract methods
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
{
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
************
Syntax :interfacename.variablename
Syntax :classname.variablename
Note :
***********
Here we can't create the object for that interface but we can create reference
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
Note :
**********
When run this program by default JVM will always call to child class
method(overriding method) not parent class method(overridden method)
Example
*********
Manual Steps
**************
1.Create Parent class
2.Create Child class from parent class
3.Create MainClass
Java code
*************
Part 3
***********
1.Print 1st student details
********************************
1.First,initialize the values for that instance vairables
2.Print 1st 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
>Create collegeName and share the collegeName for all the students
>Create Single copy and share this copy for all the objects
diagram
*********
Manual Steps
*****************
>Switch to frame
>Identify dropdown
>Select the dropdown value
driver.switchTo().frame("rightMenu");
//1.First,Identify dropdown
S.selectByIndex(1);
Manual Steps
*************
>get the selected value
>Verify selected value
//--------------------------------------------------------------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"))
{
diagram
**********
Manual Steps
***************
1.Identify the Lisbox
2.select multiple options from a list box.
javascript.executeScript("window.scrollBy(x-axis,y-axis)");
1.
2.
3.
Syntax :
***********
(javascriptExecutor)driver.executeScript(script,argument);
Syntax Explanation :
*********************
javascript code.
Note :
***********
>By default javascript,it understand arguments[0] for that every single element
Html code
*************
Syntax :
***********
//tagName[@attributeName='value']
Example
***********
//input[@type='submit']
>Here abstract method is applicable for that methods and classes but not for
variables
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()
{
Abstract method.
Example 3
*************
abstract class Test{ //Unimplemented class
//concreate method
}
//abstract method
1.
2.
3.
4.
5.
6.
7.
abstract class.
Example 3
*************
abstract class Test{ //Unimplemented class
//concreate method
Java code
************
In superclass
****************
In subclass
************
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
*************
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
*************
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
Manual Steps
***************
WebElement listbox=driver.findElement(By.id("ctl00_MainContent_lbCountry"));
S.selectByIndex(3);
S.selectByVisibleText("ARGENTINA");
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");
}
Manual Steps
***************
Identify Checkbox1
Click Checkbox1
Verify Checkbox1
checkbox1.click();
//-----------------------------------------------------------------Verification
code
// Verify Checkbox1
if(checkbox1.isSelected())
{
System.out.println("checkbox1 is selected");
}else
{
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
//-------------------------------------------------------------------
// Identify all Checkboxes
List<WebElement> allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));
//------------------------------------------------------------------------
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
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
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
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
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
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
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:
4) Observe that The ChroPath has been added to Firefox as shown below
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).
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.
1) Java Single Line Comment : The single line comment is used to comment only one
line.
Syntax:
Syntax:
/*
This
is
multi line
comment
*/
Example:
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:
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
}
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:
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.
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
import org.openqa.selenium.firefox.FirefoxDriver;
public class LaunchFireFoxBrowser {
public static void main(String[] args) {
}
}
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.
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.server.browserlaunchers.Sleeper;
}
}
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");
}
Program 5:- Program to Launch Firefox browser and navigate to yahoo mail
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
>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;
driver.get("https://www.kosmiktechnologies.com/new-batches/");
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:
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;
driver.get("https://www.google.com/");
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:
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;
driver.get("https://www.kosmiktechnologies.com/new-batches/");
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;
driver.get("https://www.kosmiktechnologies.com/new-batches/");
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;
driver.get("https://opensource-demo.orangehrmlive.com/");
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;
driver.get("https://www.facebook.com/?");
// wait 6sec
Thread.sleep(6000);
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;
driver.get("https://www.facebook.com/?");
// wait 6sec
Thread.sleep(6000);
Don’t forget:
We might find situations where we cannot use the className attribute due to the
following reasons:
7.cssSelector:
8. Xpath Locator:
Selenium performs various operations on the webelements using the following methods
HTML STATEMENTS
Loops in JAVA
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.
*
**
***
****
*****
}
}
*
**
***
****
*****
*****
****
***
**
*
Pre-requisite -
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;
driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/
eKart/admin/");
String title=driver.getTitle();
System.out.println(title);
if (title.equals("Administration")) {
System.out.println("title verified successfully");
} else {
System.out.println("title not verified successfully");
}
driver.findElement(By.name("username")).sendKeys("Kadmin");
driver.findElement(By.name("password")).sendKeys("K@admin");
driver.findElement(By.xpath("//*[@id='content']/div/div/div/div/div[2]/form/
div[3]/button")).click();
String text =
driver.findElement(By.xpath("//*[@id='content']/div[1]/div/h1")).getText();
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");
}
driver.findElement(By.xpath("//*[@id='header']/ul/li[3]/a")).click();
driver.close();
Syntax : driver.get("appURL”);
2.getTitle() : This will be used to get the title of the current Webpage.
Syntax : driver.getTitle();
Syntax : driver.findElement(By.Locator("Locator-Value"));
Ex :
Syntax :
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();
Syntax : driver.close();
Ex :
Syntax :
> driver.findElement(By.Locator("Locator-Value"));
TestSteps :
Selenium Program :
package seleniumProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findElementMethod {
driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/eKart/
admin/");
driver.close();
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 :
TestSteps :
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 {
driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/
eKart/admin/");
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.
Selenium Program :
package seleniumProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
driver.get("http://www.kosmiktechnologies.com/seleniumLiveProject/eKart/
admin/");
driver.findElement(By.name("password")).sendKeys("K@admin");
driver.findElement(By.xpath("//*[@id='content']/div/div/div/div/div[2]/form/
div[3]/button")).click();
String text =
driver.findElement(By.xpath("//*[@id='content']/div[1]/div/h1")).getText();
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");
}
driver.findElement(By.xpath("//*[@id='header']/ul/li[3]/a")).click();
driver.close();
6.What is a webDriver ?
Control statements :
Syntax :
If(Actual_value.equals(Expected_value))
{
}else
{
//Execute the code if condition is false
}
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.
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.
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"));
driver.switchTo().frame(framelist.get(0));
driver.switchTo().frame(framelist.get(1));
driver.switchTo().frame(framelist.get(2));
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”);
Html code :
Example : driver.switchTo().frame(driver.findElement(By.name(“rightMenu”)));
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>
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 {
driver.get("file:///C:/Users/Hanumanthu/Downloads/frames.html");
List<WebElement> total_frames=driver.findElements(By.tagName("iframe"));
System.out.println(total_frames.size());
driver.close();
}
}
}
}
Note :
Syntax : driver.switchTo().frame(total_frames.get(index));
Example : driver.switchTo().frame(total_frames.get(2));
Syntax : driver.switchTo().frame(WebElement);
Example : driver.switchTo().frame(driver.findElement(By.name(“selenium”);
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.
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:
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;
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
String title=driver.getTitle();
System.out.println(title);
driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
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();
System.out.println(text);
if (text.equals("Welcome selenium")) {
// Switch to Frame by ID
driver.switchTo().frame("rightMenu");
/*
If u want to select the dropdown value then we need to create the
select object for that dropdown
*/
s.selectByIndex(2);
String selected_value=s.getFirstSelectedOption().getText();
System.out.println("selected_value :"+selected_value);
driver.switchTo().defaultContent();
driver.findElement(By.xpath("//*[@id='option-menu']/li[3]/a")).click();
driver.close();
}
Working with popups – 3
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 :
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;
driver.get("http://demo.guru99.com/v4/");
driver.findElement(By.xpath("html/body/form/table/tbody/tr[1]/td[2]/
input")).sendKeys("mngr193544");
driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td[2]/
input")).sendKeys("EbepYgE");
driver.findElement(By.xpath("html/body/form/table/tbody/tr[3]/td[2]/
input[1]")).click();
// Wait 5sec
Thread.sleep(5000);
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
// click on ok button
driver.switchTo().alert().accept();
// driver.switchTo().alert().dismiss();
// close the browser
// Wait 5sec
Thread.sleep(5000);
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();
}
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.
Syntax : -
Syntax : -
Syntax : - driver.switchTo().window(parentWindow);
Ex : - driver.switchTo().window(AllWindowHandles.get(0));
Ex : - driver.switchTo().window(AllWindowHandles.get(1));
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 7 Get total windows and store into windows variable
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;
//click on feedback
driver.findElement(By.xpath(".//*[@id='navigation']/li[3]/a")).click();
TestSteps
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;
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;
}else{
}
}
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;
isMultiple() : By using this we can verify Multiple selections are allowed or Not
from a list box.
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.
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.
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;
driver.get("http://jqueryui.com/resources/demos/droppable/default.html");
WebElement draggable =
driver.findElement(By.xpath("//*[@id='draggable']"));
/*
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.
*/
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();
if(dropped_text.equals("Dropped!"))
{
System.out.println("dragAndDrop operation verified successfully");
}else
{
System.out.println("dragAndDrop operation not verified
successfully");
}
driver.close();
}
}
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;
driver.manage().window().maximize();
// navigate the AppUrl
driver.get("http://127.0.0.1/orangehrm-2.5.0.2/login.php");
System.out.println(title);
driver.findElement(By.name("txtUserName")).sendKeys("selenium");
driver.findElement(By.name("txtPassword")).sendKeys("selenium");
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();
System.out.println(text);
if (text.equals("Welcome selenium")) {
} else {
System.out.println("Welcome selenium is not verified
successfully");
}
act.moveToElement(driver.findElement(By.id("pim"))).perform();
driver.findElement(By.xpath("//*[@id='pim']/ul/li[2]/a")).click();
//wait 5sec
Thread.sleep(5000);
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();
System.out.println(addEmp);
driver.switchTo().defaultContent();
//Click on Logout
driver.findElement(By.xpath("/html/body/div[3]/ul/li[3]/a")).click();
//wait 5sec
Thread.sleep(5000);
driver.close();
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;
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"));
action.doubleClick(element).perform();
/*
Note :
*/
// Identify and get the text from input field2 and store into
entered_text variable
String entered_text =
driver.findElement(By.id("field2")).getAttribute("value");
} catch (Exception e) {
System.out.println("Unable to perform doubleClick operation");
}
driver.close();
}
4.To verify whether the rightClick operation successfully performed or Not?And How
to Click on Open Link In New Window.
TestSteps :
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;
driver.get("https://www.google.co.in/");
action.contextClick(about).perform();
//wait 5sec
Thread.sleep(5000);
} catch (Exception e) {
driver.close();
}
}
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.
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.
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
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
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.
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
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 {
//wait 3sec
Thread.sleep(3000);
driver.findElement(By.id("txtUsername")).sendKeys("Admin");
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();
System.out.println(text);
act.moveToElement(driver.findElement(By.xpath("//*[@id='menu_pim_viewPimModule']"))
).perform();
//Wait 5sec
Thread.sleep(5000);
//Wait 5sec
Thread.sleep(5000);
driver.findElement(By.id("firstName")).sendKeys("sai");
driver.findElement(By.id("lastName")).sendKeys("honey");
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);
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);
driver.close();
}
}
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.
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.
Expand Java folder and see if the TestNg is available as in the below screen shot.
Way : 2
Configuring TestNG
5. Click on Next.
6. Accept the license Agreement Click on Finish.
1. Open Eclipse
2. Click on Window Menu
3. Click on Show View
4. Click on Other
5. Expand JAVA
6. Check for 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.
@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
It will add TestNg library in your project as shown in bellow image. Now click on
OK button to close that window.
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:
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() {
//@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.
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.
<suit>
<test>
<Classess>
<class>packagename.classname</class>
</classes>
</test>
</suit>
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
https://mvnrepository.com/
After find search
EXCELL Operations :
To perform read and write operations in excel we require third party JAR files
like “Apache-POI”.
ROW:- This is an interface in the apache-POI, which is used to handle one row in
the excel sheet.
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.
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;
WebDriver driver;
@Test
public void LoginTest() throws Exception {
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.
//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();
driver.findElement(By.name("txtUserName")).sendKeys(username);
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();
System.out.println(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() {
@AfterClass
public void afterClass() {
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;
WebDriver driver;
@Test
public void LoginTest() throws Exception {
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.
//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();
driver.findElement(By.name("txtUserName")).sendKeys(username);
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();
System.out.println(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() {
@AfterClass
public void afterClass() {
driver.close();
}
4.Compare dropdown size and Excel size 3.Store Excel values in an xlvalues
variable .See below
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;
@BeforeClass
public void setUp()
{
//Launch Firefox browser
driver.manage().window().maximize();
}
@Test
public void Verify_DropdownValuesTest() throws IOException,
InterruptedException, BiffException {
driver.get("http://www.tizag.com/htmlT/htmlselect.php");
//wait 3sec
Thread.sleep(3000);
//Identify dropdown
WebElement dropdown=driver.findElement(By.name("selectionField"));
List<WebElement>
dropdownCount=dropdown.findElements(By.tagName("option"));
/*
FileInputStream – A FileInputStream is an inputstream for reading
data from a Excel File.
int total_Rows=sheet.getLastRowNum()+1;
int total_Columns=sheet.getRow(0).getLastCellNum();
/*
*/
for(int i=0;i<total_Rows;i++)
{
xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}
for(int j=0;j<dropdownCount.size();j++)
{
ddvalues.add(dropdownCount.get(j).getText());
}
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();
}
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;
WebDriver driver;
@BeforeClass
public void setUp()
{
//Launch Firefox browser
driver.manage().window().maximize();
}
@Test
public void Verify_DropdownValuesTest() throws IOException,
InterruptedException, BiffException {
driver.get("http://www.tizag.com/htmlT/htmlselect.php");
//wait 3sec
Thread.sleep(3000);
//Identify dropdown
WebElement dropdown=driver.findElement(By.name("selectionField"));
List<WebElement>
dropdownCount=dropdown.findElements(By.tagName("option"));
/*
FileInputStream – A FileInputStream is an inputstream for reading
data from a Excel File.
XSSFSheet sheet=workbook.getSheetAt(1);
int total_Rows=sheet.getLastRowNum()+1;
int total_Columns=sheet.getRow(0).getLastCellNum();
/*
*/
for(int i=0;i<total_Rows;i++)
{
xlvalues.add(sheet.getRow(i).getCell(0).getStringCellValue());
}
for(int j=0;j<dropdownCount.size();j++)
{
ddvalues.add(dropdownCount.get(j).getText());
}
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();
}
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;
WebDriver driver;
@BeforeClass
public void setUp() {
// Launch Firefox browser
driver.manage().window().maximize();
}
@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {
driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");
//Enter i into textbox field
driver.findElement(By.id("myInput")).sendKeys("i");
List<WebElement> AutoSuggets =
driver.findElements(By.xpath("//*[@id='myInputautocomplete-list']/div"));
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
*/
//Identify AutoSugget and get the text and store into value
variable
String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();
System.out.println(value);
AutoSugget_values.add(value);
}
HSSFSheet sheet=workbook.getSheet("Sheet5");
int total_Rows=sheet.getLastRowNum()+1;
/*
*/
for(int i=0;i<total_Rows;i++)
{
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();
}
}
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;
WebDriver driver;
@BeforeClass
public void setUp() {
// Launch Firefox browser
driver.manage().window().maximize();
}
@Test
public void VerifyAutoSearchResultsTest() throws IOException,
InterruptedException {
driver.get("file:///E:/SeleniumSoftware%20dump/AutoSearchResult.html");
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"));
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
*/
//Identify AutoSugget and get the text and store into value
variable
String value =
driver.findElement(By.xpath("//*[@id='myInputautocomplete-list']/div[" + i +
"]")).getText();
System.out.println(value);
AutoSugget_values.add(value);
}
XSSFSheet sheet=workbook.getSheet("Sheet1");
/*
*/
for(int i=0;i<total_Rows;i++)
{
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;
WebDriver driver;
@BeforeClass
public void openWebSite() {
@Test
public void CountRowsTest() throws IOException, BiffException {
//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xls_File.xls");
System.out.println();
System.out.println("**************Excel data*****************\n");
//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();
}
System.out.println();
System.out.println("**************WebTable data*****************\n");
}
System.out.println();
}
System.out.println();
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;
WebDriver driver;
@BeforeClass
public void openWebSite() {
@Test
public void CountRowsTest() throws IOException, BiffException {
//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xlsx_File.xlsx");
System.out.println();
System.out.println("**************Excel data*****************\n");
//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");
}
System.out.println();
}
System.out.println();
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();
}
}
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;
WebDriver driver;
@BeforeClass
public void openWebSite() {
@Test
public void CountRowsTest() throws IOException {
//If you want to read the excel file then we use FileInputStream object
FileInputStream fis=new FileInputStream("E:\\SeleniumSoftware dump\\
Xls_File.xls");
System.out.println();
System.out.println("**************Excel data*****************\n");
//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();
}
System.out.println();
System.out.println("**************WebTable data*****************\n");
}
System.out.println();
}
System.out.println();
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();
}
}
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;
WebDriver driver;
@BeforeClass
public void openWebSite() {
@Test
public void CountRowsTest() throws IOException {
//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);
System.out.println();
System.out.println("**************Excel data*****************\n");
//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();
}
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()
;
}
System.out.println();
}
System.out.println();
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();
}
}
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;
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:
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;
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");
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;
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 :
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 {
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();
String str=driver.switchTo().alert().getText();
System.out.println(str);
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.
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’]))
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
Let us see : To generate the Relative Xpath , you need to follow the following
steps
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.
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.
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
Where Dynamic id
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
Selenium Code :
package tests;
import java.util.ArrayList;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
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);
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);
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);
}
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).
Ends-with function ():We can use this function when ID in ending is constant then
before dynamic.
To overcome the above situations we need to use the above said JavaScript
functions.
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;
}
}
How to use functions in xpath in selenium ?
Open notepad and type the below and save as .html file
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]"));
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
Note:
Where arguments[1] means second element which has same name.
((JavascriptExecutor) driver).executeScript("arguments[0].value =
'selenium';",username);
Maven :
>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 :
Part 2 :
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>
<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.
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.
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 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.
Step 1 : First of all, Open eclipse IDE and go for creating new project from New ->
Other as shown In bellow Image.
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.
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.
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>
<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>
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;
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");
}
@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.
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.
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.
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
Step 2: Open Excel Sheet and create some test data. Here I have saved my excel
sheet on my D Drive.
Config.property:
This file will hold all are configuration info
For ex:
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;
//@BeforeClass defines this Test has to run before every @Test methods in
the current class/program
@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
{
}
//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;
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
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;
Capturing ScreenShots
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;
3. TakesScreenshot scr=(TakesScreenshot)driver;
4. File srcFile=scr.getScreenshotAs(OutputType.FILE);
5. FileUtils.copyFile(srcFile,new File("C:\\Hanumanth.png"));
1. File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
2. FileUtils.copyFile(srcFile,new File("C:\\Hanumanth.png"));
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
Priority Testing
Prioritization testing in TestNG
@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(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");
}
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.
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.
TC_1 :
------
package RunMultipleGroups;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@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");
@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;
@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");
}
<suite name="Suite">
<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>
</test>
<suite name="Suite">
<classes>
<class name="RunMultipleGroups.GroupTest1"/>
<class name="RunMultipleGroups.GroupTest2"/>
</classes>
</test>
<suite name="Suite">
<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>
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.
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.
3- Now simply run testng-failed.xml.an be easily done by running one simple 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.
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.
• 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
<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>
Step 3): In this step run the build.xml file from eclipse as shown below:
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.
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.
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.
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;
}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>
5) Also, the ChroPath Add-on got added to the Chrome Browser as shown below:
4) Observe that The ChroPath has been added to Firefox as shown below
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).
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
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 .
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.
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
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.
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.
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’.
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‘
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.
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
IMPORTENT Questions :
IMPORTENT Questions :
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 :
Java :
package JAVAExamples;
System.out.println(revstring);
}
}
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 ?
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();",
element);
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Syntax
***********
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Example
**************
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,500)");
Program
************
Syntax
***********
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Example
**************
((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
Syntax
***********
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Example
**************
((JavascriptExecutor) driver).executeScript("window.scrollBy(500,0)");
program
***********
Syntax
***********
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Example
**************
((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);
((JavascriptExecutor) driver).executeScript("window.scrollBy(-250,0)");
Manual Steps
*************
Selenium Javascript code
***********************
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:
if(driver.findElement(By.linkText("News")).isDisplayed())
{
driver.findElement(By.linkText("News")).click();
Case 3 :
//wait 10 sec
Thread.sleep(10000);
School project
*****************
Case 1
*************
abstract class
*****************
//concreate methods
//abstract method
Case 2
*************
//concreate class
*************************
//concreate methods
Case 3
*************
interface concept
**********************
//abstract methods
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.
extends keyword : By using this ,we can inherit the subclass from superclass
Note :
**********
>We can't create object for that abstract class(Unimplemented class) and
interface(Unimplemented inteface)
are created
>Here always created from class to object,not object to class
1.state / properties
2.Behavior / Actions
Object syntax
*****************
Class syntax
****************
class <classname>
{
//1.state / properties-----------vairables
<datatype> variablename 1;
<datatype> variablename 2;
return-type methodname1()
{
}
return-type methodname2()
{
main()
{
}
}
class and object Example
**************************
Object
**********
1.It exists really / physically
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
Ans :
Examples
************
1.
2.
************
System.out.println("totalLinks : "+totalLinks.size());//3
Manual Steps
**************
List<WebElement> totalFrames =
driver.findElements(By.tagName("iframe"));
System.out.println("totalFrames : "+totalFrames.size());//3
driver.findElement(By.className("inputtext _55r1
_6luy")).sendKeys("*********@gmail.com");
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
***********
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
{
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.
Syntax : Interfacename.variablename
Syntax : classname.variablename
Note :
*********
>Here we can't create object for that interface but we can create reference for
that interface
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 block
}
Syntax Explanation:
***********************
1.
2.
Example 1
*************
public class If_Statement {
int cat_age=5;
int dog_age=7;
if(cat_age==dog_age)
{
}
>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
Example 2
*************
public class If_Statement {
int cat_age=5;
int dog_age=7;
if(cat_age==dog_age)
{
Conclusion
**************
1.Suppose if u want to check only true condition then we have to go if statement
Example 3
*************
public class If_Statement {
int A=100;
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
Found : int
Required : boolean
Example 4
*************
public class If_Statement {
int A=100;
Example 5
*************
public class If_Statement {
int x=10;
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 {
int x=10;
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
Example 7
*************
public class If_Statement {
boolean b=true;
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;
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){
break;
break;
break;
Syntax Explanation:
************************
1.
2.
3.
4.
5.
6.
Example 1
**********
public class Switch_Statement {
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
Example 2
**********
public class Switch_Statement {
int x=0;
int y=1;
switch(x){
case 0 : System.out.println("Hello");//valid
case y : System.out.println("Hanumanth");//invalid
Example 3
**********
public class Switch_Statement {
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 {
//local variables
int x=0;
switch(x){
case 0 : System.out.println("Hello");//Hello
case y : System.out.println("Hanumanth");//valid
1.private
2.public
3.protected
4.default
Example 5
**********
public class Switch_Statement {
//local variables
switch(b){
case 10 : System.out.println("Hello");//valid
case 100 : System.out.println("Hi");//valid
}
>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
will be executed automatically until break statement then this concept is called
fall-through
Example 6
**********
public class Switch_Statement {
//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 {
//local variables
char ch='r';
switch(ch){
break;
case value
3.In switch block,we can write default case anywhere but switch is recommended to
write
at last.
Example 7
**********
public class Switch_Statement {
//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");//
Loops in java
*****************
Example
************
public class Loops_Statement {
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
Syntax
***********
Syntax Explanation
********************
1.
2.
Example 2
*************
Hpw to print (starting)1-10(ending) nos ?
****************************
1
2
3
4
5
...10
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
**************
for(int i=1;i<=5;i++)
{
System.out.println(i);
System.out.println(j);
System.out.println(i);
System.out.println(j);
Syntax :
**************
for(initialization-part ; condition-part/Testing-part ;
increment/decrement-part)
{
Syntax Explanation:
*********************
Example
**********
Output
*********
0 1 2
3 4 5
6 7 8
>By using this, we can print the text (Hello---)and the curser waits on the same
line to
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
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
Types of Testing
*********************
1.Functional Testing
2.Non-functional Testing
2.commercial
===============
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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 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,
TestNG---------part 3
**********
TestNG(latest)-------Junit(old)
AutoIT
logs
grid
Git
jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
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,
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 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
Why we are using xml file ? or Why we are using Test suite ?
***************************************************************
Ans :
Where we can create xml file ?
***********************************
Ans :
Example
***********
>Suppose if u want to store only float values in an arrayList then we should follow
below syntax
Syntax:
*********
arraylist.remove(index);
Example
***********
Program
**********
Can we replace 20 with 50 in an arrayList ?
*************************************************
Ans : Yes
Syntax :
***********
arraylist.set(int index,Object obj);
Example
*********
Program
***********
Syntax :
***********
Example
*********
Program
************
Syntax:
************
arralist.clear();
Example
************
Program
*********
Verify arraylist has empty or not ?
***************************************
Syntax :
***************
arraylist.isEmpty();
Example
***********
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;
0 1 2
2 3 4
5 6 7
How to Verify multiple rows and columns of the Webtable data Using _xlsFile?
**************************************************************
Company Contact Country
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
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 ?
//switch to alert
//---------------------------------------------------------Operation
code
//---------------------------------------------------------Verification
code
//click on ok
alt.accept();
diagram:
************
Manual Steps
***************
>Switch to model popup window
>Do some action
>click on model popup window
driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();
get() :
Manual Steps
***************
>Get the Title of the WebPage
>Print tile of the WebPage
>verify title of the webpage
//---------------------------------------------------------operation code
Selenium WebDriver
***********************
sendkeys() :
getText() :
return-type : String
getTitle() :
return-type : String
Manual Steps
***************
Identify and get the Welcome Selenium Text
Print the Welcome Selenium Text
To verify whether the welcome page successfully opened or not
//---------------------------------------------------------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"))
{
Manual Steps
*************
System.out.println("totalWindows : "+totalWindows.size());//2
System.out.println(driver.getTitle());
driver.close();
driver.switchTo().window(allWindowsHandle.get(0));
System.out.println(driver.getTitle());
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)
Manual Steps
*****************
>First,get the dropdown size or count dropdown values
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown
List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));
List<WebElement> droplist =
dropdown.findElements(By.tagName("option"));
for(int i=0;i<droplist.size();i++)
{
System.out.println(droplist.get(i).getText());
Manual Steps
*****************
>Switch to frame
>Identify dropdown
>Select the dropdown value
driver.switchTo().frame(0);
//1.First,Identify dropdown
WebElement dropdown = driver.findElement(By.id("loc_code"));
S.selectByIndex(1);
//-----------------------------------------------------operation code
//>get the selected value
System.out.println("selected_value : "+selected_value);//Emp. Id
//----------------------------------------------------Verification code
if(selected_value.equals("Emp. Id"))
{
Manual Steps
****************
Manual Steps
***************
Manual Steps
***************
1.dragAndDrop()
2.moveToElement()
3.doubleClick()
4.contextClick()
1.sendKeys()
2.keyDown()-->perform the keypress without release
3.keyUp()--->perform the key release
Examples:
***************
keyDown,keyUp,Enter,Delete,F11 ...etc
Examples
************
Constructor in java
**********************
This is similar to method
Types of constructors
**********************
1.default constructor
2.parameterized constructor
1.default constructor
************************
Syntax :
*************
Student()
{
2.parameterized constructor
******************************
Student(int i)
{
In method,return-type is mandatory ?
**************************************
Ans :Yes
Example
***********
void m1()
{
}
Example
**************
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
************
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
**********
Example 2
*************
xpath in selenium
**********************
1.
2.
3.
xpath types
*************
1.Absolute xpath
2.Relative xpath
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']
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']
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']
//input[starts-with(@name,'btnchkavail')]
driver.findElement(By.xpath("//input[starts-with(@name,'btnchkavail')]")).click();
//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();
>starts-with(),ends-with(),contains(),text(),position()
text()
***********
1.
2.
Html code
**********
<h1>Welcome to Hanumanth</h1>
Syntax :
***********
//tagName[text()='value']
Example
***********
//h1[text()='Welcome to
HanumanthsahgdjhasgjkdhasjkhdjkahskdjhaskjdhkjaHDSLKJAHkjshAKJHSKJahskjhAS']
Program
**********
Html code
**********
<h1>Welcome to
HanumanthsahgdjhasgjkdhasjkhdjkahskdjhaskjdhkjaHDSLKJAHkjshAKJHSKJahskjhAS</h1>
Syntax :
***********
//tagName[contains(text(),'value')]
Example
*********
//h1[contains(text(),'Hanumanth')]
Program
**********
Example 1
*********
//h1[contains(text(),'Hanumanth')][position()=2]
Example 2
*********
//tagName[@attributeName='value']
xpath function
*****************
position()
Example
***********
//input[@name='chk'][position()=5]
Element : Password
Html code
**************
Syntax :
**********
//tagName[@attributeName='value']
Example
**********
//input[@name='password']
Program
***********
Html code
**************
Syntax :
**********
//tagName[@attributeName='value']
Example
**********
//a[@class='gb_f']
Program
***********
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
write the absolute xpath for that Username : Follow the Red line
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
Element : Username
Html code
**************
Syntax :
***********
//tagName[@attributeName='value']
Example
********
//input[@name='username']
Program
**********
driver.get("file:///E:/Browser%20Elements/Browser%20Element.html");
driver.findElement(By.xpath("//input[@name='username']")).sendKeys("selenium");
Element : Password
Html code
**************
Syntax :
***********
//tagName[@attributeName='value']
Example
********
//input[@name='password']
Program
**********
driver.get("file:///E:/Browser%20Elements/Browser%20Element.html");
driver.findElement(By.xpath("//input[@name='password']")).sendKeys("selenium123");
Element : Gmail
Html code
**************
Syntax :
***********
//tagName[@attributeName='value']
Example
********
//a[@class='gb_f']
Program
**********
driver.get("file:///E:/Browser%20Elements/Browser%20Element.html");
driver.findElement(By.xpath("//input[@name='password']")).sendKeys("selenium123");
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)
In superclass
****************
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--->
$x("path")
Example
**********
$x("//input[@name='q'")
javascript syntax
*******************
(javascriptExecutor)driver.executeScript(script,argument);
Syntax Explanation
*********************
javascript syntax
*******************
(javascriptExecutor)driver.executeScript(script,argument);
Example
***************
((JavascriptExecutor) driver).executeScript("arguments[0].value =
'selenium';",driver.findElement(By.name("frame")));
Note :
********
Element : SearchBox
Html code
************
Syntax
**********
$x("xpath")
Example
********
$x("//input[@name='q']")
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">
1.
2.
javascript syntax
*******************
(javascriptExecutor)driver.executeScript(script,argument);
Syntax Explanation
***********************
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 ?
******************************************************************************
Example
***********
Manual Steps
************
config.load(fis);
OR.load(fiss);
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
Types of Testing
****************
1.Functional Testing
2.Non-functional Testing
2.commercial
===============
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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 Components---IQ
***************************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
-------------------------------------part 1
Java,
80%------------>selenium WebDriver + java(java oops concepts + collections)
TestNG----------part 3
************************
TestNG(latest)---Junit(old)
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Example
**********
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,1000)");
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-500)");
Program
**********
Syntax:
**********
((JavascriptExecutor) driver).executeScript("window.scrollBy(x-axis,y-axis)");
Example
**********
((JavascriptExecutor) driver).executeScript("window.scrollBy(1000,0)");
((JavascriptExecutor) driver).executeScript("window.scrollBy(-500,0)");
program
***********
Manual Steps
*****************
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();
}else
{
case 3
**********
1.Why this type of error is coming
2.How to resolve this type of error
Thread.sleep(10000);
1.
2.
3.
Ex 1
******
How to count total links in a webpage ?
****************************************
Manual Steps
**************
Ex 2
******
How to count total frames in a webpage ?
****************************************
Manual Steps
**************
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
********
Part 2
*********
Datatype in java ?
*********************
int x=10;
7386467494
>Suppose if u want to access the java and selenium then we need to download
JDK(java Development kit) file first
Part 1
*********
Part 2
********
Datatypes in java ?
**********************
int x=10;
>In java or other programming languages,we know we need variables to store some
data based on datatype
types of datatype
******************
1.primitive datatype
2.Non-primitive datatype
Example 1
***********
System.out.println(b);//
Code Explanation
******************
>Here providing value 125
>Here expected value is byte type
>min -128 to max 127
Example 2
***********
System.out.println(b);//
Code Explanation
******************
Examples
************
Example 3
***********
System.out.println(b);//
Code Explanation
******************
F : boolean
R : byte
Example 4
***********
System.out.println(b);//
Code Explanation
******************
>127
>byte type value
>min -128 to max 127
F : byte
R : byte
Example 5
***********
System.out.println(b);//
Example 5
***********
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
Example 6
***********
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
***********
System.out.println(b);//
F : double
R : byte
>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
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
Example 1
***********
System.out.println(s);//
F : short
R : short
Code Explanation
******************
>32767
>short type value
>min -32768 to max 32767
Example 2
***********
System.out.println(s);//
F : double
R : short
Example 3
***********
System.out.println(s);//
Example 4
***********
System.out.println(s);//
F : int
R : short
>32768
>short type value
>min -32768 to max 32767
WebElement listbox =
driver.findElement(By.id("ctl00_MainContent_lbCountry"));
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"));
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");
}
Manual Steps
************
>Identify Checkbox1
>Click Checkbox1
>Verify Checkbox1
//-------------------------------------------------operation code
// Identify Checkbox1
checkbox1.click();
//-------------------------------------------verification code
if(checkbox1.isSelected())
{
System.out.println("checkbox1 selected");
}else
{
xpath syntax
**************
//tagName[@attributeName='value']
Example
*********
//input[@type='checkbox']
Program
**********
//-----------------------------------------------------operation code
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");
}
Example 1
**********
System.out.println(i);//
Code Explanation
******************
>2345
>int type value
>min -2147483648 to max 2147483647
Found : int
Required : int
Example 2
**********
System.out.println(i);//
Example 3
**********
System.out.println(i);//
Example 1
**********
System.out.println(l);//
Example 2
**********
System.out.println(l);//
F : int
R : long
What are the integral literal values ?
*****************************************
Ans : byte,short,int,long
Example 3
**********
System.out.println(l);//
Examples
***********
Example 1
**********
System.out.println(S);//
Example 2
**********
System.out.println(S);//
Example 3
**********
System.out.println(S);//
Example 4
**********
System.out.println(S);//
Ans :
1.
2.
Javascript Syntax
********************
(javascriptExecutor)driver.executeScript(script,argument);
Syntax Explanation
*********************
Note :
**********
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.
Manual Steps
***************
1.switch to alert
2.verify alert text
3.click on ok
//1.switch to alert
//------------------------------------------------------operation code
//--------------------------------------------------verification code
//3.click on ok
alt.accept();
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());
driver.findElement(By.xpath("/html/body/div[76]/div/div[3]/div/div/
div[1]")).click();
System.out.println("totalWindows : "+totalWindows.size());//2
Example 1
*************
System.out.println(b);
F :int
R : boolean
Example 2
*************
System.out.println(b);
F : String
R : boolean
Example 3
*************
System.out.println(b);
>Here boolean type variable can store only boolean value by prefixed with 't' not
'T'
Example 4
*************
System.out.println(b);
>Here we can specify floating-point literal value(float and double) only in decimal
form
Example 1
*************
System.out.println(f);
Example 2
*************
System.out.println(f);
Example 3
*************
System.out.println(f);
Note :
*******
>Here float type vairable can store only decimal value upto 6 digits after decimal
Example 4
*************
System.out.println(f);
Example 5
*************
System.out.println(f);
>Here we can specify floating-point literal value(float and double) only in decimal
form
Example 1
*************
System.out.println(d);
Example 2
*************
System.out.println(d);
Note :
*******
>Here double type vairable can store only decimal value upto 14 digits after
decimal
Example 3
*************
System.out.println(d);
if()
{
}else
{
Assert.asserEquals(act,exp);
Syntax :
************
try
{
}catch(Exception e)
{
Verify
********
if(condition)
{
}else
{
}
Assert
************
Assert.assertEquals(act, exp);
Without inheritance
************************
Manual Steps
*************
1.Create Teacher class
2.Create Student class
3.Create MainClass
Java code
**************
>
What are the advantages of inheritance ?
****************************************
Ans : By using Inheritance,
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
****************
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();
Case 2
**********
Parent C = new Child();
Case 3
*********
Parent C = new Parent();
Multi-Level Inheritance
*****************************
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
Types of Testing
*********************
1.Functional Testing
2.Non-functional Testing
2.commercial
================
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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 components---IQ
****************************
1.Selenium IDE
2.Selenium Rc
3.Selenium Webdriver
4.Selenium Grid
-----------------------part 1
Java,
TestNG------------part 3
*********
TestNG(Latest)---------Junit(old)
2.Selenium RC outdated(old)
3.Selenium WebDriver doesn't generate the Test Reports and here selenium webDriver
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-xslt-reports
Data-Driven framework
Keyword driven framework
Hybrid framework
page object modal
Syntax:
***********
Example
**********
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,1000)");
//Scroll Vertically Up by -500 pixels
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,-500)");
program
********
Syntax:
***********
Example
***********
//Scroll Horizontally right by 1000 pixels
((JavascriptExecutor) driver).executeScript("window.scrollBy(1000,0)");
((JavascriptExecutor) driver).executeScript("window.scrollBy(-500,0)");
program
***********
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
********************************
ElementNotVisible Exception
******************************
case 1
*********
CAse 2
*********
driver.findElement(By.linkText("News")).click();
}else
{
Case 3
**********
1.Why this type of error is coming
2.How to resolve this type of error
>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;
>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.
Types of datatypes
*******************
1.primitive datatypes
2.Non-primitive datatypes
7386467494
boolean datatype in java ?
****************************
>This will be used to store only boolean value such as true/false
Example 1
*************
System.out.println(b);
Example 2
*************
System.out.println(b);
Example 3
*************
System.out.println(b);
Example 4
*************
System.out.println(b);
>Here we can specify floating-point literal value(float and double) only in decimal
form
Example 1
*************
System.out.println(f);
Example 2
*************
Example 3
*************
System.out.println(f);
Example 4
*************
System.out.println(f);
Example 5
*************
System.out.println(f);
>Here we can specify floating-point literal value(float and double) only in decimal
form
Example 1
*************
System.out.println(d);
Example 2
*************
System.out.println(d);
Example 3
*************
System.out.println(d);
Diagram:
************
Manual Steps
**************
1.Count total windows
*************************
Set<String> totalWindows = driver.getWindowHandles();
System.out.println("totalWindows : "+totalWindows.size());//2
driver.switchTo().window(allWindowHandles.get(1));
System.out.println(driver.getTitle());
driver.close();
>Here char datatype variable can store in the range of the values min 0 to max
65535
Example 1
************
System.out.println(ch);//
Example 2
************
char ch = C; // invalid
System.out.println(ch);//
Example 3
************
System.out.println(ch);//
Example 4
************
System.out.println(ch);// A
Example 5
************
System.out.println(i);// 83
Examples
************
'C' or '5' or '@'---------valid
Example 1
************
System.out.println(ch);
Example 2
************
char ch = C ; // invalid
System.out.println(ch);
Example 3
************
System.out.println(ch);
Example 4
************
System.out.println(ch);
What is the ASCII value(65) of a character ?
******************************************
Ans : 'A'
Example 5
************
System.out.println(i);//
int x = 10;
Ans :
Types of variables
********************
1.Instance variables
2.Local variables
3.Static variables
1.The values of the name and rollNo are different from student to student such type
of variables
2.The values of the name and rollNo are different from object to object such type
of variables
if,if-else,ladder if-else,switch,forloop,while,do-while,static)
Example 1
**************
//instance variable
String name="Sai";
System.out.println(name);//error
int x= 10;
Types variables
******************
1.Instance variables
2.Local variables
3.Static variables
>The values of the name and rollno are different from student to student such type
of
>The values of the name and rollno are different from object to object such type of
if,if-else,ladder if-else,switch,while,do-while,forloop,static)
Example 1
************
public class FirstProgram {
//instance variable
Example 2
************
public class FirstProgram {
//instance variable
System.out.println(name);//error
Object syntax
******************
Example 3
************
public class FirstProgram {
//instance variable
System.out.println(name);//error
Example 2
***********
//Instance variable
Object Syntax
****************
Example 3
***********
//Instance variable
Example 4
***********
//Instance variable
int i=10;
String name;
boolean b;
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
***********
//Instance variable
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
Example 1
************
class Test{
//create method
void m1()
{
int x=10; //local variable
}
//create Constructor
Test()
{
int y=20;//local variable
//create block
if()
{
Example 2
************
TestNg(Next generation)
************************
TestNg(Latest)-------Junit(old)
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
TestSteps
***********
1.Open browser
2.Navigate the App URL
3.Verify OrangeHRM Login Page Title
4.close the browser
Example 5
**************
public class Student {
//instance variables
System.out.println(S.a);//10
System.out.println(S.name);//null
System.out.println(S.b);//false
}
}
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
//create method
void m1()
{
//create constructor
Student()
{
//create block
if()
{
int z = 30;//local variable
Example 2
*************
public class Student {
public static void main(String[] args) {
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 {
//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
int i;//valid
int i=0;//valid
int i=10;//valid
Example 3
*************
public class Student {
//local variables
>Here can we assign final modifier for that local variable ,instance
variable,static variable?
****************************************************************
Ans : Yes
1.private
2.public
3.protected
4.default
CAn we assign access modifiers for that instance variables and static variables?
************************************************************
Ans :Yes
static variable.
>The name of the college is same from object to object such type of variable is
called
static variable.
Example 1
************
How to work with xls file ?
*******************************
Manual Steps
**************
//static variable
}
}
Example 2
***********
public class Student {
//static variable
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
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
System.out.println(name);//Sai
}
}
@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
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)
// Identify dropdown
List<WebElement> dropdownCount =
dropdown.findElements(By.tagName("option"));
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
>If i change the 1st student marks then there are any effect for that remaining
student marks ?
************************************************************************
Ans :No effect
>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"
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));
Ans : By Using typecasting: This way is a very simple and user friendly.
Example 1
System.out.println(i);//Output : 1234
Example 2
System.out.println(variable);//Output : 1234.0
Syso(f);
Example :
**********
Important methods In Apache-POI
*************************************
How to get boolean cell value from excel sheet ?
*************************************************
Ans : By using getBooleanCellValue()
Example
***********
System.out.println(S1==S2); //false
System.out.println(S1.equals(S2));//true
1.
2.
3.
Syntax:
**********
return-type methodname(para1,para2,para3)
{
statement1;
statement2;
statement3;
}
Examples
*********
void add()
{
}
void addfunction()
{
}
void addFunction()
{
Examples
************
return c; //valid
return a,b;//invalid
return a,return b;//invalid
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
***********************************************************************************
Write a program for a method ,without return-type and with passing parameters
***********************************************************************************
Write a program for a method ,with return-type and with passing parameters
***********************************************************************************
Examples
*************
return c; //valid
return a,b;//invalid
return a,return b;//invalid
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
Types of Testing
*******************
1.Functional Testing
2.Non-functional Testing
2.commercial
===============
1.QTP(Quick Test Professional)
2.Test partner
3.Test complete
4.Rft
5.silk test etc.
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 components---IQ
*********************
1.Selenium IDE
2.Selenium Rc
3.Selenium WebDriver
4.Selenium Grid
------------------------part 1
Java,
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,
AutoIT
logs
grid
Git
Jenkin
Maven
Apache-POI-Excel
Ant-XSLT-Reports
1.State / properties
2.Behavior / Actions
>
>
Object syntax
*****************
Student S = new Student();
class Syntax:
**************
class <classname>
{
//1.State / properties---------variables
<datatype> variable1;
<datatype> variable2;
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
Object
***********
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
Test-1
Test-2
Reusable Functions(R.F)
}
Output
***********
@BC
Test-1
Test-2
@AC
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 :
************
//body
}
Syntax Explanation
********************
>
>
Example 1
***********
if(cat_age==dog_age)
{
System.out.println("Animals age matched");
}
}
Example 2
***********
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
***********
}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
***********
}else
{
System.out.println("A less than 50");
}
}
}
Example 5
***********
public class Student {
}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
F : int
R : boolean
Example 6
***********
}else
{
System.out.println("Hanumanth");
}
}
}
Example 6
***********
}else
{
System.out.println("Hanumanth");
}
}
}
F : boolean
R : boolean
Example 7
***********
}else
{
System.out.println("Hanumanth");
}
}
}
Syntax:
**********
switch(Expression value){
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:
***********
//body
}
Syntax Explanation:
***********
1.
2.
Example 1
***********
public class Student {
if(cat_age==dog_age)
{
System.out.println("Animals age matched");
}
}
Example 2
***********
public class Student {
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.
Example 3
***********
public class Student {
if(A)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
}
if(A)==>if(100)==>
Found : int
Required : boolean
Example 4
***********
public class Student {
if(A>50)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
Example 5
***********
public class Student {
if(x=20)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
>if(20)==>
F : int
R : boolean
Example 6
***********
public class Student {
if(x==20)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
Example 7
***********
public class Student {
if(b=false)
{
System.out.println("Hello");
}else
{
System.out.println("Hanumanth");
}
}
>if(false)
F : boolean
R : boolean
Example 8
***********
public class Student {
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){
break;
break;
break;
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
Sanity Testing
*****************
>To verify whether the main functionalities of the application as well as optional
that is a Sanity Testing
Checking Drafts
Checking Promotions
Checking Account Details
Account Logout
Syntax :
************
//tagName[@Attributename='value']
//input[@name='clear']
$x("xpath")
$x("//input[@name='clear']")
//input[@name='clear'][position()]
//label[text()='CHARTS / VACANCY'][position()=1]
switch statement
*******************
Syntax :
***********
switch(Expression value){
Example 1
**********
int x=10;
switch(x){
System.out.println("Hanumanth"); // error
}
}
}
>In switch block,every statement should be under case value and default case
Example 2
**********
int x=0;
int y=1;
switch(x){
}
}
}
Example 3
**********
int x=0;
final int y=1; //Here Y is called constant variable
switch(x){
}
}
}
Example 4
**********
switch(x){
case 1 : System.out.println("Hanumanth");//invalid
}
}
}
Example 5
**********
switch(b){
>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
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
Example 6
**********
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");
}
}
}
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
Email id : hanumanthu.palla15@gmail.com
Ph no : 7386035382
Location : Guntur
CCTC : 7.2L
ECTC : 12L
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)
In SuperClass
***************
Common code
***************
@BC
@AC
R.F's
In Subclass
***************
Example 7
**************
public class Student {
char ch = 'r';
switch(ch){
break;
break;
break;
default :System.out.println("no color");
}
}
}
Example 8
**************
public class Student {
int furniture=0;
switch(furniture){
case 0 :System.out.println("table");
break;
case 1 :System.out.println("chair");
case 2 :System.out.println("cot");
}
}
}
Loops in java?
******************
is true.
How to print Hanumanth 100 times ?
************************************
Example 1
************
types of loops
*****************
3.forloop
Syntax :
***********
//loop body
}
Syntax Explanation :
***********************
How to print 1(starting)-10(ending value) nos ?
******************************
1
2
3
4
5
........10
Example 2
************
public class Student {
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 {
System.out.println("Hanumanth");
}
}
2 years 1 months----1
1 years 0 months----2
2 years 1 months
Hi all,
Today no class
Saturday : @5pm-8pm
Sunday : @5pm-8pm
Please consider
Company
Launch Pad
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 ){
Example 1
**********
public class Student {
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 {
int y = 10;
switch(x){
case 0 : System.out.println("Hello");//valid
case y : System.out.println("HANUMANTH");//invalid
}
}
Example 3
**********
public class Student {
int x=0;//valid
switch(x){
case 0 : System.out.println("Hello");//valid
case y : System.out.println("HANUMANTH");//valid
}
}
>
>
>
Example 4
**********
public class Student {
//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
}
}
Example 5
**********
public class Student {
switch(b){
case 10 : System.out.println("Hello");//valid
}
}
>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
will be executed automatically until break statement then this concept is called
fall-through.
Example 6
**********
public class Student {
//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");//
}
}
>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
Syntax:
***********
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
**************
if(x)
{
break;//error
}
}
}
Where we can create break statement ?
****************************************
Ans : Inside the loops and switch block
Example 6
**********
public class Student {
//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");//
}
}
Example 6
**********
public class Student {
//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");//
}
}
Syntax:
***********
if(condition to break)
{
break;
statements;
}
Synta Explanation
*********************
1.
2.
3.
4.
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
continue statement
*********************
Example 1
*********
public class Student {
int x=10;
if(x)
{
continue;//error
System.out.println("HANUMANTH");
}
}
Example 2
*********
public class Student {
for(int i=1;i<=10;i++)
{
System.out.println(i);
}
}
Syntax:
*************
for(initialization-part; condition-part/Testing-part;
increment/decrement-part)
{
if(condition to continue)
{
continue;
statements;
Syntax Explanation:
********************
1.
2.
3.
4.
for(int i=1;i<=10;i++)
{
if(i==3)
{
continue;
System.out.println(i);
}
}
Constructor in java ?
************************
types constructor
********************
1.default constructor
2.parameterized constructor
1.default constructor
***************************
Student()
{
}
2.parameterized constructor
******************************
Student(para1,para2,para3)
{
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
3.A method is called and executed multiple times per single object
*********************************************************************
4.A constructor is called and executed only once per single object
********************************************************************
5.Here instance variable and local variable both are not same So in this case this
keyword an optional.
***********************************************************************************
*****
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);
Example 2
***********
Note :
*********
When i run this program by default JVM will provide default constructor and
initialize
Student()
{
name = null;
rollno = 0;
}
Output
*********
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.
public LoginPage(){
PageFactory.initElements(Driver.get(), this);
}
//--------------Alternative way----------------------
PageFactory.initElements(driver, LoginPageObjects);
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.
Without inheritance
*********************
Example
***********
Manual Steps
***************
1.Create Teacher class
2.Create Student class
3.Create MainClass
Java code
***********
advantages of inheritance
***************************
Ans : By using inheritance
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
****************
In Subclass
**************
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();
Case 2
*******
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.
PageFactory.initElements(driver, LoginPageObjects);
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.
Case 1
********
Child C = new Child();
Case 2
********
Parent C = new Child();
C.m1();//call the m1()----valid
C.m2();//call the m2()------invalid
Case 3
********
Parent C = new Parent();
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();
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.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();
Case 2
*********
Animal D = new Dog();
Example 2
********
Student()
{
System.out.println("Hanumanth");
super();//invalid
Example 2
**************
public class Student {
Student()
{
super();//valid
System.out.println("Hanumanth");
Student()
{
System.out.println("Hanumanth");
this();//invalid
Example 4
**************
public class Student {
Student()
{
this();//valid
System.out.println("Hanumanth");
Example 5
**************
public class Student {
Student()
{
super();//valid-------1st place
this();//invalid----2nd place
System.out.println("Hanumanth");
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
Java code
*************
Example
*********
Example
***********
Manual Steps
***************
1.Create Superclass(Shape)
2.Create Subclass(Rectangel) from Superclass(Shape)
3.Create MainClass
Java code
*************
Example
**************
Manual Steps
***************
1.Create Superclass(Animal)
2.Create Subclass(Cat) from Superclass(Animal)
3.Create MainClass
Java code
*************
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)
************************************************************* 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")));
<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
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
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
9Am Link:https://www.gotomeet.me/kosmiktech3608
---------------------------------------------------
Hanumanth SeleniumJavaTraining
hseleniumjavatraining@gmail.com
Asdfghjkl@123
------------------------------------------------
SeleniumJava Training's Meeting
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Selenium training
trainingselenium9@gmail.com
Asdfghjkl@123
************************************************************
hseleniumjavatraining@gmail.com------june,2021
hanumanth.selenium@gmail.com
hanumanthkt2020@gmail.com
hanumanthseleniumtraining@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
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
seleniumjavahanumanth@gmail.com
Asdfghjkl@123
Hanumanth SeleniumJava Training's Meeting
https://www.toolsqa.com/selenium-cucumber-framework/read-configurations-from-
property-file/
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---->
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
1.First,Identify dropdown
2.Next,Identify all the values from this dropdown
>Switch to frame
>Identify dropdown
>Select the dropdown value
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
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
wait.until(ExpectedConditions.visibilityOfElementLocated(By.Locator("LocatorValue")
));
until()==>wait for certain amount time until the See all element is visible on a
webpage
>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);
Rediff mail
***************
http://register.rediff.com/register/register.php?FormName=user_details
Syntax : this.variable
Syntax : this()
Syntax :this(value)
Syntax : this.methodname()
https://www.eclipse.org/downloads/packages/release/oxygen/3a
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)
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
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
short b = 32768;
>Int datatype can store in the range of values min -2147483648 to max 2147483647
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
long b=9223372036854775807L;
long l=100;
long d=92.23372036854775807;
long e=true;
long f="Kosmik";
boolean a = 0;
boolean b = "true";
boolean c = True;
boolean d = true;
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
double a = 2.356;
double b = -125.563;
double d=10.1111d;
double h = true;
double h = "Hanumanth";
byte(least) < short < 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
Example
*********
List<WebElement> allchk =
driver.findElements(By.xpath("//input[@type='checkbox']"));
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']"));
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.
Example
*********
//click on ok button
alert.accept();
>Material
>Videos
>Interview Questions
>Material
>Videos
>Interview Questions
https://chat.whatsapp.com/JJI9TKM6EcrCqStHw4cWSe
Whatsapp no : 7386467494
>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';
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")));
https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
Chromedriver.exe
*****************
https://sites.google.com/a/chromium.org/chromedriver/
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
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
wait.until(ExpectedConditions.visibilityOfElementLocated(By.Locator("LocatorValue")
));
https://github.com/mozilla/geckodriver/releases
1. id----1
2. Name---------2
3. Linktext
4. PartialLinktext
5. TagName
6. ClassName-------3
7. cssSelector
8. Xpath----------4
Syntax : this()
Syntax :this(value)
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(){})
@Tes-2
******************
Manual Steps
*****************
1.Read the property files
2.Open the FF
3.Navigate the app URL
----
----
@Test -3
*************
Manual Steps
*****************
1.Read the property files
2.Open the FF
3.Navigate the app URL
----
----
>Click on logout
>close the browser
class Superclass
{
@BT
@AT
R.F
}
class Subclass1 extends Superclass
{
@BT
@AT
R.F
@Test 1
R.F
@Test 2
<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";
int x=125;
String.valueOf(x);
String.valueOf(125);
"125"
@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?
class Test{
@BC
@AC
@Test1
@Test2
@Test3
output
********
@BC
@Test1
@Test2
@Test3
@AC
class Superclass{
@BT
@AT
}
class Subclass1 extends Superclass{
@BT
@AT
@Test1
@BT
@AT
@Test2
----------------------
@BT
@Test1
@Test2
@AT
Output
***********
@BT
@Test1
@Test2
@AT
get() :
getTitle() :
//operation code
//verification code
}else
{
System.out.println("title not verified successfully");
}
Selenium WebDriver
*********************
<class name="Packagename.classname">
<methods>
<include name="testMethod"/>
<include name="testMethod"/>
<include name="testMethod"/>
<exclude name="testMethod"/>
</methods>
</class>
Chromedriver.exe
*****************
https://sites.google.com/a/chromium.org/chromedriver/
geckodriver.exe
https://github.com/mozilla/geckodriver/releases
https://code.google.com/archive/p/fire-ie-selenium/downloads
Hi Hanumanth,
Key Notes :
1.Understanding requirements-2hours
2.Prepared the Test cases-2hours
3.Execute the Test cases-2hours
4.Meeting with Project manager-2hours
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")));
Hi Rajasekhar,
Key Notes :
Thank You,
Hanumanth. P,
Sr. Software Test Engineer,
Melstar Information Technologies,
ph no:+91- 7386467494
3157836470,