基于TestNG开发的自动化测试框架,自动化测试平台后端接口参考项目:WinTestNG-platform-api
- 适用于HTTP接口测试
- 测试数据维护在DB
- 支持Redis、Mongo、Mysql等操作
- 支持测试模板设置,可抽象通用功能、
- 全局变量设置
- 支持断言
- 使用FreeMarker作为模板引擎
- 生成测试报告数据存储在DB
- 涉及测试概念:测试用例、数据驱动、断言、测试报告、接口测试、自动化测试、测试模板
- 建表语句: wintestng-core/src/resources/WinTestNG.sql
- 执行SQL语句 wintestng-core/src/main/resources/WinTestNG.sql
- 修改配置文件 wintestng-core/src/main/resources/application.yml
- 执行TestNG文件 example/src/test/resources/projectname/example.xml
涉及
- 表resource_config
{
"url":"jdbc:mysql://xx.mysql.rds.aliyuncs.com:3306/baoxian",
"userName":"userName",
"password":"password"
}
{
"host":"12.26.1.94",
"port":3736,
"database":8,
"password":"D6eAtdxxxxxxsaisf"
}
{
"url":"mongodb://wyxx_app:[email protected]:3717,11.41.53.215:27017/wyxx_app"
}
涉及
- 表test_cases(测试计划) 字段data_preparation_config
{
"showTitle":"3333-${mobile}",
"text":"[{\"mobile\":\"15967126512\"},{\"mobile\":\"15967122137\"}]",
"type":"text"
}
{
"fieldNameList":[
"id",
"name",
"mobile"
],
"fileName":"http://xx.winbaoxian.com/xx.1csv",
"separator":",",
"type":"csv"
}
{
"resourceId":2,
"showTitle":"3333-${mobile}",
"sql":"select mobile from sales_user limit 3",
"type":"resource"
}
涉及
- 表action_template(测试模板) 字段actions
- 表test_cases(测试计划) 字段pre_action、main_actions、post_actions
示例
[
{
"name":"调用APP登录",
"actionType":"TPL",
"templateId":21,
"mappings":{
"a":"18757101098",
"b":"0000"
},
"delayTimes":2000,
"alias":"template"
},
{
"name":"更新数据库",
"delayTimes":2000,
"actionType":"RESOURCE",
"resourceId":1,
"sql":"update big_guy_share_info set status=0 where id=8"
},
{
"name":"教你赚钱-获取大咖分享分页数据-20条",
"actionType":"HTTP",
"requestHeader":{
},
"requestUrl":"http://xx.winbaoxian.cn/xx/1/getBigGuyShareInfoPageList",
"requestParams":{
"t":1,
"n":1,
"u":"[email protected]",
"di":"mockDeviceId",
"m":1,
"s":"${template.token}"
},
"requestMethod":"POST",
"requestContentType":"e/b",
"requestBody":"{\"pageNo\": 1}",
"alias":"getBigGuyShareInfoPageList",
"delayTimes":2000
},
{
"actionType":"ASSERTION",
"delayTimes":2000,
"name":"断言",
"verifyList":[
{
"type":"eq",
"value1":"${getBigGuyShareInfoPageList.body.r.isEnd?c}",
"value2":"true"
}
]
}
]
{
"name":"教你赚钱-获取大咖分享分页数据-20条",
"actionType":"HTTP",
"requestHeader":{},
"requestUrl":"http://xx.winbaoxian.cn/xx/1/getBigGuyShareInfoPageList",
"requestParams":{
"t":1,
"n":1,
"u":"[email protected]",
"di":"mockDeviceId",
"m":1,
"s":"${template.token}"
},
"requestMethod":"POST",
"requestContentType":"e/b",
"requestBody":"{\"pageNo\": 1}",
"delayTimes":2000,
"alias":"template"
}
{
"name":"更新数据库",
"actionType":"RESOURCE",
"resourceId":1,
"sql":"SELECT id,`name`,mobile from sales_user limit 1",
"fetchOne":true,
"delayTimes":2000,
"alias":"ret"
}
{
"name":"常量设置",
"actionType":"SETV",
"params":{
"ip":"x-api.winbaoxian.cn",
"calculate":"/api/product/data/calculate",
"get_captcha":"/api/policy/getCaptcha",
"pre_order":"/api/policy/pre-order"
},
"delayTimes":2000,
"alias":"ret"
}
{
"name":"调用APP登录",
"actionType":"TPL",
"templateId":21,
"mappings":{
"a":"18757101098",
"b":"0000"
},
"delayTimes":2000,
"alias":"template"
}
{
"name":"断言",
"actionType":"ASSERTION",
"templateId":21,
"verifyList":[
{
"type":"condition",
"value1":"${getExpirePolicyCollate.body.r.policyExpireRemindList?exists?c}==true"
},
{
"type":"eq",
"value1":"${getExpirePolicyCollate.body.r.policyExpireRemindList[0].policyUuid}",
"value2":"5108"
}
],
"delayTimes":2000,
"alias":"v"
}
{
"name":"分组",
"actionType":"GROUP",
"stepList":[
{
"name":"调用APP登录",
"actionType":"TPL",
"templateId":21,
"mappings":{
"a":"18757101098",
"b":"0000"
},
"delayTimes":2000,
"alias":"template"
}
]
}
{
"name":"IF判断",
"actionType":"IF",
"condition": "${res.success?c}",
"stepList":[
{
"name":"调用APP登录",
"actionType":"TPL",
"templateId":21,
"mappings":{
"a":"18757101098",
"b":"0000"
},
"delayTimes":2000,
"alias":"template"
}
]
}
{
"name":"IF判断",
"actionType":"IF",
"iterData": "${toJSONString(res.list)}",
"iterAlias": "a",
"stepList":[
{
"name":"调用APP登录",
"actionType":"TPL",
"templateId":21,
"mappings":{
"a":"${a.mobile}",
"b":"0000"
},
"delayTimes":2000,
"alias":"template"
}
]
}
{
"name":"脚本",
"actionType":"SCRIPT",
"lang":"PYTHON",
"content":"a=1+2",
"extractVars": ["a"],
"alias": "xx"
}
- QQ:
- Email: [email protected]