需求:管理后台有个商品保存并上架功能,当我们需要建多个商品时,利用接口自动化实现更方便;商品分为两种,一种有规格,一种无规格;实现方式如下:

Step1-添加元素
1、test plan添加参数,存放token值,token可以在多个thread groups中使用。

2、添加相关元素
- http request defaults(设置服务器地址);
- http header manager(设置请求头部信息);
- counter(产生自增变量):
The counter config lets the user configure a starting point, a maximum, and the increment. The counter will loop from the start to the max, and then start over with the start, continuing on like that until the test is ended
- 4个requests:
保存有规格商品(添加JSON Extractor,提取商品spu_id,保存到SpuID)
发布有规格商品(使用参数${SpuID})(添加JSON Assertion,判断是否上架成功)
保存无规格商品(添加JSON Extractor,提取商品spu_id,保存到SpuID)
发布无规格商品(使用参数${SpuID})(添加JSON Assertion,判断是否上架成功)
- view result tree: 查看结果

counter设置一个开始值,在每个循环中增加1
保存商品的request,需用到counter中的变量${cnt}来改变商品名称
![]()
Step2-设置循环

Step3-跑接口

查看管理后台数据

the end!!!
本文介绍如何使用接口自动化实现管理后台商品的批量创建与上架,包括有规格和无规格商品,通过设置JMeter参数、请求及循环,实现商品信息的动态生成与验证。
5万+

被折叠的 条评论
为什么被折叠?



