PageObject Design Pattern
The PageObject Design models areas of a UI as objects within test code. which considered as Object Repository for Web UI Elements PageObjects and PageFactory in C#.
PageObjects and PageFactory in C#
The classes in design represent a logical marriage between the web page application. Each class is known as a PageObjects. it comes back other PageObjects to do the movement between pages. Site Object school is responsible to find the WebElements of this web page. The carry methods which perform operations on those WebElements.
Benefits of using Page Subject Pattern:
- Easy to keep up
- Easy Readability of scripts
- Reduce or End duplicacy
- Re-usability of code
PageFactory in C#
The PageFactory in C# Course is an extension to the Web page Object Design Design. It is an inbuilt POM concept for Selenium WebDriver but it's very optimized. It initializes the components of the Page Subject or instantiates Page Objects itself. Annotations for elements created the explaining properties not be share subject from other. It employed to Initialize Components of a Page school and 'FindElement' or 'FindElements'. Annotations may supply descriptive titles of target objects to boost code readability.
@FindBy Annotation As the name suggests, it helps to get the elements in the web page using By strategy. @FindBy can accept TagName, PartialLinkText, Name, LinkText, Id, CSS, ClassName, XPath as attributes. An alternative device for seeking the factor or a list of elements. This enables users to create PageObjects. [FindsBy(How = How.Id, Using = "username")] private IWebElement UserName get; set; The code will create a PageObject and name it as UserName by finding it which consists of ID locator.
This Instantiate an example of the given school. This technique will attempt to instantiate the class directed at it. which takes a WebDriver occasion as its only debate or falling back over a no-arg. An exception thrown if the school can't instantiate. PageFactory.InitElements(WebDriver, PageObject); Parameters: WebDriver - The driver used to research the elements PageObjects - A course initialised PageFactory NameSpace PageFactory features resides in OpenQA.Selenium.Support.PageObjects.
How to Install PageFactory in Selenium Framework
Create Home Page Objects 1. Create a fresh Folder and name it as PageObjects. This doing Right Select OnlineStore in the Job Solution and choose Add >> New Folder. 2. Create a New Class document and send it as HomePage. This can be done by doing Right Select PageObjects folder in the Project Solution and choose Add >> .
Create LogIN Web page Objects
1. Create a New Class record and send it to the login page. 2. LogIn web page has three important things to add, which we could interest in using in the test
Write Test for LogIN Functionality
1. Create a New Class record in the TestCases folder and refer it as login test. Then make a Test method in it with [Test] annotation of NUnit Framework. 2. Write the test using HomePage & login page objects.
That type homePage in the test script and the moment press the dot, all the methods in the Home Page will screen. We are able to expose methods to reduce duplicated code. We're able to call these method many times. This will ensure a much better maintainable test code. We make changes and improvements particular place. Run the test from the Test Explorer and pageFactory initializes all the web page objects. That manage those objects to test to continued the execution.