Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Page Object Pattern in Selenium WebDriver? [closed]

What is page object pattern in Selenium WebDriver?

What is the use of it and how can we use this in Selenium WebDriver?

Example will be appreciated.

like image 430
bugCracker Avatar asked Aug 07 '13 03:08

bugCracker


People also ask

What is the page object pattern?

Page Object Model, also known as POM, is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and improves test case maintenance. In Page Object Model, consider each web page of an application as a class file.

What are the types of page object model in Selenium?

Page object model (POM) can be used in any kind of framework such as modular, data-driven, keyword driven, hybrid framework etc. A page object is an object-oriented class that serves as an interface to a page of your Application Under Test(AUT).

Why PageFactory is used in Selenium?

Introduction to PageFactory Class in Selenium The major benefit of the @FindBy annotation is that it lets you initialize page elements without using the FindElement (or FindElements) in Selenium. PageFactory class in Selenium also provides the initElements method for initializing the web elements.

How do you pass a driver in page object model?

static WebDriver driver; Use the same driver inside your @BeforeTest . So inside the before method, instead of doing WebDriver driver = new FirefoxDriver(); write like driver = new FirefoxDriver(); Do same for other browser types (ie, safari, chrome).


2 Answers

The documentation has already covered this. If you have any specific questions, feel free to edit your main post.

Official:

  • Page Objects and PageFactory on Selenuim Wiki.
  • Page Object Design Pattern on Selenium official site.

Unofficial: Do a Google search, you will get a lot info on this.

  • Page Object Pattern
  • Page Objects in Selenium 2.0
  • Selenium 2/WebDriver Quick Tips: Page Object Navigation Strategies
  • PageObject by Martin Fowler
like image 194
Yi Zeng Avatar answered Oct 20 '22 03:10

Yi Zeng


[Edited to respond to the reply below. And thanks, I'll do better.]

The purpose of the page object pattern is to completely encapsulate the testing interface to the web page. This follows the time-honored practice of data hiding.

Here's the Selenium article about the page object.

And here's my post "Keep Your Page Objects DRY".

like image 26
Burdette Lamar Avatar answered Oct 20 '22 03:10

Burdette Lamar