Selenium PageObjects Model and Components

What is the standard approach when applying the PageObjects template to page components?

For example, let's say that I write tests for functions on the Amazon product page.

This page contains a large number of individual functions, product information, customers who have considered this, other customers offered, etc. etc.

The current examples I've seen for PageObjects really only cover how to work with one page with limited functionality. What I'm looking for is something like a PageObject line that will represent the Product page, and then consists of ComponentObjects that represent each component.

eg:

public class ProductPage { [FindsBy(How = How.Id, Using = "productInformation")] public ProductInformationControl ProductionInformation{get;set} [FindsBy(How = How.Id, Using = "customersViewed")] public CustomersAlsoViewedControl CustomersAlsoViewed{get;set} [FindsBy(How = How.Id, Using = "customersSuggested")] public CustomersSuggestedControl CustomersSuggested{get;set} } public class ProductInformationControl { //Ideally the FindsBy here would find the element based on the Controls context // So only resolving to an element that was within the context of this control. [FindsBy(How = How.ClassName, Using = "title")] private IWebElement _title; public string Title { get { return _title.Text; } } } 

Then, as part of the test, I would gain access to the control as follows:

  var productPage = ScenarioContext.Current.Get<ProductPage>(); Assert.That(productPage.ProductInformation.GetTitle(), Is.EqualTo("My Title")); 

I used this approach earlier, but with a custom structure built on top of Selenium, which allowed resolving child objects and their components. What I'm looking for is an approach that you can take with Selenium 2 and C # out of the box.

+4
source share
1 answer

Impossible to do this. Your approach is very good, you can implement it by calling PageFactory.InitElements () with a custom implementation for IElementLocator and IPageObjectMemberDecorator See This Answer: How to initialize SelectElements when using PageFactory / FindsBy in Selenium C #?

0
source

Source: https://habr.com/ru/post/1438835/


All Articles