我在测试Grails应用程序的身份验证时遇到了问题。浏览器似乎不接受cookie,所以我创建了一个简单的grails应用程序作为测试。
<html>
<head>
<title>Welcome to Grails</title>
</head>
<body>
<g:each in="${request.cookies}">
<h1>${it.name} = <span class="value">${it.value}</span></h1>
</g:each>
<span class="value">test test</span>
</body>
我的Geb测试:
import spock.lang.Stepwise;
import geb.Page;
import geb.spock.GebReportingSpec
@Stepwise
class LoginSmokeTests extends GebReportingSpec {
String getBaseUrl() {
return "http://localhost:8080/test123/"
}
def "testing stuff"() {
given:
to HomePage
when:
println header
then:
at HomePage
}
}
class HomePage extends Page {
static at = { title == "Welcome to Grails" }
static content = {
header { $("span.value").first().text() }
}
}当我通过浏览器查看时,将打印两个cookie的值。当通过我的Geb测试访问它时,会捕获<span class="value">test test</span> HTML --因为请求中没有需要迭代的cookies。
我已经对如何使用Geb +cookie做了一些搜索,但是由于它是一个相对较新的软件,似乎没有太多的信息(尽管它的手册很棒)。
但是,每个测试方法都会创建一个新的浏览器实例,因为默认行为是在浏览器实例中重用默认驱动程序,因此驱动程序的cookie将在
清理()方法中清除。但是,如果您的规范是逐步的(即用@spock.lang.Stepwise注解--请参阅Spock中的详细信息),cookies不会在cleanupSpec()中被清除,而是在cleanupSpec()中被清除,这意味着浏览器状态不会在测试方法之间重置(这对于逐步规范来说是有意义的)。
而且,我只执行一种测试方法--但是没有发送cookie。有什么想法吗?
发布于 2010-12-13 03:17:03
因为这是您的第一个请求,所以浏览器不会有任何cookie,因为服务器没有发送任何cookie。
如果您执行后续请求,您应该会看到cookie。
https://stackoverflow.com/questions/3814954
复制相似问题