I'm just starting out with BDD on a web project, using SpecFlow and WatiN to automate things through the browser, and I'm not quite sure how to write my steps.
I'm trying to drive everything from the tests, and in a TDD manner, not write anything unless it's needed to make a test pass. (I am also doing unit tests to drive the detail, but this question isn't about that). One thing I'm confused about is navigation between pages, and if/how this should be defined in the specs.
The first test involves entering some details and ensuring they get displayed in a list. My first attempt goes something like this:
Scenario: Add Details Option 1
Given I am on the "Home" page
When I click "Add Details"
And I enter "John Smith" in the Name field
And I click "Save"
Then "John Smith" appears in the list
However, this involves navigating between a couple of pages, so I don't know if that needs to be explicit - otherwise, I just have to assume I'm on the right page, or steps which are apparently unrelated to which page I'm on (for example, 'When I click Add Details') have assertions to check which page I'm on.
Do we check the pages with explicit steps in the scenario?
Scenario: Add Details Option 2
Given I am on the "Home" page
When I click "Add Details"
And I am on the "Add Details" page
And I enter "John Smith" in the Name field
And I click "Save"
And I am on the "Home" page
Then "John Smith" appears in the list
Or do we do it in the steps from option 1, just not mentioning it explicitly?
For example, Should clicking on 'Add Details' check that we end up on the right page?
public void WhenIClickAddDetils{
// syntax probably wrong, not important
Assert.That(IE.Button("AddDetails").exists);
IE.Button("AddDetails").click();
Assert.That(IE.PageTitle = "Add Details")); // do we check this here?
}
Or should we check we are on the right page before entering the details?
public void WhenIEnterDetils{
Assert.That(IE.PageTitle = "Add Details")); // do we check this here?
IE.TextField("Name").value = "John Smith";
// etc
}
Alternatively, we could start with
Given I am on the "Add Details" page
And just make that step include starting on the home page and clicking the 'Add Details button' in order to get to that page. Although this still leaves the same issue with navigating back to the Home page after we click 'Save'.
Any thoughts?