What is the standard approach when applying the PageObjects pattern to components of a page?
For the sake of an example lets say I am writing tests for the Features on an Amazon product page.
That page contains a large number of separate features, Product Information, Customers who Viewed this, Other Customers Suggested etc etc.
Current examples I have seen for PageObjects really only cover how to deal with a single page that has limited functionality. What I am looking for is something along the line of a PageObject that would represent the Product page and then be composed 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 within a test I would access the control like so:
var productPage = ScenarioContext.Current.Get<ProductPage>();
Assert.That(productPage.ProductInformation.GetTitle(), Is.EqualTo("My Title"));
I've used this approach previously but with a custom framework built on top of Selenium that allowed for resolution of the child objects and their components. What I'm looking for is the approach to take with Selenium 2 and C# out of the box.