我知道如何在步骤定义链接中放置步骤:
[Binding]
public class PaymentPrerequisiteDefinitions : Steps
{
private readonly IWebDriver _driver;
public PaymentPrerequisiteDefinitions(IWebDriver driver)
{
_driver = driver;
}
[Given(@"the prerequisite steps before the payment page are successful for a holiday over 70 days)")]
public void GivenThePrerequisiteStepsBeforeThePaymentPageAreSuccessfulForAHolidayOverDays()
{
Given(@"I have a valid holiday to (*.)");
}
但我的问题是我想如何处理参数?我在这里反映的实际步骤定义是:
[Given(@"I have a valid holiday to (.*)")]
public void GivenINeedToReadInFlightData(string holidayFilter)
{
string selectedHoliday = _dataSource.GetFlightData(holidayFilter);
}
我遇到对象引用错误:
string selectedHoliday = _dataSource.GetFlightData(holidayFilter);
如果在我的嵌套给定语句(此问题中发布的第一个代码块)中,我将该行更改为:
Given(@"I have a valid holiday to Marjorca");
然后它工作正常,但我希望能够使用像实际给定语句的参数来允许动态目标。
如何实施?
答案 0 :(得分:0)
我们倾向于做#2(通常步骤包含许多干预步骤以使测试更具可读性),但偶尔我们会做#3,通常使用context injection来共享步骤之间的值。