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

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

Jmeter入门使用5 - 更多参数使用方法_第1张图片

  • 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},

Jmeter入门使用5 - 更多参数使用方法_第2张图片

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:获取商城端某个分类下的商品,对比数据库的商品数量,相等则通过

Jmeter入门使用5 - 更多参数使用方法_第3张图片

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

Jmeter入门使用5 - 更多参数使用方法_第4张图片

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

Jmeter入门使用5 - 更多参数使用方法_第5张图片

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

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

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

the end!!!

你可能感兴趣的:(Jmeter)