Geb + Cucumber:在场景之间重新启动浏览器

时间:2012-12-31 02:51:34

标签: grails cucumber geb cucumber-jvm

我正在使用带有Cucumber和Geb的Grails 2.1.1。我有一个包含2个场景的Auth.feature。一个用于成功验证,另一个用于测试无效凭证。

我认为我必须解决这个问题的方法是让geb从第一个场景中注销用户,然后才能运行第二个场景。这是因为我的Given步骤检查以确保我在登录页面。方案1执行后,我在仪表板页面上。

我想我的问题是我是否(a)在完成方案之前使用geb签署有效用户,或者(b)是否有办法让方案在方案之间重新开始?

现在,我已经实现了(a)并且它工作得很好。只是想知道这是否是最佳的。

这是我的功能

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

这是我的Geb步骤

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
}

2 个答案:

答案 0 :(得分:3)

根据我已经完成的一些研究,看起来有几种方法可以解决这个问题:

  • 就像我已经在做的那样,通过在场景结束时退出(或者你可以在开始时这样做)
  • 登出自己的方案
  • 在env.groovy Before hook中,添加to LogoutPage
  • 使用背景退出

答案 1 :(得分:0)

将以下行添加到env.groovy中的After hook:

bindingUpdater.browser.clearCookies()
相关问题