Skip to main content

Selenium Page Object Automation Framework Using Java

 

Selenium Page Object Automation-Framework

Selenium page object automation framework using java & Maven & TestNG & Extent Report


Page Object Model (POM) : Design pattern.

The Page Object Design Pattern provides the following advantages:

  • There is a clean separation between test code and page specific code such as locators (or their use if you’re using a UI Map) and layout.
  • There is a single Object repository for the services or operations offered by the page rather than having these services scattered throughout the tests.

ExampleHomePage,Login Page are object repository 

Page Factory : 

Page Factory is a class provided by Selenium WebDriver to support Page Object Design patterns. In Page Factory we have @FindBy annotation. The  PageFactory.initElements method is used to initialize web elements.


@FindBy can accept tagName, partialLinkText, name, linkText, id, css, className, xpath


 @FindBy(xpath = "xpath")

 @FindBy(tagName = "tagName")


Example : BasePageClass is used to initialize web elements.


Repository  : https://github.com/Ashishjublsdet/Selenium-PageObject-Java-AutomationFramework

Steps to Setup

1. Clone the application

git clone 

2. Import project in any Editor(Eclispe/Intellij)

3. Run test.xml

Project Structure

Package & Classes Details

actionHelper : In this package common web functions is present
WebActionHelperMethods : All the common web functions is present in this class like click(),Scroll(),Enter() etc.
driverManager : In this package We are handling drivers initialization on the basis of browser
DriverManagerType : We have create an enum for Driver types and its definations
Webdrivers : In this class we are creating driver object on the Basis of DriverType  like DriverManagerType.CHROME,DriverManagerType.firefoxdriver
listners : In this package we are using TestNg ITestlistner for creating report on the basis of Test result
TestListner :In order to listen to test events such as passed, failed, skipped, etc. we have TestListener class which implements ITestListener.
**onFinish:** This method is invoked after all tests methods gets executed.

**onTestStart:** This method is invoked before any test methods are invoked. This can be used to indicate that the particular test method has been started.

**onTestSkipped:** This method is invoked when each test method is skipped. This can be used to indicate that the particular test method has been skipped.

**onTestSuccess:** This method is invoked when any test method succeeds. This can be used to indicate that the particular test method has successfully finished its execution.

**onTestFailure:** This method is invoked when any test method fails. This can be used to indicate that the particular test method has failed. You can create an event for taking a screenshot which will show where the test has been failed.
reportManager : In this package we are using Extent report for reporting testCases
ExtentManager :In this class we are using Extent api and  initialization of Extent object 
Pages : In this package all the pages of application is present.
BasePageClass :In this class we have initialize all the page classes using PagePafctory conecepts(PageFactory.initElements)
HomePage,Login Page :In this class we have all the locators and associated methods.
TestCases : In this package all the TestCases is present.
BaseTest :In this class we have initialize drivers and all the pages.

Comments

Popular posts from this blog

Handle radio button & Check Boxes in Selenium

The main difference between Radio button and Checkbox is that, using radio button we will be able to select only one option from the options available. whereas using checkbox, we can select multiple options. Selenium WebDriver supports Radio Button and Radio Group controls using the WebElement class. We can select and deselect the radio buttons using the click() method of the WebElement class and check whether a radio button is selected or deselected using the isSelected() method. Before performing the click on the Radio buttons or check boxes we will have to verify follwing scenarios :- If Radio button or Checkbox is displayed on the webpage If Radio button or Checkbox is enabled on the webpage Check the default selection of the Radio button or Checkbox We use predefined methods present in selenium to handle check Box and Radio  button :- isDisplayed() isEnabled() isSelected() 1.  isDisplayed () this method returns a Boolean value, if it returns t

How To Send Report In Mail Using Java In Selenium Web driver

Today we will share code how to send any type of selenium report in mail using java. For sending the email using JavaMail API, you need to load the two jar files: mail.jar activation.jar package SeleniumNew; import java.util.Properties; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.mail.*;  import javax.mail.internet.*;  public class SendEmail {     public static void main(String[] args)     {                 String host="smtp.gmail.com";          final String user="ashishxx@gmail.com";//change accordingly          final String password="XXX";//change accordingly                    /*String[] to={"AshishXX@gmail.com","Ashishxxx@gmail.com"};           String[] cc={};           String[] bcc={};         */           String to="ashishxx@gmail.com";//change accordingly                     //Get the session object            Properties props = new

Appium architecture (How Appium works internally)

Appium Architecture  A ppium is a cross-platform automation tool, API of it supports both OS (Android and iOS) test scripts.It is tested on simulators (iOS,), emulators (Android), and real devices (iOS, Android)   Appium is an HTTP server written in Node.js that creates and handles WebDriver sessions.The Appium web server follows the same approach as the Selenium WebDriver, which receives HTTP requests from client libraries through JSON and then handles those requests in different ways   JSON wire protocol The JSON wire protocol  ( JSONWP ) is a transport mechanism created by WebDriver developers. This wire protocol is a specific set of predefined, standardized endpoints exposed via a RESTful API.   Appium implements the Mobile JSONWP, the extension to the Selenium JSONWP, and it controls the different mobile device behaviors, such as installing/uninstalling apps over the session Let’s have a look at some of the endpoints from the API which are used to interact with