【问题标题】:Geb Test DOM Element Exists And Then Is Removed On Next Page LoadGeb 测试 DOM 元素存在,然后在下一页加载时被删除
【发布时间】: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)

【问题讨论】:

    标签: gradle spock geb


    【解决方案1】:

    按钮元素是没有包含在 html 中还是只是被隐藏了?如果它是隐藏的,那么您需要检查它是否没有显示:

    !applyButton.displayed
    

    【讨论】:

    • 我在移动到该页面之前添加了一个 sleep(5000) 并且它按预期工作。这不应该是必要的,但它确实有效。
    猜你喜欢
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    相关资源
    最近更新 更多