开发者

Confused about my Gherkin - navigation between web pages

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 ju开发者_运维知识库st 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?


I would say that you do not have to check it in this scenario. Basically, the test is Given-When-Then (arrange-act-assert), and And I am on the "Add Details" page is actually a Then (assert) inside When (act), which does not look right to me.

My gut feeling is that it should look like this instead:

Scenario: Add Details directs to "Add Details" page

Given I am on the "Home" page
When I click "Add Details"
Then I am on "Add Details" page


Scenario: "Add Details" adds person to the list

Given I am on the "Add Details" page
And I enter "John Smith" in the Name field
And I click "Save"
Then I am on the "Home" page
And "John Smith" appears in the list
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜