ASP.NET MVC, BDD, Specflow, and WatiN: Hosting an Application in a Specific State

I am new to BDD, Specflow and WatiN. I would like to use these acceptance test automation tools for my ASP.NET MVC application.

I already understood how to mainly use these tools, and I successfully built my first acceptance test: Register on the website.

Here is the Hunter for this test:

Feature: Log on to the web 
    As a normal user
    I want to log on to the web site

Scenario: Log on
    Given I am not logged in
    And I have entered my name in the username textbox
    And I have entered my password in the password textbox
    When I click on the login button
    Then I should be logged and redirected to home

Now I would like to write a bunch of other tests, and all of them require user authentication. For instance:

Feature: List the products 
    As an authenticated user
    I want to list all the products

Scenario: Get Products
    Given I am authenticated
    And I am on the products page
    When I click the GetProducts button
    Then I should get a list of products

What bothers me, to make this test independent of the others, I would have to write code to enter the website again. Is that the way? I doubt.

, . ? MVC ?

+5
2

, Gherkin:

Given I am signed in as user@domain.tld

, . "", , :

Given I am signed in as user@domain.tld using password "<Password>"

[Binding]
public class SignInSteps
{
    [Given(@"I am signed in as (.*)")]
    public void SignIn(string email)
    {
        SignInWithSpecialPassword(email, "asdfasdf");
    }

    [Given(@"I am signed in as (.*) using password ""(.*)""")]
    public void SignInWithSpecialPassword(string email, string password)
    {
        var nav = new NavigationSteps();
        var button = new ButtonSteps();
        var text = new TextFieldSteps();
        var link = new LinkSteps();

        nav.GoToPage(SignOutPage.TitleText);
        nav.GoToPage(SignInPage.TitleText);
        nav.SeePage(SignInPage.TitleText);
        text.TypeIntoTextField(email, SignInPage.EmailAddressLabel);
        text.TypeIntoTextField(password, SignInPage.PasswordLabel);
        button.ClickLabeledSubmitButton(SignInPage.SubmitButtonLabel);
        nav.SeePage(MyHomePage.TitleText);
        link.SeeLinkWithText("Sign Out");
    }
}

, , , .

, SpecFlow, BeforeScenario. :

Feature: List the products 
    As an authenticated user
    I want to list all the products

@GivenIAmAuthenticated
Scenario: Get Products
    Given I am on the products page
    When I click the GetProducts button
    Then I should get a list of products

[BeforeScenario("GivenIAmAuthenticated")]
public void AuthenticateUser()
{
    // code to sign on the user using Watin, or by reusing step methods
}

... MVC ?

MVC, , , , , cookie . , , , cookie auth . SF .

+4

, . Dan North Who Domain , , . , , danludwig, . .

, , " " .

+1

All Articles