我的示例脚本如下所示:
@Stepwise
class RandomTest extends GebReportingSpec {
@Shared
Random random = new Random()
def tag = random.nextInt(999)+1
def setupSpec() {
new File('/ProgramData/geb.properties').withInputStream {
properties.load(it)
}
}
def "Random Test"(){
when:
println("Random1: ${tag}")
println("Random2: ${tag}")
then:
Thread.sleep(1000)
}
def "Random test2"(){
when:
println("Random3: ${tag}")
then:
Thread.sleep(1000)
}
}
Random1: 528
Random2: 528
Random3: 285
我假设这是因为共享变量是在特征方法之间重新计算的。我已经尝试将这些变量声明移到
@Shared
注释无效。
我希望随机标记变量在规范的开头生成,并且我希望它保留其值,但是我不确定如何设置全局变量来实现这一点。我需要实例化setupSpec中的变量吗?