Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
574 views
by
Hi All,

I frequently hear the team Page Object Model (POM).

Can you tel me what it is? And how it is being used in Software Testing?

5 Answers

1 like 0 dislike
by
Page object modal is a framework .

Which is known for easy maintainability , flexible for scripting . With use of page object modal tester can easily make changes in scripts on one change only .

As selenium don't have object repository feature inbuilt but page object modal gives that feature to selenium testers .

Structure of page object model is - in one java class ( object repository ) all object of web pages would be stored and in another class ( test case ) objects would be used .

Suppose we have used same object in 30 classes and java script developer changed the object property  in that case we only need to change the object property in object repository class .
0 like 0 dislike
by

Page Object Model (POM) is a design pattern that is very popular in the test automation field. 

You basically create a class that serves as an interface to the page you are testing in your app. For example, if you test the login page of your app, you should create a new class that will find the elements in that page and creates some utility functions to work with those elements. The actual test logic will be in a different class.

I think you will find these articles useful: 

  1. https://blog.testproject.io/2016/09/06/test-automation-selenium-page-object-model-page-factory/
  2. https://blog.testproject.io/2018/12/18/net-core-test-automation-selenium-page-object-page-factory/
  3. https://blog.testproject.io/2018/07/31/page-object-model-appium-java-android/
0 like 0 dislike
by New User (11 points)

Page Object Model Multi-Layer Structure:

1. First layer– consists of the driver layer which could be either Appium or Selenium and the implementation of methods and logic we don’t change often (such as cross browser supportreporting moduledata driven implementation).

2. Second layer-  can be a library code that is built on top of the driver layer (Appium or Selenium), good examples for such are: Robot framework and Selenide. These layers are used to hide any complex actions as waits, page elements validations and more.

3. Third layer- the third layer could be used by the test automation developer for any complexes action that can come on top of the first or second layer. For example, after utilizing the wait function and validation in the second layer, we’ll be able to add several other actions such as calls to externals libraries or any other specific logic.

4. Fourth layer- we’ll be able to easily call actions we established in the third layer creating functional test cases and will eventually become our testing layer.

Next, I would like to demonstrate a basic example of page abstraction using page object model in C#:

Page abstraction using page object model in C#

First, we’ll create a class named Page and connect a builder to it which will receive the driver and the time frame which will be the upper limit for all ‘waits’ in our test implementation.

  1. public class Page
  2. {
  3. private IWebDriver driver;
  4. private TimeSpan defaultTimeSpan;
  5.  
  6. public Page(IWebDriver driver, TimeSpan defaultTimeSpan)
  7. {
  8. this.driver = driver;
  9. this.defaultTimeSpan = defaultTimeSpan;
  10. }
  11. }

Now, we will implement the locators which are the methods for identification, and the same object that Selenium uses to identify elements. Overall, we’ll have 8 different types of locators (read more about determining element locators).

  1. By.Id
  2. By.Name
  3. By.ClassName
  4. By.TagName
  5. By.LinkText
  6. By.PartialLinkText
  7. By.CssSelector
  8. By.XPath

‘By’ is the object also called the locator and the implementation will look as follows:

  1. private By ByLocator(string element, Locator locator)
  2. {
  3. switch (locator)
  4. {
  5. case Locator.Id:
  6. return By.Id(element);
  7. case Locator.Name:
  8. return By.Name(element);
  9. case Locator.TagName:
  10. return By.TagName(element);
  11. case Locator.ClassName:
  12. return By.ClassName(element);
  13. case Locator.LinkText:
  14. return By.LinkText(element);
  15. case Locator.PartialLinkText:
  16. return By.TagName(element);
  17. case Locator.XPath:
  18. return By.XPath(element);
  19. case Locator.CssSelector:
  20. return By.CssSelector(element);
  21. default:
  22. throw new Exception("No Locator Found");
  23. }

Next we’ll implement the ‘Find’ method which will be the base for several locations later on (using the ByLocator method we created earlier):

  1. public IWebElement Find(string element, Locator locator)
  2. {
  3. return driver.FindElement(ByLocator(element, locator));
  4. }

We will continue implementing the rest of the methods (while utilizing the Find method)

  1. public Page Fill(string element, string value, Locator locator)
  2. {
  3. Find(element, locator).Clear();
  4. Find(element, locator).SendKeys(value);
  5. return this;
  6. }
  1. public Page WaitUntil(Func<IWebDriver, TResult> condiction)
  2. {
  3. new WebDriverWait(driver, this.defaultTimeSpan).Until(condiction);
  4. return this;
  5. }
  1. public Page NavigateTo(string url, string proofElement, Locator locator)
  2. {
  3. driver.Navigate().GoToUrl(url);
  4. new WebDriverWait(driver, this.defaultTimeSpan)
  5. .Until(d => d.FindElement(ByLocator(proofElement, locator)));
  6.  
  7. return this;
  8. }

In the top layer, we will initialize the methods same as ‘Fill’, while sending the required arguments (these arguments come from the same tester as a part of the automated test). Nonetheless, the test automation engineer which creates the test case scenario, is unfamiliar with the complexity of the Fill method which itself uses other methods.

Please note: the example presented above, does not represent a classic case of an Abstract Class in which we are declaring methods and making sure to implement in inherited classes, but another method to use abstraction over pages.

0 like 0 dislike
by Contributing Tester (49 points)

Page Object Model is a design pattern that is extensively used by the Selenium community for automation tests. The basic design principle that the Page Object Model in Selenium C# follows is that a central object repository should be created for controls on a web page. Hence, each web page will be represented by a separate class.
The Page Objects (or page classes) contain the elements of the corresponding web page along with the necessary methods to access the elements on the page. Hence, Selenium test automation implementation that uses the Page Object Model in Selenium C# will constitute different classes for each web page thereby making code maintenance easier.
For example, if automation for a login page & check-out page is to be performed, our implementation will have a class each for login & check-out. The controls for the login page are in the ‘login page’ class and controls for the check-out page are in the ‘check out page’ class.
The Selenium test automation scripts do not interact directly with web elements on the page, instead, a new layer (i.e. page class/page object) resides between the test code and UI on the web page.
In complex Selenium test automation scenarios, Selenium test automation scripts based on Page Object Model can have several page classes (or page objects). It is recommended that you follow a common nomenclature while coming up with file names (representing page objects) as well as the methods used in the corresponding classes.

Sourcehttps://bit.ly/31x7FNI

0 like 0 dislike
by Contributing Tester (95 points)

The page object model is an object design pattern in Selenium test automation used to make a repository of Web UI elements. POM improves test readability and reduces code duplication, by acting as an interface for the page under test. In the Page object model, all the webpages have individual page classes. These page classes find the web elements on the page and contain all the relevant page methods.

clickLoginButton();  
enterCredentials(user_name,user_password);  
checkIfImageIsDisplayed();  

So, while performing Selenium test automation, the test case uses the object of this Page class to call the various methods to perform actions on the web page. Since all the web elements related to a page are present at a common location, it becomes easy to implement Selenium Java testing routines, and update them when required.

Informative Source: Selenium Java Testing: Page Object Model


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...