BeanShell断言-----两个变量之间的断言对比

在jmeter中,断言无法对两个变量进行对比后判断,只能用BeanShell断言来进行。 

需求: 

获取某个用户对应的设备个数接口与数据库查询的个数结果进行对比 

Bean Shell断言解决方案: 

获取某个用户对应的设备个数接口这个普通的Http接口,这里就不就列出了 

与Oracle数据库的查询,如下图 

先建立JDBC连接配置,进行JDBC查询,然后用正则提取器 

JDBC Connection Configuration 
JOBC Connection Configuration 
Variable Name Bound to Pool 
Variable Name: Oracle 
Connection Pool Configuration 
Max Number of Connections: 10 
Max Wait (ms): 10000 
Time Between o.'iction Runs (ms): 60000 
Auto Commit: True 
Transaction Isolation: DEFAULT 
Connection Validation by Pool 
Test While Idle: True 
Soft Min Evictable Idle Time(ms): 5000 
Validation Query: Select 1 
Database Connection Configuration 
Database URL: 
JD8C Driver class: oracle jdbc driverOracleOriver 
Username: 
Password: •
Joacg-' 
Variable Name Bound to Pool 
Variable Name: Oracle 
SQL Query 
Query Type: Select Statement 
select 
from USER SHARE SQUARE VIDEO ussv 
right join 
and 
right join 
dbi on 
Query: 
where ussv.status
正 则 表 达 式 捏 取 器 
名 称 : 正 则 表 达 式 提 取 器 
Apply to : 
O Main sample and sub-samples Main sample on 
要 椧 查 的 响 应 享 段 
引 用 名 称 : 
正 则 达 式 : 
匹 謝 訕 享 ( 0 代 距 机 ) . 
缺 省 值 : 
主 体 O Body(un 
streamid 
Camera 旧 (

再建立Bean Shell断言,如下 

BeanShellMä 
BeanShell*fiä 
C] Reset bsh.lnterpreterbefore each call 
( > String Parameters *a String []bash.args) 
Script (see below for variables that are defined) 
if ( ! . 
Failure—true; 
Failuremessage 
Failuremessage 
'error, check error ' 
"ok, check current";

这里介绍下。${streamid_matchNr}是jmeter正则个数的统计 

if (!"${streamid_matchNr}".equals("${res_1}")) 

表示${streamid_matchNr}与${res_1}不相等则运行下面的代码。 

posted @ 2017-11-28 12:42  春田花花同学会  阅读(224)  评论(0编辑  收藏  举报