【发布时间】:2018-01-26 22:05:37
【问题描述】:
我正在使用 Fluent API 作为我在项目中进行的 Selenium UI 测试的一部分。
我读这篇文章是为了参考 fluent api Scott Lilly Fluent API。
目的是控制测试流程并使其尽可能具有可读性。
如图所示,我有一个简单的向导。
登录页面指向指向第二页的第一页(到目前为止一切都很简单),但问题从第二页开始,可以将您带回第一页或最后一页。
所以我想知道我应该返回什么来让用户两个选项,但只有那些选项?
我希望它看起来像这样:
DoLogin().WithText().FillForm().GoToSecondPage().FillForm().xxx
xxx = 在这里我希望有两个选项可以返回第一页或最后一页
到目前为止,它的代码看起来像这样:
public interface IFirstPage
{
void WithText();
IGoToSecondPage FillForm();
}
public interface ISecondPage
{
//Here starts the problem
//From this page you can go back to the first page or continue to the last page
Object FillForm();
}
public interface ILastPage
{
void SetSomething();
IGoToSecondPage FillForm();
}
public interface IGoToSecondPage
{
void GoToSecondPage();
}
public interface IGoToFirstPage
{
void GoToFirstPage();
}
public interface IGoToLastPage
{
void GoToSecondPage();
}
public class FirstPage : IFirstPage
{
public void WithText()
{
}
public IGoToSecondPage FillForm()
{
throw new System.NotImplementedException();
}
}
public class SecondPage : ISecondPage
{
public object FillForm()
{
throw new NotImplementedException();
}
}
【问题讨论】:
-
FirstPage和SecondPage是否有任何关联?可以创建另一个接口ILoggedInPage,它包含FirstPage和SecondPage使用的常用方法(或者它可以是一个空的占位符)。然后让FirstPage和SecondPage继承自ILoggedInPage,这样两个页面就有一个共同的祖先,你的返回类型可以是ILoggedInPage。
标签: c# selenium testing fluent method-chaining