这就是我所拥有的
Feature: Register a new customer
As a user
I need to be able to register myself
so that I can place orders
Scenario: Register a new customer with Valid information
Given I fill in valid customer information
When I press submit
Then I should be notified that I'm registered
Scenario: Register a new customer with Invalid information
Given I fill in invalid customer information
When I press submit
Then I should be notified it was invalid
问题是我重复了 When 两次,但我没有看到解决方法,我需要做的是弄清楚如何在 2 个场景中正确设置它,还是我没有正确看待这个?
这是 Step 定义,但它们对我来说似乎不正确,因为我必须将所有这些都放在同一个 Steps 类中才能运行。在我看来阅读不正确。当我将这两个分开并将它们放在自己的 step 类中时,我得到了错误:
binding error: Ambiguous step definitions found for step 'When I press submit':
[Binding]
public class RegisterAValidCustomerSteps
{
private RegisterCustomerViewModel _registerCustomerVm;
[Given(@"I fill in valid customer information")]
public void GivenIFillInValidCustomerInformation()
{
// use the ViewModel to represent the User interacting with the View
_registerCustomerVm = new RegisterCustomerViewModel();
_registerCustomerVm.FirstName = "Mark";
_registerCustomerVm.LastName = "W";
_registerCustomerVm.Email = "mark@whatever.com";
}
[Given(@"I fill in invalid customer information")]
public void GivenIFillInInvalidCustomerInformation()
{
// simulate possible invalid name by missing the Last Name
_registerCustomerVm = new RegisterCustomerViewModel();
_registerCustomerVm.FirstName = "Mark";
_registerCustomerVm.Email = "markl@whatever.com";
}
[When(@"I press submit")]
public void WhenIPressSubmit()
{
_registerCustomerVm.Submit();
}
[Then(@"I should be notified that I'm registered")]
public void ThenIShouldBeAbleToPlaceOrders()
{
_registerCustomerVm.MessageText.ShouldBe("Success! Check your inbox for confirmation");
}
[Then(@"I should be notified it was invalid")]
public void ThenIShouldBeNotifiedItWasInvalid()
{
_registerCustomerVm.MessageText.ShouldBe("Failure! Last Name can't be blank.");
}
}