41K Views

page refr

As we know that in creating of selenium test cases can result in an un-maintainable project. one of reason is that too many duplicated codes used. Duplicate code could be caused by duplicated functionality and this will result in duplicate use of locators. The disadvantage of duplicated code is that the project is less maintainable. If some locator will get change we have to walk through whole code to adjust locator where necessary. By using page object pattern using pagefactory we can reduce duplicate test code, and also it improve readability of test code. Implementaion of page object model created by writing seperate  test object and test script.

Advantage of  using Page Object Pattern
  • Easy to maintain Test scripts
  • It improve readability of scripts
  • Re-usability of code
  • Reduce or Eliminate duplicacy
How to implement Page Object Model

There are two different ways of implementing pom:

1) Regular java classes: Please visit Page Object Model

2) Page Factory class:  Please follow  the article

Selenium PageFactory

In PageFactory we use Annotations and it is like

@FindBy(id = “Username”)

public WebElement EnterUsername;

As i told above that PageFactory contains all the elements of webpage at start when we initalize any page class objects. In PageFactory we call a method on the webelement, the driver will go and find it on the current once again.

Divide the single PageFactory Objects in to different Page Classes

1. Create a ‘New Package‘ file and name it as ‘pageObjects’, by right click on the Project and select New > Package.

2. Create  ‘New class‘ file for Home Page & LogIn Page and  select New > Class. In our case it is Home Page and LogIn Page.

Home Page Class

As in below code i explain  in Shopify Store how customer will create ticket regarding his query related to any products.

LogIn Page Class

Test Case

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php