InterviewSolution
| 1. |
What is Page Factory? |
|
Answer» Page Factory class in selenium is an extension of the Page object design pattern. Page Factory is an inbuilt concept that provides an optimized way to implement the Page Object Model. Here optimization is, it refers to the fact that the memory utilization is very good and ALSO the implementation is done in an object-oriented manner. It is used to initialize the elements on the Page Object or instantiate the Page Objects. Annotations for elements can be created and recommended as the describing properties may not always be descriptive enough to differentiate one object with the other. Here the concept of separating the Page Object Repository and Test Methods is followed. Instead of using ‘FindElements’, here we use annotations like @FindBy to find WebElement, and the initElements method to initialize web elements from the Page Factory class. It makes handling "Page Objects" easier and optimized by providing the @FindBy ANNOTATION and initElements method. @FindBy annotation - can accept attributes tagName, partialLinkText, name, linkText, id, CSS, className & XPath and is used to locate and declare web elements using different locators. Example - @FindBy(id="elementId") WebElement element; initElements() - is a static method of PageFactory class used in conjunction with @FindBy annotation. Web elements located by @FindBy annotation can be initialized using the initElements method. Example - initElements(WebDriver driver, java.lang.Class pageObjectClass) |
|