我正在将 Specflow 与页面对象一起使用,并且我有很多非常相似的场景。例如:
Given I view the 'page1'
When I click 'link1'
Then I should be on 'page2'
Given I view the 'page1'
When I click 'link2'
Then I should be on 'page3'
我正在努力了解如何为“单击时...”步骤进行一步绑定。如果我遵循页面对象模式,我应该始终返回在“那么我应该...”步骤中导航到的特定页面对象。
我有一个基本步骤定义类,其中包含一个存储当前页面对象的属性。
public class BaseStep : Steps
{
protected RemoteWebDriver Driver {
get
{
return ScenarioContext.Current.Get<RemoteWebDriver>();
}
set
{
ScenarioContext.Current.Set(value);
}
}
protected BasePageObject CurrentPageObject
{
get
{
return ScenarioContext.Current.Get<BasePageObject>();
}
set
{
ScenarioContext.Current.Set(value);
}
}
}
我不想为每个场景编写一个步骤定义,因为它重用了很多我宁愿在一个方法中使用的代码。那么如何重用步骤定义并仍然使用页面对象模式呢?
谢谢。