我正在使用带有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
}
答案 0 :(得分:3)
根据我已经完成的一些研究,看起来有几种方法可以解决这个问题:
to LogoutPage
答案 1 :(得分:0)
将以下行添加到env.groovy中的After hook:
bindingUpdater.browser.clearCookies()