将PageObjects模式应用于页面的组件时,标准方法是什么?
为了举例,假设我正在为Amazon产品页面上的功能编写测试。
该页面包含大量独立的功能、产品信息、查看此页面的客户、其他客户建议等。
我目前看到的PageObjects示例实际上只涵盖了如何处理功能有限的单个页面。我正在寻找的是沿着PageObject的线,将代表产品页面,然后由代表每个组件的ComponentObjects组成的东西。
例如:
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;
}
}
}然后在测试中,我会像这样访问控件:
var productPage = ScenarioContext.Current.Get<ProductPage>();
Assert.That(productPage.ProductInformation.GetTitle(), Is.EqualTo("My Title"));我以前使用过这种方法,但是使用了一个构建在Selenium之上的自定义框架,该框架允许解析子对象及其组件。我正在寻找的是将Selenium 2和C#开箱即用的方法。
发布于 2016-11-15 17:16:10
没有开箱即用的方法可以做到这一点。您的方法非常好,您可以通过使用IElementLocator和IPageObjectMemberDecorator的自定义实现调用PageFactory.InitElements()来实现它。请参阅此答案:How to initialize SelectElements while using PageFactory / FindsBy in Selenium C#?
https://stackoverflow.com/questions/12815145
复制相似问题