Selenium Quick Reference
I) Selenium Fundamentals
i) What is Selenium?
> Selenium is a Suite of Tools to automate Browsers, Selenium tin automate Web Applications only, It doesn't automate Desktop Applications.
> Selenium is opened upward origin software, anybody tin download too utilisation amongst complimentary of cost.
ii) History of the Selenium Project
> Selenium outset came to life inward 2004 when Jason Huggins was testing an internal application at ThoughtWorks. He developed a Javascript library that could receive interactions amongst the page, allowing him to automatically rerun tests against multiple browsers.
> In 2006 an engineer at Google named Simon Stewart started piece of occupation on a projection he called WebDriver.
> In 2008, the whole Selenium Team decided to merge WebDriver too Selenium RC to shape a to a greater extent than powerful tool called Selenium 2.
> Selenium RC is nonetheless beingness developed but only for maintenance.
iii) Selenium License
All Selenium projects are licensed nether the Apache 2.0 License, It is Open origin anybody tin download too utilisation selenium suite(Selenium IDE, Selenium RC, Selenium WebDriver too Selenium Grid) of tools amongst complimentary of cost.
Note: Anybody tin download too utilisation Selenium components, but selling updated code is non permited.
iv) Selenium Supporting Platforms too Environments
a) Operating Systems:
Microsoft Windows
UNIX/ Linux
Macintosh
Apple OS X etc...
b) Browsers:
Mozilla Firefox
Internet Explorer
Google Chrome
Safari
Opera etc...
c) Scripting/Programming:
Java
C#
Perl
Python
PHP
Ruby
d) Software Applications
> CUI based Applications (* It doesn't support)
> Desktop Applications (I-Tier too II-tier Applications) (* It doesn't support)
> Web Applications (It Supports)
> Mobile Applications (*Which bring spider web forms) (It supports)
v) Selenium suite of tools or Selenium Components
a) Selenium IDE:Selenium IDE, It is a tool for creating examination cases.
It is a Firefox plugin too provides an easy-to-use interface for developing automated tests.
b) Selenium RCSelenium RC solves the limitations of Selenium IDE. It supports diverse programming languages similar Java, C#, PHP, Perl, Python too Ruby languages to attain logic required inward examination cases similar conditional statements, iterations, exception handling, examination reporting, database testing, capturing covert shots of failed tests, examination illustration grouping etc...
c) Selenium WebDriverThe biggest alter inward Selenium lately has been the inclusion of the WebDriver API. Selenium WebDriver fits inward the same role every bit RC did.
WebDriver is designed inward a simpler too to a greater extent than concise programming interface along amongst addressing to a greater extent than or less limitations inward the Selenium-RC API.
d) Selenium GridSelenium Grid allows yous to run your tests inward parallel, that is, dissimilar tests tin endure run at the same fourth dimension on dissimilar remote machines.
vi) Advantages of Selenium
> It is Open origin Software, no license cost, anybody tin download too utilisation amongst complimentary of cost.
> Selenium was outset written inward Java but it also supports C#, Ruby, Perl, PHP too Python. This is a large addition when nosotros desire to construct our framework inward a linguistic communication that has the highest adoption inward the arrangement it is beingness built within. Tools similar UFT / QTP forcefulness yous to utilisation VBScript – which is almost never the preferred scripting linguistic communication for developers.
> It has back upward for all of the pop browsers similar IE, Firefox, Chrome, Safari etc. It also supports several Operating Systems too that makes it a tool of selection for cross browser/ cross platform certification.
> Once yous larn Selenium to piece of occupation for you, it industrial plant reliably when used for running the tests over too over again. It’s definitely a lot to a greater extent than reliable than tools similar QEngine or JExplorer but virtually the same every bit tools similar UFT / QTP.
> You tin instantiate several concurrent tests (Parallel Test execution) amongst Selenium Grid.
vii) Disadvantages of Selenium
> Supports Web based (Browser based) Application only, doesn't back upward Desktop or standalone Application examination automation.
> Since it is Open origin software, no reliable technical back upward from anybody.
> No centralized maintenance of Elements (Objects)
> Limited back upward for Image testing.
> Some novel features may or may non piece of occupation properly.
> Deploying Selenium Tool is hard than UFT (Formerly QTP) Tool.
II) Java for Selenium
A) coffee Basics
i) Comments inward Java
Purpose of comments
> To brand the code readable
> To brand the Disable from execution
Java supports Single business comment too multiple lines comment.
------------------------
ii) Data Types inward Java
There are 2 categories of Data types inward Java
a) Primitive information types
b) Reference information types
------------------------
iii) Variables
a) Local variables
b) Instance variables
c) Class / Static variables
------------------------
iv) Java Modifiers
Modifiers are used to laid access levels for Classes, variables, methods etc...
a) Access Modifiers (Default, Public, Private, Protected)
b) Non-access Modifiers (Static, Final, Abstract, Synchronized)
------------------------
v) Operators inward java
Operators are used to perform mathematical, comparing too logical operations.
Categories of operators:
a) Arithmetic
b) Relational operators
c) Bit-wise operators
d) Logical operators
e) Assignment operators
f) Mise Operators
------------------------
vi) Conditional statements
Used to insert verification points too for fault handling.
Types of conditional statements inward Java:
a) If Statement
b) Switch statement
Types of Condition:
a) Single condition
b) Compound conditions
c) Nested conditions
Usage of conditional statements:
a) Executing a block of statements when status is true.
b) Execute a block of statements when status is truthful otherwise execute to a greater extent than or less other block of statements.
c) Decide amidst several alternates (Else if)
d) Executing a block of statements when to a greater extent than than 1 status is true.(Nested if)
e) Decide amidst several alternates (Switch statement)
------------------------
vii) Loop statements
used for repetitive execution.
Types of Loop Statements
a) For Loop
b) While Loop
c) Do...While Loop
d) Enhanced For Loop (mainly used for Arrays)
--------------------------------------------------------------
viii) Arrays inward Java
Generally, Array is a collection of similar type of elements.
In Java, Array is an object that contains elements of similar information types.
Java Array is index based, index starts from zero.
The length of an Array is established when the Array is created too Array length is fixed.
Each item inward an Array is called an Element.
Declaration of Arrays
Assigning values to elements
Advantages too Disadvantages of Arrays.
-----------------------------------
ix) Java Methods
Methods are also known every bit procedures or functions
A Java method is a collection of statements that are grouped together to perform an operation.
Ex:
System.out.println
If yous telephone phone the method, the scheme genuinely executes several statements, inward guild to display a message on the console.
We tin create methods amongst or without returning whatever value.
Basically Methods are 2 types
a) Built-in or Pre-defined
Number Methods
Character methods
String methods
Date & Time Methods
Etc...
b) User defined
Method amongst returning value
Method without returning whatever value
-------------------------------------------------
x) Regular Expressions
It is a formula for matching patterns, Influenza A virus subtype H5N1 Regular appear defines search pattern for strings.
Java provides the java.util.regex packet for pattern matching amongst regular expressions.
--------------------------------------------------------
xi) File too I/O operations inward Java.
The java.io packet contains classes to perform input too output (I/O) operations inward Java.
Reading using input devices
Displaying on the console
Reading too writing text files
Working amongst Excel files.
---------------------------------------------------------
xii) Exception treatment inward Java
In Computer programming, Exception is an abnormal condition.
An exception is an consequence that occurs during the execution of a programme that disrupts the normal time period of instructions.
The exception treatment inward coffee is 1 of the powerful machinery to grip the runtime errors thus that normal time period of the application tin endure maintained.
----------------------------------------------------------
Java object oriented Programming
Class, Object, Method
In object oriented programming system(OOPS), nosotros designing a programme using Objects too classes.
Object:
It is an entity that has states too behaviors is known every bit Object.
Ex: Pen, Chair, Table, Computer etc...
States / Properties of Dog object are color, height, weight etc... too behaviors moving, barking, jumping etc...
-------------------
Class:
Class is a template or designing from amongst objects are created.
A Class a grouping of objects that has mutual properties.
----------------
Method: An functioning on Object.
--------------------------------------------
i) Inheritance
Inheritance is a machinery inward which 1 object acquires all the properties too behaviors of rear object.
Using Inheritance nosotros tin create classes that are built upon existing classes.
When nosotros Inherit from an existing class, nosotros tin reuse methods too fields from rear shape too nosotros tin add together novel methods too fields also.
Java Supports:
a) Single Inheritance
b) Multi degree Inheritance
c) Hierarchical Inheritance
Note: Java doesn't back upward Multiple Inheritance.
--------------------------------------------------------
ii) Polymorphism
If a shape having multiple methods amongst same name, but dissimilar parameters is known every bit method overloading.
Method overloading increases the readability of the program.
There are 2 ways to overload the method inward Java
a) past times changing position out of arguments
Ex:
add (int a, int b)
add (int a, int b, int c)
b) past times changing information types
Ex:
add (int a, int b)
add (char a, char b)
In Object Oriented programming overriding agency to override the functionality of an existing method.
Method overriding provides a specific implementation of a method that is already provided past times its super shape (Parent class)
It is used for runtime polymorphism.
-------------------------------------------
Polymorphism
------------------
It is a concept past times which nosotros tin perform a unmarried inward dissimilar ways.
Polymorphism derived from 2 Greek discussion poly too morphs
Poly agency -many
morphs agency -forms / ways, thus polymorphism agency many forms.
we bring 2 types of Polymorphism inward java
a) Compile fourth dimension polymorphism
b) Runtime polymorphism.
We tin perform polymorphism inward coffee past times method overloading too method overriding.
--------------------------------------------------
iii) Abstraction
Abstraction is a physical care for of hiding the implementation details too showing functionality to the user.
Another way, it shows of import things to the user too hides internal details.
Ex: Sending email
you but type the electronic mail too send, yous don't internal physical care for of the electronic mail delivery.
Abstraction focuses on what the object does instead of how it does.
In 2 ways nosotros tin attain Abstraction
a) Abstract Class (0 to 100%)
b) Interface (100%)
--------------------------------------------------
iv) Encapsulation
Encapsulation is 1 of the 4 fundamental oops concepts, other 3 are Inheritance, Polymorphism too Abstraction.
Encapsulation is a physical care for of wrapping code too information together into a unmarried unit.
Ex: Capsule (mixed of several medicines)
It provides the command over the data, suppose nosotros desire to value of the id greater than 100 only, nosotros tin write the logic within the setter method.
------------------------------------------------------
Java packagesA Java packet is a grouping of similar type of classes, interfaces too sub-packages.
There are 2 types of coffee packages
a) Built inward packages
Ex: io, util, sql etc...
b) User defined packages
----------------------------------------------
Interfaces inward JavaAn interface is a collection of abstract methods.
An interface is non a class, writing an interface is similar to writing a class, but 2 are dissimilar concepts.
------------------------------------------------------
III) Selenium WebDriver
Selenium WebDriver Introduction:
> Selenium 1.0 (Selenium IDE + selenium RC + Selenium Grid)
> Selenium 2.0 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)
Note: Selenium WebDriver merged amongst Selenium 1.0
> It is a most of import tool inward Selenium suite.
> It is has programming interface allows us to create too execute Test cases against dissimilar browsers (ex: Firefox, IE, Google Chrome etc...)
> WebDriver supports diverse programming languages to heighten Test cases.
Java
.NET
PHP
Perl
Python
Ruby
> WebDriver supports diverse operating environments to create too execute Test cases(Ex: MS Windows, UNIX too Macintosh etc...)
> WebDriver supports Data Driven testing, cross browser testing.
> Webdriver is faster than other tools of Selenium suite.
> WebDriver supports Parallel examination execution amongst the aid of TestNG.
> WebDriver doesn't bring IDE, only Programming interface.
> WebDriver doesn't bring built inward Result reporting facility, it provides summary only.(* amongst the aid of TestNG nosotros tin generate HTML examination reports.)
> No object Repository inward selenium WebDriver (It is for entire Suite), thus no centralized maintenance of Objects)
Using Element locators, Webdriver methods too Java programming features nosotros tin create too execute Test cases.
Element Locators - to recognize / position Elements (Objects)
Webdriver Methods - to perform operations on Elements.
Java programming features - for Enhancing Test Cases.
Selenium Webdriver Environment Setup:
> Download too install Java (JDK) software - to heighten examination cases using Java programming features.
> Set Path surround variable- to access Java from whatever directory.
> Download Eclipse IDE too extract
> Download WebDriver Java Language binding too add together Webdriver jounce files (in Eclipse)
> Install Firebug too FirePath plug ins for Mozilla Firefox browser to inspect Elements.
Note 1: For Internet explorer too Google chrome, no postulate to install whatever plug ins, They bring built inward Developer tools.
Note 2: Element locators too WebDriver methods are mutual for all browsers, browser driver only varies from 1 browser to another.
Note 3: Firefox driver is default driver inward Webdriver, For IE too Chrome nosotros postulate to download drivers.
Download Selenium WebDriver Java binding from www.seleniumhq.org website too extract.
Navigation for adding Webdriver jounce files inward Eclipse.
> Create Java project
> Select src too correct click
> Build path
> Configure Build Path
> pick out Libraries tab
> Click "Add External JARs
> Browser path of the WebDriver jars
> Add
Pre-requisites to Create Automated Tests / Test Scripts / Test Cases
> Import WebDriver Libraries too Firefox driver/IE driver/Chrome Driver
> Using Web Element (object) locators too WebDriver methods write object telephone phone statements
> Insert Java programmatic statements to heighten Test cases.
Element Locators
Selenium supports 8 chemical element locators to position objects/elements on spider web pages.
We tin utilisation whatever 1 unique locator to position elements.
1) id
2) name
3) classname
4) tagName
5) linkText
6) partialLinkText
7) cssSelector
8) xpath
IV) TestNG Framework
TestNG Introduction
> In Selenium using Java at that topographic point are 2 Automation frameworks available:
i) JUnit
ii) TestNG
> TestNG is to a greater extent than powerful than JUnit framework.
> TestNG is an opened upward origin examination automation framework, where NG stands for Next Generation
> TestNG inspired from JUNit but introduced to a greater extent than or less novel functionality.
Benefits of TestNG:
> It generates HTML examination reports
> TestNG Annotations are slowly to create Test cases.
> Test cases tin endure grouped too prioritized to a greater extent than easily.
> Parallel Testing is possible
> Parameterization is possible.
Note: Using TestNG nosotros tin create Test cases, execute Test cases too generate reports inward HTML format.
Install TestNG:
In Eclipse IDE,
Help card -> Install New Software -> Click Add
-> Enter Name every bit "TestNG"
-> Enter URL every bit "http://beust.com/eclipse/"
-> Select TestNG
-> Next -> Next -> Accept the Agreement -> Finish
A Sample TestNG Program
public shape SampleTest {
@Test
populace void verifyTitle()
{
WebDriver driver = novel FirefoxDriver();
driver.get("http:/www.gmail.com");
String Actual = driver.getTitle();
Assert.assertEquals(Actual, "Gmail");
}
}
Create Multiple Test cases inward a Program/Class
TestNG examination cases tin endure executed inward alphabetical order, if yous desire to command the Test execution too thus utilisation Attributes.
public shape SampleTest {
@Test
populace void testA()
{
Assert.assertEquals("Google", "Google");
}
@Test
populace void testC()
{
Assert.assertEquals("Gmail", "Google");
}
@Test
populace void testB()
{
Assert.assertEquals("Yahoo", "Yahoo");
}
}
TestNG Annotations
@Test
@BeforeMethod
@AfterMethod
@BeforeClass
@AfterClass
@BeforeTest
@AfterTest
@BeforeSuite
@AfterSuite
@DataProvider
@BeforeGroups
@AfterGroups
@Parameters
@Factory
@Listeners
V) Selenium IDE
Selenium IDE Introduction:
> Selenium IDE (Integrated Environment) is a Tool, used to prepare Selenium Test Cases.
> It is Firefox plug in, industrial plant only on Firefox Browser.
> It provides Graphical user interface for Recording user actions using Firefox Browser.
> Firebug Add on is used to inspect elements.
> Selenium IDE should only endure used every bit a prototyping tool.
Note: We can't prepare complex Test cases using Selenium IDE.
Test Step inward Selenium IDE Test Case
Test Step Syntax:
Command + Target + value
Command - forms the functionality of the Test step
Target - Identifies the Element on the spider web page.
Value - Input information (This applicable only for few commands)
Example:
Type id=Email abcd123
Download Install Selenium IDE
> Using Firefox browser, download selenium IDE from the Seleniumhq.org website.
> Firefox volition protect yous from installing add together ons from unfamiliar locations, thus we volition postulate to click "Allow" to proceed amongst the installation.
> Install multiple items to back upward Java, Ruby, Python etc... formats.
> Restart Firefox browser.
> After Firefox reboots too thus nosotros tin utilisation Selenium IDE.
Features of Selenium IDE
Using Selenium IDE, nosotros can,
> Create Test cases too Test suites
> Open existing Test case
> Run Test illustration too Run Test suite.
> Export Test illustration inward a Language of our choice.
> Debug Test cases.
> Add Comments, Insert verification points.
Etc...
Drawbacks of Selenium IDE
> It supports Firefox Browser only, thus cross browser testing is non possible.
> No Flow command statements (Conditions too Loops)
> Parametrization is non possible.
> Not suitable for creating complex Test cases.
> Doesn't supply detailed examination reports, provides summary only.
> No Object Repository, thus no centralized maintenance of Objects(Elements)
Create Test cases inward Selenium IDE
By Recording Or Type steps using Selenese commands too chemical element locators.
Difference betwixt "assert" too "verify" Commands
> When an "assert" command fails too thus examination execution volition endure aborted.
> When a "verify" command fails too thus examination volition move past times away on execution too logging the failure.
VI) Selenium Grid
Selenium Grid Introduction:
> Selenium Grid is part of the Selenium project.
> Using Selenium Grid nosotros tin distribute examination execution across several machines.
> There are 2 top dog elements to Selenium Grid -- a hub, too nodes.
> First nosotros postulate to stand upward up a hub, too and thus yous tin connect (or "register") nodes to that hub. Nodes are where your tests volition run, too the hub is responsible for making certain your tests goal upward on the correct 1 (e.g., the machine amongst the operating scheme too browser yous specified).
Sumber http://www.gcreddy.com/
I) Selenium Fundamentals
i) What is Selenium?
> Selenium is a Suite of Tools to automate Browsers, Selenium tin automate Web Applications only, It doesn't automate Desktop Applications.
> Selenium is opened upward origin software, anybody tin download too utilisation amongst complimentary of cost.
ii) History of the Selenium Project
> Selenium outset came to life inward 2004 when Jason Huggins was testing an internal application at ThoughtWorks. He developed a Javascript library that could receive interactions amongst the page, allowing him to automatically rerun tests against multiple browsers.
> In 2006 an engineer at Google named Simon Stewart started piece of occupation on a projection he called WebDriver.
> In 2008, the whole Selenium Team decided to merge WebDriver too Selenium RC to shape a to a greater extent than powerful tool called Selenium 2.
> Selenium RC is nonetheless beingness developed but only for maintenance.
iii) Selenium License
All Selenium projects are licensed nether the Apache 2.0 License, It is Open origin anybody tin download too utilisation selenium suite(Selenium IDE, Selenium RC, Selenium WebDriver too Selenium Grid) of tools amongst complimentary of cost.
Note: Anybody tin download too utilisation Selenium components, but selling updated code is non permited.
iv) Selenium Supporting Platforms too Environments
a) Operating Systems:
Microsoft Windows
UNIX/ Linux
Macintosh
Apple OS X etc...
b) Browsers:
Mozilla Firefox
Internet Explorer
Google Chrome
Safari
Opera etc...
c) Scripting/Programming:
Java
C#
Perl
Python
PHP
Ruby
d) Software Applications
> CUI based Applications (* It doesn't support)
> Desktop Applications (I-Tier too II-tier Applications) (* It doesn't support)
> Web Applications (It Supports)
> Mobile Applications (*Which bring spider web forms) (It supports)
v) Selenium suite of tools or Selenium Components
a) Selenium IDE:Selenium IDE, It is a tool for creating examination cases.
It is a Firefox plugin too provides an easy-to-use interface for developing automated tests.
b) Selenium RCSelenium RC solves the limitations of Selenium IDE. It supports diverse programming languages similar Java, C#, PHP, Perl, Python too Ruby languages to attain logic required inward examination cases similar conditional statements, iterations, exception handling, examination reporting, database testing, capturing covert shots of failed tests, examination illustration grouping etc...
c) Selenium WebDriverThe biggest alter inward Selenium lately has been the inclusion of the WebDriver API. Selenium WebDriver fits inward the same role every bit RC did.
WebDriver is designed inward a simpler too to a greater extent than concise programming interface along amongst addressing to a greater extent than or less limitations inward the Selenium-RC API.
d) Selenium GridSelenium Grid allows yous to run your tests inward parallel, that is, dissimilar tests tin endure run at the same fourth dimension on dissimilar remote machines.
vi) Advantages of Selenium
> It is Open origin Software, no license cost, anybody tin download too utilisation amongst complimentary of cost.
> Selenium was outset written inward Java but it also supports C#, Ruby, Perl, PHP too Python. This is a large addition when nosotros desire to construct our framework inward a linguistic communication that has the highest adoption inward the arrangement it is beingness built within. Tools similar UFT / QTP forcefulness yous to utilisation VBScript – which is almost never the preferred scripting linguistic communication for developers.
> It has back upward for all of the pop browsers similar IE, Firefox, Chrome, Safari etc. It also supports several Operating Systems too that makes it a tool of selection for cross browser/ cross platform certification.
> Once yous larn Selenium to piece of occupation for you, it industrial plant reliably when used for running the tests over too over again. It’s definitely a lot to a greater extent than reliable than tools similar QEngine or JExplorer but virtually the same every bit tools similar UFT / QTP.
> You tin instantiate several concurrent tests (Parallel Test execution) amongst Selenium Grid.
vii) Disadvantages of Selenium
> Supports Web based (Browser based) Application only, doesn't back upward Desktop or standalone Application examination automation.
> Since it is Open origin software, no reliable technical back upward from anybody.
> No centralized maintenance of Elements (Objects)
> Limited back upward for Image testing.
> Some novel features may or may non piece of occupation properly.
> Deploying Selenium Tool is hard than UFT (Formerly QTP) Tool.
II) Java for Selenium
A) coffee Basics
i) Comments inward Java
Purpose of comments
> To brand the code readable
> To brand the Disable from execution
Java supports Single business comment too multiple lines comment.
------------------------
ii) Data Types inward Java
There are 2 categories of Data types inward Java
a) Primitive information types
b) Reference information types
------------------------
iii) Variables
a) Local variables
b) Instance variables
c) Class / Static variables
------------------------
iv) Java Modifiers
Modifiers are used to laid access levels for Classes, variables, methods etc...
a) Access Modifiers (Default, Public, Private, Protected)
b) Non-access Modifiers (Static, Final, Abstract, Synchronized)
------------------------
v) Operators inward java
Operators are used to perform mathematical, comparing too logical operations.
Categories of operators:
a) Arithmetic
b) Relational operators
c) Bit-wise operators
d) Logical operators
e) Assignment operators
f) Mise Operators
------------------------
vi) Conditional statements
Used to insert verification points too for fault handling.
Types of conditional statements inward Java:
a) If Statement
b) Switch statement
Types of Condition:
a) Single condition
b) Compound conditions
c) Nested conditions
Usage of conditional statements:
a) Executing a block of statements when status is true.
b) Execute a block of statements when status is truthful otherwise execute to a greater extent than or less other block of statements.
c) Decide amidst several alternates (Else if)
d) Executing a block of statements when to a greater extent than than 1 status is true.(Nested if)
e) Decide amidst several alternates (Switch statement)
------------------------
vii) Loop statements
used for repetitive execution.
Types of Loop Statements
a) For Loop
b) While Loop
c) Do...While Loop
d) Enhanced For Loop (mainly used for Arrays)
--------------------------------------------------------------
viii) Arrays inward Java
Generally, Array is a collection of similar type of elements.
In Java, Array is an object that contains elements of similar information types.
Java Array is index based, index starts from zero.
The length of an Array is established when the Array is created too Array length is fixed.
Each item inward an Array is called an Element.
Declaration of Arrays
Assigning values to elements
Advantages too Disadvantages of Arrays.
-----------------------------------
ix) Java Methods
Methods are also known every bit procedures or functions
A Java method is a collection of statements that are grouped together to perform an operation.
Ex:
System.out.println
If yous telephone phone the method, the scheme genuinely executes several statements, inward guild to display a message on the console.
We tin create methods amongst or without returning whatever value.
Basically Methods are 2 types
a) Built-in or Pre-defined
Number Methods
Character methods
String methods
Date & Time Methods
Etc...
b) User defined
Method amongst returning value
Method without returning whatever value
-------------------------------------------------
x) Regular Expressions
It is a formula for matching patterns, Influenza A virus subtype H5N1 Regular appear defines search pattern for strings.
Java provides the java.util.regex packet for pattern matching amongst regular expressions.
--------------------------------------------------------
xi) File too I/O operations inward Java.
The java.io packet contains classes to perform input too output (I/O) operations inward Java.
Reading using input devices
Displaying on the console
Reading too writing text files
Working amongst Excel files.
---------------------------------------------------------
xii) Exception treatment inward Java
In Computer programming, Exception is an abnormal condition.
An exception is an consequence that occurs during the execution of a programme that disrupts the normal time period of instructions.
The exception treatment inward coffee is 1 of the powerful machinery to grip the runtime errors thus that normal time period of the application tin endure maintained.
----------------------------------------------------------
Java object oriented Programming
Class, Object, Method
In object oriented programming system(OOPS), nosotros designing a programme using Objects too classes.
Object:
It is an entity that has states too behaviors is known every bit Object.
Ex: Pen, Chair, Table, Computer etc...
States / Properties of Dog object are color, height, weight etc... too behaviors moving, barking, jumping etc...
-------------------
Class:
Class is a template or designing from amongst objects are created.
A Class a grouping of objects that has mutual properties.
----------------
Method: An functioning on Object.
--------------------------------------------
i) Inheritance
Inheritance is a machinery inward which 1 object acquires all the properties too behaviors of rear object.
Using Inheritance nosotros tin create classes that are built upon existing classes.
When nosotros Inherit from an existing class, nosotros tin reuse methods too fields from rear shape too nosotros tin add together novel methods too fields also.
Java Supports:
a) Single Inheritance
b) Multi degree Inheritance
c) Hierarchical Inheritance
Note: Java doesn't back upward Multiple Inheritance.
--------------------------------------------------------
ii) Polymorphism
If a shape having multiple methods amongst same name, but dissimilar parameters is known every bit method overloading.
Method overloading increases the readability of the program.
There are 2 ways to overload the method inward Java
a) past times changing position out of arguments
Ex:
add (int a, int b)
add (int a, int b, int c)
b) past times changing information types
Ex:
add (int a, int b)
add (char a, char b)
In Object Oriented programming overriding agency to override the functionality of an existing method.
Method overriding provides a specific implementation of a method that is already provided past times its super shape (Parent class)
It is used for runtime polymorphism.
-------------------------------------------
Polymorphism
------------------
It is a concept past times which nosotros tin perform a unmarried inward dissimilar ways.
Polymorphism derived from 2 Greek discussion poly too morphs
Poly agency -many
morphs agency -forms / ways, thus polymorphism agency many forms.
we bring 2 types of Polymorphism inward java
a) Compile fourth dimension polymorphism
b) Runtime polymorphism.
We tin perform polymorphism inward coffee past times method overloading too method overriding.
--------------------------------------------------
iii) Abstraction
Abstraction is a physical care for of hiding the implementation details too showing functionality to the user.
Another way, it shows of import things to the user too hides internal details.
Ex: Sending email
you but type the electronic mail too send, yous don't internal physical care for of the electronic mail delivery.
Abstraction focuses on what the object does instead of how it does.
In 2 ways nosotros tin attain Abstraction
a) Abstract Class (0 to 100%)
b) Interface (100%)
--------------------------------------------------
iv) Encapsulation
Encapsulation is 1 of the 4 fundamental oops concepts, other 3 are Inheritance, Polymorphism too Abstraction.
Encapsulation is a physical care for of wrapping code too information together into a unmarried unit.
Ex: Capsule (mixed of several medicines)
It provides the command over the data, suppose nosotros desire to value of the id greater than 100 only, nosotros tin write the logic within the setter method.
------------------------------------------------------
Java packagesA Java packet is a grouping of similar type of classes, interfaces too sub-packages.
There are 2 types of coffee packages
a) Built inward packages
Ex: io, util, sql etc...
b) User defined packages
----------------------------------------------
Interfaces inward JavaAn interface is a collection of abstract methods.
An interface is non a class, writing an interface is similar to writing a class, but 2 are dissimilar concepts.
------------------------------------------------------
III) Selenium WebDriver
Selenium WebDriver Introduction:
> Selenium 1.0 (Selenium IDE + selenium RC + Selenium Grid)
> Selenium 2.0 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)
Note: Selenium WebDriver merged amongst Selenium 1.0
> It is a most of import tool inward Selenium suite.
> It is has programming interface allows us to create too execute Test cases against dissimilar browsers (ex: Firefox, IE, Google Chrome etc...)
> WebDriver supports diverse programming languages to heighten Test cases.
Java
.NET
PHP
Perl
Python
Ruby
> WebDriver supports diverse operating environments to create too execute Test cases(Ex: MS Windows, UNIX too Macintosh etc...)
> WebDriver supports Data Driven testing, cross browser testing.
> Webdriver is faster than other tools of Selenium suite.
> WebDriver supports Parallel examination execution amongst the aid of TestNG.
> WebDriver doesn't bring IDE, only Programming interface.
> WebDriver doesn't bring built inward Result reporting facility, it provides summary only.(* amongst the aid of TestNG nosotros tin generate HTML examination reports.)
> No object Repository inward selenium WebDriver (It is for entire Suite), thus no centralized maintenance of Objects)
Using Element locators, Webdriver methods too Java programming features nosotros tin create too execute Test cases.
Element Locators - to recognize / position Elements (Objects)
Webdriver Methods - to perform operations on Elements.
Java programming features - for Enhancing Test Cases.
Selenium Webdriver Environment Setup:
> Download too install Java (JDK) software - to heighten examination cases using Java programming features.
> Set Path surround variable- to access Java from whatever directory.
> Download Eclipse IDE too extract
> Download WebDriver Java Language binding too add together Webdriver jounce files (in Eclipse)
> Install Firebug too FirePath plug ins for Mozilla Firefox browser to inspect Elements.
Note 1: For Internet explorer too Google chrome, no postulate to install whatever plug ins, They bring built inward Developer tools.
Note 2: Element locators too WebDriver methods are mutual for all browsers, browser driver only varies from 1 browser to another.
Note 3: Firefox driver is default driver inward Webdriver, For IE too Chrome nosotros postulate to download drivers.
Download Selenium WebDriver Java binding from www.seleniumhq.org website too extract.
Navigation for adding Webdriver jounce files inward Eclipse.
> Create Java project
> Select src too correct click
> Build path
> Configure Build Path
> pick out Libraries tab
> Click "Add External JARs
> Browser path of the WebDriver jars
> Add
Pre-requisites to Create Automated Tests / Test Scripts / Test Cases
> Import WebDriver Libraries too Firefox driver/IE driver/Chrome Driver
> Using Web Element (object) locators too WebDriver methods write object telephone phone statements
> Insert Java programmatic statements to heighten Test cases.
Element Locators
Selenium supports 8 chemical element locators to position objects/elements on spider web pages.
We tin utilisation whatever 1 unique locator to position elements.
1) id
2) name
3) classname
4) tagName
5) linkText
6) partialLinkText
7) cssSelector
8) xpath
IV) TestNG Framework
TestNG Introduction
> In Selenium using Java at that topographic point are 2 Automation frameworks available:
i) JUnit
ii) TestNG
> TestNG is to a greater extent than powerful than JUnit framework.
> TestNG is an opened upward origin examination automation framework, where NG stands for Next Generation
> TestNG inspired from JUNit but introduced to a greater extent than or less novel functionality.
Benefits of TestNG:
> It generates HTML examination reports
> TestNG Annotations are slowly to create Test cases.
> Test cases tin endure grouped too prioritized to a greater extent than easily.
> Parallel Testing is possible
> Parameterization is possible.
Note: Using TestNG nosotros tin create Test cases, execute Test cases too generate reports inward HTML format.
Install TestNG:
In Eclipse IDE,
Help card -> Install New Software -> Click Add
-> Enter Name every bit "TestNG"
-> Enter URL every bit "http://beust.com/eclipse/"
-> Select TestNG
-> Next -> Next -> Accept the Agreement -> Finish
A Sample TestNG Program
public shape SampleTest {
@Test
populace void verifyTitle()
{
WebDriver driver = novel FirefoxDriver();
driver.get("http:/www.gmail.com");
String Actual = driver.getTitle();
Assert.assertEquals(Actual, "Gmail");
}
}
Create Multiple Test cases inward a Program/Class
TestNG examination cases tin endure executed inward alphabetical order, if yous desire to command the Test execution too thus utilisation Attributes.
public shape SampleTest {
@Test
populace void testA()
{
Assert.assertEquals("Google", "Google");
}
@Test
populace void testC()
{
Assert.assertEquals("Gmail", "Google");
}
@Test
populace void testB()
{
Assert.assertEquals("Yahoo", "Yahoo");
}
}
TestNG Annotations
@Test
@BeforeMethod
@AfterMethod
@BeforeClass
@AfterClass
@BeforeTest
@AfterTest
@BeforeSuite
@AfterSuite
@DataProvider
@BeforeGroups
@AfterGroups
@Parameters
@Factory
@Listeners
V) Selenium IDE
Selenium IDE Introduction:
> Selenium IDE (Integrated Environment) is a Tool, used to prepare Selenium Test Cases.
> It is Firefox plug in, industrial plant only on Firefox Browser.
> It provides Graphical user interface for Recording user actions using Firefox Browser.
> Firebug Add on is used to inspect elements.
> Selenium IDE should only endure used every bit a prototyping tool.
Note: We can't prepare complex Test cases using Selenium IDE.
Test Step inward Selenium IDE Test Case
Test Step Syntax:
Command + Target + value
Command - forms the functionality of the Test step
Target - Identifies the Element on the spider web page.
Value - Input information (This applicable only for few commands)
Example:
Type id=Email abcd123
Download Install Selenium IDE
> Using Firefox browser, download selenium IDE from the Seleniumhq.org website.
> Firefox volition protect yous from installing add together ons from unfamiliar locations, thus we volition postulate to click "Allow" to proceed amongst the installation.
> Install multiple items to back upward Java, Ruby, Python etc... formats.
> Restart Firefox browser.
> After Firefox reboots too thus nosotros tin utilisation Selenium IDE.
Features of Selenium IDE
Using Selenium IDE, nosotros can,
> Create Test cases too Test suites
> Open existing Test case
> Run Test illustration too Run Test suite.
> Export Test illustration inward a Language of our choice.
> Debug Test cases.
> Add Comments, Insert verification points.
Etc...
Drawbacks of Selenium IDE
> It supports Firefox Browser only, thus cross browser testing is non possible.
> No Flow command statements (Conditions too Loops)
> Parametrization is non possible.
> Not suitable for creating complex Test cases.
> Doesn't supply detailed examination reports, provides summary only.
> No Object Repository, thus no centralized maintenance of Objects(Elements)
Create Test cases inward Selenium IDE
By Recording Or Type steps using Selenese commands too chemical element locators.
Difference betwixt "assert" too "verify" Commands
> When an "assert" command fails too thus examination execution volition endure aborted.
> When a "verify" command fails too thus examination volition move past times away on execution too logging the failure.
VI) Selenium Grid
Selenium Grid Introduction:
> Selenium Grid is part of the Selenium project.
> Using Selenium Grid nosotros tin distribute examination execution across several machines.
> There are 2 top dog elements to Selenium Grid -- a hub, too nodes.
> First nosotros postulate to stand upward up a hub, too and thus yous tin connect (or "register") nodes to that hub. Nodes are where your tests volition run, too the hub is responsible for making certain your tests goal upward on the correct 1 (e.g., the machine amongst the operating scheme too browser yous specified).