title: Geb + Cucumber: Restart Browser Between Scenarios
body: <p>I'm using Grails 2.1.1 with Cucumber and Geb.  I have an Auth.feature that contains 2 scenarios.  One is for authenticating successfully and the other is for testing invalid credentials.</p>
  
  <p>The way I think I have to work this out is to have geb log out the user from the first scenario before it can run the second scenario.  This is because my Given step checks to make sure I'm at the login page.  After scenario 1 executes, I'm on a Dashboard page.</p>
  
  <p>I guess my question is do I (a) use geb to sign out the valid user before completing the scenario or (b) is there a way to have it start over between scenarios?</p>
  
  <p>Right now, I've implemented (a) and it works just fine.  Just want to know if this is optimal.</p>
  
  <p>Here is my feature</p>
  
  <pre><code>Feature: login to system
    As a user of the system
    I want to log in to the application
    so that I can use it
  
    Scenario: login
      Given I access the login page
      When I enter valid credentials
      Then I see the dashboard
  
    Scenario: auth fail
      Given I access the login page
      When I enter invalid credentials
      Then I see appropriate error messages
  </code></pre>
  
  <p>And here is my Geb steps</p>
  
  <pre><code>Given(~'^I access the login page$') {-&gt;
    to LoginPage
    at LoginPage
  }
  
  When(~'^I enter valid credentials$') {
    page.add('user_10001@test.com', '10001')
  }
  
  Then(~'^I see the dashboard$') {-&gt;
    at DashboardPage
  }
  
  Then(~'^I see an error message on the login page$') { -&gt;
    at LoginPage
  }
  
  When(~'^I enter invalid credentials$') { -&gt;
    page.add('baduser', 'paddpassword')
  }
  
  Then(~'^I see appropriate error messages$') { -&gt;
    at LoginPage
    // check for error message
  }
  </code></pre>