Jmeter入门使用5 - 更多参数使用方法

本文介绍如何使用JMeter进行团购活动结束后的下单失败测试,通过预处理器设置团购价并验证返回code为120014。同时,演示如何对比API与数据库的商品数量,确保数据一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

场景1:当活动已结束下单失败,提交订单接口返回code为120014,验证该code

  • http request defaults: 设置主机地址信息
  • http header manager:设置头部参数信息
  • http request (commitSaleOrder):提交团购订单,价格为pre processors - User paramter提供,用beanshell assertion判断
  • view results tree:查看结果

1、pre processors - User paramter设置商品价格为团购价,传递给commitSaleOrder,该request使用团购价作为商品价格          

"skuPrice": ${skuPrice},
"skuInstallPrice": ${skuInstallPrice},

2、BeanShell Assertion判断是否返回了120014, 需在lib\ext添加json的jar包。

import org.json.*;

code = prev.getResponseCode();

if(code.equals("200")){
	String jsons = prev.getResponseDataAsString();
	JSONObject resJson = new JSONObject(jsons);
	if(!resJson.getString("code").equals("120014")){		
		Failure = true;
	     FailureMessage= resJson.getString("msg");
	}	
	}
else{
	Failure = true;
	FailureMessage=resJson.getString("you have a bad request");
	}

 场景2:获取商城端某个分类下的商品,对比数据库的商品数量,相等则通过

  •  http request defaults: 设置主机地址信息
  • http header manager:设置头部参数信息
  • jdbc connection configuration: 设置数据库连接信息
  • http request (getGoods):获取某分类下的商品;添加json获取商品总数
  • JDBC Request:查询数据库,获取数据库中的数据;添加beanshell assertion判断商品总数是否一致
  • view results tree:查看结果

1、通过api获取的商品总数,存放到变量totalCountAPI中

 2、通过数据库查询的商品总数存放到变量totalCountDB中

3、在BeanShell Assertion中添加如下断言:两者不相等,则验证失败

if(totalCountDB != totalCountAPI){
	Failure = true;
        FailureMessage = "商品数量不正确";	
}

the end!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值