【问题标题】:What's the correct way to close and open the browser within a Geb test?在 Geb 测试中关闭和打开浏览器的正确方法是什么?
【发布时间】:2013-08-22 15:34:05
【问题描述】:

我使用 Geb 进行了以下 Spock 测试:

def "The session should expire when the browser is closed."() {
    given:
    to LoginPage

    expect:
    waitFor { at LoginPage }

    when:
    auth.login(Constants.USERNAME)

    then:
    waitFor { at DashboardPage }

    when:
    browser.close()
    // ???
    to SetupAccountPage //fails with SessionNotFoundException: Session ID is null

    then:
    waitFor { at LoginPage }
}

在测试中关闭和重新打开浏览器的正确方法是什么?
顺便说一句 - 我知道 this question,但我不想手动显式注销或清除 cookie,因为这是该测试正在验证的内容。

【问题讨论】:

  • 设置一个查看about:blank,然后查看to BlankPage ; to SetupAccountPage 而不是browser.close() 的页面是否有效?
  • 谢谢蒂姆。不,它不起作用...会话 cookie 没有被删除,因此测试失败,因为用户不需要重新验证。
  • 啊,是的......抱歉没有完全投入大脑:-(

标签: groovy functional-testing spock geb


【解决方案1】:

添加您的测试,用于保存会话 cookie。

autoClearCookies = false

link

【讨论】:

  • 这个测试是为了验证关闭浏览器会清除cookies...我看到的问题是浏览器关闭后测试无法继续。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-22
  • 2020-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-31
  • 1970-01-01
相关资源
最近更新 更多