【发布时间】:2016-01-11 14:31:26
【问题描述】:
我对 Geb 很陌生,但我遇到了一个奇怪的问题,文档似乎没有解决。我有一个非常简单的场景要测试:以管理员身份登录,打开应用程序,验证主页上是否出现“应用”按钮。然后关闭应用程序并确认该按钮已从主页中消失。我可以成功手动执行此测试,并且服务器端没有任何东西(缓存明智)阻止此成功但是当我通过 Gradle 运行测试时它失败了,因为在“关闭”之后按钮仍然显示在主页上测试。请注意,该测试还会验证配置是否以正确的值保存。
这是我的测试代码:
def "can open applications"(){
when:
to ManageConfigPage
and:
configFormModule.toggleApplications(true)
then:
at ManageConfigPage
assert $('#messages').text() == "Config successfully updated"
assert $('td', text: 'config.application_closed').closest('tr').find('input').value() == "0"
then:
to HomePage
assert applyButton
}
def "can close applications"(){
when:
to ManageConfigPage
and:
configFormModule.toggleApplications(false)
then:
at ManageConfigPage
assert $('#messages').text() == "Config successfully updated"
assert $('td', text: 'config.application_closed').closest('tr').find('input').value() == "1"
then:
to HomePage
assert !applyButton
}
applyButton 内容定义如下:
applyButton(cache: false, required: false){ $('#apply_button') }
我还尝试在测试中直接使用选择器,而不是在内容定义中使用,但这也不起作用。
那么这里发生了什么?主页是否被全部缓存?如果是这样,我该如何防止或刷新它?这看起来像 Geb 101,但手册并没有真正解决这个问题。
编辑:添加测试结果以确保完整性:
条件不满足:
!applyButton || |applyButton - SimplePageContent(所有者:主页,参数:[],值:null) 假的
at AdminSpec.can close applications(AdminSpec.groovy:59)
【问题讨论】: