问题描述
有没有办法等待的测试之间所设时间?我需要的解决方案,以补偿服务器延迟。当创建一个记录,它需要记录之前的时间一点点在我的环境进行搜索。
在以下code例如,如何将我等了初试和第二测试间隔为30秒,并有第二次测试和第三次测试之间无等待时间?
类MySpec扩展GebReportingSpec {
//第一个测试
DEF应该建立一个名为myRecord记录(){
给定:
到CreateRecordsPage 什么时候:
name_field =myRecord 和:
saveButton.click() 然后:
在IndexPage
} //第二个测试
DEF应该找到记录中名为myRecord(){
给定:
到SearchPage 什么时候:
SEARCH_QUERY =myRecord 和:
searchButton.click() 然后:
//还没有想通了这部分还没有出来,但会寻找myRecord在结果页上
} //第三个测试
DEF应该删除名为myRecord记录(){
//做删除
}
}
您可能不希望等到一个设定的时间量 - 它会让你的测试缓慢。你将理想想尽快记录被添加继续。你可以用盖布的 WAITFOR {}
轮询要满足的条件。
//第二个测试
DEF应该找到记录中名为myRecord(){
什么时候:
到SearchPage 然后:
WAITFOR(30){
SEARCH_QUERY =myRecord
searchButton.click()
//验证该记录被发现
}
}
这将轮询30秒每隔半秒钟争取尽快通过,因为它是和失败,如果它仍然没有30秒后完成需满足的条件。
要看看你有什么选项用于设置等待时间和间隔有一下部分在的。
如果您的第二个特征的方法取决于第一个成功那么你或许应该考虑注释本规范使用@Stepwise.
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.
这篇关于创业板:测试之间等待/睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!