Geb:在测试之间等待/睡觉 [英] Geb: Waiting/sleeping between tests

查看:21
本文介绍了Geb:在测试之间等待/睡觉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Is there a way to wait a set amount of time between tests? I need a solution to compensate for server lag. When creating a record, it takes a little bit of time before the record is searchable in my environment.

In the following code example, how would I wait 30 seconds between the first test and the second test and have no wait time between second test and third test?

    class MySpec extends GebReportingSpec {
        // First Test
        def "should create a record named myRecord"() {
            given:
            to CreateRecordsPage

            when:
            name_field = "myRecord"

            and:
            saveButton.click()

            then:
            at IndexPage
        }

        // Second Test
        def "should find record named myRecord"() {
            given:
            to SearchPage

            when:
            search_query = "myRecord"

            and:
            searchButton.click()

            then:
            // haven't figured this part out yet, but would look for "myRecord" on the results page
        }

        // Third Test
        def "should delete the record named myRecord"() {
            // do the delete
        }
    }

解决方案

You probably don't want to wait a set amount of time - it will make your tests slow. You would ideally want to continue as soon as the record is added. You can use Geb's waitFor {} to poll for a condition to be fulfilled.

    // Second Test
    def "should find record named myRecord"() {
        when:
        to SearchPage

        then:
        waitFor(30) {
            search_query = "myRecord"
            searchButton.click()
            //verify that the record was found
        }
    }

This will poll every half a second for 30 seconds for the condition to be fulfilled passing as soon as it is and failing if it's still not fulfilled after 30 seconds.

To see what options you have for setting waiting time and interval have look at section on waiting in The Book of Geb. You might also want to check out the section on implicit assertions in waitFor blocks.

If your second feature method depends on success of the first one then you should probably consider annotating this specification with @Stepwise.

这篇关于Geb:在测试之间等待/睡觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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