Main Notes
Main Notes
Main Notes
AUTOMATION TESTING
Performing testing on the software application / product with the help of
automation tools is called Automation testing. Automation tools are divided into
3 types.
A tool which we are using to test the functionality of the application is called
functional testing tool.
Eg:- Selenium, QTP (Quicks test professional), Sills touch, RFT (Rational
functional tester)
A tool which we are using to manage the entire testing process is called test
management tools.
Performance Tools:-
A tool which we are using to test the performance of the application is called
performance tools.
Time saving by implementing automation testing we can save the time during
performing testing in a project
Eg: If we are executing 1 test case manually in 1 hour, same test case we can
able to execute in 5 minutes with help of automation tool.
Technical Feasibility:-
SELENIUM
Selenium is the functional and regression testing tool which has developed by
Jason huggins and team in thought works in the year of 2004.
The original name of the Selenium was JSFT(Java Script Functional Tester).
Selenium supports multiple languages like Java, dotnet, PHP, rube, python, perl
scripting etc.
Advantages of Selenium:-
1. Selenium is the open source tool mainly used for functional regression
test tools.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
3
Disadvantages of selenium:-
1. Selenium IDE
2. Selenium RC/Set-1
3. Selenium WD/Set-2
4. Selenium Grid(Test Execution)
:- Selenium IDE is the record & playback tool for web based
applications. This is the add in /plug in for firefox browser. That
means we can install the selenium IDE in firefox browser, launch
the IDE from firefox browser, design the scripts and executes the
scripts only in the firefox browser.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
4
Click on enter
Click on download latest released version from add on, Mozilla.org link under
selenium IDE
Click on Install
When we click on restart now, firefox browser will be restarting & selenium
IDE will be installing with firefox.
This is the one of the key functionality in selenium IDE. When the selenium
IDE is in recording mode> If we perform any action on the application, tool will
capture the actions and generates the scripts. When we click on play button tool
will perform the same actions in the application.
What is element?
Element locators:-
Locators are nothing but the identifications of the elements in application. Since
every product in the world is having some identifications, in the same way
every element in the application also is having some identifications. These
identifications we called as locators/ properties & valued/ attributes.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
5
List of locators:-
1. ID
2. Name
3. Class
4. Tagname
5. Xpath
6. Link text
7. CSS(Cascade style sheets)
8. DOM(Document object model)
Firebug:- firebug is adding for firefox browser which we can use to see the list
of locators of the elements in a firefox browser. Before working with frirebug
we need to install firebug in firefox browser.
Enter URL(https://addons.mozilla.org/en-us/firefox/addon/firebug/)
Click on enter
Click on install
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
6
Selenium
Uid
OK disabled
Pwd
OK enabled
Click on Ok
Able to login
Selenium will identify the elements based on the locators. Every element in the
application is having list of locators. In these locators most of them are common
locators (default locators) and some of them are unique locators with the
common locators. It is difficult for the selenium to identify the elements and
with unique locators only selenium can easily identify the elements.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
7
1. Actions
2. Assertions
3. Accessers
Actions:- Type:-
Syntax:
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
8
Syntax
Syntax:
Syntax:
Eg:- prepare the test script to enter email, pwd, select day, month
Syntax
Syntax
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
9
Syntax
1. Verify
2. Assert
3. Wait for
Note:- Which ever commands is available in verify, All those commands also
available in assert & wait for.
Assert:- We are using assert commands to perform the validations. And tool
continues the execution only if the validation is true. If the validation is false
tool will stop the execution
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
10
Wait for: we are using wait for commands to perform the validations. And tool
continues the execution if the validation is true. Or it will stop the execution for
default time and continues the execution if the validation is false
Text Present:- To verify whether the text is present in the application or not.
Syntax
Syntax
Checked:- To verify whether the click box or radio button is checked or not.
Syntax:
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
11
Syntax:
Negative commands:-
Accessors: we are using Accessors to perform the validations but tool will be
storing output into variable. That is the reason all the accessors commands start
with keyword called “store”
NOTE:- Once we store the output into variable that variable value we can print
by using the command called “echo”.
Eg:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
12
Syntax:
Eg:-
Script:-
CORE JAVA
JAVA is the object oriented programming language which has developed by
“SUN MICROSYSTEMS” & later on it was acquired by oracle. JAVA is the
secured and “platform independent” language which is using to develop the
online applications, secured applications online games etc.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
14
We need to design JAVA program in notepad, save the file with .java extension
and then we need to compile the java file by using the command called javac.
When we compile the java file, compiler will create one class which contains
byte code, we need to execute the java class file by using the command called
java. When we execute JVM will be converting the byte code of the class file
into specific machine understandable format.
linux
Propertied
Click on ok
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
15
Click on ok
Click on ok
Click on ok
Class ClassName{
P S V M{
______
_______
________(statements)
JAVA is pure case sensitive language and strictly following the below naming
conventions.
Class:- Class name should starts with upper case and first character of every
word in a class name should be upper case.
Class ClassOneTwo
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
16
Method:- Method/function should starts with lower case and first character of
second word onwards should be upper case.
Eg:- methodOne
methodOneTwo
NOTE:- method name, package name, class name should not contain spaces,
should start with alphabets and can contains numarics. If we are specifying the
public class in java pgm, the file name should be same as class name.
Statements:-
Operators in JAVA:-
Data types:- We are using data types to preserve space to the variables into
memory. That is the reason while creating the variables we should specify the
data type in JAVA so that based on the data type system allocates the space to
the variable into memory.
Based on the range there 8 different types of data types available in java.
Byte
Short
Int
Long
Double
Float
Char
Boolean
A statement which we are using to get the output from the program is called
output statement. We are using two different types of o/p statements in java.
System.out.print
System.out.println
System.out.print:- We are using this statement to get all the o/p from the
program in a single line.
System.out.print(variable-“value”);
System.out.Println:- We are using this statement to get all the o/p from the
program in a line by line.
System.out.println(Variable/value);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
18
Eg:
Class output{
Int a=10;
Int b= 20;
Int c=10*20;
Int d= b-a;
Int e=a+b;
s.o.p(c);
s.o.p(e);
Class output
Int a=10;
Int b=20;
Int c=a*b;
s.o.pln(c); 200
s,o.pln(d); 20
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
19
Conditional statements:-
If condition
If else condition
Switch case
If :-
We are using if statement to check/verify the condition and will get the output
only when the condition is true. We will not get the o/p if the condition is false.
Syntax:- if (condition)
Statement;
Class conditional{
Int a =30;
Int b=40;
If (a<b)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
20
Else:- We are using if else statement to check/verify the condition and will get
the output even though the condition is true/false.
Syntax:-
If (condition)
Statement 1;
Else
Statement 2;
Class conditional{
Int a=30;
Int b=40;
If (a<b)
else
If else if condition:- We are using these statements to verify the condition and
tool will print the output if the condition is true or it will check the another
condition if the condition is false.
Syntax:-
If (condition1)
Statement 1;
Else
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
21
If(condition 2)
Statement 2;
Else
If (condition 3)
Statement 3;
Else
Statement 4;
Class conditional{
Int a=30;
Int b=40;
Int c=50;
s.o.p(“A is greater”);
else
if(b>c)
s.o.p(“B is greater”);
else
s.o.p(“C is greater”);
O/P: C is greater
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
22
Syntax:
Switch variable/value{
Case condition 1:
Statement 1;
Break;
Case conditon2:
Statement 2;
Break;
Case condition 3:
Statement 3;
Break;
Default:
Statement default;
Break;
Eg:-
Class conditional{
Int a=10;
Int b=6;
Int c=a-b;
Switch(c)
Break;
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
23
Break;
Break;
Break;
Default:
break;
} } O/P: C value is 4.
ECLIPSE
Eclipse is the IDE/ Editor for Java which we can use to design the java
programs and execute the programs. Like as eclipse we have a different editors
like net Beans, editplus, notepad++ etc but eclipse the popular editor for java>
Before working with eclipse we need to download it & create the java project.
Navigation steps:-
Install JDK
Down eclipse
Double click on eclipse icon(now we can see work space location window)
Specify the work space location(This is the location where all java programs
will be storing)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
24
Click on ok
Click on work bench in welcome page of eclipse (Now we can navigate to home
page of eclipse)
New project
Click on finish
New
Package
Click on finish
New
Class
Click on ok
Looping statements:
We are using looping statements to execute the some code for multiple no of
times in a java program.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
25
For loop
While loop
For loop:- we are suing for loop to execute the same line of the code for specific
number of times.
Int i;
For (i=0;i<6;i++){
int a=30;
Int b=40;
Int c+a*b;
O/P:-
C value is 1200-1
C value is 1200-2
C value is 1200-3
C value is 1200-4
C value is 1200-5
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
26
Eg:-
Int i;
For (i=1;i<6;i++){
Int a=30;
Int b=40;
Int c=a X b;
I=i+1;
O/P;
C value is 1200-1
C value is 1200-3
C value is 1200-5
In nested for loop we are inserting one for loop inside another for loop.
Execution starts always from main loop, it goes to sub loop, complete the sub
loop all the iterations then its come back to main loop
Int i; o/p
Int j; 1-1
For (i=1;i<5;i++){ 1-2
For (j=1; j<4;j++){ 1-3
s.o.p(i+”-“+j); 2-1
} 2-2
} 2-3
3-1
3-2
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
27
3-3
4-1
4-2
4-3
While loop:-
We are using while loop to execute the same lines of the code until the
condition is satisfied.
Syntax:- initialization
While(condition){
Statement
Increment/decrement
String functions:-
We are using string functions to perform the string related validations in java.
Length:- we are using this variable to know the length of the string.
Syntax:- variable.length
Eg:-
Package packone
If (a.length()==10)
System.out.println(“pass”);
Else
System.out.Println(“fail”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
28
Output:- pass
If (a.startswith(“k”)==true)
System.out.println(“pass”);
Else
System.out.println(“fial”);
If(a.endswith(“6”)==true)
System.out.println(“pass”);
Else
System.out.println(“fail”);
Output:-fail
Pass
syntax:- variable.toLowerCase();
syntax:- variable.toUpperCase();
example:-string a=”ABCDEF”;
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
29
string b=”abcdef”;
System.out.println(a.toLowerCase());
System.out.Println(b.toUpperCase());
Output:-
Abcdef
ABCDEF
String b=”abcdef”;
String c=”ABCdef”;
If(a.equals(b)==false)
System.out.println(“pass”);
Else
System.out.println(“fail”);
If(a.equlsIgnoreCase(b)==true)
System.out.println(“pass”);
Else
System.out.println(“fail”);
If(b.equalsIgnoreCase(c)==true)
System.out.println(“pass”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
30
Else
System.pit.println(“Fail”);
Output:- pass
Pass
Pass
Contains:-
String=”abcdef”;
If(a.contains(“d”0==true)
System.out.println(“pass”);
Else
System.out.println(“fail”);
Output:- pass
String b=”XYZ1234”;
Sring c=”abcxy”;
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
31
Package packone;
String a=”abcdef”;
String b=”XYZ1234”;
String c=”abcxy”;
System.out.println(“pass”);
Else
System.out.println(“fail”);
System.out.println(“pass”);
Else
System.out.println(“fail”);
If(c.equlsIgnoreCase(a)==true)
System.out.println(“pass”);
Else
System.out.println(“fail”);
If(a.contains(“cd”)==true&&a.contains(“xy”)!=true)
System.out.println(“pass”);
Else
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
32
System.out.println(“fail”);
System.out.println(“pass”);
Else
System.out.println(“fail”);
String a=”abcdef”;
String b=”XYZ1234”;
String c=”abcxy”;
System.out.println(a.concat(b).concat(c));
Output:- abcdefxyz1234abcxy
String a =”abcdef”;
System.out.println(a.charAt(4));
}}
output:-e
String a =”abcdef”;
System.out.println(a.indexof(“b”));
Output:- 1
Trim:- We are using this function to eliminate starting and ending spaces of the
string
Syntax:- variable.trim()
System.out.println(a.lenth());
String b=a.trim();
System.out.println(b);
System.out.println(b.length());
}
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
34
Output:- 18
10
System.out.println(a.replace(“ “, “ “));
Output:-
Int i;
{
if(b[i].length()==3)
System.out.println(b[i]);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
35
System.out.println(b[1].length());
System.out.println(b[2]);
System.out.println(b[0]);
3. first string of the a variable should be same as last string of the b variable &
second string of the c variable irrespective of the case.
4. length of the first string of the b variable should be greater than last string of
the b variable and should be same as last string of the c variable.
7. second string in a variable should starts with x and should ends with z.
For applying commenting for single line of the code we are using “//”
Variables in Java:- We are using variables to store the values which we can
reuse them for multiple times. There are 3 different types of variables available
in java.
Local variables
Static variables
Local variables:- Local variables are the variables which we are creating inside
the method/block and the scope of the local variable is only within the method.
That means when we close the method, automatically the usage of the local
variable also will be closed.
Local variables
System.out.println(a*b);
Local variables
System.out.println(a+b);
a1();
b1();
}
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
37
Output:-1200
70
Static variables:- static variables are the variables which we are creating inside
the class and these variables are loading while class is laoded. These static
variables we can access directly within the class, classname. Variable name in
different class, class name. Variable name in different package but make sure
that variable should be public.
Example:
Pckage p1;
System.out.println(a*b);
System.out.println(Abc.a*Abc.b);
Package p2;
Import p1.Abc;
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
38
{
system.out.println(Abc.a*Abc.b);
Non-static variables:- non-static variables are creating inside the class and these
variables are loading while object creation.
Package packone;
//creating object
System.out.println(v.a*v.b)
Output:- 1200
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
39
(different class)
Package packone;
// creating object
System.out.println(v.a+v.b);
Output:- 70
(different package)
Package packtwo;
Import packone.var;
//creating object
System.out.println(v.a*v.b);
Output:- 1200
ACCESS SPECIFIERS
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
40
Access specifiers allowing variables are using to give the access permissions to
variables, methods, constructors and classes
Public
Private
Protected
Default
Public:- with this we can access variables and methods across the globe(same
class, different class, different package)
Protected-with this we can access variables and methods within the package.
Private:- with this we can access variables and methods only with in the class.
Default:- with this we can access variables and methods within the same
package.
(Same class)
Package packone;
System.out.println(Access.a* Access.b*Access.c*Access.d);
Output:-(Different class)
Package packone;
Package packtwo;
Import packone.Access;
System.out.println(Access.a);
Output:-
Methods:-
A group of statements, set of logic which we can reuse for multiple times.
If any logic is reusable for multiple times, we are identifying that logic make it
as method or function. Here after whenever we require that logic, instead of
writing that logic again and again simply we are calling the methods.
1. Static method
2. Non-static method
Static methods:-
Static methods are loading while class is loading and we can access these
methods directly within the class, class name. Method name in different class.
Non-static methods:-
a1();
m.b1();
Sometimes we need to execute the same methods multiple times with different
data. In that case we are creating methods with arguments so that while
accessing the methods we can pass the data into methods through arguments.
Example:-
Package packone;
System.out.println(a*b*c);
a1(10,20,30);
a1(40,50,60);
a1(70,80,90);
Output:- 6000
1,20,000
5,04,000
Constructors in Java:-
Constructors are similar to methods which is loading while creating the object
with the help of constructors we can pass the data into the methods through
objects.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
44
If we are not creating any constructor in a class by default compiler will create
default constructor.
One class can contains any number of constructors. All the constructors should
be same as class name but with different arguments.
(constructor overloading)
//creating constructor
Const(){
System.out.println(“This is constructor”);
//creating method
Void a1(){
System.out.println(“This is method”);
c.a1();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
45
This is method
Example:-
Package packone;
//creating constructor
Height=h;
Width=w;
Name=n;
Height=k;
Width=l;
//creating method
Void buttoncreation(){
Void emptyButton(){
Ok.buttonCreation();
Cancel.ButtonCreation();
Empty1.emptybutton();
Example2:-
Package packone;
A=x; b=y;}
SampleConst(int d){
C=d;}
Void multiply(){
System.out.println(a*b*c);}
Void addition(){
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
47
System.out.println(a+b);
Void square(){
System.out.println(a*a);
s.multiply();
S1.square();
S2.addition();
Class:-
This variables and methods we called as the members of the class. These
members might be static members or non-static members or both.
//creating variables
Int a =30;
//creating methods
Void a1(){
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
48
System.out.println(“This is method”);
Object:-
Objects are the instances of the class that means if you want to access the
instance members of the class we need to create the reference object. So that
with the help of object we can access instance members.
//creating variables
Int a=30;
//creating methods
Voida1(){
System.out.println(“This is method”);
System.out.println(c.a*c.a);
c.a1();
Package:- Packages are the collection of classes and interfaces. There are 2
different packages available in java.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
49
User defined packages created by user and reusing for multiple times.
Built in package:-
Built in packages are the packages which are created by vendor and reusing for
multiple time.
Java.io Com.thoughtworks.selenium
File input string Default selenium
Open();
Close(); Start();
File output string Open();
Create(); Close();
Available(); Create();
File
Start();
Ecllipse
Java project
Package packtwothree
Import java.io.fileinputstring
f.open();
f.close();
f0.create();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
50
f0.available();
https://selenum.release.storage.googleapis.com/index.html?path-2.44/
click on ok
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
51
new
project
click on finish
Build path
Click on apply
Click on ok
Click on apply
Click on ok
When we click on run selenium server and we can see server started
information in the console page of eclipse
Syntax:-
s.start();
s.open(http://facebook.com);
s.windowMaximize();
Start()
To start the browser which we specify in the browser start command argument.
Syntax:- object.start();
Open()
windowMaximize();-
Syntax:- object.windowMaximize();
Syntax:- object.close();
Example
Prepare the test script to launch the facebook application in firefox browser,
maximize the application & close the application.
Package seleniumrc;
Import com.thoughtworks.selenium.DefaultSelenium;
s.start();
s.open(http://facebook.com);
s.windowMaximize();
s.close();
Example:-
Prepare the test script to launch fb to enter email, password, select day, select
month, check the male radio button and click on create an account button.
s.start();
s.open(http://facebook.com);
s.windowMaximize();
s.type(“id=email”,”kishore”);
s.type(“id=’ass”,”abcdefg”);
s.select(“id=day”,”24”);
s.select(“id=month”,”Apr;
s.check(“id=u-o-f”);
s.click(“id=u-o-i”);
Iselementpresent:-
Istextpresent:-
Syntax:- variable=object.istextpresent(“text”)
Example:-
Package seleniumrc;
Import com.thoughworks.selenium.DefaultSelenium;
s.start();
s.open(http://facebook.com);
s.windowMaximize();
s.type(“id=email”,”abcdef”);
Boolean a=s.iselementpresent(“id=pass”);
If(a==true)
System.out.println(“pass”+”password Available”);
Else
If(a.iselementpresent(“id=u-o-i”==true)
System.out.println(“pass”+”firstname available”);
Else
//entering password
s.type(“id=pass”,”XYZ123”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
56
if(s.Textpresent(“account”)==false)
else
Syntax:-variable=object.isChecked(“element locator”);
isSomethingSelected:- To verify whether any value has selected in the list box
or not.
syntax:- variable=object.getTitle();
should contains k
2. Enter email Password should be available, it
should be editable
3. Enter password First name should be available, should
not be editable, account text should be
available
4 Enter firstname Accounts text should nhot be
available. Day list box should be
available
5. Select day and month list Female radio button should not be
boxed checked and male radio button should
be checked
6. Launch yahoo mail Length of title of yahoo mail
application in the same application should be 10, it should be
browser less than facebook application title
length, 7th character should be k and
10th character should not be z.
7. Enter user name in yahoo Number of links in yahoo mail
mail application application should be greater than no
of buttons.
Package seleniumRC;
Import com.thoughtworkds.selenium.DefualtSelenium;
s.start();
s.open(http://facebook.com_;
s.windowMaximize();
string a=s.getTitle();
if(a.startswith(“f”)==true)
system.out.println(“pass”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
58
else
system.out.println(“fail”);
if(a.endswith(“m”)==true)
system.out.println(“pass”);
else
system.put.println(“fail”);
if(a.length()==20)
system.out.println(“pass”);
else
system.out.println(“fail”);
if(a.contains(“k”)==true)
system.out.println(“pass”0;
else
system.out.println(“fail”);
s.type(“id=email”, “sharanya”);
if(s.iselementpresent(“id=pass”)==true)
system.out.println(“pass”+”password Available);
else
system.out.println(“fail”)
if(s.iseditable(“id=pass”)==true)
system.out.println(“pass”);
else
system.out.println(“fail”);
s.type(“id=pass”,”123456”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
59
if(s.iselementpresent(“id=u-o-1”)==true)
system.out.println(“pass”);
else
system.out.println(“pass”);
else
system.out.println(“fail”);
if(s.iseditable(“id=u-o-1”)==false)
system.out.println(“pass”);
else
system.out.println(“fail”);
if(s.istextpresent(“account”)==true)
system.out.println(“pass”);
else
system.out.println(“fail”);
s.type(“id=u-o-v”,”Aravelli”);
if(s.istextpresent(“account”)==false)
system.out.println(“pass”);
else
system.out.println(“fail”)
if(s.iselementpresent(“id=day”)==true)
system.out.println(“pass”);
else
system.out.println(“fail”);
s.select(“id=day”,”25”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
60
s.select(“id=month”, “Apr”);
if(s.ischecked(“id=u-o-i”)==false)
system.out.println(“pass”);
else
system.out.println(“fail”);
if(s.checked(“id=u-o-f”)==true)
system.out.println(“pass”);
else
system.out.println(“fail”);
s.open(http://yahoo mail.com)
b=s.gettitle();
if(b.length()==10)
system.out.println(“pass”);
else
system.out.println(“fail”);
if(b.length()<a.length())
system.out.println(“pass”);
else
system.out.println(“fail”);
if(b.charAt(6)==true)
system.out.println(“pass”);
else
system.out.println(“fail”);
if(b.charAt(9)==false)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
61
system.out.println(“pass”);
else
system.out.println(“fail”);
s.type(“id=email”,”XYZ”);
string[] c=s.getAllLinks();
string[] d=s.getAllButtons();
if(c.length()>d.length())
system.out.println(“pass”);
else
system.out.println(“fail”);
1. Class
2. Object
3. Package
4. Inheritance
5. Polymorphism
6. Encapsulation
7. Abstraction
Single Inheritance:-
In this we are inheriting the behaviour from one class to another class.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
62
Class Abcdef{
System.out.println(“This is subclass”);
system.out.println(“This is superclass”);
i.b1();
i.a1();
Multi level Inheritance:- in this we are inheriting the behaviour from one class
to another class from that class to another class.
Class Abcdef{
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
63
s.o.p(“This is klmn”);
i.c1();
i.b1();
i.a1();
Hierarchial Inheritance:-
In this we can inherit the behaviour from one class to multiple class.
Class Abcdef{
s.o.p(“This is KLMN”);
i.a1();
i.b1();
.c1();
i.a1();
Hybrid Inheritance:-
In this we can inherit the behaviour from one class to another class into another
class etc.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
65
Method Overloading:- one class contains same method name with different
arguments is called method overloading. Compiler will identify the methods
based on the arguments.
Package packone;
//method overloading
system.out.println(“a*b);
system.out.println(“k+l+m);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
66
a1(20,20);
a1(40,30,100);
}
o/p: 400,170
Example:-
Package packone;
Class Abcd{
Void a1(){
system.out.println(“This is first”);
Void a1(){
system.out.println(“This is second”);
m.a1();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
67
SELENIUM WEBDRIVER(2.53)
Web driver is the advanced for selenium RC which we can use to design the test
scripts and execute the test scripts in different browsers and in the different
environments.
Navigation
Syntax:-
webDriver driver=f;
or
example:-
package WD;
import org.openqa.selenium.webDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
driver.get(http://facebook.com);
driver.manage().window().maximize();
driver.quit();
By default webdriver supports firefox browser. If you want to work with other
browsers, we need to download the browser driver server.exe files and set up
the system properties.
To see the list of locators of elements in a chrome browser we are using firebug
lite and to see the list of locators in a IE we are using debugbar.
System.setproperty(“webdriver.ie.driver”,”C://users//vamshi//desktop//setwebD
river//jars//IEDriverserver.exe”);
Driver.get(http://yahoomail.com);
Driver.Manage().window().maximize();
Driver.get(http://yahoomail.com);
Driver.mange().window().maximize();
FirebugLite:- This is the add-in for chrome browser which we can use to see the
list of locators of the elements in a chrome browser
Debugbar:- This is the add-in for internet explorer which we can use to see the
list of locators of the elements in a internet explorer browser.
Note:-
In every browser the locators of the elements will be same. But the way we are
seeing the locators will be different from one browser to another browser.
How webdriver will identify the elements webdriver will identify the elements
in application based on the locators by using find element method.
Syntax:- Driver.findelement(by.locator(“value”))
SendKeys:- To enter the value in a text box and to select the value in a list box.
Example:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
70
driver.get(http://facebook.com);
driver.manage().window().maximize();
driver.findElement(By.id(“email”)).sendKeys(“kishore”);
driver.findElement(By.id(“pass”)).sendKeys(“abcdef”);
Syntax:- Driver.findElement(By.locator(“value”)).click
Syntax:- Driver.findelement(by.locator(“value”)).clear();
Prepare the test script to launch the fb application in firefox browser, enter the
email, select the day as 24, select male radio button, clear the email value and
close the facebook application.
driver.get(http://facebook.com);
driver.manage().window().maximize();
driver.findElement(By.id(“email”)).sendKeys(“sharanya”);
driver.findElement(By.id(“day”)).sendKeys(“24”);
driver.findElement(By.id(“u-o-f”)).click();
driver.findElement(By.id(“email”)).clear();
driver.quit();
We are using this option to access RC commands into webdriver. For accessing
RC commands we need to import a class called weDriverBacked selenium. By
creating an object so that with help o f the object we can access RC commands.
Syntax:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
71
webDriverBackedSelenium rc=new
WebDriverBackedSelenium(webDriverdrives “base URL”);
Driver.get(http://facebook.com);
Driver.manage().window().maximize();
Driver.findElement(By.id(“meial”)).sendKeys(“abcdef”);
rc.type(“id=”pass”,”Abcdef”);
rc.check(“jik”);
driver.findElement(By.id(“ds”)).click();
driver.findElement(By.id(“pass”)).sendKeys(“sheres”);
isDisplayed():-
Syntax:- driver.findElement(By.id(“locatorvalue”)).isDispalyed();
Example:-
driver.get(http://facebook.com);
driver.manage().window().maximize();
driver.findElement(By.id(“email”)).sendKeys(“kishore”)
Boolean a –driver.findElement(By.id(“pass”)).isDisplayed();
If(a==true)
Sopln(“pass”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
72
Else
Sopln(“fail”);
isEnabled():-
Syntax:- driver.findElement(By.locator(“value”)).isEnabled();
Syntax:- driver.findElement(By.locator(“value”)).isSelected();
Syntax:- driver.getTitle();
Syntax:- driver.getCurrentUrl();
Syntax:-driver.getPageSorce();
getAttribute():- To capture the locator value of the element from the application.
Syntax:- driver.findElement(by.locator(“value”)).getAttribute);
Syntax:-driver.findElement(by.locator(“value”)).getTagName(“locahost”);
Syntax:-driver.findElelement(by.locator(“value”)).getLocation(“local host”);
Syntax;-
Webdriver driver.get(“URL”)
Syntax:- driver.findElement(By.locator(“value”)).getText();
Driver.get(http://yahoomail.com);
Driver.manage().window().maxmize();
STRING App-url=driver.getCurrentUrl();
Sopln(App-url);
String a=drivr.findElement(By.id(“login-username”)).getAttribute(“class”);
System.out.println(a);
System.out.println(driver.findElement(By.id(“login-
username”)).getTagName());
Sopln(driver.findElement(By.id(“login-username”)).getSize());
Sopln(driver.findElemtn(By.id(“login-username”)).getRect());
Sopln(drivr.getTitle());
Sopln(driver.getPageSource());
webElement:-
sometimes we are working on the same element repeatedly for multiple times.
In that case instead of identifying the same element again and again for multiple
times, we are creating the ref object for that element using weelement. So that
here after we can start working on the element with the help of the object.
driver.get(http://yahoomail.com);
driver.manage().window().maximize();
webElement uid=driver.findElement(By.id(“login-username”))
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
74
uid.sendKeys(“Abcdef”);
uid.clear();
booloean a =uid.isDisplayed();
uid.getTagName();
Xpath:-
Xpath is nothing but the location of the element in a html tree structure /pge.
We are considering Xpath is the unique locator of the element in application.
Because in one location two elements will not appear. We can identify the
Xpath either manually/ by using the add-in called Firepath.
What is Firepath?
driver.get(http://facebook.com);
driver.manage().window().maximize();
driver.findElement(By.Xpath(“html path”)).senKeys(“abcdef”);
drivr.findElement(By.Xpath(“/”*[@id=’pass’]”)).sendKeys(“sss”);
webElement uid=driver.findElement(By.Xpath(“html”));
webElement pwd=driver.findElement(By.Xpath(“id=pg”));
uid.clear();
pwd.clear();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
75
Example:-
Package webd;
Import org.openqa.selenium.By;
Import org.openqa.selenium.webDriver;
Import org.openqa.selenium.firefox.FirefoxDriver;
Driver=new FirefoxDriver();
Driver.get(url);
Driver.manage().window().maximize();
Driver.quit();
Boolean a=driver.findElement(By.id(loc)).isDisplayed();
If(a==exp)
System.out.println(“pass”);
Elese
System.out.println(“pass”);
Else
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
76
System.out.println(“fail”);
String a=driver.getTitle();
If (a.length()==exp)
s.o.p(”pass”+”-“+a.length());
else
s.o.p(”fail”+”-“+a.length());
ReusableMethods.launchApp(“http://yahoomail.com”);
ReusableMethods.title_Length(15);
ReusbleMethods.ElementPresent(“login-username”,true);
ReusableMethods.CloseApp();
ReusableMethods.launchApp(http://facebook.com);
ReusableMethods.title-length(30);
ReusableMethod.elementpresent(“email”,true);
ReusableMethods.elementpresent(“pass”,false);
ReusableMethods.elementpresent(“day”,true);
ReusableMethods.closeApp();
Jxl.jar
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
77
FromExcel:- we are using this option to read the data from excel. For reading
the data from excel we need to configure JXL.jar/POI.jar with eclipse.
Example:-
Workbook wb=workbook.getworkbook(f);
Sheet s =wb.getSheet(“abcd”);
Sopln(s.getCell(0,0).getContents());
Sopln(s.getCell(1,0).getContents());
Sopln(s.getCell(2,0).getContents());
Example:-
P s v m throws exception{
Workbook wb=workbook.getWorkbook(f);
Sheet s=wb.getSheet(“abcd”);
Driver.get(s.getCell(4,0).getContents());
Driver.manage().window().maximize();
Driver.findElement(By.id(s.getCell(0,0).getContents())).SendKeys(s.getCell(2,0
).getContents()));
Driver.findElement(By.id(s.getCell(1,0).getContents())).SendKeys(s.getCell(3,0
).getContents()));
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
78
Workbook wb=workbook.getworkbook(f);
Sheet s=wb.getSheet(“abcd”);
Int rc=s.getRows();
Int i;
For(i=0;i<rc;i++){
Sopln(s.getCell(0,i).getContents());
A B C D
o/p Abc
abc 123
123 Def
Def XYZ
XYZ
Workbook wb=workbook.getworkbook(f);
Sheet s=wb.getSheet(“sheet1”);
Int cc=s.getColumns();
Int i;
For(i=0;i<cc;i++){
sopln(s.getCell(i,0).getContents());
123
456
789
We are using this option to write the data into excel into test scripts.
Workbook wb=workbook.getworkbook(f);
Sheet s=wb.getSheet(“abcd”);
Int cc=s.getColumns();
Int rc=s.getRows();
Inti;
Intj;
For(i=0;i<cc;i++){
For(j=0;j<rc;j++){
String val=s.getCell(i,j).getContents();
If(val.equals(“sharanya”==true)
Sopln(i+”-“+j);
P s v m throws exception{
Writableworkbook wwb=workbook.createworkbook(fo);
Writablesheet ws=wwb.createSheet(“value”,1);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
80
Writablesheet ws1=wwb.cretesheet(“value1”,2);
Ws.addCell(l);
Ws1.addCell(l1);
Wwb.close();
From notepad:-
We are using this option to execute the test scripts by passing the data from
notepad.
Example:-
Package webd;
Import java.io.BufferReader;
Import java.io.FileReader;
P s v m throws Exception{
Sopln(b.readline());
String a=b.readline();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
81
driver.get(c[0]);
driver.manage().window().maximize();
driver.findElement(By.id(“email”)).SendKeys(c[1]);
driver.findElement(By.id(“pass”)).SendKeys(c[2]);
P s v m throws exception{
String s;
While ((s=b.readline())!null){
Sopln(s);
Sharanya
1234
5678
9101112
From Console:-
We are suing this option to execute the test scripts by passing the data from
console during execution. For reading the data from console we are creating the
object for scanner class.
Syntax:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
82
Example:-
Package webd;
Import java.util.scanner;
Psvm{
Sopln(“enter A”);
Int a=s.nextInt();
Sopln(“enter B”);
Int b=s.nextInt();
Sopln(a*b);
o/p:- enter A 10
enter B 20
200
From Application:
sopln(“enter URL”);
driver.get(s.next());
driver.manage().window().maximize();
string email=s.next();
string email-val=s.next();
string pwd=s.next();
string pwd-val=s.next();
driver.findElement(By.id(email)).sendKeys(email-val);
driver.findElement(By.id(pwd)).SendKeys(pwd-val);
output:-
From Database:- we are using this option to read the data from database. For
working with database we need to configure OJDBC.jar file (oracle java
database connection) with eclipse.
Prepare the topic to open the login page of Rediffmail application, click on go
button (now alert msg will display) capture the text of alert msg and close the
alert message.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
84
We are using this option to handle the alert messages in application. Sometimes
during execution some alert messages interrupt the application. Tool cannot
able to continue the execution. In that case we need to switch/capture to that
alert message and handle the alert message. We can eliminate them by
implementing alert interface.
Example:-
P s v m throws exception{
Driver.get(https://mail.refiff.com/lgi-bin/login-lgi);
Driver.manage().window().maximize();
//clicking on go button
Driver.findElement(By.Xpath(“path”)).click();
//switch to alert
Alert a =driver.switchTo().alert();
Sopln(a.getText());
Thread.Sleep(5000);
//closing alert
a.dismiss();
Working with web tables:- We are using this option to work with web tables in
application.
Result
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
85
Prepare the test script to read the data from 2nd row 4th column cell from the
gainer table of nseindia.com application.
driver.get(“https://www.nseindia.com----“);
driver.manage().window().maximize();
sopln(driver.findElement(By.Xpath(“html/body----,getText());
driver.get(https://www.nseindia.com);
driver.manage().window().maximize();
webElement table=driver.findElement(By.Xpath(“html/body----“):
list<webelement>rc=table.findelements(By.tagName(“tr”);
int i;
for(i=2;i<=rc.size();i++){
sopln(driver.findElement(By.Xpath(“html/body/---tr[+”i+”]td[]”,getText());
Print the script names from the gainers table which are having greater than 2%
d.get(https://nseindia.com.....);
d.manage().window().maximize();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
86
list<webElement>rc.table.findElements(By.tagName(“tr”));
int i;
for(i=2;i<rc.size();i++){
double val=double.parseDouble(a);
if(val>=2.0)
string
val=driver.findelement(By.Xpath(“html/tbody/tr[“+i+”]/td[3]”)).getText();
We are using this option to handle the file uploads and downloads in selenium.
For handling file uploads, we are using AutoIT and executes the AutoIT
through webdriver.
What is AutoIT:-
AutoIT is the tool, which we can use to automate the windows applications, for
working with AutoIT, we need to download the tool, run to script in AutoIT and
also execute the script through webdriver.
AutoIT program:-
winActivate(“File Upload”)
sleep(5000)
controlclick(“fileUpload”,” “, “Button1”)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
87
By using webDriver:- Once we prepare the AutoIT program like above we need
to save the file and compile the file. When we compile the AutoIT file, one
“exe” file will generate. Once exe file has generated we can execute the file
through webdriver.
Example:-
driver.get(http://www.megafileupload.com/);
driver.mange().window().maximize();
driver.findElement(By.Xpath(“path”).Click());
driver.findElement(By.Xpath(“path”).Click());
Runtime.getRuntime().exec(“//path//filename.exe”);
We are using this option to handle multiple windows using webdriver. Before
working with multiple windows we need to count (through) those windows by
using get window handles.
Example:-
Prepare the test script to open the facebook application click on data policy link,
print the no. Of links in every window and close every window.
Program:-
Driver.get(http://facebook.com);
Driver.manage().window().maximize();
Driver.findElement(By.Xpath(“datapolicypath”)).click();
Int i;
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
88
For(i=0;i<a.Size();i++){
Sopln(driver.SwitchTo().window((string)a.get(i)).findElements(By.tagName(“a
)).Size());
Driver.SwitchTo().Window((string)a.get(i)).close();
Example:-
Prepare the test script to count the no. Of windows, enter something in the first
window, enter something in the second window.
Program:-
driver.get(http://facebook.com);
driver.manage().window().maximize();
webDriver
first=driver.SwitchTo().window((string)a.get(0));first.findElement(By.id(“day”)
).SendKeys(“24”);
first.findElement(By.id(“month”)).SendKeys(“Apr;
WebDriver second=driver.SwitchTo().Window((string)a.get(1));
Second.findElement(By.id(“email”)).SendKeys(“sharanya”);
Working with web Tables:- We are using this option to work with web Tables
in selenium
a.SendKeys(Keys.CONTROL+”t”).build().perform();
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
89
a.SendKeys(Keys.F5).build().perform();
a.SendKeys(Keys.F3).build().perform();
a.doubleclick(on element);
a.draganddrop(source,target);
drag drop
webElement img=driver.findElement(By.Xpath(“html/”));
WebElement uid=driver.findElement(By.Xpath(“html/”));
a.dragAndDrop(img,uid).build().perform();
Synchronization point:-
The time gap between tool and application is called synchronization point.
During the execution if the application is taking more time to display the
elements, tool cannot able to continue the execution. In that case we are giving
instructions to tool to wait for some more extra time until the elements are
available. This instructions we are providing to the tool in two different ways.
1. Explicit wait
2. Implicit wait
Explicit wait:- We are using explicit wait to stop the execution temporarily
irrespective of the application. We are using thread. Sleep for explicit wait in
selenium.
Syntax:-
Thread.Sleep(time in milliseconds);
Example:-
P s v m throws exception{
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
90
driver.get(http://facebook.com);
driver.manage().window().maximize();
driver.findelement(By.id(“email”)).SendKeys(“sheru”);
thread.sleep(60,000);
driver.findelement(By.id(“pass”)).SendKeys(“1234”);
Implicit wait:-
We are using implicit wait to stop the execution temporarily based on the
availability of the element in a application.
Syntax:-
Driver.manage().timeouts().implicitlywait(60,Timeunit.SECONDS);
P s v m throws exception{
Driver.manage().timeouts().implicitlywait(60,Timeunit,SECONDS);
Driver.get(http://facebook.com);
Driver.manage().window().maximize();
Driver.findelement(By.id(“email”)).SendKeys(“sharaya”);
Driver.findelement(By.id(“pass”)).SendKeys(“1234”);
Webdriver wait:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
91
We are using webdriver wait to stop the execution temporarily based on the
behaviour/availability of the element in application.
Example:-
P s v m throws exceptions{
Driver.get(http://facebook.com);
Driver.manage().window().maximize();
Driver.findelement(by.id(“email”)).SendKeys(“abcdef”);
w.untill(ExpectedConditions.numberofElementsToBe(By.tagName(“a”),50));
driver.findelement(By.id(“pass”)).SendKeys(“1234”);
list<webelement>a=driver.findElements(By.tagName(“a”));
sopln(a.size());
We are using this option to handle the mouse moments and keyboard operations
in webDriver.
Prepare the test script to launch the nseindia.com application, move the cursor
to corporate menu and click on benefits of listing under the menu
P s v m throws exception {
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
92
driver.manage().timeout().implicitlywait(60,Timeunit.SECONDS);
driver.get(“http://www.nseindia.com”);
driver.manage().window().maximize();
a.moveToElement(corporate).build().perform();
Thread.Sleep(5000);
Driver.findElement(By.Xpath(“ “)).Click();
[re[are the test script to move the cursor to corporate and print all the links
FRAMEWORKS
Framework is the folder structure which contains folders, subfolders and files
can be accessed by across the project. There are 2 different types of frameworks
available in selenium.
1. Built in framework
2. User defined framework
Built in framework:-
Built in framework is the framework which has created by vendor and we are
using this to automate the project. Thee are two different Buillt in frameworks.
We are implementing in selenium.
1. JUnit(java unit)
2. TestNg(Testnextgeneration)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
93
JUnit:- Junit is the unit testing framework which is using by the java developers
to perform unit testing. For working with JUnit framework we need to configure
junit.jar file with eclipse. (jnit.jar download)
Once we download the jnit.jar file and configure with eclipse we can start
working on Junit framework. For working with Junit framework we are using
Annotations.
What is Annotation?
Annotations are nothing but predefined classes which contains reusable line of
the code.
List of Annotations:-
@Beforeclass
Sopln(“This is Before”);
@Afterclass
Sopln(“This is after”);
@test
Sopln(“This is test1);
@test
Sopln(“This is test2”);
@test
@Ignore
Sopln(“This is test3);
Output:-
This is before
This is test1
This is test2
This is after
@Before
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
95
Sopln(“This is Before”);}
@After
Sopln(“This is After”);}
@Test
Sopln(“This is Test1”);
@Test
Sopln(“This is Test2”);}
@Test
Sopln(“This is Test3”);
o/p:-
This is Before
This is Test1
This is After
This is Before
This is Test2
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
96
This is After
This is Before
This is Test3
This is After
Example:-
Package junit;
Import java.util.list;
Import java.util.concurrent.Timeunit;
Import org.junit.After;
Import org.junit.Before;
Import org.junit.test;
Import org.openqa.selenium.By;
Import org.openqa.selenium.webdriver;
Import org.openqa.selenium.webelement;
Import org.openqa.selenium.firefox.FirefoxDriver;
Import junit.framework.Assert;
@Before
Driver=new firefoxDriver();
Driver.manage().timeouts().implicitlywait(60,Timeunit.SECONDS);
Driver.get(“http://nseindia.com”);
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
97
Driver.manage().window().maximize();
@After
Driver.Close();
@Test
String url=driver.getCurrentUrl();
Assert.assertequals(true,url.contains(“.com”));}
@Test
List<webelement>links_count=driver.findelements(By.tagName(“a”));
Assert.assertEquals(20,links_count.Size());}
TestNG:- TestNG is the advanced for Junit which we can us to perform unit
testing and automate the project.
Advantages:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
98
http://tesng.org/doc/download.html
click on enter
eclipse plug-in
copy the update site for release link under eclipse plug-in
go to eclipse
help
click on ok
click on next
click on next
select terms
click on finish
restart
click on go button
click on install
click on next
click on finish
restart now
We can also install the test NG with eclipse from eclipse place under help menu
in eclipse
@before suite
@After suite
]@Before Test
@After Test
@Before class
@After Class
@Before method
@After method
@test ignore
Example:-
@Test (priority=2)
Sopln(“This is test1”);}
@Test(priority=3)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
100
Sopln(“This is test2”);}
@Test(priority=1)
Sopln(“This is test3”);
@Before method
Sopln(“This is Beforemethod”);}
@After method
@Before class
@After class
Sopln(“This is Afterclass”);}
@Before Test
@AfterTest
Sopln(“This is AfterTest”);}
@BeforeSuite
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
101
Sopln(“This is BeforeSuite”);}
@After Suite
Output:-
After compilation of design the test script like above. We need to run the script
as test NG test. Once we run the script test NG will execute and we can see the
result in test o/p folder in package project.
Usually in project we are designing one manual test NG test in one class
Import org.testng.annotations.test;
@Test
Driver.findelement(By.name(“new user”)).click();
List<webelement>list_count=driver.findelements(By.tagname(“select”));
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
102
Assert.assetEquals(lst_count.Size(),2);}
@Beforemethod
Driver=new firefoxDriver();
Driver.manage().timeouts().implicitlywait(60,Timeunit,SECONDS);
Driver.get(http://qshore.com/unum/login.php);
Driver.manage().window().maximize();}
@After method
Driver.close();}
Example:-
@Test
Driver.findElement(By.name(“txt”)).SendKeys(“sharanya”);
Org.testng.Assertequals(driver.findelement(By.name(“pwd”)).isenabled()true);
Driver.findelement(By.name(“pwd”)).SendKeys(“1234”);
Driver.findelement(By.name(“sub”)).click();
String url=driver.getcurrenturl();
Org.testng.Assert.assetequals(url.contains(“cases”),ture);
(Repeat it down)
New
Click on file(xml)
Click on ok
Example:-
<classes>
<class name=”testngg.class2”/>
<class name=”testngg.class1”/>
</classes>
</test>
After </suite>
Once we prepare the xml script like above, we need to run the script by right
clicking on the file and click on “test ng suite”
When we run as “test ng suite’, all the test ng test in xml file will execute and
generate the result.
Linear framework
Datadriven framework
Hybrid framework
Data driven framework:- In this framework we design one test script in one
class by passing dta from excel and export the output in excel and executes
individual test script.
Modular framework:- In this framework we are designing one test script in one
method by passing the data from excel and export the output into excel. After
successfully completion of design the individual scripts into individual methods,
we are calling the required scripts into driver scripts with method name.
Note:- In every project automation testing process starts with designing the
framework folder structure. It will be designing by automaton, test load or
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
105
Package com.Qshore;
Import java.io.fileInputStream;
Public Sheet s;
Note:-
Folders which are available in framework are customized folders. That measns
according to the project requirement we can customize the no of folders, the no
of folders and also edit the names of the folders. Creating hydbrid framework is
the one time activity. Once we design senior tester in a project will be involving
to design/create the files in framework folder strcture.
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
106
Once the framework structure is available with all the required files, we need to
start designing the test script with framework structure.
While designing we are writing one test script in one method in a class.
Example:-
//***************
//TestName: launchApp
//Author : Sharayna
//***************
//****
//******
//******
Etc
Example:-
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
107
r.launchApp();
r.CloseApp();
r.elementpresent();
Driver Script:- driver script is the script which we are using to execute multiple
scripts. After successfully completion of designing the individual scripts in
individual methods like above, we need to call all the required scripts into driver
script and execute multiple scripts at a time.
m.registration();
Selenium Grid:- We are using selenium grid to execute the test script parallely
in different browsers and in different environments. For working with selenium
grid we need to configure the Hub and register notes with hub.
What is Hub:- Hub is the Central system where we can write the scripts.
What is Node:- Node is the individual machine which has register under hub.
Click on enter
When we click on enter grid hub will be starting and we can see the hub
configuration information in the below location “local host: 4444/grid/console”
Note:- Once we start the grid hub we should not close that command prompt.
(don’t close cmd prompt when we work with node)
Registering nodes with the hub:- Once we start the hub we need to register
individual nodes with the hub.
Navigation:-
Enter the below command java – jar < selenium server.jar role node – hub
http://localhost:4444/grid/register
Click on enter
When we click on enter node will be registering with the hub and we can see the
node information in the below location.
Localhost: 4444/grid/console.
Once we register the nodes with the hub we need to design the script in eclipse
for executing through grid for working webdriver in grid we are using desired
capabilities and remote webdriver.
P s v m{
Usually while starting they are creating few methods in a class and the same
class will be updating in future with multiple methods by the team members
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
109
//counting no of links
r.elementscount(“a”,20);
r.elementscount(“select”,2);
Webelement industry=r.driver.findelement(By.Xpath(“-
“)(r.s.getCell(0,5).getContents()));
List<weelement>values_count=industry.findelements(By.tagname(“option”));
If(values_count.Size()==5)
Sopln(“pass”)
Else
Sopln(“fail”);
r.closeapp();
Reusable Method:-
Count=driver.findelements(By.tagName(loc));
If(count.size()==exp)
Sopln(“pass”)
Else
Sopln(“fail”)
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
110
Package driver;
P s v m throws exception
e.er_login();
Apache Maven:- Maven is the build configuration and version controlling tool
which has developed by Apache. We are using maven to implement frameworks
to automate the projects.
Navigation:-
Open eclipse
Next
Next
Finish
Once we install the maven with eclipse we need to create maven project in
eclipse.
Navigation
New
Other
Maven
Next
Next
Click on finish
Once we create the maven project we need to add dependencies (required jar
files we can add) with pom.xml(project object model). This pom.xml file we are
using to configure the required jar files (dependiencies).
Mavencentral repository
Pom.xml syntax
</dependency>
<groupId>jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6</version>
</dependency>
Once we add the required dependencies, we can start designing the test scripts
under src/test/java in maven project.
Selenium Grid:-
Psvm{
d.firefox();
Driver.get(http://facebook.com);
Driver.manage().window().maximize();
Grid with RC
Psvm{
s.start;
Log4J is using by the java developers in the frameworks during unit testing to
generate the log files. For working with log4j we need to download the jar file
and configure with eclipse.
Log4j.properties file:-
We are using this file to configure log4j settings with eclipse. This
log4j.properties file we need to create under src in a package explored.
File=> log4j.properties:-
#Application logs
Log4j.logger.devpinoglogger=DEBUG,dest1
Log4j.appender.dest1=org.apache.log4j.RollingFile
Log4j.appender.dest1.maxFileSize=5000KB
Log4j.appender.dest1.MaxBackupIndex=3
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
113
Log4j.appender.dest1layout=org.apache.log4j.pattern
Log4j.appender.dest1.layout.conversion pattern=%d{MM/DD/YYYY
HH:MM:SS} %c %m %n
Log4j.appender.dest1.File=C:\\users\\Vamshi\\desktiop\\framework\\Results\\12
3.log
//do not append the old file. Create a new log file every time.
Log47.appender.dest1.Append=false
Package sharanya;
Import com.gargoylesoftware.htmlunit.webconsole.logger.
P s v m{
Logger APPLICATION_LOGS=logger.getLogger(
Int a=20;
Int b=30;
If(a>b)
APPLICATION_LOGS.debug(“pass”);
Else
APPLICATION_LOGS.debug(“fail”);
Once we prepare the log4J script, we need to execute the script. Once we run
the script log4j file will be creating along with the logs information.
Navigation:-
Click on enter
Onece we start the Jenkins through cmd prompt. We can schedule the batches
through Jenkins configuration
Navigation:-
Click on next
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
115
Click on ok
Click on apply
Click on save
When we click on save button, all the batches information we can see in the
Jenkins dashboard.
Once the batches run through Jenkins, we can see the Jenkins batches info in the
dashboard of Jenkins and the history of the batches exefcution we can see in the
build history
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur
116
Release-> 3-monhts
QSHORE 9030821111/9703921111
Experience the quality www.qshore.com https://www.facebook.com/qshoretech/
Gachibowli | Kondapur