SoapUI请求生成随机字母数字字符串的方法

时间:2014-09-17 22:40:47

标签: groovy soapui

我有一种生成8个字符的字母数字字符串的方法。

log.info(
    new Random().with {
    (1..8).collect { (('A'..'Z')+('0'..'9')).join()[ nextInt( (('A'..'Z')+('0'..'9')).join().length() ) ] }.join()
  })

我将它作为测试用例设置脚本运行,然后返回:

Thu Sep 18 10:37:18 NZST 2014:INFO:L7S76IP1

当我将其作为属性之一包含在测试请求中时:

${new Random().with {(1..8).collect { (('A'..'Z')+('0'..'9')).join()[ nextInt( (('A'..'Z')+('0'..'9')).join().length() ) ] }.join()}}

然后它没有像我预期的那样返回随机字符串。

你能帮帮我吗?

感谢。

1 个答案:

答案 0 :(得分:0)

您需要在属性扩展中使用相等符号,如下所示:${=new Random .....}

另外,您可能需要查看Apache RandomStringUtils