Geb + Cucumber:在情景之间重新启动浏览器 [英] Geb + Cucumber: Restart Browser Between Scenarios

查看:362
本文介绍了Geb + Cucumber:在情景之间重新启动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Grails 2.1.1与Cucumber和Geb.我有一个Auth.feature,包含2个方案。一个是成功验证,另一个是用于测试无效凭据。

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.

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

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.

我想我的问题是我(a)使用geb签出有效的用户,

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?

现在,我已经实现了(a),它工作正常。

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

这是我的功能

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
}


推荐答案

根据我做过的一些更多的研究,看起来有几种方法来处理:

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


  • 就像我已经在做的一样,通过在场景结束时注销(或者你可以在开始时注销)

  • 记录自己的场景

  • 在env.groovy之前,将添加到LogoutPage

  • 使用背景注销

  • 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

这篇关于Geb + Cucumber:在情景之间重新启动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆