记录在项目中对soapui的简单使用, soapui 里面脚本语言是Groovy, Groovy的基础语法可以到W3C school 学习:https://www.w3cschool.cn/groovy/groovy_basic_syntax.html, 参考这篇文章:http://www.cnblogs.com/soundcode/p/6561207.html
1. REST 项目结构

2. 简单的GET请求

3. 对返回的数据(response)进行验证(assertion)
返回的数据(Response Data):

JsonPath Count assertion:

Scripts Assertion:
1). 定义一个变量获取返回的数据,变量类型是JSONArray, 下面语句中:messageExchange.responseContent 返回的是String类型。
def root = net.sf.json.JSONSerializer.toJSON(messageExchange.responseContent)
2). 定位到第一块数据中的name 的值: root[0].name
3). log:
log.info(String), 把自定义信息或者变量信息输入到console台: log.info("I am a good man")
log.error(boolean, message). 如果boolean是false,将输入错误信息: log.error(false, "Error occurred")

4. 定义全局变量,并在scripts assertion中调动变量
定义变量: 点击项目名称,左下角会出现: project properties 和 Custom Properties, 在Custom Properties 中点击‘+’ 图标输入变量名称及值。

assertion中调用变量:

网友评论