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.
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.
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).
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.
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).
The documentation has already covered this. If you have any specific questions, feel free to edit your main post.
Official:
Unofficial: Do a Google search, you will get a lot info on this.
[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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With