Question

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.

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.

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?

Right now, I've implemented (a) and it works just fine. Just want to know if this is optimal.

Here is my feature

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

And here is my Geb steps

Given(~'^I access the login page$') {->
  to LoginPage
  at LoginPage
}

When(~'^I enter valid credentials$') {
  page.add('user_10001@test.com', '10001')
}

Then(~'^I see the dashboard$') {->
  at DashboardPage
}

Then(~'^I see an error message on the login page$') { ->
  at LoginPage
}

When(~'^I enter invalid credentials$') { ->
  page.add('baduser', 'paddpassword')
}

Then(~'^I see appropriate error messages$') { ->
  at LoginPage
  // check for error message
}
Était-ce utile?

La solution

Based on some more research I've done, it looks like there are a few ways to handle this:

  • Just like I am already doing it, by logging out at the end of a scenario (or you could do it at the beginning
  • Make logging out its own scenario
  • In the env.groovy Before hook, add to LogoutPage
  • Logout using a Background

Autres conseils

Add the following line to the After hook in env.groovy:

bindingUpdater.browser.clearCookies()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top