Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8017087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:44:12+00:00 2026-06-04T20:44:12+00:00

I’m new to BDD, Specflow and WatiN. I would like to use these tools

  • 0

I’m new to BDD, Specflow and WatiN. I would like to use these tools to automate acceptance tests for my ASP.NET MVC application.

I’ve already figured out how to basically use these tools, and I successfully built my first acceptance test: Log on to the website.

Here is the Gherkin 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 they all require the user to be authenticated. For example:

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 bugs me is that to make this test independent of the others, I’d have to write code to log on the website again. Is this the way to go? I doubt.

I’m wondering if there are best practices to follow for testing scenarios like that. Should I keep the browser open and have the tests run in a specific order, on the same browser? Or should I put the MVC application in a specific state?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:44:14+00:00Added an answer on June 4, 2026 at 8:44 pm

    For this, we have a specific Given step, that looks something like this in Gherkin:

    Given I am signed in as user@domain.tld
    

    Like you mentioned, this step basically reuses other steps to sign in the user. We also have an “overload” that takes a password, in case the test user has a non-default test password:

    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");
        }
    }
    

    I think this is the best approach, since you should not be able to guarantee that all of the tests run in a specific order.

    You may also be able to do this with a SpecFlow tag though, and have that tag execute BeforeScenario. That might look something like this:

    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
    }
    

    …should I put the MVC application in a specific state?

    When signing in users, it’s not the MVC application that needs to be put into a specific state, but rather the browser that needs to be put into a specific state — namely, writing the authentication cookie. I’m not sure if you can do this or not, given that the auth cookie is encrypted. I always found it easier to just let SF walk though the authentication steps at the beginning of each scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.